chore: remove setup.cfg, add aiofiles dep, and fix this context in Socket connect
This commit is contained in:
+25
-19
@@ -166,9 +166,10 @@ class Socket extends EventHandler {
|
||||
if (this.ensureTimer) {
|
||||
return this.connect();
|
||||
}
|
||||
const me = this;
|
||||
this.ensureTimer = setInterval(() => {
|
||||
if (this.isConnecting) this.isConnecting = false;
|
||||
this.connect();
|
||||
if (me.isConnecting) me.isConnecting = false;
|
||||
me.connect();
|
||||
}, 5000);
|
||||
return this.connect();
|
||||
}
|
||||
@@ -178,32 +179,34 @@ class Socket extends EventHandler {
|
||||
}
|
||||
|
||||
connect() {
|
||||
|
||||
const me = this
|
||||
if (this.isConnected || this.isConnecting) {
|
||||
return new Promise((resolve) => {
|
||||
this.connectPromises.push(resolve);
|
||||
if (!this.isConnected) resolve(this);
|
||||
me.connectPromises.push(resolve);
|
||||
if (!me.isConnecting) resolve(me);
|
||||
});
|
||||
}
|
||||
this.isConnecting = true;
|
||||
return new Promise((resolve) => {
|
||||
this.connectPromises.push(resolve);
|
||||
me.connectPromises.push(resolve);
|
||||
console.debug("Connecting..");
|
||||
|
||||
const ws = new WebSocket(this.url);
|
||||
const ws = new WebSocket(me.url);
|
||||
ws.onopen = () => {
|
||||
this.ws = ws;
|
||||
this.isConnected = true;
|
||||
this.isConnecting = false;
|
||||
me.ws = ws;
|
||||
me.isConnected = true;
|
||||
me.isConnecting = false;
|
||||
ws.onmessage = (event) => {
|
||||
this.onData(JSON.parse(event.data));
|
||||
me.onData(JSON.parse(event.data));
|
||||
};
|
||||
ws.onclose = () => {
|
||||
this.onClose();
|
||||
me.onClose();
|
||||
};
|
||||
ws.onerror = () => {
|
||||
this.onClose();
|
||||
me.onClose();
|
||||
};
|
||||
this.connectPromises.forEach(resolver => resolver(this));
|
||||
me.connectPromises.forEach(resolver => resolver(me));
|
||||
};
|
||||
});
|
||||
}
|
||||
@@ -233,9 +236,10 @@ class Socket extends EventHandler {
|
||||
method,
|
||||
args,
|
||||
};
|
||||
const me = this
|
||||
return new Promise((resolve) => {
|
||||
this.addEventListener(call.callId, data => resolve(data));
|
||||
this.sendJson(call);
|
||||
me.addEventListener(call.callId, data => resolve(data));
|
||||
me.sendJson(call);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -281,12 +285,13 @@ class App extends EventHandler {
|
||||
this.ws = new Socket();
|
||||
this.rpc = this.ws.client;
|
||||
this.audio = new NotificationAudio(500);
|
||||
const me = this
|
||||
this.ws.addEventListener("channel-message", (data) => {
|
||||
this.emit(data.channel_uid, data);
|
||||
me.emit(data.channel_uid, data);
|
||||
});
|
||||
|
||||
this.rpc.getUser(null).then(user => {
|
||||
this.user = user;
|
||||
me.user = user;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -296,14 +301,15 @@ class App extends EventHandler {
|
||||
|
||||
async benchMark(times = 100, message = "Benchmark Message") {
|
||||
const promises = [];
|
||||
const me = this;
|
||||
for (let i = 0; i < times; i++) {
|
||||
promises.push(this.rpc.getChannels().then(channels => {
|
||||
channels.forEach(channel => {
|
||||
this.rpc.sendMessage(channel.uid, `${message} ${i}`);
|
||||
me.rpc.sendMessage(channel.uid, `${message} ${i}`);
|
||||
});
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const app = new App();
|
||||
const app = new App();
|
||||
|
||||
Reference in New Issue
Block a user