Skip to content
This repository has been archived by the owner on Dec 20, 2018. It is now read-only.

Commit

Permalink
fix: add in some handling of disconnected ports and debug info
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-feek committed Dec 2, 2018
1 parent 4acbb46 commit 1daf4a5
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,15 @@ function getHands(session, playerId, hands, startTime, done) {
}

function updateStatus(message) {
port.postMessage({
action: 'hc.updateStatus',
message,
});
try {
port.postMessage({
action: 'hc.updateStatus',
message,
});
} catch (err) {
console.log('could not communicate with port');
console.log(JSON.stringify(err));
}
}

function initializePort() {
Expand All @@ -104,6 +109,12 @@ function initializePort() {
return reject();
}
port = window.chrome.tabs.connect(tabs[0].id);

port.onDisconnect.addListener(disconnectedPort => {
console.log('port disconnected. ' + JSON.stringify(disconnectedPort));
initializePort();
});

return resolve(port);
});
});
Expand Down

0 comments on commit 1daf4a5

Please sign in to comment.