Browse Source

Merge pull request #189 from jitsi/dc_send_throw

Changes methods that use RTCDatachanel#send to throw exception on fail
dev1
bgrozev 9 years ago
parent
commit
1817b80302
4 changed files with 81 additions and 33 deletions
  1. 14
    13
      JitsiConference.js
  2. 14
    0
      doc/API.md
  3. 28
    18
      modules/RTC/DataChannels.js
  4. 25
    2
      modules/RTC/RTC.js

+ 14
- 13
JitsiConference.js View File

@@ -591,23 +591,24 @@ JitsiConference.prototype.unlock = function () {
591 591
 };
592 592
 
593 593
 /**
594
- * Elects the participant with the given id to be the selected participant or the speaker.
595
- * @param id the identifier of the participant
594
+ * Elects the participant with the given id to be the selected participant in
595
+ * order to receive higher video quality (if simulcast is enabled).
596
+ * @param participantId the identifier of the participant
597
+ * @throws NetworkError or InvalidStateError or Error if the operation fails.
596 598
  */
597 599
 JitsiConference.prototype.selectParticipant = function(participantId) {
598
-    if (this.rtc) {
599
-        this.rtc.selectEndpoint(participantId);
600
-    }
600
+    this.rtc.selectEndpoint(participantId);
601 601
 };
602 602
 
603 603
 /**
604
- *
605
- * @param id the identifier of the participant
604
+ * Elects the participant with the given id to be the pinned participant in
605
+ * order to always receive video for this participant (even when last n is
606
+ * enabled).
607
+ * @param participantId the identifier of the participant
608
+ * @throws NetworkError or InvalidStateError or Error if the operation fails.
606 609
  */
607 610
 JitsiConference.prototype.pinParticipant = function(participantId) {
608
-    if (this.rtc) {
609
-        this.rtc.pinEndpoint(participantId);
610
-    }
611
+    this.rtc.pinEndpoint(participantId);
611 612
 };
612 613
 
613 614
 /**
@@ -1240,16 +1241,16 @@ JitsiConference.prototype._fireIncompatibleVersionsEvent = function () {
1240 1241
  * @param to {string} the id of the endpoint that should receive the message.
1241 1242
  * If "" the message will be sent to all participants.
1242 1243
  * @param payload {object} the payload of the message.
1244
+ * @throws NetworkError or InvalidStateError or Error if the operation fails.
1243 1245
  */
1244 1246
 JitsiConference.prototype.sendEndpointMessage = function (to, payload) {
1245
-    if(this.rtc) {
1246
-        this.rtc.sendDataChannelMessage(to, payload);
1247
-    }
1247
+    this.rtc.sendDataChannelMessage(to, payload);
1248 1248
 }
1249 1249
 
1250 1250
 /**
1251 1251
  * Sends broadcast message via the datachannels.
1252 1252
  * @param payload {object} the payload of the message.
1253
+ * @throws NetworkError or InvalidStateError or Error if the operation fails.
1253 1254
  */
