|
@@ -143,6 +143,10 @@ 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);
|
146
|
150
|
}
|
147
|
151
|
else {
|
148
|
152
|
logger.debug("Data channel JSON-formatted message: ", obj);
|
|
@@ -204,34 +208,22 @@ DataChannels.prototype._onXXXEndpointChanged = function (xxx, userResource) {
|
204
|
208
|
var tail = xxx.substring(1);
|
205
|
209
|
var lower = head.toLowerCase() + tail;
|
206
|
210
|
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);
|
207
|
223
|
|
208
|
224
|
// Notify Videobridge about the specified endpoint change.
|
209
|
225
|
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
|
|
- }
|
231
|
226
|
|
232
|
|
- return true;
|
233
|
|
- }
|
234
|
|
- });
|
235
|
227
|
};
|
236
|
228
|
|
237
|
229
|
DataChannels.prototype._some = function (callback, thisArg) {
|
|
@@ -247,4 +239,37 @@ DataChannels.prototype._some = function (callback, thisArg) {
|
247
|
239
|
}
|
248
|
240
|
};
|
249
|
241
|
|
|
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
|
+
|
250
|
275
|
module.exports = DataChannels;
|