Project

General

Profile

Download (604 Bytes) Statistics
| Branch: | Tag: | Revision:

haketilo / background / message_server.js @ 261548ff

1
/**
2
 * Myext message server
3
 *
4
 * Copyright (C) 2021 Wojtek Kosior
5
 * Redistribution terms are gathered in the `copyright' file.
6
 */
7

    
8
/*
9
 * IMPORTS_START
10
 * IMPORT browser
11
 * IMPORTS_END
12
 */
13

    
14
var listeners = {};
15

    
16
/* magic should be one of the constants from /common/connection_types.js */
17

    
18
function listen_for_connection(magic, cb)
19
{
20
    listeners[magic] = cb;
21
}
22

    
23
function raw_listen(port)
24
{
25
    if (listeners[port.name] === undefined)
26
	return;
27

    
28
    listeners[port.name](port);
29
}
30

    
31
browser.runtime.onConnect.addListener(raw_listen);
32

    
33
/*
34
 * EXPORTS_START
35
 * EXPORT listen_for_connection
36
 * EXPORTS_END
37
 */
(2-2/7)