Skip to content

Commit

Permalink
Add listener for external connections
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurentTrk committed Sep 28, 2021
1 parent 1ae22c1 commit 90e130d
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/extension/src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ chrome.runtime.onConnect.addListener((port): void => {
port.onDisconnect.addListener(() => console.log(`Disconnected from ${port.name}`));
});

// listen to all messages and handle appropriately
chrome.runtime.onConnectExternal.addListener((port): void => {
// shouldn't happen, however... only listen to what we know about
// assert([PORT_CONTENT, PORT_EXTENSION].includes(port.name), `Unknown connection from ${port.name}`);

// message and disconnect handlers
console.log('adding external message listener');
port.onMessage.addListener((data) => handlers(data, port));
port.onDisconnect.addListener(() => console.log(`Disconnected from ${port.name}`));
});

// initial setup
cryptoWaitReady()
.then((): void => {
Expand Down

0 comments on commit 90e130d

Please sign in to comment.