Bug 1329902 - Part 1, fix device changed/removed event in AndroidCastDeviceProvider. r=kuoe0
MozReview-Commit-ID: 3f57zJvRbhb
--- a/dom/presentation/provider/AndroidCastDeviceProvider.js
+++ b/dom/presentation/provider/AndroidCastDeviceProvider.js
@@ -38,16 +38,17 @@ function descriptionToString(aDescriptio
json.dataChannelSDP = aDescription.dataChannelSDP;
break;
}
return JSON.stringify(json);
}
const TOPIC_ANDROID_CAST_DEVICE_SYNCDEVICE = "AndroidCastDevice:SyncDevice";
const TOPIC_ANDROID_CAST_DEVICE_ADDED = "AndroidCastDevice:Added";
+const TOPIC_ANDROID_CAST_DEVICE_CHANGED = "AndroidCastDevice:Changed";
const TOPIC_ANDROID_CAST_DEVICE_REMOVED = "AndroidCastDevice:Removed";
const TOPIC_ANDROID_CAST_DEVICE_START = "AndroidCastDevice:Start";
const TOPIC_ANDROID_CAST_DEVICE_STOP = "AndroidCastDevice:Stop";
const TOPIC_PRESENTATION_VIEW_READY = "presentation-view-ready";
function LocalControlChannel(aProvider, aDeviceId, aRole) {
log("LocalControlChannel - create new LocalControlChannel for : "
+ aRole);
@@ -398,39 +399,43 @@ AndroidCastDeviceProvider.prototype = {
// nsIPresentationDeviceProvider
set listener(aListener) {
this._listener = aListener;
// When unload this provider.
if (!this._listener) {
// remove observer
Services.obs.removeObserver(this, TOPIC_ANDROID_CAST_DEVICE_ADDED);
+ Services.obs.removeObserver(this, TOPIC_ANDROID_CAST_DEVICE_CHANGED);
Services.obs.removeObserver(this, TOPIC_ANDROID_CAST_DEVICE_REMOVED);
return;
}
// Sync all device already found by Android.
Messaging.sendRequest({ type: TOPIC_ANDROID_CAST_DEVICE_SYNCDEVICE });
// Observer registration
Services.obs.addObserver(this, TOPIC_ANDROID_CAST_DEVICE_ADDED, false);
+ Services.obs.addObserver(this, TOPIC_ANDROID_CAST_DEVICE_CHANGED, false);
Services.obs.addObserver(this, TOPIC_ANDROID_CAST_DEVICE_REMOVED, false);
},
get listener() {
return this._listener;
},
forceDiscovery: function APDP_forceDiscovery() {
// There is no API to do force discovery in Android SDK.
},
// nsIObserver
observe: function APDP_observe(aSubject, aTopic, aData) {
+ log('observe ' + aTopic + ': ' + aData);
switch (aTopic) {
- case TOPIC_ANDROID_CAST_DEVICE_ADDED: {
+ case TOPIC_ANDROID_CAST_DEVICE_ADDED:
+ case TOPIC_ANDROID_CAST_DEVICE_CHANGED: {
let deviceInfo = JSON.parse(aData);
let deviceId = deviceInfo.uuid;
if (!this._deviceList.has(deviceId)) {
let device = new ChromecastRemoteDisplayDevice(this,
deviceInfo.uuid,
deviceInfo.friendlyName,
Ci.nsIPresentationService.ROLE_CONTROLLER);
@@ -440,16 +445,20 @@ AndroidCastDeviceProvider.prototype = {
let device = this._deviceList.get(deviceId);
device.update(deviceInfo.friendlyName);
this._listener.updateDevice(device);
}
break;
}
case TOPIC_ANDROID_CAST_DEVICE_REMOVED: {
let deviceId = aData;
+ if (!this._deviceList.has(deviceId)) {
+ break;
+ }
+
let device = this._deviceList.get(deviceId);
this._listener.removeDevice(device);
this._deviceList.delete(deviceId);
break;
}
}
},