Skip to content

Instantly share code, notes, and snippets.

Created January 10, 2013 10:06
Show Gist options
  • Save anonymous/59997651144b3a094c44 to your computer and use it in GitHub Desktop.
Save anonymous/59997651144b3a094c44 to your computer and use it in GitHub Desktop.
var xmlhttp;
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
StartWS(xmlhttp.responseText);
}
};
xmlhttp.open("POST", "/ws-auth", true);
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlhttp.send("roomId=17&fkey=" + fkey().fkey);
function StartWS(response) {
var WS = new WebSocket(JSON.parse(response).url + '?l=99999999999');
console.log(WS.url);
WS.onopen = function () {
console.log('Connection Open!');
};
WS.onmessage = function (text) {
console.log(text);
};
WS.onclose = function (text) {
console.log(text);
};
WS.onerror = function () {
console.log('error');
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment