diff options
author | Alex Yatskov <alex@foosoft.net> | 2019-09-23 17:35:36 -0700 |
---|---|---|
committer | Alex Yatskov <alex@foosoft.net> | 2019-09-23 17:35:36 -0700 |
commit | f4b6527ed6ed1f0f4f5a63b94766b20f3b90e6ec (patch) | |
tree | 0d2f733c13597dd4067d3dc01e6da27f96bfe81b /ext/fg/js/frontend-api-sender.js | |
parent | cfc6363a01ee00e89866c54709006d6f55d093de (diff) | |
parent | f5afe590ad0730a695614b32032b7ea70b46c7b0 (diff) |
Merge branch 'master' into testing
Diffstat (limited to 'ext/fg/js/frontend-api-sender.js')
-rw-r--r-- | ext/fg/js/frontend-api-sender.js | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/ext/fg/js/frontend-api-sender.js b/ext/fg/js/frontend-api-sender.js index a1cb02c4..2e037e62 100644 --- a/ext/fg/js/frontend-api-sender.js +++ b/ext/fg/js/frontend-api-sender.js @@ -26,9 +26,7 @@ class FrontendApiSender { this.disconnected = false; this.nextId = 0; - this.port = chrome.runtime.connect(null, {name: 'backend-api-forwarder'}); - this.port.onDisconnect.addListener(this.onDisconnect.bind(this)); - this.port.onMessage.addListener(this.onMessage.bind(this)); + this.port = null; } invoke(action, params, target) { @@ -36,6 +34,10 @@ class FrontendApiSender { return Promise.reject('Disconnected'); } + if (this.port === null) { + this.createPort(); + } + const id = `${this.nextId}`; ++this.nextId; @@ -48,6 +50,12 @@ class FrontendApiSender { }); } + createPort() { + this.port = chrome.runtime.connect(null, {name: 'backend-api-forwarder'}); + this.port.onDisconnect.addListener(this.onDisconnect.bind(this)); + this.port.onMessage.addListener(this.onMessage.bind(this)); + } + onMessage({type, id, data, senderId}) { if (senderId !== this.senderId) { return; } switch (type) { |