This repository was archived by the owner on May 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathOutputSample.java
More file actions
147 lines (113 loc) · 4.08 KB
/
OutputSample.java
File metadata and controls
147 lines (113 loc) · 4.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package samples;
import com.rayo.client.SimpleXmppConnection;
import com.rayo.client.XmppConnection;
import com.rayo.client.listener.RayoMessageListener;
import com.rayo.client.verb.ClientPauseCommand;
import com.rayo.client.verb.ClientResumeCommand;
import com.rayo.client.verb.RefEvent;
import com.rayo.client.xmpp.extensions.Extension;
import com.rayo.client.xmpp.stanza.IQ;
import com.rayo.client.xmpp.stanza.Stanza;
import com.rayo.core.verb.Output;
import com.rayo.core.verb.SeekCommand;
import com.rayo.core.verb.SpeedDownCommand;
import com.rayo.core.verb.SpeedUpCommand;
import com.rayo.core.verb.Ssml;
import com.rayo.core.verb.VolumeDownCommand;
import com.rayo.core.verb.VolumeUpCommand;
import com.rayo.core.AnswerCommand;
public class OutputSample {
private String callId;
public void run() throws Exception {
XmppConnection connection = new SimpleXmppConnection("localhost");
connection.addStanzaListener(new RayoMessageListener("offer") {
@Override
@SuppressWarnings("rawtypes")
public void messageReceived(Object object) {
Stanza stanza = (Stanza)object;
callId = stanza.getFrom().substring(0, stanza.getFrom().indexOf('@'));
}
});
connection.connect();
connection.login("usera", "1", "voxeo");
connection.waitForExtension("offer");
AnswerCommand answer = new AnswerCommand();
IQ iq = new IQ(IQ.Type.set)
.setFrom(buildFrom(connection))
.setTo(buildTo(connection,callId))
.setChild(Extension.create(answer));
connection.send(iq);
Ssml item = new Ssml("<audio src='http://ccmixter.org/content/7OOP3D/7OOP3D_-_One_Two_Three_(Countess_Cipher).mp3'/>");
Output output = new Output();
output.setPrompt(item);
iq = new IQ(IQ.Type.set)
.setFrom(buildFrom(connection))
.setTo(buildTo(connection,callId))
.setChild(Extension.create(output));
System.out.println(String.format("Sending out IQ: %s", iq));
IQ result = ((IQ)connection.sendAndWait(iq));
RefEvent reference = (RefEvent)result.getExtension().getObject();
System.out.println(String.format("Received ref: %s", reference));
String to = callId+"@localhost/"+reference.getJid();
ClientPauseCommand pause = new ClientPauseCommand();
iq = new IQ(IQ.Type.set)
.setFrom(buildFrom(connection))
.setTo(to)
.setChild(Extension.create(pause));
connection.send(iq);
Thread.sleep(3000);
ClientResumeCommand resume = new ClientResumeCommand();
iq = new IQ(IQ.Type.set)
.setFrom(buildFrom(connection))
.setTo(to)
.setChild(Extension.create(resume));
connection.send(iq);
Thread.sleep(3000);
SeekCommand seek = new SeekCommand();
seek.setDirection(SeekCommand.Direction.FORWARD);
seek.setAmount(10);
iq = new IQ(IQ.Type.set)
.setFrom(buildFrom(connection))
.setTo(to)
.setChild(Extension.create(seek));
connection.send(iq);
Thread.sleep(3000);
SpeedDownCommand speeddown = new SpeedDownCommand();
iq = new IQ(IQ.Type.set)
.setFrom(buildFrom(connection))
.setTo(to)
.setChild(Extension.create(speeddown));
connection.send(iq);
Thread.sleep(3000);
SpeedUpCommand speedup = new SpeedUpCommand();
iq = new IQ(IQ.Type.set)
.setFrom(buildFrom(connection))
.setTo(to)
.setChild(Extension.create(speedup));
connection.send(iq);
Thread.sleep(3000);
VolumeUpCommand volumeup = new VolumeUpCommand();
iq = new IQ(IQ.Type.set)
.setFrom(buildFrom(connection))
.setTo(to)
.setChild(Extension.create(volumeup));
connection.send(iq);
Thread.sleep(3000);
VolumeDownCommand volumedown = new VolumeDownCommand();
iq = new IQ(IQ.Type.set)
.setFrom(buildFrom(connection))
.setTo(to)
.setChild(Extension.create(volumedown));
connection.send(iq);
Thread.sleep(3000);
}
private String buildFrom(XmppConnection connection) {
return connection.getUsername() + "@" + connection.getServiceName() + "/" + connection.getResource();
}
private String buildTo(XmppConnection connection, String callid) {
return callid + "@" + connection.getServiceName();
}
public static void main(String[] args) throws Exception {
new OutputSample().run();
}
}