1254 1255
 JitsiConference.prototype.broadcastEndpointMessage = function (payload) {
1255 1256
     this.sendEndpointMessage("", payload);

+ 14
- 0
doc/API.md View File

@@ -347,9 +347,23 @@ The object represents a conference. We have the following methods to control the
347 347
     - to - the id of the endpoint that should receive the message. If "" the message will be sent to all participants.
348 348
     - payload - JSON object - the payload of the message.
349 349
 
350
+Throws NetworkError or InvalidStateError or Error if the operation fails.
351
+
350 352
 32. broadcastEndpointMessage(payload) - Sends broadcast message via the datachannels.
351 353
     - payload - JSON object - the payload of the message.
352 354
 
355
+Throws NetworkError or InvalidStateError or Error if the operation fails.
356
+
357
+33. selectParticipant(participantId) - Elects the participant with the given id to be the selected participant in order to receive higher video quality (if simulcast is enabled).
358
+    - participantId - the identifier of the participant
359
+
360
+Throws NetworkError or InvalidStateError or Error if the operation fails.
361
+
362
+34. pinParticipant(participantId) - Elects the participant with the given id to be the pinned participant in order to always receive video for this participant (even when last n is enabled).
363
+    - participantId - the identifier of the participant
364
+
365
+Throws NetworkError or InvalidStateError or Error if the operation fails.
366
+
353 367
 JitsiTrack
354 368
 ======
355 369
 The object represents single track - video or audio. They can be remote tracks ( from the other participants in the call) or local tracks (from the devices of the local participant).

+ 28
- 18
modules/RTC/DataChannels.js View File

@@ -69,7 +69,13 @@ DataChannels.prototype.onDataChannel = function (event) {
69 69
         // we want the notification to trigger even if userJid is undefined,
70 70
         // or null.
71 71
         // XXX why do we not do the same for pinned endpoints?
72
-        self.sendSelectedEndpointMessage(self.selectedEndpoint);
72
+        try {
73
+            self.sendSelectedEndpointMessage(self.selectedEndpoint);
74
+        } catch (error) {
75
+            GlobalOnErrorHandler.callErrorHandler(error);
76
+            logger.error("Cannot sendSelectedEndpointMessage ",
77
+                self.selectedEndpoint, ". Error: ", error);
78
+        }
73 79
     };
74 80
 
75 81
     dataChannel.onerror = function (error) {
@@ -180,6 +186,10 @@ DataChannels.prototype.closeAllChannels = function () {
180 186
 
181 187
 /**
182 188
  * Sends a "selected endpoint changed" message via the data channel.
189
+ * @param endpointId {string} the id of the selected endpoint
190
+ * @throws NetworkError or InvalidStateError from RTCDataChannel#send (@see
191
+ * {@link https://developer.mozilla.org/en-US/docs/Web/API/RTCDataChannel/send})
192
+ * or Error with "No opened data channels found!" message.
183 193
  */
184 194
 DataChannels.prototype.sendSelectedEndpointMessage = function (endpointId) {
185 195
     this.selectedEndpoint = endpointId;
@@ -188,6 +198,10 @@ DataChannels.prototype.sendSelectedEndpointMessage = function (endpointId) {
188 198
 
189 199
 /**
190 200
  * Sends a "pinned endpoint changed" message via the data channel.
201
+ * @param endpointId {string} the id of the pinned endpoint
202
+ * @throws NetworkError or InvalidStateError from RTCDataChannel#send (@see
203
+ * {@link https://developer.mozilla.org/en-US/docs/Web/API/RTCDataChannel/send})
204
+ * or Error with "No opened data channels found!" message.
191 205
  */
192 206
 DataChannels.prototype.sendPinnedEndpointMessage = function (endpointId) {
193 207
     this._onXXXEndpointChanged("pinnned", endpointId);
@@ -200,6 +214,9 @@ DataChannels.prototype.sendPinnedEndpointMessage = function (endpointId) {
200 214
  * @param xxx the name of the endpoint-related property whose value changed
201 215
  * @param userResource the new value of the endpoint-related property after the
202 216
  * change
217
+ * @throws NetworkError or InvalidStateError from RTCDataChannel#send (@see
218
+ * {@link https://developer.mozilla.org/en-US/docs/Web/API/RTCDataChannel/send})
219
+ * or Error with "No opened data channels found!" message.
203 220
  */
204 221
 DataChannels.prototype._onXXXEndpointChanged = function (xxx, userResource) {
205 222
     // Derive the correct words from xxx such as selected and Selected, pinned
@@ -223,7 +240,6 @@ DataChannels.prototype._onXXXEndpointChanged = function (xxx, userResource) {
223 240
 
224 241
     // Notify Videobridge about the specified endpoint change.
225 242
     logger.log(lower + ' endpoint changed: ', userResource);
226
-
227 243
 };
228 244
 
229 245
 DataChannels.prototype._some = function (callback, thisArg) {
@@ -242,28 +258,19 @@ DataChannels.prototype._some = function (callback, thisArg) {
242 258
 /**
243 259
  * Sends passed object via the first found open datachannel
244 260
  * @param jsonObject {object} the object that will be sent
261
+ * @throws NetworkError or InvalidStateError from RTCDataChannel#send (@see
262
+ * {@link https://developer.mozilla.org/en-US/docs/Web/API/RTCDataChannel/send})
263
+ * or Error with "No opened data channels found!" message.
245 264
  */
246 265
 DataChannels.prototype.send = function (jsonObject) {
247
-    this._some(function (dataChannel) {
266
+    if(!this._some(function (dataChannel) {
248 267
         if (dataChannel.readyState == 'open') {
249
-            try {
250
-                // Can throw NetworkError and InvalidStateError. We
251
-                // shouldn't be experiencing InvalidStateError. But NetworkError
252
-                // is easily reproducable when start leaving the conference.
253
-                // I cannot reproduce it in any other use cases and for this one
254
-                // we can safely ignore the error and just report it to the
255
-                // global error handler. If we notice this error during the
256
-                // conference maybe it's better to throw it to the user of the
257
-                // library in order to notify the caller of the method for
258
-                // the failure.
259 268
                 dataChannel.send(JSON.stringify(jsonObject));
260
-            } catch (error) {
261
-                GlobalOnErrorHandler.callErrorHandler(error);
262
-                logger.error("Cannot send ", jsonObject, ". Error: ", error);
263
-            }
264 269
             return true;
265 270
         }
266
-    });
271
+    })) {
272
+        throw new Error("No opened data channels found!");
273
+    }
267 274
 }
268 275
 
269 276
 /**
@@ -271,6 +278,9 @@ DataChannels.prototype.send = function (jsonObject) {
271 278
  * @param to {string} the id of the endpoint that should receive the message.
272 279
  * If "" the message will be sent to all participants.
273 280
  * @param payload {object} the payload of the message.
281
+ * @throws NetworkError or InvalidStateError from RTCDataChannel#send (@see
282
+ * {@link https://developer.mozilla.org/en-US/docs/Web/API/RTCDataChannel/send})
283
+ * or Error with "No opened data channels found!" message.
274 284
  */
275 285
 DataChannels.prototype.sendDataChannelMessage = function (to, payload) {
276 286
     this.send({

+ 25
- 2
modules/RTC/RTC.js View File

@@ -86,14 +86,34 @@ RTC.prototype.onIncommingCall = function(event) {
86 86
             this.eventEmitter);
87 87
 };
88 88
 
89
+/**
90
+ * Elects the participant with the given id to be the pinned participant in
91
+ * order to always receive video for this participant (even when last n is
92
+ * enabled).
93
+ * @param id {string} the user id.
94
+ * @throws NetworkError or InvalidStateError or Error if the operation fails.
95
+*/
89 96
 RTC.prototype.selectEndpoint = function (id) {
90
-    if(this.dataChannels)
97
+    if(this.dataChannels) {
91 98
         this.dataChannels.sendSelectedEndpointMessage(id);
99
+    } else {
100
+        throw new Error("Data channels support is disabled!");
101
+    }
92 102
 };
93 103
 
104
+/**
105
+ * Elects the participant with the given id to be the pinned participant in
106
+ * order to always receive video for this participant (even when last n is
107
+ * enabled).
108
+ * @param id {string} the user id
109
+ * @throws NetworkError or InvalidStateError or Error if the operation fails.
110
+ */
94 111
 RTC.prototype.pinEndpoint = function (id) {
95
-    if(this.dataChannels)
112
+    if(this.dataChannels) {
96 113
         this.dataChannels.sendPinnedEndpointMessage(id);
114
+    } else {
115
+        throw new Error("Data channels support is disabled!");
116
+    }
97 117
 };
98 118
 
99 119
 RTC.prototype.addListener = function (type, listener) {
@@ -490,10 +510,13 @@ RTC.prototype.handleRemoteTrackVideoTypeChanged = function (value, from) {
490 510
  * @param to {string} the id of the endpoint that should receive the message.
491 511
  * If "" the message will be sent to all participants.
492 512
  * @param payload {object} the payload of the message.
513
+ * @throws NetworkError or InvalidStateError or Error if the operation fails.
493 514
  */
494 515
 RTC.prototype.sendDataChannelMessage = function (to, payload) {
495 516
     if(this.dataChannels) {
496 517
         this.dataChannels.sendDataChannelMessage(to, payload);
518
+    } else {
519
+        throw new Error("Data channels support is disabled!");
497 520
     }
498 521
 }
499 522
 

Loading…
Cancel
Save