Project

General

Profile

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

haketilo / common / message_server.js @ 2bd35bc4

1
/**
2
 * This file is part of Haketilo.
3
 *
4
 * Function: Message server.
5
 *
6
 * Copyright (C) 2021 Wojtek Kosior
7
 * Redistribution terms are gathered in the `copyright' file.
8
 */
9

    
10
/*
11
 * IMPORTS_START
12
 * IMPORT browser
13
 * IMPORTS_END
14
 */
15

    
16
var listeners = {};
17

    
18
/* magic should be one of the constants from /common/connection_types.js */
19

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

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

    
30
    listeners[port.name](port);
31
}
32

    
33
browser.runtime.onConnect.addListener(raw_listen);
34

    
35
/*
36
 * EXPORTS_START
37
 * EXPORT listen_for_connection
38
 * EXPORTS_END
39
 */
(4-4/16)