aboutsummaryrefslogtreecommitdiff
path: root/background/message_server.js
blob: 612be0c394a0ae47669c3a4298708dc6393b0f74 (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
32
33
34
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;
})();