Bug 1276072 - wait for 'connect' event and replace 'statechange' event with 'terminate' event. r=kershaw.
authorShih-Chiang Chien <schien@mozilla.com>
Wed, 01 Jun 2016 18:42:15 +0800
changeset 339115 3cb234c21f033552ac9de149592498ec25643cc6
parent 339114 ac3c2afcc1d78153c4ace5b41e7c238c4d54ee8d
child 339116 cd31d578be5865d5646f59a123b0b9056d9d93c9
push id6249
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 13:59:36 +0000
treeherdermozilla-beta@bad9d4f5bf7e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskershaw
bugs1276072
milestone49.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1276072 - wait for 'connect' event and replace 'statechange' event with 'terminate' event. r=kershaw. MozReview-Commit-ID: KRKTVUtbpNo
toolkit/modules/secondscreen/PresentationApp.jsm
--- a/toolkit/modules/secondscreen/PresentationApp.jsm
+++ b/toolkit/modules/secondscreen/PresentationApp.jsm
@@ -34,17 +34,19 @@ function PresentationApp(service, reques
 }
 
 PresentationApp.prototype = {
   start: function start(callback) {
     this.request.startWithDevice(this.service.uuid)
     .then((session) => {
       this._session = session;
       if (callback) {
-        callback(true);
+        session.addEventListener('connect', () => {
+          callback(true);
+        });
       }
     }, () => {
       if (callback) {
         callback(false);
       }
     });
   },
 
@@ -77,35 +79,35 @@ PresentationApp.prototype = {
  * see https://github.com/mozilla-b2g/gaia/tree/master/tv_apps/fling-player
  */
 function RemoteMedia(session, listener) {
   this._session = session ;
   this._listener = 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() {
       this._listener.onRemoteMediaStart(this);
     }).bind(this), Ci.nsIThread.DISPATCH_NORMAL);
   }
 }
 
 RemoteMedia.prototype = {
   _seq: 0,
 
   handleEvent: function(e) {
     switch (e.type) {
       case "message":
         this._onmessage(e);
         break;
-      case "statechange":
-        this._onstatechange(e);
+      case "terminate":
+        this._onterminate(e);
         break;
     }
   },
 
   _onmessage: function(e) {
     DEBUG && debug("onmessage: " + e.data);
     if (this.status === STATE_SHUTDOWN) {
       return;
@@ -123,23 +125,21 @@ RemoteMedia.prototype = {
         this._status = STATE_STARTED;
         if (this._listener && "onRemoteMediaStatus" in this._listener) {
           this._listener.onRemoteMediaStatus(this);
         }
       }
     }
   },
 
-  _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);
     }
   },
 
   _sendCommand: function(command, data) {
     let msg = {
       'type': command,
       'seq': ++this._seq
     };