-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathws.html
70 lines (59 loc) · 2.31 KB
/
ws.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
<html>
<head>
<script type="text/javascript">
function WebSocketTest() {
if ("WebSocket" in window) {
console.log("WebSocket is supported by your Browser!");
// Let us open a web socket
// var ws = new WebSocket("wss://ddhub-gateway-dev.energyweb.org/events?clientId=alphanumberic", 'ddhub-protocol');
var ws = new WebSocket("ws://localhost:3333/events?clientId=alphanumberic", 'ddhub-protocol');
ws.onopen = function () {
// Web Socket is connected, send data using send()
ws.send(JSON.stringify({
event: 'message',
data: "{\n \"fqcn\": \"azam.3\",\n \"topicName\": \"Topic_azam_2\",\n \"topicVersion\": \"1.0.0\",\n \"topicOwner\": \"mini.apps.sliced.carrot.vege.iam.ewc\",\n \"payload\": \"{ \\\"data\\\": 49 }\"\n}",
}));
console.log("Message is sent...");
};
ws.onmessage = function (evt) {
var received_msg = evt.data;
console.log("Message is received..." + received_msg);
};
ws.onclose = function (e) {
// websocket is closed.
console.log("Connection is closed...");
console.error(e);
};
} else {
// The browser doesn't support WebSocket
console.log("WebSocket NOT supported by your Browser!");
}
}
WebSocketTest()
</script>
<script src="https://cdn.socket.io/4.3.2/socket.io.min.js"
integrity="sha384-KAZ4DtjNhLChOB/hxXuKqhMLYvx3b5MlT55xPEiNmREKRzeEm+RVPlTnAn0ajQNs"
crossorigin="anonymous"></script>
<!-- <script>-->
<!-- const socket = io('http://localhost:3333/events');-->
<!-- console.log("ASD");-->
<!-- socket.on('connect', function() {-->
<!-- console.log('Connected');-->
<!-- socket.emit('events', { test: 'test' });-->
<!-- socket.emit('identity', 0, response =>-->
<!-- console.log('Identity:', response),-->
<!-- );-->
<!-- });-->
<!-- socket.on('events', function(data) {-->
<!-- console.log('event', data);-->
<!-- });-->
<!-- socket.on('exception', function(data) {-->
<!-- console.log('event', data);-->
<!-- });-->
<!-- socket.on('disconnect', function() {-->
<!-- console.log('Disconnected');-->
<!-- });-->
<!-- </script>-->
</head>
<body></body>
</html>