Bug 786419 - Part 5 - Check app offline status in PeerConnection.js r=rjesup
authorValentin Gosu <valentin.gosu@gmail.com>
Sat, 23 Aug 2014 02:16:51 +0300
changeset 209172 b5e1ffced7d04ee01e9f4079f09eb9d523aec0bf
parent 209171 39d37ed686c38121ce6cdf7ed7be2c0519c8a20b
child 209173 1ca5026b6e8af8dc782a668cf843df476ef88457
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersrjesup
bugs786419
milestone35.0a1
Bug 786419 - Part 5 - Check app offline status in PeerConnection.js r=rjesup
dom/media/PeerConnection.js
--- a/dom/media/PeerConnection.js
+++ b/dom/media/PeerConnection.js
@@ -145,16 +145,25 @@ GlobalPCList.prototype = {
     }
     else if (topic == "network:offline-status-changed") {
       if (data == "offline") {
         // this._list shold be empty here
         this._networkdown = true;
       } else if (data == "online") {
         this._networkdown = false;
       }
+    } else if (topic == "network:app-offline-status-changed") {
+      // App just went offline. The subject also contains the appId,
+      // but navigator.onLine checks that for us
+      if (!this._networkdown && !this._win.navigator.onLine) {
+        for (let winId in this._list) {
+          cleanupWinId(this._list, winId);
+        }
+      }
+      this._networkdown = !this._win.navigator.onLine;
     } else if (topic == "gmp-plugin-crash") {
       // a plugin crashed; if it's associated with any of our PCs, fire an
       // event to the DOM window
       let sep = data.indexOf(' ');
       let pluginId = data.slice(0, sep);
       let rest = data.slice(sep+1);
       // This presumes no spaces in the name!
       sep = rest.indexOf(' ');
@@ -327,17 +336,17 @@ RTCPeerConnection.prototype = {
   __init: function(rtcConfig) {
     if (!rtcConfig.iceServers ||
         !Services.prefs.getBoolPref("media.peerconnection.use_document_iceservers")) {
       rtcConfig.iceServers =
         JSON.parse(Services.prefs.getCharPref("media.peerconnection.default_iceservers"));
     }
     this._mustValidateRTCConfiguration(rtcConfig,
         "RTCPeerConnection constructor passed invalid RTCConfiguration");
-    if (_globalPCList._networkdown) {
+    if (_globalPCList._networkdown || !this._win.navigator.onLine) {
       throw new this._win.DOMError("",
           "Can't create RTCPeerConnections when the network is down");
     }
 
     this.makeGetterSetterEH("onaddstream");
     this.makeGetterSetterEH("onaddtrack");
     this.makeGetterSetterEH("onicecandidate");
     this.makeGetterSetterEH("onnegotiationneeded");