forked from thingsboard/thingsboard.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
11c69a3
commit e634b96
Showing
3 changed files
with
85 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<!DOCTYPE HTML> | ||
<html> | ||
<head> | ||
|
||
<script type="text/javascript"> | ||
function WebSocketTest() { | ||
if ("WebSocket" in window) { | ||
alert("WebSocket is supported by your Browser!"); | ||
|
||
var token = "YOUR_JWT_TOKEN"; | ||
var entityId = "YOUR_DEVICE_ID"; | ||
var webSocket = new WebSocket("ws(s)://host:port/api/ws/plugins/telemetry?token=" + token); | ||
|
||
if (entityId === "YOUR_DEVICE_ID" || token === "YOUR_JWT_TOKEN") { | ||
alert("Invalid token or device id!"); | ||
webSocket.close(); | ||
} | ||
|
||
webSocket.onopen = function () { | ||
var object = { | ||
tsSubCmds: [ | ||
{ | ||
entityType: "DEVICE", | ||
entityId: entityId, | ||
scope: "LATEST_TELEMETRY", | ||
cmdId: 10 | ||
} | ||
], | ||
historyCmds: [], | ||
attrSubCmds: [] | ||
}; | ||
var data = JSON.stringify(object); | ||
webSocket.send(data); | ||
alert("Message is sent: " + data); | ||
}; | ||
|
||
webSocket.onmessage = function (event) { | ||
var received_msg = event.data; | ||
alert("Message is received: " + received_msg); | ||
}; | ||
|
||
webSocket.onclose = function (event) { | ||
alert("Connection is closed!"); | ||
}; | ||
|
||
window.onbeforeunload = function (event) { | ||
webSocket.close(); | ||
}; | ||
} | ||
|
||
else { | ||
alert("WebSocket is NOT supported by your Browser!"); | ||
} | ||
} | ||
</script> | ||
|
||
</head> | ||
<body> | ||
|
||
<div id="sse"> | ||
<a href="javascript:WebSocketTest()">Run WebSocket</a> | ||
</div> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters