Skip to content

Instantly share code, notes, and snippets.

@The-Quill
Last active January 5, 2016 15:08
Show Gist options
  • Save The-Quill/7febc934873171a4012e to your computer and use it in GitHub Desktop.
Save The-Quill/7febc934873171a4012e to your computer and use it in GitHub Desktop.
Monitor chat things
var socket, url;
connect();
var ROOMID = 89; //Tavern
ROOMID = 8595; //2nd Monitor
function connect() {
$.post('/ws-auth', fkey({
roomid: ROOMID
})).done(function (data) {
url = data.url;
poll();
});
}
function poll() {
socket = new WebSocket(url + '?l=' + Date.now());
socket.onmessage = ondata;
socket.onclose = onclose;
}
function ondata(data) {
var frame = JSON.parse(data.data);
for (var room in frame) {
if ('e' in frame[room]) {
console.log(frame[room].e[0]);
}
}
}
function onclose() {
socket.close();
socket = null;
setTimeout(poll, 1000 * 10);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment