* Unified profiles, rather than instantiating profiles every time we want to access one
* Socket and live instance changes * Possible problem with Deno's handling of sockets, compatibility issue with Node?
This commit is contained in:
@@ -11,10 +11,14 @@ function randomId(length: number) {
|
||||
return result;
|
||||
}
|
||||
|
||||
// Lots of this is redundant. The WebSocket request already contains an access token for the profile, but I'd
|
||||
// like to make sure that connectionIds are freed automatically.
|
||||
/**
|
||||
* Reserve `connectionId`s for each connected client, hand off to socket handler when complete or timed out
|
||||
*/
|
||||
export class SocketHandoff {
|
||||
|
||||
static all() {
|
||||
return Array.from(handoffs.values());
|
||||
}
|
||||
static generateId() {
|
||||
let id = randomId(48);
|
||||
while (handoffs.values().find(handoff => handoff.id == id)) id = randomId(48);
|
||||
@@ -32,19 +36,15 @@ export class SocketHandoff {
|
||||
this.id = SocketHandoff.generateId();
|
||||
|
||||
this.#timeout = setTimeout(() => {
|
||||
handoffs.delete(this);
|
||||
this.complete();
|
||||
});
|
||||
|
||||
handoffs.add(this);
|
||||
}
|
||||
|
||||
delete() {
|
||||
complete() {
|
||||
clearTimeout(this.#timeout);
|
||||
handoffs.delete(this);
|
||||
}
|
||||
|
||||
complete() {
|
||||
this.delete();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user