|
|
@@ -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({
|