summaryrefslogtreecommitdiff
path: root/background/broadcast_broker.js
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2021-12-22 16:39:34 +0100
committerWojtek Kosior <koszko@koszko.org>2021-12-22 16:39:34 +0100
commitb590eaa2f64ead3384eadc6fe58f6358aa1a0478 (patch)
tree8f1e9403c1a75246c2a9a0afc4ab30706ea7afbe /background/broadcast_broker.js
parentb7378a9994724750198e0d165c575be8538334fb (diff)
downloadbrowser-extension-b590eaa2f64ead3384eadc6fe58f6358aa1a0478.tar.gz
browser-extension-b590eaa2f64ead3384eadc6fe58f6358aa1a0478.zip
reworked build system; added missing license notices
Diffstat (limited to 'background/broadcast_broker.js')
-rw-r--r--background/broadcast_broker.js24
1 files changed, 8 insertions, 16 deletions
diff --git a/background/broadcast_broker.js b/background/broadcast_broker.js
index 7af8769..9847d7e 100644
--- a/background/broadcast_broker.js
+++ b/background/broadcast_broker.js
@@ -42,12 +42,9 @@
* proprietary program, I am not going to enforce this in court.
*/
-/*
- * IMPORTS_START
- * IMPORT listen_for_connection
- * IMPORT CONNECTION_TYPE
- * IMPORTS_END
- */
+#IMPORT common/connection_types.js AS CONNECTION_TYPE
+
+#FROM common/message_server.js IMPORT listen_for_connection
let next_id = 1;
@@ -55,7 +52,7 @@ const listeners_by_channel = new Map();
function new_broadcast_listener(port)
{
- listener_ctx = {port, id: ++next_id, channels: new Set()};
+ const listener_ctx = {port, id: ++next_id, channels: new Set()};
port.onMessage.addListener(msg => listener_command(msg, listener_ctx));
port.onDisconnect.addListener(msg => listener_remove(msg, listener_ctx));
}
@@ -102,7 +99,7 @@ function remove_broadcast_listener(listener_ctx)
function new_broadcast_sender(port)
{
- sender_ctx = {prepared_broadcasts: new Set()};
+ const sender_ctx = {prepared_broadcasts: new Set()};
port.onMessage.addListener(msg => sender_command(msg, sender_ctx));
port.onDisconnect.addListener(msg => flush(sender_ctx));
}
@@ -125,7 +122,7 @@ function sender_command(msg, sender_ctx)
function prepare(sender_ctx, channel_name, value, timeout)
{
- broadcast_data = [channel_name, value];
+ const broadcast_data = [channel_name, value];
sender_ctx.prepared_broadcasts.add(broadcast_data);
if (timeout === 0)
@@ -170,15 +167,10 @@ function remove_broadcast_sender(sender_ctx)
sender_ctx.prepared_broadcasts.forEach(nv => broadcast(...nv));
}
-function start_broadcast_broker()
+function start()
{
listen_for_connection(CONNECTION_TYPE.BROADCAST_SEND, new_broadcast_sender);
listen_for_connection(CONNECTION_TYPE.BROADCAST_LISTEN,
new_broadcast_listener);
}
-
-/*
- * EXPORTS_START
- * EXPORT start_broadcast_broker
- * EXPORTS_END
- */
+#EXPORT start