|
1
|
|
|
/* |
|
2
|
|
|
* MikoPBX - free phone system for small business |
|
3
|
|
|
* Copyright © 2017-2024 Alexey Portnov and Nikolay Beketov |
|
4
|
|
|
* |
|
5
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
6
|
|
|
* it under the terms of the GNU General Public License as published by |
|
7
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
|
8
|
|
|
* (at your option) any later version. |
|
9
|
|
|
* |
|
10
|
|
|
* This program is distributed in the hope that it will be useful, |
|
11
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13
|
|
|
* GNU General Public License for more details. |
|
14
|
|
|
* |
|
15
|
|
|
* You should have received a copy of the GNU General Public License along with this program. |
|
16
|
|
|
* If not, see <https://www.gnu.org/licenses/>. |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
/* global globalDebugMode, EventSource */ |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* The nchanStatusWorker object is responsible for receiving signals from backend |
|
23
|
|
|
* |
|
24
|
|
|
* @module nchanStatusWorker |
|
25
|
|
|
*/ |
|
26
|
|
|
const nchanStatusWorker = { |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* EventSource object for the module installation and upgrade status |
|
30
|
|
|
* @type {EventSource} |
|
31
|
|
|
*/ |
|
32
|
|
|
eventSource: null, |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Initialize the connection check worker. |
|
36
|
|
|
*/ |
|
37
|
|
|
initialize() { |
|
38
|
|
|
nchanStatusWorker.eventSource = new EventSource('/pbxcore/api/nchan/sub/install-module'); |
|
39
|
|
|
|
|
40
|
|
|
nchanStatusWorker.eventSource.addEventListener('error', e => { |
|
41
|
|
|
if (e.readyState === EventSource.CLOSED) { |
|
42
|
|
|
console.log('Connection was closed! ', e); |
|
|
|
|
|
|
43
|
|
|
} else { |
|
44
|
|
|
console.log('An unknown error occurred: ', e); |
|
45
|
|
|
} |
|
46
|
|
|
}, false); |
|
47
|
|
|
|
|
48
|
|
|
nchanStatusWorker.eventSource.addEventListener('message', e => { |
|
49
|
|
|
const message = JSON.parse(e.data); |
|
50
|
|
|
console.log('New message: ', message); |
|
|
|
|
|
|
51
|
|
|
}); |
|
52
|
|
|
}, |
|
53
|
|
|
}; |
|
54
|
|
|
|
|
55
|
|
|
// When the document is ready, initialize the module installation/upgrade status worker |
|
56
|
|
|
$(document).ready(() => { |
|
57
|
|
|
if (!globalDebugMode) { |
|
58
|
|
|
nchanStatusWorker.initialize(); |
|
59
|
|
|
} |
|
60
|
|
|
}); |