From 1040650ae40bb1160e950977e41842a45a552c8b Mon Sep 17 00:00:00 2001 From: Jiiks Date: Mon, 15 Jan 2018 08:01:34 +0200 Subject: [PATCH] addEventListener instead --- client/dist/betterdiscord.client.js | 22 ++++++++++++---------- client/src/modules/discordsocket.js | 11 +---------- core/src/sparkplug.js | 17 +++++++++++++++++ 3 files changed, 30 insertions(+), 20 deletions(-) diff --git a/client/dist/betterdiscord.client.js b/client/dist/betterdiscord.client.js index f733e3af..1f489aba 100644 --- a/client/dist/betterdiscord.client.js +++ b/client/dist/betterdiscord.client.js @@ -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) { diff --git a/client/src/modules/discordsocket.js b/client/src/modules/discordsocket.js index ea32fc47..8410fd54 100644 --- a/client/src/modules/discordsocket.js +++ b/client/src/modules/discordsocket.js @@ -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) { diff --git a/core/src/sparkplug.js b/core/src/sparkplug.js index 4d35c42b..782cbd39 100644 --- a/core/src/sparkplug.js +++ b/core/src/sparkplug.js @@ -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;