Many changes. Commit before I break down.
- Authentication middleware uses Zod - PhotonRegionId in config - DB key changes and additions - WebSocket for SignalR mock - Presence additions * Needs modification for playerIds (do not store `Profile` in a set, this will cause sync issues) - Profile settings - Profile Device Class - Zod properly checks for issuer in token - Room scene type bug - Setting key import started - Instancing changes - PlayerReporting API route - Deduplicated auth/connect/token - match/player/login begin - WebSocket hands off connection to SignalR handler
This commit is contained in:
50
src/socket/handoff.ts
Normal file
50
src/socket/handoff.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
const handoffs: Set<SocketHandoff> = new Set();
|
||||
|
||||
function randomId(length: number) {
|
||||
let result = '';
|
||||
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
||||
let counter = 0;
|
||||
while (counter < length) {
|
||||
result += characters.charAt(Math.floor(Math.random() * characters.length));
|
||||
counter += 1;
|
||||
}
|
||||
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.
|
||||
export class SocketHandoff {
|
||||
|
||||
static generateId() {
|
||||
let id = randomId(48);
|
||||
while (handoffs.values().find(handoff => handoff.id == id)) id = randomId(48);
|
||||
return id;
|
||||
}
|
||||
static find(id: string) {
|
||||
return handoffs.values().find(handoff => handoff.id === id);
|
||||
}
|
||||
|
||||
id: string;
|
||||
|
||||
#timeout: number;
|
||||
|
||||
constructor() {
|
||||
this.id = SocketHandoff.generateId();
|
||||
|
||||
this.#timeout = setTimeout(() => {
|
||||
handoffs.delete(this);
|
||||
});
|
||||
|
||||
handoffs.add(this);
|
||||
}
|
||||
|
||||
delete() {
|
||||
clearTimeout(this.#timeout);
|
||||
handoffs.delete(this);
|
||||
}
|
||||
|
||||
complete() {
|
||||
this.delete();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user