aboutsummaryrefslogtreecommitdiff
path: root/background/message_server.mjs
blob: e3f83d06f79c49b03b2846dfbb0f42a61f4396c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/**
* Myext message server
*
* Copyright (C) 2021 Wojtek Kosior
*
* Dual-licensed under:
*   - 0BSD license
*   - GPLv3 or (at your option) any later version
*/

"use strict";

import browser from '/common/browser.mjs';

var listeners = {};

/* magic should be one of the constants from /common/connection_types.mjs */

export default 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);