Bug 1026669 - Limit SSDP polling to when Firefox is in the foreground r=margaret

This commit is contained in:
Mark Finkle 2015-10-06 08:11:52 -04:00
Родитель 03a2ea5f2e
Коммит 3656c863e9
1 изменённых файлов: 18 добавлений и 10 удалений

Просмотреть файл

@ -65,6 +65,7 @@ var CastingApps = {
mirrorStopMenuId: -1,
_blocked: null,
_bound: null,
_interval: 120 * 1000, // 120 seconds
init: function ca_init() {
if (!this.isCastingEnabled()) {
@ -78,8 +79,8 @@ var CastingApps = {
mediaPlayerDevice.init();
SimpleServiceDiscovery.registerDevice(mediaPlayerDevice);
// Search for devices continuously every 120 seconds
SimpleServiceDiscovery.search(120 * 1000);
// Search for devices continuously
SimpleServiceDiscovery.search(this._interval);
this._castMenuId = NativeWindow.contextmenus.add(
Strings.browser.GetStringFromName("contextmenu.sendToDevice"),
@ -93,6 +94,8 @@ var CastingApps = {
Services.obs.addObserver(this, "Casting:Mirror", false);
Services.obs.addObserver(this, "ssdp-service-found", false);
Services.obs.addObserver(this, "ssdp-service-lost", false);
Services.obs.addObserver(this, "application-background", false);
Services.obs.addObserver(this, "application-foreground", false);
BrowserApp.deck.addEventListener("TabSelect", this, true);
BrowserApp.deck.addEventListener("pageshow", this, true);
@ -195,15 +198,20 @@ var CastingApps = {
}
break;
case "ssdp-service-found":
{
this.serviceAdded(SimpleServiceDiscovery.findServiceForID(aData));
break;
}
this.serviceAdded(SimpleServiceDiscovery.findServiceForID(aData));
break;
case "ssdp-service-lost":
{
this.serviceLost(SimpleServiceDiscovery.findServiceForID(aData));
break;
}
this.serviceLost(SimpleServiceDiscovery.findServiceForID(aData));
break;
case "application-background":
// Turn off polling while in the background
this._interval = SimpleServiceDiscovery.search(0);
SimpleServiceDiscovery.stopSearch();
break;
case "application-foreground":
// Turn polling on when app comes back to foreground
SimpleServiceDiscovery.search(this._interval);
break;
}
},