Bug 1276072 - wait for 'connect' event and replace 'statechange' event with 'terminate' event. r=kershaw.

MozReview-Commit-ID: KRKTVUtbpNo

--HG--
extra : rebase_source : 4fc8be4b21966523cad78d2ea50e41937d2bea63
This commit is contained in:
Shih-Chiang Chien 2016-06-01 18:42:15 +08:00
parent 2fda0872c8
commit af6d3abb4d

View File

@ -39,7 +39,9 @@ PresentationApp.prototype = {
.then((session) => {
this._session = session;
if (callback) {
callback(true);
session.addEventListener('connect', () => {
callback(true);
});
}
}, () => {
if (callback) {
@ -82,7 +84,7 @@ function RemoteMedia(session, listener) {
this._status = STATE_UNINIT;
this._session.addEventListener("message", this);
this._session.addEventListener("statechange", this);
this._session.addEventListener("terminate", this);
if (this._listener && "onRemoteMediaStart" in this._listener) {
Services.tm.mainThread.dispatch((function() {
@ -99,8 +101,8 @@ RemoteMedia.prototype = {
case "message":
this._onmessage(e);
break;
case "statechange":
this._onstatechange(e);
case "terminate":
this._onterminate(e);
break;
}
},
@ -128,13 +130,11 @@ RemoteMedia.prototype = {
}
},
_onstatechange: function(e) {
DEBUG && debug("onstatechange: " + this._session.state);
if (this._session.state !== "connected") {
this._status = STATE_SHUTDOWN;
if (this._listener && "onRemoteMediaStop" in this._listener) {
this._listener.onRemoteMediaStop(this);
}
_onterminate: function(e) {
DEBUG && debug("onterminate: " + this._session.state);
this._status = STATE_SHUTDOWN;
if (this._listener && "onRemoteMediaStop" in this._listener) {
this._listener.onRemoteMediaStop(this);
}
},