Passed
Push — develop ( a24ba0...f685b5 )
by Nikolay
05:57 queued 35s
created

sites/admin-cabinet/assets/js/src/PbxExtensionModules/pbx-extension-module-nchan-worker.js   A

Complexity

Total Complexity 6
Complexity/F 1.5

Size

Lines of Code 35
Function Count 4

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 16
dl 0
loc 35
rs 10
c 0
b 0
f 0
mnd 2
bc 2
fnc 4
bpm 0.5
cpm 1.5
noi 2
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);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
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);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
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
});