summaryrefslogtreecommitdiff
path: root/background/message_server.js
diff options
context:
space:
mode:
Diffstat (limited to 'background/message_server.js')
-rw-r--r--background/message_server.js35
1 files changed, 35 insertions, 0 deletions
diff --git a/background/message_server.js b/background/message_server.js
new file mode 100644
index 0000000..612be0c
--- /dev/null
+++ b/background/message_server.js
@@ -0,0 +1,35 @@
+/**
+* Myext message server
+*
+* Copyright (C) 2021 Wojtek Kosior
+*
+* Dual-licensed under:
+* - 0BSD license
+* - GPLv3 or (at your option) any later version
+*/
+
+"use strict";
+
+(() => {
+ const browser = window.browser;
+
+ var listeners = {};
+
+ /* magic should be one of the constants from /common/connection_types.js */
+
+ function listen_for_connection(magic, cb)
+ {
+ listeners[magic] = cb;
+ }
+
+ function raw_listen(port) {
+ if (listeners[port.name] === undefined)
+ return;
+
+ listeners[port.name](port);
+ }
+
+ browser.runtime.onConnect.addListener(raw_listen);
+
+ window.listen_for_connection = listen_for_connection;
+})();