Created
July 13, 2017 14:43
-
-
Save jamespet77/623958815f9db6aedbf22751a320a4a1 to your computer and use it in GitHub Desktop.
Testing Websockets
This file contains hidden or 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
<body> | |
//var WebSocket = require('ws'); | |
var username = 'admin'; //replace with admin username | |
var password = 'my password'; //replace with admin password | |
var host = 'isy.linuxjet.com:2653'; //replace with your ISY IP | |
var auth = username + ':' + password; | |
var url = 'wss://' + auth + '@' + host + '/rest/subscribe'; | |
var ws = new WebSocket(url, 'ISYSUB', { | |
origin: 'com.universal-devices.websockets.isy', | |
protocolVersion: 13 | |
}); | |
ws.onopen = function() { | |
console.log('connected'); | |
document.getElementById("log").innerText = "OPEN"; | |
}; | |
ws.onclose = function() { | |
console.log('disconnected'); | |
document.getElementById("log").innerText = "CLOSE"; | |
}; | |
ws.onmessage = function(data, flags) { | |
document.getElementById("log").innerText = data + String.fromCharCode(13) + document.getElementById("log").innerText; | |
}; | |
ws.onerror = function(error) { | |
document.getElementById("log").innerText = "ERROR"; | |
}; | |
</script> | |
<p id="log">HELLO</p> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment