Skip to content

Instantly share code, notes, and snippets.

@jamespet77
Created July 13, 2017 14:43
Show Gist options
  • Save jamespet77/623958815f9db6aedbf22751a320a4a1 to your computer and use it in GitHub Desktop.
Save jamespet77/623958815f9db6aedbf22751a320a4a1 to your computer and use it in GitHub Desktop.
Testing Websockets
<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