Browse Source

Implements interfaces for data channel communication

dev1
hristoterezov 8 years ago
parent
commit
dd24d1bee1

+ 10
- 0
JitsiConference.js View File

1228
         JitsiConferenceErrors.INCOMPATIBLE_SERVER_VERSIONS);
1228
         JitsiConferenceErrors.INCOMPATIBLE_SERVER_VERSIONS);
1229
 };
1229
 };
1230
 
1230
 
1231
+/**
1232
+ * Sends broadcast message via the datachannels.
1233
+ * @param payload {object} the payload of the message.
1234
+ */
1235
+JitsiConference.prototype.sendDataChannelBroadcast = function (payload) {
1236
+    if(this.rtc) {
1237
+        this.rtc.sendDataChannelBroadcast(payload);
1238
+    }
1239
+}
1240
+
1231
 module.exports = JitsiConference;
1241
 module.exports = JitsiConference;

+ 11
- 11
JitsiConferenceEventManager.js View File

394
  */
394
  */
395
 JitsiConferenceEventManager.prototype.setupRTCListeners = function () {
395
 JitsiConferenceEventManager.prototype.setupRTCListeners = function () {
396
     var conference = this.conference;
396
     var conference = this.conference;
397
+
398
+    this.rtcForwarder = new EventEmitterForwarder(conference.rtc,
399
+        this.conference.eventEmitter);
400
+
397
     conference.rtc.addListener(RTCEvents.DOMINANTSPEAKER_CHANGED,
401
     conference.rtc.addListener(RTCEvents.DOMINANTSPEAKER_CHANGED,
398
         function (id) {
402
         function (id) {
399
             if(conference.lastDominantSpeaker !== id && conference.room) {
403
             if(conference.lastDominantSpeaker !== id && conference.room) {
413
         conference.room.connectionTimes["data.channel.opened"] = now;
417
         conference.room.connectionTimes["data.channel.opened"] = now;
414
     });
418
     });
415
 
419
 
416
-    conference.rtc.addListener(RTCEvents.LASTN_CHANGED,
417
-        function (oldValue, newValue) {
418
-            conference.eventEmitter.emit(
419
-                JitsiConferenceEvents.IN_LAST_N_CHANGED, oldValue, newValue);
420
-        });
420
+    this.rtcForwarder.forward(RTCEvents.LASTN_CHANGED,
421
+        JitsiConferenceEvents.IN_LAST_N_CHANGED);
421
 
422
 
422
-    conference.rtc.addListener(RTCEvents.LASTN_ENDPOINT_CHANGED,
423
-        function (lastNEndpoints, endpointsEnteringLastN) {
424
-            conference.eventEmitter.emit(
425
-                JitsiConferenceEvents.LAST_N_ENDPOINTS_CHANGED,
426
-                lastNEndpoints, endpointsEnteringLastN);
427
-        });
423
+    this.rtcForwarder.forward(RTCEvents.LASTN_ENDPOINT_CHANGED,
424
+        JitsiConferenceEvents.LAST_N_ENDPOINTS_CHANGED);
428
 
425
 
429
     conference.rtc.addListener(RTCEvents.AVAILABLE_DEVICES_CHANGED,
426
     conference.rtc.addListener(RTCEvents.AVAILABLE_DEVICES_CHANGED,
430
         function (devices) {
427
         function (devices) {
431
             conference.room.updateDeviceAvailability(devices);
428
             conference.room.updateDeviceAvailability(devices);
432
         });
429
         });
430
+
431
+    this.rtcForwarder.forward(RTCEvents.DATACHANNEL_ENDPOINT_MESSAGE_RECEIVED,
432
+        JitsiConferenceEvents.DATACHANNEL_ENDPOINT_MESSAGE_RECEIVED);
433
 };
433
 };
434
 
434
 
435
 /**
435
 /**

+ 7
- 1
JitsiConferenceEvents.js View File

135
      * Indicates that a the value of a specific property of a specific
135
      * Indicates that a the value of a specific property of a specific
136
      * participant has changed.
136
      * participant has changed.
137
      */
137
      */
138
-    PARTICIPANT_PROPERTY_CHANGED: "conference.participant_property_changed"
138
+    PARTICIPANT_PROPERTY_CHANGED: "conference.participant_property_changed",
139
+    /**
140
+     * Indicates that a message from another participant is received on
141
+     * data channel.
142
+     */
143
+    DATACHANNEL_ENDPOINT_MESSAGE_RECEIVED:
144
+        "conference.datachannel_endpoint_message_received"
139
 };
145
 };
