소스 검색

Implements interfaces for data channel communication

master
hristoterezov 8 년 전
부모
커밋
dd24d1bee1
7개의 변경된 파일99개의 추가작업 그리고 40개의 파일을 삭제
  1. 10
    0
      JitsiConference.js
  2. 11
    11
      JitsiConferenceEventManager.js
  3. 7
    1
      JitsiConferenceEvents.js
  4. 5
    3
      doc/API.md
  5. 49
    24
      modules/RTC/DataChannels.js
  6. 10
    0
      modules/RTC/RTC.js
  7. 7
    1
      service/RTC/RTCEvents.js

+ 10
- 0
JitsiConference.js 파일 보기

@@ -1228,4 +1228,14 @@ JitsiConference.prototype._fireIncompatibleVersionsEvent = function () {
1228 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 1241
 module.exports = JitsiConference;

+ 11
- 11
JitsiConferenceEventManager.js 파일 보기

@@ -394,6 +394,10 @@ JitsiConferenceEventManager.prototype.setupChatRoomListeners = function () {
394 394
  */
395 395
 JitsiConferenceEventManager.prototype.setupRTCListeners = function () {
396 396
     var conference = this.conference;
397
+
398
+    this.rtcForwarder = new EventEmitterForwarder(conference.rtc,
399
+        this.conference.eventEmitter);
400
+
397 401
     conference.rtc.addListener(RTCEvents.DOMINANTSPEAKER_CHANGED,
398 402
         function (id) {
399 403
             if(conference.lastDominantSpeaker !== id && conference.room) {
@@ -413,23 +417,19 @@ JitsiConferenceEventManager.prototype.setupRTCListeners = function () {
413 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 426
     conference.rtc.addListener(RTCEvents.AVAILABLE_DEVICES_CHANGED,
430 427
         function (devices) {
431 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 파일 보기

@@ -135,7 +135,13 @@ var JitsiConferenceEvents = {
135 135
      * Indicates that a the value of a specific property of a specific
136 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 147
 module.exports = JitsiConferenceEvents;

+ 5
- 3
doc/API.md 파일 보기

@@ -118,6 +118,8 @@ JitsiMeetJS.setLogLevel(JitsiMeetJS.logLevels.ERROR);
118 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 119
         - CONNECTION_STATS - New local connection statistics are received. (parameters - stats(object))
120 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 124
     2. connection
123 125
         - CONNECTION_FAILED - indicates that the server connection failed.
@@ -170,10 +172,10 @@ JitsiMeetJS.setLogLevel(JitsiMeetJS.logLevels.ERROR);
170 172
         - CHROME_EXTENSION_USER_CANCELED - an error which indicates that user canceled screen sharing window selection dialog in jidesha extension for Chrome.
171 173
         - CHROME_EXTENSION_INSTALLATION_ERROR - an error which indicates that the jidesha extension for Chrome is failed to install.
172 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 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 177
     1. ```JitsiTrackError``` - Error that happened to a JitsiTrack.
176
-        
178
+
177 179
 * ```JitsiMeetJS.logLevels``` - object with the log levels:
178 180
     1. TRACE
179 181
     2. DEBUG
@@ -381,7 +383,7 @@ We have the following methods for controling the tracks:
381 383
 
382 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 387
 so ```"name"```, ```"message"``` and ```"stack"``` properties are available. For GUM-related errors,
386 388
 exposes additional ```"gum"``` property, which is an object with following properties:
387 389
  - error - original GUM error

+ 49
- 24
modules/RTC/DataChannels.js 파일 보기

@@ -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;

+ 10
- 0
modules/RTC/RTC.js 파일 보기

@@ -485,4 +485,14 @@ RTC.prototype.handleRemoteTrackVideoTypeChanged = function (value, from) {
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 498
 module.exports = RTC;

+ 7
- 1
service/RTC/RTCEvents.js 파일 보기

@@ -8,7 +8,13 @@ var RTCEvents = {
8 8
     TRACK_ATTACHED: "rtc.track_attached",
9 9
     AUDIO_OUTPUT_DEVICE_CHANGED: "rtc.audio_output_device_changed",
10 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 20
 module.exports = RTCEvents;

Loading…
취소
저장