Bläddra i källkod

Merge pull request #189 from jitsi/dc_send_throw

Changes methods that use RTCDatachanel#send to throw exception on fail
dev1
bgrozev 9 år sedan
förälder
incheckning
1817b80302
4 ändrade filer med 81 tillägg och 33 borttagningar
  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 Visa fil

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
 JitsiConference.prototype.selectParticipant = function(participantId) {
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
 JitsiConference.prototype.pinParticipant = function(participantId) {
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
  * @param to {string} the id of the endpoint that should receive the message.
1241
  * @param to {string} the id of the endpoint that should receive the message.
1241
  * If "" the message will be sent to all participants.
1242
  * If "" the message will be sent to all participants.
1242
  * @param payload {object} the payload of the message.
1243
  * @param payload {object} the payload of the message.
1244
+ * @throws NetworkError or InvalidStateError or Error if the operation fails.
1243
  */
1245
  */
1244
 JitsiConference.prototype.sendEndpointMessage = function (to, payload) {
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
  * Sends broadcast message via the datachannels.
1251
  * Sends broadcast message via the datachannels.
1252
  * @param payload {object} the payload of the message.
1252
  * @param payload {object} the payload of the message.
1253
+ * @throws NetworkError or InvalidStateError or Error if the operation fails.
1253
  */
1254
  */
1254
 JitsiConference.prototype.broadcastEndpointMessage = function (payload) {
1255
 JitsiConference.prototype.broadcastEndpointMessage = function (payload) {
1255
     this.sendEndpointMessage("", payload);
1256
     this.sendEndpointMessage("", payload);

+ 14
- 0
doc/API.md Visa fil

347
     - to - the id of the endpoint that should receive the message. If "" the message will be sent to all participants.
347
     - to - the id of the endpoint that should receive the message. If "" the message will be sent to all participants.
348
     - payload - JSON object - the payload of the message.
348
     - payload - JSON object - the payload of the message.
349
 
349
 
350
+Throws NetworkError or InvalidStateError or Error if the operation fails.
351
+
350
 32. broadcastEndpointMessage(payload) - Sends broadcast message via the datachannels.
352
 32. broadcastEndpointMessage(payload) - Sends broadcast message via the datachannels.
351
     - payload - JSON object - the payload of the message.
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
 JitsiTrack
367
 JitsiTrack
354
 ======
368
 ======
355
 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).
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 Visa fil

69
         // we want the notification to trigger even if userJid is undefined,
69
         // we want the notification to trigger even if userJid is undefined,
70
         // or null.
70
         // or null.
71
         // XXX why do we not do the same for pinned endpoints?
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
     dataChannel.onerror = function (error) {
81
     dataChannel.onerror = function (error) {
180
 
186
 
181
 /**
187
 /**
182
  * Sends a "selected endpoint changed" message via the data channel.
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
 DataChannels.prototype.sendSelectedEndpointMessage = function (endpointId) {
194
 DataChannels.prototype.sendSelectedEndpointMessage = function (endpointId) {
185
     this.selectedEndpoint = endpointId;
195
     this.selectedEndpoint = endpointId;
188
 
198
 
189
 /**
199
 /**
190
  * Sends a "pinned endpoint changed" message via the data channel.
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
 DataChannels.prototype.sendPinnedEndpointMessage = function (endpointId) {
206
 DataChannels.prototype.sendPinnedEndpointMessage = function (endpointId) {
193
     this._onXXXEndpointChanged("pinnned", endpointId);
207
     this._onXXXEndpointChanged("pinnned", endpointId);
200
  * @param xxx the name of the endpoint-related property whose value changed
214
  * @param xxx the name of the endpoint-related property whose value changed
201
  * @param userResource the new value of the endpoint-related property after the
215
  * @param userResource the new value of the endpoint-related property after the
202
  * change
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
 DataChannels.prototype._onXXXEndpointChanged = function (xxx, userResource) {
221
 DataChannels.prototype._onXXXEndpointChanged = function (xxx, userResource) {
205
     // Derive the correct words from xxx such as selected and Selected, pinned
222
     // Derive the correct words from xxx such as selected and Selected, pinned
223
 
240
 
224
     // Notify Videobridge about the specified endpoint change.
241
     // Notify Videobridge about the specified endpoint change.
225
     logger.log(lower + ' endpoint changed: ', userResource);
242
     logger.log(lower + ' endpoint changed: ', userResource);
226
-
227
 };
243
 };
228
 
244
 
229
 DataChannels.prototype._some = function (callback, thisArg) {
245
 DataChannels.prototype._some = function (callback, thisArg) {
242
 /**
258
 /**
243
  * Sends passed object via the first found open datachannel
259
  * Sends passed object via the first found open datachannel
244
  * @param jsonObject {object} the object that will be sent
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
 DataChannels.prototype.send = function (jsonObject) {
265
 DataChannels.prototype.send = function (jsonObject) {
247
-    this._some(function (dataChannel) {
266
+    if(!this._some(function (dataChannel) {
248
         if (dataChannel.readyState == 'open') {
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
                 dataChannel.send(JSON.stringify(jsonObject));
268
                 dataChannel.send(JSON.stringify(jsonObject));
260
-            } catch (error) {
261
-                GlobalOnErrorHandler.callErrorHandler(error);
262
-                logger.error("Cannot send ", jsonObject, ". Error: ", error);
263
-            }
264
             return true;
269
             return true;
265
         }
270
         }
266
-    });
271
+    })) {
272
+        throw new Error("No opened data channels found!");
273
+    }
267
 }
274
 }
268
 
275
 
269
 /**
276
 /**
271
  * @param to {string} the id of the endpoint that should receive the message.
278
  * @param to {string} the id of the endpoint that should receive the message.
272
  * If "" the message will be sent to all participants.
279
  * If "" the message will be sent to all participants.
273
  * @param payload {object} the payload of the message.
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
 DataChannels.prototype.sendDataChannelMessage = function (to, payload) {
285
 DataChannels.prototype.sendDataChannelMessage = function (to, payload) {
276
     this.send({
286
     this.send({

+ 25
- 2
modules/RTC/RTC.js Visa fil

86
             this.eventEmitter);
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
 RTC.prototype.selectEndpoint = function (id) {
96
 RTC.prototype.selectEndpoint = function (id) {
90
-    if(this.dataChannels)
97
+    if(this.dataChannels) {
91
         this.dataChannels.sendSelectedEndpointMessage(id);
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
 RTC.prototype.pinEndpoint = function (id) {
111
 RTC.prototype.pinEndpoint = function (id) {
95
-    if(this.dataChannels)
112
+    if(this.dataChannels) {
96
         this.dataChannels.sendPinnedEndpointMessage(id);
113
         this.dataChannels.sendPinnedEndpointMessage(id);
114
+    } else {
115
+        throw new Error("Data channels support is disabled!");
116
+    }
97
 };
117
 };
98
 
118
 
99
 RTC.prototype.addListener = function (type, listener) {
119
 RTC.prototype.addListener = function (type, listener) {
490
  * @param to {string} the id of the endpoint that should receive the message.
510
  * @param to {string} the id of the endpoint that should receive the message.
491
  * If "" the message will be sent to all participants.
511
  * If "" the message will be sent to all participants.
492
  * @param payload {object} the payload of the message.
512
  * @param payload {object} the payload of the message.
513
+ * @throws NetworkError or InvalidStateError or Error if the operation fails.
493
  */
514
  */
494
 RTC.prototype.sendDataChannelMessage = function (to, payload) {
515
 RTC.prototype.sendDataChannelMessage = function (to, payload) {
495
     if(this.dataChannels) {
516
     if(this.dataChannels) {
496
         this.dataChannels.sendDataChannelMessage(to, payload);
517
         this.dataChannels.sendDataChannelMessage(to, payload);
518
+    } else {
519
+        throw new Error("Data channels support is disabled!");
497
     }
520
     }
498
 }
521
 }
499
 
522
 

Laddar…
Avbryt
Spara