/
RtmpClient.java
270 lines (238 loc) · 8.97 KB
/
RtmpClient.java
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
/*
Copyright (c) 2011 Flashphoner
All rights reserved. This Code and the accompanying materials
are made available under the terms of the GNU Public License v2.0
which accompanies this distribution, and is available at
http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
Contributors:
Flashphoner - initial API and implementation
This code and accompanying materials also available under LGPL and MPL license for Flashphoner buyers. Other license versions by negatiation. Write us support@flashphoner.com with any questions.
*/
package com.flashphoner.phone_app;
import com.flashphoner.sdk.media.RecordReport;
import com.flashphoner.sdk.rtmp.AbstractRtmpClient;
import com.flashphoner.sdk.rtmp.Config;
import com.flashphoner.sdk.rtmp.IConfig;
import com.flashphoner.sdk.rtmp.RtmpClientConfig;
import com.flashphoner.sdk.sip.SipMessageObject;
import com.flashphoner.sdk.softphone.ISoftphoneCall;
import com.flashphoner.sdk.softphone.InstantMessage;
import com.wowza.wms.amf.AMFDataObj;
import com.wowza.wms.client.IClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.sip.RequestEvent;
/**
* Implementation of IRtmpClient class via {@link AbstractRtmpClient}.<br/>
* RtmpClient is a main class of Flashphoner server side application responsible for RTMP-SIP bridge.<br/>
* See more info in {@link com.flashphoner.sdk.rtmp.IRtmpClient} and in {@link AbstractRtmpClient} class.
*/
public class RtmpClient extends AbstractRtmpClient {
private static Logger log = LoggerFactory.getLogger(RtmpClient.class);
private OptionsCallResult optionsCallResult;
protected Recorder recorder;
/**
* @param rtmpClientConfig config contains all parameters for the instance creation
* @param iClient
*/
public RtmpClient(RtmpClientConfig rtmpClientConfig, IClient iClient) {
super(rtmpClientConfig, iClient);
this.recorder = new Recorder(this);
}
/**
* Notifies flash-client about softphone registered
*
* @param sipHeader
*/
public void registered(SipMessageObject sipHeader) {
log.info("registered");
getClient().call("registered", null, sipHeader.toAMFObj());
}
/**
* Notifies flash-client about balance value
*
* @param balance balance header value
* @param sipHeader SipMessageObject object, wich contains raw SIP message data
*/
public void notifyBalance(String balance, SipMessageObject sipHeader) {
log.info("notifyBalance");
getClient().call("notifyBalance", null, balance, sipHeader.toAMFObj());
}
/**
* Notifies flash-client about incommin call
*
* @param call - call
*/
public void incommingCall(ISoftphoneCall call) {
log.info("incommingCall " + call.getId());
}
/**
* Notifies flash-client about RING status of call
*
* @param call ISoftphoneCall
* @param sipHeader SipMessageObject object, wich contains raw SIP message data
*/
public void ring(ISoftphoneCall call, SipMessageObject sipHeader) {
log.info("ring " + call.getId());
if (sipHeader == null) {
sipHeader = new SipMessageObject();
}
getClient().call("ring", null, call.toAMFDataObj(), sipHeader.toAMFObj());
}
/**
* Notifies flash-client about RINGING status of call
*
* @param call ISoftphoneCall
* @param sipHeader SipMessageObject object, wich contains raw SIP message data
*/
public void ringing(ISoftphoneCall call, SipMessageObject sipHeader) {
log.info("ringing " + call.getId());
}
/**
* Notifies flash-client about SESSION_PROGRESS status of call
*
* @param call ISoftphoneCall
* @param sipHeader SipMessageObject object, wich contains raw SIP message data
*/
public void sessionProgress(ISoftphoneCall call, SipMessageObject sipHeader) {
log.info("sessionProgress");
if (sipHeader == null) {
sipHeader = new SipMessageObject();
}
getClient().call("sessionProgress", null, call.toAMFDataObj(), sipHeader.toAMFObj());
}
/**
* Notifies flash-client about TALK status of call and starts incoming stream
*
* @param call ISoftphoneCall
* @param sipHeader SipMessageObject object, wich contains raw SIP message data
*/
public void talk(ISoftphoneCall call, SipMessageObject sipHeader) {
log.info("talk " + call.getId());
if (sipHeader == null) {
sipHeader = new SipMessageObject();
}
getClient().call("talk", new TalkCallResult(this), call.toAMFDataObj(), sipHeader.toAMFObj());
}
/**
* Notifies flash-client about hold status
*
* @param call ISoftphoneCall
* @param sipHeader SipHeader object, wich contains raw SIP message data
*/
public void notifyHold(ISoftphoneCall call, SipMessageObject sipHeader) {
log.info("notifyHold " + call.getId());
if (sipHeader == null) {
sipHeader = new SipMessageObject();
}
getClient().call("hold", null, call.toAMFDataObj(), sipHeader.toAMFObj());
}
/**
* Notifies flash-client about hold status
*
* @param call ISoftphoneCall
* @param isHold is hold true
*/
public void callbackHold(ISoftphoneCall call, Boolean isHold) {
log.info("callbackHold");
getClient().call("callbackHold", null, call.toAMFDataObj(), isHold);
}
/**
* Notifies flash-client about FINISH status of call
*
* @param call ISoftphoneCall
* @param sipHeader SipHeader object, wich contains raw SIP message data
*/
public void finish(ISoftphoneCall call, SipMessageObject sipHeader) {
log.info("finish " + call.getId());
if (sipHeader == null) {
sipHeader = new SipMessageObject();
}
streamAudioStop(call.getId());
streamVideoStop(call.getId());
getClient().call("finish", null, call.toAMFDataObj(), sipHeader.toAMFObj());
recorder.stopRecording(call.getId());
}
/**
* Notifies flash-client about abonent BUSY
*
* @param call ISoftphoneCall
* @param sipHeader SipHeader object, wich contains raw SIP message data
*/
public void busy(ISoftphoneCall call, SipMessageObject sipHeader) {
log.info("busy " + call.getId());
if (sipHeader == null) {
sipHeader = new SipMessageObject();
}
getClient().call("busy", null, call.toAMFDataObj(), sipHeader.toAMFObj());
}
/**
* Notifies flash-client about fail
*
* @param errorCode
* @param sipHeader SipHeader object, wich contains raw SIP message data
*/
public void fail(String errorCode, SipMessageObject sipHeader) {
log.info("fail " + errorCode);
if (sipHeader == null) {
sipHeader = new SipMessageObject();
}
if (getClient() != null) {
getClient().call("fail", null, errorCode, sipHeader.toAMFObj());
}
}
/**
* Notifies flash-client about video format
*
* @param call
*/
public void notifyVideoFormat(ISoftphoneCall call) {
log.info("notifyVideoFormat " + call.getId());
if (getClient() != null) {
getClient().call("notifyVideoFormat", null, call.toAMFDataObj());
}
}
/**
* Retrives Flashphoner config
*
* @return Flashphoner config
*/
public IConfig getConfig() {
return Config.getInstance();
}
@Override
public void notifyRequest(RequestEvent requestEvent) {
log.info("Notify request: " + requestEvent.getRequest().toString());
//getClient().call("notifyRequest", null, requestObj);
}
public void notifyMessage(InstantMessage instantMessage) {
log.info("notifyMessage: " + instantMessage);
getClient().call("notifyMessage", null, instantMessage.toAmfDataObj());
}
//speex, pcma, pcmu
public void notifyAudioCodec(String audioCodec) {
log.info("notifyAudioCodec " + audioCodec);
AMFDataObj codecObj = new AMFDataObj();
codecObj.put("name", audioCodec.toLowerCase());
if (getClient() != null) {
getClient().call("notifyAudioCodec", null, codecObj);
}
}
public void notifyOptions(SipMessageObject sipMessageObject) {
log.info("notifyOptions: " + getRtmpClientConfig().getLogin());
OptionsCallResult optionsCallResult = new OptionsCallResult(this, sipMessageObject);
if (getClient() != null) {
getClient().call("notifyOptions", optionsCallResult, sipMessageObject.toAMFObj());
}
}
@Override
public void notifyRecordComplete(RecordReport recordReport) {
log.info("notifyRecordComplete for clientID + " + getClient().getClientId() + ", " + recordReport.getMixedFilename());
}
public void startRecording() {
if (log.isDebugEnabled()) {
log.debug("startRecording clientID " + getClient().getClientId());
}
recorder.startRecording();
}
}