Last active
January 5, 2016 15:08
-
-
Save The-Quill/7febc934873171a4012e to your computer and use it in GitHub Desktop.
Monitor chat things
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
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