1
|
|
|
/* |
2
|
|
|
* MikoPBX - free phone system for small business |
3
|
|
|
* Copyright (C) 2017-2021 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
|
|
|
|
20
|
|
|
/* global globalTranslate, extension, DebuggerInfo, PbxApi */ |
21
|
|
|
|
22
|
|
|
const extensionStatusLoopWorker = { |
23
|
|
|
timeOut: 3000, |
24
|
|
|
timeOutHandle: '', |
25
|
|
|
$statusLabel: $('#status'), |
26
|
|
|
/** |
27
|
|
|
* initialize() создание объектов и запуск их |
28
|
|
|
*/ |
29
|
|
|
initialize() { |
30
|
|
|
DebuggerInfo.initialize(); |
31
|
|
|
if (extension.$formObj.form('get value','id')!==''){ |
32
|
|
|
extensionStatusLoopWorker.restartWorker(); |
33
|
|
|
} |
34
|
|
|
}, |
35
|
|
|
restartWorker() { |
36
|
|
|
window.clearTimeout(extensionStatusLoopWorker.timeoutHandle); |
37
|
|
|
extensionStatusLoopWorker.worker(); |
38
|
|
|
}, |
39
|
|
|
worker() { |
40
|
|
|
if (extension.defaultNumber.length === 0) return; |
41
|
|
|
const param = { peer: extension.defaultNumber }; |
42
|
|
|
window.clearTimeout(extensionStatusLoopWorker.timeoutHandle); |
43
|
|
|
PbxApi.GetPeerStatus(param, extensionStatusLoopWorker.cbRefreshExtensionStatus); |
44
|
|
|
}, |
45
|
|
|
/** |
46
|
|
|
* cbRefreshExtensionStatus() Обновление статусов пира |
47
|
|
|
*/ |
48
|
|
|
cbRefreshExtensionStatus(response) { |
49
|
|
|
extensionStatusLoopWorker.timeoutHandle = |
50
|
|
|
window.setTimeout(extensionStatusLoopWorker.worker, extensionStatusLoopWorker.timeOut); |
51
|
|
|
if (response.length === 0 || response === false) return; |
52
|
|
|
const $status = extensionStatusLoopWorker.$statusLabel; |
53
|
|
|
|
54
|
|
|
let htmlTable = '<table class="ui very compact table">'; |
55
|
|
|
$.each(response, (key, value) => { |
56
|
|
|
htmlTable += '<tr>'; |
57
|
|
|
htmlTable += `<td>${key}</td>`; |
58
|
|
|
htmlTable += `<td>${value}</td>`; |
59
|
|
|
htmlTable += '</tr>'; |
60
|
|
|
}); |
61
|
|
|
htmlTable += '</table>'; |
62
|
|
|
DebuggerInfo.UpdateContent(htmlTable); |
63
|
|
|
|
64
|
|
|
if ('Status' in response && response.Status.toUpperCase().indexOf('REACHABLE') >= 0) { |
65
|
|
|
$status.removeClass('grey').addClass('green'); |
66
|
|
|
} else { |
67
|
|
|
$status.removeClass('green').addClass('grey'); |
68
|
|
|
} |
69
|
|
|
if ($status.hasClass('green')) { |
70
|
|
|
$status.html(globalTranslate.ex_Online); |
71
|
|
|
} else { |
72
|
|
|
$status.html(globalTranslate.ex_Offline); |
73
|
|
|
} |
74
|
|
|
}, |
75
|
|
|
}; |