|
|
@@ -143,10 +143,6 @@ DataChannels.prototype.onDataChannel = function (event) {
|
|
143
|
143
|
lastNEndpoints, endpointsEnteringLastN, obj);
|
|
144
|
144
|
self.eventEmitter.emit(RTCEvents.LASTN_ENDPOINT_CHANGED,
|
|
145
|
145
|
lastNEndpoints, endpointsEnteringLastN, obj);
|
|
146
|
|
- } else if("EndpointMessage" === colibriClass) {
|
|
147
|
|
- self.eventEmitter.emit(
|
|
148
|
|
- RTCEvents.DATACHANNEL_ENDPOINT_MESSAGE_RECEIVED,
|
|
149
|
|
- obj.msgPayload);
|
|
150
|
146
|
}
|
|
151
|
147
|
else {
|
|
152
|
148
|
logger.debug("Data channel JSON-formatted message: ", obj);
|
|
|
@@ -208,22 +204,34 @@ DataChannels.prototype._onXXXEndpointChanged = function (xxx, userResource) {
|
|
208
|
204
|
var tail = xxx.substring(1);
|
|
209
|
205
|
var lower = head.toLowerCase() + tail;
|
|
210
|
206
|
var upper = head.toUpperCase() + tail;
|
|
211
|
|
- logger.log(
|
|
212
|
|
- 'sending ' + lower
|
|
213
|
|
- + ' endpoint changed notification to the bridge: ',
|
|
214
|
|
- userResource);
|
|
215
|
|
-
|
|
216
|
|
- var jsonObject = {};
|
|
217
|
|
-
|
|
218
|
|
- jsonObject.colibriClass = (upper + 'EndpointChangedEvent');
|
|
219
|
|
- jsonObject[lower + "Endpoint"]
|
|
220
|
|
- = (userResource ? userResource : null);
|
|
221
|
|
-
|
|
222
|
|
- this.send(jsonObject);
|
|
223
|
207
|
|
|
224
|
208
|
// Notify Videobridge about the specified endpoint change.
|
|
225
|
209
|
logger.log(lower + ' endpoint changed: ', userResource);
|
|
|
210
|
+ this._some(function (dataChannel) {
|
|
|
211
|
+ if (dataChannel.readyState == 'open') {
|
|
|
212
|
+ logger.log(
|
|
|
213
|
+ 'sending ' + lower
|
|
|
214
|
+ + ' endpoint changed notification to the bridge: ',
|
|
|
215
|
+ userResource);
|
|
|
216
|
+
|
|
|
217
|
+ var jsonObject = {};
|
|
|
218
|
+
|
|
|
219
|
+ jsonObject.colibriClass = (upper + 'EndpointChangedEvent');
|
|
|
220
|
+ jsonObject[lower + "Endpoint"]
|
|
|
221
|
+ = (userResource ? userResource : null);
|
|
|
222
|
+ try {
|
|
|
223
|
+ dataChannel.send(JSON.stringify(jsonObject));
|
|
|
224
|
+ } catch (e) {
|
|
|
225
|
+ // FIXME: Maybe we should check if the conference is left
|
|
|
226
|
+ // before calling _onXXXEndpointChanged method.
|
|
|
227
|
+ // FIXME: We should check if we are disposing correctly the
|
|
|
228
|
+ // data channels.
|
|
|
229
|
+ logger.warn(e);
|
|
|
230
|
+ }
|
|
226
|
231
|
|
|
|
232
|
+ return true;
|
|
|
233
|
+ }
|
|
|
234
|
+ });
|
|
227
|
235
|
};
|
|
228
|
236
|
|
|
229
|
237
|
DataChannels.prototype._some = function (callback, thisArg) {
|
|
|
@@ -239,37 +247,4 @@ DataChannels.prototype._some = function (callback, thisArg) {
|
|
239
|
247
|
}
|
|
240
|
248
|
};
|
|
241
|
249
|
|
|
242
|
|
-/**
|
|
243
|
|
- * Sends passed object via the first found open datachannel
|
|
244
|
|
- * @param jsonObject {object} the object that will be sent
|
|
245
|
|
- */
|
|
246
|
|
-DataChannels.prototype.send = function (jsonObject) {
|
|
247
|
|
- this._some(function (dataChannel) {
|
|
248
|
|
- if (dataChannel.readyState == 'open') {
|
|
249
|
|
- dataChannel.send(JSON.stringify(jsonObject));
|
|
250
|
|
- return true;
|
|
251
|
|
- }
|
|
252
|
|
- });
|
|
253
|
|
-}
|
|
254
|
|
-
|
|
255
|
|
-/**
|
|
256
|
|
- * Sends broadcast message via the datachannels.
|
|
257
|
|
- * @param payload {object} the payload of the message.
|
|
258
|
|
- */
|
|
259
|
|
-DataChannels.prototype.sendBroadcastMessage = function (payload) {
|
|
260
|
|
- var jsonObject = {};
|
|
261
|
|
-
|
|
262
|
|
- jsonObject.colibriClass = "EndpointMessage";
|
|
263
|
|
- jsonObject.to = "";
|
|
264
|
|
- // following the same format for the payload in order to be able to
|
|
265
|
|
- // recognise the message on the receiving side.
|
|
266
|
|
- jsonObject.msgPayload = {
|
|
267
|
|
- colibriClass: "EndpointMessage",
|
|
268
|
|
- to: "",
|
|
269
|
|
- msgPayload: payload
|
|
270
|
|
- };
|
|
271
|
|
-
|
|
272
|
|
- this.send(jsonObject);
|
|
273
|
|
-}
|
|
274
|
|
-
|
|
275
|
250
|
module.exports = DataChannels;
|