-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.html
104 lines (94 loc) · 2.6 KB
/
test.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>
<body class="container">
<script>
var ws = null;
function init() {
if (ws && ws.OPEN) ws.close();
var el = document.getElementById('output');
el.innerHTML = '';
output('Refreshing connection...');
var sip = document.getElementById('sip').value;
ws = new WebSocket('ws://localhost:8088');
ws.onopen = function () {
output('Client: sending ready event');
var action = {
name: 'HANDSHAKE',
params: {
sipNr: sip
}
};
ws.send(JSON.stringify(action));
};
ws.onmessage = function (msg) {
var event = JSON.parse(msg.data);
console.log(event);
var string = event.name;
if (event.name === 'ERROR') {
string = 'ERROR: ';
event.errors.map(function (e, i) {
i++;
string = string + i + '. => Code: ' + e.code;
if (e.data) string = string + ' (Data: ' + e.data + ')';
});
}
if (event.params) string = string + ' params => ' + JSON.stringify(event.params);
output('Server: ' + string);
};
ws.onerror = function (err) {
output(err);
};
ws.onclose = function () {
output("connection closed");
};
}
function call() {
var phoneNb = document.getElementById('phone').value;
var displayName = document.getElementById('displayName').value;
var action = {
name: 'OUTBOUND_CALL',
params: {
remoteEndpoint: phoneNb,
displayName: displayName
}
};
ws.send(JSON.stringify(action));
}
function hangup() {
var action = {
name: 'HANGUP'
};
ws.send(JSON.stringify(action));
}
function output(msg) {
var el = document.getElementById('output');
el.innerHTML = el.innerHTML + "<br>" + msg;
}
</script>
<div class="well">
<div class="form-group">
<label>client Sip nb</label>
<input class="form-control" id="sip" placeholder="sip nb" value="308">
</div>
<div class="form-group">
<label>Phone number</label>
<input class="form-control" id="phone" placeholder="phone nb" value="3001">
</div>
<div class="form-group">
<label>Display Name</label>
<input class="form-control" id="displayName" placeholder="displayName" value="tim">
</div>
<div class="form-group">
<button class="btn" onclick="init()">Init</button>
<button class="btn" onclick="call()">Call</button>
<button class="btn" onclick="hangup()">Hang Up</button>
</div>
</div>
<div class="well" id="output"></div>
</body>
</html>