-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathwebsocket_client.html
79 lines (67 loc) · 2.18 KB
/
websocket_client.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
<!DOCTYPE html>
<!-- Your use of this Software is pursuant to the Silver Peak Disclaimer - see the README file for this repository -->
<html>
<head>
<title>WebSocket Playground</title>
</head>
<button onclick="requestActiveAlarm()">Request Active Alarm</button>
<br><br>
<button onclick="requestAlarmByIds()">Resubmission By ID</button>
<br><br>
<button onclick="closeConnection()">Close Connection</button>
<body>
</body>
<script>
var ws = null;
/**
* Update these variables for your own test
* @type {string}
* ipOrDNS: ip address or FQDN of Orchestrator. ipOrDNS should not contain the https:// prefix.
* key: key that Orchestrator generates after websocket server is configured
* receiverId: id of websocket remote log receiver created on Orchestrator (integer)
*/
var ipOrDNS = "www.example.com";
var key = ""
var receiverId = NULL;
//used for specifying esubmission of specific notifications by seq ids
var ids = ["2", "3", "4-6"];
ws = new WebSocket(`wss://${ipOrDNS}/remoteLogWebSocket/${receiverId}?key=${key}`);
ws.onopen = function () {
console.log('WS1: WebSocket Client Connected');
ws.send('WS1: Hi this is browser ws client.');
};
ws.onmessage = function (e) {
console.log("WS1: Received: ");
console.log(JSON.parse(e.data));
};
ws.onclose = function () {
console.log("WS1: socket closed");
};
function requestActiveAlarm() {
if (ws != null) {
var req = {
action: "ACTIVE_ALARMS"
}
ws.send(JSON.stringify(req));
console.log(`Send request to ws, ${JSON.stringify(req)}`);
}
}
function requestAlarmByIds() {
//Modify the seqId here to fetch alarm
if (ws != null) {
var req = {
action: "RESUBMISSION",
type: "SEQUENCE_ID",
data: JSON.stringify(ids)
}
ws.send(JSON.stringify(req));
console.log(`Send request to ws, ${JSON.stringify(req)}`);
}
}
function closeConnection() {
if (ws != null) {
ws.close();
}
}
</script>
</html>