Przeglądaj źródła

Catch JS errors on Datachannel.send

dev1
hristoterezov 9 lat temu
rodzic
commit
8d7bd558bd
1 zmienionych plików z 15 dodań i 1 usunięć
  1. 15
    1
      modules/RTC/DataChannels.js

+ 15
- 1
modules/RTC/DataChannels.js Wyświetl plik

@@ -246,7 +246,21 @@ DataChannels.prototype._some = function (callback, thisArg) {
246 246
 DataChannels.prototype.send = function (jsonObject) {
247 247
     this._some(function (dataChannel) {
248 248
         if (dataChannel.readyState == 'open') {
249
-            dataChannel.send(JSON.stringify(jsonObject));
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));
260
+            } catch (error) {
261
+                GlobalOnErrorHandler.callErrorHandler(error);
262
+                logger.error("Cannot send ", jsonObject, ". Error: ", error);
263
+            }
250 264
             return true;
251 265
         }
252 266
     });

Ładowanie…
Anuluj
Zapisz