node-haxball
Version:
The most powerful and lightweight API that allows you to develop your original Haxball(www.haxball.com) host, client, and standalone applications both on node.js and browser environments and also includes every possible hack and functionality that you can
20 lines (19 loc) • 595 B
JavaScript
function startStreaming(room){ // this is currently using the interval mode for streaming.
var socket, int, s = room.startStreaming({/*onClientCount: (cc)=>{},*/ emitData: (data)=>{socket.send(data);}});
if (!s)
return;
var socket = new WebSocket("ws://localhost:1935");
socket.onopen = ()=>{
int = setInterval(s.interval, 50);
s.onOpen();
};
function clear(){
clearInterval(int);
int = null;
s = null;
socket = null;
}
socket.onclose = clear;
socket.onerror = clear;
socket.onmessage = ({data})=>{ s.onDataReceived(data); };
}