1
|
/**
|
2
|
* Myext message server
|
3
|
*
|
4
|
* Copyright (C) 2021 Wojtek Kosior
|
5
|
* Redistribution terms are gathered in the `copyright' file.
|
6
|
*/
|
7
|
|
8
|
"use strict";
|
9
|
|
10
|
(() => {
|
11
|
const browser = window.browser;
|
12
|
|
13
|
var listeners = {};
|
14
|
|
15
|
/* magic should be one of the constants from /common/connection_types.js */
|
16
|
|
17
|
function listen_for_connection(magic, cb)
|
18
|
{
|
19
|
listeners[magic] = cb;
|
20
|
}
|
21
|
|
22
|
function raw_listen(port) {
|
23
|
if (listeners[port.name] === undefined)
|
24
|
return;
|
25
|
|
26
|
listeners[port.name](port);
|
27
|
}
|
28
|
|
29
|
browser.runtime.onConnect.addListener(raw_listen);
|
30
|
|
31
|
window.listen_for_connection = listen_for_connection;
|
32
|
})();
|