-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.html
53 lines (37 loc) · 1.05 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
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<button onclick="makeEvent();">make event</button>
<script>
// go-http-light test page
// run server and open page
function makeEvent() {
var xhr = new XMLHttpRequest();
xhr.open('GET', 'http://127.0.0.1:8095/pub?intent=channelname.taskname.12345&obj={"id":123}', false);
xhr.send();
}
var socket = new WebSocket("ws://127.0.0.1:8095/sub");
socket.onopen = function() {
console.log("Соединение установлено.");
socket.send('{"op": "sub", "intent": "channelname.taskname.12345"}');
//socket.send('{"op": "unsub", "task": "channelname.taskname.12345"}');
};
socket.onclose = function(event) {
if (event.wasClean) {
console.log('Connection closed gracefull');
} else {
console.log('Connection closed')
}
console.log('disconnect code: ' + event.code + ' reason: ' + event.reason);
};
socket.onmessage = function(event) {
alert("Received data: " + event.data);
};
socket.onerror = function(error) {
console.log("Error: " + error.message);
};
</script>
</body>
</html>