Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #33805 from ChunMinChang/bug-1237515
Browse files Browse the repository at this point in the history
Bug 1237515 - Closing presentation session after TV receives commands. r=rexboy
  • Loading branch information
BavarianTomcat committed Jan 12, 2016
2 parents 3c97d6a + dbe8256 commit 886bd71
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tv_apps/notification-receiver/js/receiver.js
Expand Up @@ -14,6 +14,7 @@
_onMessage: undefined,
_onStateChange: undefined,
_connection: undefined,
_sequence: undefined,

init: function r_init() {
this._onMessage = this._handleMessage.bind(this);
Expand All @@ -25,6 +26,7 @@
this._connection = connection;
this._connection.addEventListener('message', this._onMessage);
this._connection.addEventListener('statechange', this._onStateChange);
this._sequence = 0;
}.bind(this),
function connectionError() {
console.warn('Getting connection failed.');
Expand All @@ -37,9 +39,27 @@
this._connection.removeEventListener(
'statechange', this._onStateChange);
this._connection = null;
this._sequence = 0;
}
},

_sendMessage: function r_sendMessage(type, data) {
if (!this._connection) {
return;
}

var msg = {
'type': type,
'seq': ++this._sequence
};

for (var i in data) {
msg[i] = data [i];
}

this._connection.send(JSON.stringify(msg));
},

_renderMessage: function r_renderMessage(message) {
var result;
switch(message.type) {
Expand Down Expand Up @@ -73,9 +93,11 @@
ports.forEach(function(port) {
port.postMessage(iacmsg);
});
this._sendMessage('ack');
}.bind(this),
function () {
console.warn('Sending view request failed.');
this._sendMessage('ack', {'error': 'webpage-open failed'});
});
}.bind(this);
},
Expand Down

0 comments on commit 886bd71

Please sign in to comment.