140
 
146
 
141
 module.exports = JitsiConferenceEvents;
147
 module.exports = JitsiConferenceEvents;

+ 5
- 3
doc/API.md View File

118
         - AVAILABLE_DEVICES_CHANGED - notifies that available participant devices changed (camera or microphone was added or removed) (parameters - id(string), devices(JS object with 2 properties - audio(boolean), video(boolean)))
118
         - AVAILABLE_DEVICES_CHANGED - notifies that available participant devices changed (camera or microphone was added or removed) (parameters - id(string), devices(JS object with 2 properties - audio(boolean), video(boolean)))
119
         - CONNECTION_STATS - New local connection statistics are received. (parameters - stats(object))
119
         - CONNECTION_STATS - New local connection statistics are received. (parameters - stats(object))
120
         - AUTH_STATUS_CHANGED - notifies that authentication is enabled or disabled, or local user authenticated (logged in). (parameters - isAuthEnabled(boolean), authIdentity(string))
120
         - AUTH_STATUS_CHANGED - notifies that authentication is enabled or disabled, or local user authenticated (logged in). (parameters - isAuthEnabled(boolean), authIdentity(string))
121
+        - DATACHANNEL_ENDPOINT_MESSAGE_RECEIVED - notifies that a new message
122
+        from another participant is received on a data channel.
121
 
123
 
122
     2. connection
124
     2. connection
123
         - CONNECTION_FAILED - indicates that the server connection failed.
125
         - CONNECTION_FAILED - indicates that the server connection failed.
170
         - CHROME_EXTENSION_USER_CANCELED - an error which indicates that user canceled screen sharing window selection dialog in jidesha extension for Chrome.
172
         - CHROME_EXTENSION_USER_CANCELED - an error which indicates that user canceled screen sharing window selection dialog in jidesha extension for Chrome.
171
         - CHROME_EXTENSION_INSTALLATION_ERROR - an error which indicates that the jidesha extension for Chrome is failed to install.
173
         - CHROME_EXTENSION_INSTALLATION_ERROR - an error which indicates that the jidesha extension for Chrome is failed to install.
172
         - FIREFOX_EXTENSION_NEEDED - An error which indicates that the jidesha extension for Firefox is needed to proceed with screen sharing, and that it is not installed.
174
         - FIREFOX_EXTENSION_NEEDED - An error which indicates that the jidesha extension for Firefox is needed to proceed with screen sharing, and that it is not installed.
173
-        
175
+
174
 * ```JitsiMeetJS.errorTypes``` - constructors for Error instances that can be produced by library. Are useful for checks like ```error instanceof JitsiMeetJS.errorTypes.JitsiTrackError```. Following Errors are available:
176
 * ```JitsiMeetJS.errorTypes``` - constructors for Error instances that can be produced by library. Are useful for checks like ```error instanceof JitsiMeetJS.errorTypes.JitsiTrackError```. Following Errors are available:
175
     1. ```JitsiTrackError``` - Error that happened to a JitsiTrack.
177
     1. ```JitsiTrackError``` - Error that happened to a JitsiTrack.
176
-        
178
+
177
 * ```JitsiMeetJS.logLevels``` - object with the log levels:
