Socket proxy base

This commit is contained in:
Jiiks 2018-01-15 07:09:28 +02:00
parent 403ffc839d
commit 8c2692caba
3 changed files with 469 additions and 432 deletions

File diff suppressed because it is too large Load Diff

View File

@ -16,6 +16,7 @@ class BetterDiscord {
constructor() { constructor() {
Global.first(); Global.first();
window.bdUtils = Utils;
} }
} }

View File

@ -11,6 +11,7 @@
const { Events } = require('./events'); const { Events } = require('./events');
const { Module } = require('./modulebase'); const { Module } = require('./modulebase');
const { Global } = require('./global'); const { Global } = require('./global');
const { Utils } = require('./utils');
class SocketProxy extends Module { class SocketProxy extends Module {
@ -20,12 +21,29 @@ class SocketProxy extends Module {
bindings() { bindings() {
this.socketCreated = this.socketCreated.bind(this); this.socketCreated = this.socketCreated.bind(this);
window.test = this; this.onmessage = this.onmessage.bind(this);
} }
socketCreated() { socketCreated() {
console.log('SOCKET CREATED!'); const wsHook = Global.getObject('wsHook');
console.log(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);
}
onmessage(e) {
console.log(e);
//TODO fix unpacking
const unpacked = this.erlpack.unpack(e.data);
console.log(unpacked);
} }
get erlpack() { get erlpack() {