addEventListener instead

This commit is contained in:
Jiiks 2018-01-15 08:01:34 +02:00
parent 8c2692caba
commit 1040650ae4
3 changed files with 30 additions and 20 deletions

View File

@ -27623,16 +27623,18 @@ class SocketProxy extends Module {
socketCreated() {
const wsHook = Global.getObject('wsHook');
//TODO make this better and bind other events
const onMessageHook = setInterval(() => {
if (wsHook.onmessage !== null) {
clearInterval(onMessageHook);
//Discord sets onmessage twice so a timeout for now
setTimeout(() => {
wsHook.onmessage = Utils.overload(wsHook.onmessage, this.onmessage);
}, 2000);
}
}, 100);
wsHook.addEventListener('message', this.onmessage);
////TODO make this better and bind other events
/* const onMessageHook = setInterval(() => {
if (wsHook.onmessage !== null) {
clearInterval(onMessageHook);
//Discord sets onmessage twice so a timeout for now
setTimeout(() => {
wsHook.onmessage = Utils.overload(wsHook.onmessage, this.onmessage);
}, 2000);
}
}, 100);*/
}
onmessage(e) {

View File

@ -27,16 +27,7 @@ class SocketProxy extends Module {
socketCreated() {
const wsHook = Global.getObject('wsHook');
//TODO make this better and bind other events
const onMessageHook = setInterval(() => {
if (wsHook.onmessage !== null) {
clearInterval(onMessageHook);
//Discord sets onmessage twice so a timeout for now
setTimeout(() => {
wsHook.onmessage = Utils.overload(wsHook.onmessage, this.onmessage);
}, 2000);
}
}, 100);
wsHook.addEventListener('message', this.onmessage);
}
onmessage(e) {

View File

@ -35,6 +35,23 @@
window.__bd.wsHook = this;
}
/* set onmessage(fn) {
//Don't set it
this.__onmessage = fn;
console.log(fn);
console.log("Attempted to set onmessage");
}
onmessage(e) {
console.log("ON MESSAGE!!!!!!!!!!!!!!!!!!!!");
if (this.__onmessage) this.__onmessage(e);
}*/
/* onmessage(e) {
console.log("ON MESSAGE!");
if (this.__onmessage) this.__onmessage(e);
}*/
}
window.WebSocket = WSHook;