179
 * ```JitsiMeetJS.logLevels``` - object with the log levels:
178
     1. TRACE
180
     1. TRACE
179
     2. DEBUG
181
     2. DEBUG
381
 
383
 
382
 JitsiTrackError
384
 JitsiTrackError
383
 ======
385
 ======
384
-The object represents error that happened to a JitsiTrack. Is inherited from JavaScript base ```Error``` object, 
386
+The object represents error that happened to a JitsiTrack. Is inherited from JavaScript base ```Error``` object,
385
 so ```"name"```, ```"message"``` and ```"stack"``` properties are available. For GUM-related errors,
387
 so ```"name"```, ```"message"``` and ```"stack"``` properties are available. For GUM-related errors,
386
 exposes additional ```"gum"``` property, which is an object with following properties:
388
 exposes additional ```"gum"``` property, which is an object with following properties:
387
  - error - original GUM error
389
  - error - original GUM error

+ 49
- 24
modules/RTC/DataChannels.js View File

143
                     lastNEndpoints, endpointsEnteringLastN, obj);
143
                     lastNEndpoints, endpointsEnteringLastN, obj);
144
                 self.eventEmitter.emit(RTCEvents.LASTN_ENDPOINT_CHANGED,
144
                 self.eventEmitter.emit(RTCEvents.LASTN_ENDPOINT_CHANGED,
145
                     lastNEndpoints, endpointsEnteringLastN, obj);
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
             else {
151
             else {
148
                 logger.debug("Data channel JSON-formatted message: ", obj);
152
                 logger.debug("Data channel JSON-formatted message: ", obj);
204
     var tail = xxx.substring(1);
208
     var tail = xxx.substring(1);
205
     var lower = head.toLowerCase() + tail;
209
     var lower = head.toLowerCase() + tail;
206
     var upper = head.toUpperCase() + tail;
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
     // Notify Videobridge about the specified endpoint change.
224
     // Notify Videobridge about the specified endpoint change.
209
     logger.log(lower + ' endpoint changed: ', userResource);
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
 DataChannels.prototype._some = function (callback, thisArg) {
229
 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
 module.exports = DataChannels;
275
 module.exports = DataChannels;

+ 10
- 0
modules/RTC/RTC.js View File

485
     }
485
     }
486
 }
486
 }
487
 
487
 
488
+/**
489
+ * Sends broadcast message via the datachannels.
490
+ * @param payload {object} the payload of the message.
491
+ */
492
+RTC.prototype.sendDataChannelBroadcast = function (payload) {
493
+    if(this.dataChannels) {
494
+        this.dataChannels.sendBroadcastMessage(payload);
495
+    }
496
+}
497
+
488
 module.exports = RTC;
498
 module.exports = RTC;

+ 7
- 1
service/RTC/RTCEvents.js View File

8
     TRACK_ATTACHED: "rtc.track_attached",
8
     TRACK_ATTACHED: "rtc.track_attached",
9
     AUDIO_OUTPUT_DEVICE_CHANGED: "rtc.audio_output_device_changed",
9
     AUDIO_OUTPUT_DEVICE_CHANGED: "rtc.audio_output_device_changed",
10
     DEVICE_LIST_CHANGED: "rtc.device_list_changed",
10
     DEVICE_LIST_CHANGED: "rtc.device_list_changed",
11
-    DEVICE_LIST_AVAILABLE: "rtc.device_list_available"
11
+    DEVICE_LIST_AVAILABLE: "rtc.device_list_available",
12
+    /**
13
+     * Indicates that a message from another participant is received on
14
+     * data channel.
15
+     */
16
+    DATACHANNEL_ENDPOINT_MESSAGE_RECEIVED:
17
+        "rtc.datachannel_endpoint_message_received"
12
 };
18
 };
13
 
19
 
14
 module.exports = RTCEvents;
20
 module.exports = RTCEvents;

Loading…
Cancel
Save