This commit is contained in:
Emily 2019-08-01 19:02:47 +02:00
parent c9350aa8db
commit 9c2cbb1921

View File

@ -1,7 +1,7 @@
class FLYSocket { class FLYSocket {
constructor(ws, constructor(ws,
callbackData = this.callbackDummy, callbackData = null,
callbackRaw = this.callbackDummy) { callbackRaw = null) {
this.ws = new WebSocket(ws); this.ws = new WebSocket(ws);
this.pointer = 0; this.pointer = 0;
@ -15,11 +15,10 @@ class FLYSocket {
new Response(event.data).arrayBuffer().then( new Response(event.data).arrayBuffer().then(
function(buff) { function(buff) {
let data = new DataView(buff); let data = new DataView(buff);
this.callbackRaw(data); if (this.callbackRaw !== null)
this.callbackRaw(data);
if (this.callbackData != this.callbackDummy) { if (this.callbackData !== null)
this.callbackData( this.parse(data) ); this.callbackData( this.parse(data) );
}
}.bind(this) }.bind(this)
); );
} }
@ -186,11 +185,7 @@ class FLYSocket {
*buffer2HexArray(buff, start = 0, end = buff.byteLength) { *buffer2HexArray(buff, start = 0, end = buff.byteLength) {
for (let i = start; i < end; i++) { for (let i = start; i < end; i++) {
yield hex.push( buff.getUint8(i).toString(16) ); yield buff.getUint8(i).toString(16);
} }
} }
}
callbackDummy(_) {}
}
console.log("OK") // TODO: please remove...