Files
piik/src/client/media/viewer-message-authority.ts
T
AAA b76d2cc0a5 feat(rooms): replace SQLite with leased memory rooms (#211)
Implements the accepted memory-resident room and access model on the single piik-v8 Browser wire. Local repository, full Web, build, and Chrome access/privacy gates passed before merge.
2026-08-23 21:47:49 +08:00

30 lines
603 B
TypeScript

import type { ServerMessage } from "../../shared/protocol";
const AUTHORITY_MESSAGE_TYPES = new Set<ServerMessage["type"]>([
"authenticated",
"host-status",
"sharing-stopped",
"viewer-grant-revoked",
"room-closed",
"error",
]);
export class ViewerMessageAuthority {
private generation = 0;
tokenFor(message: ServerMessage): number {
if (AUTHORITY_MESSAGE_TYPES.has(message.type)) {
this.generation += 1;
}
return this.generation;
}
invalidate(): void {
this.generation += 1;
}
owns(token: number): boolean {
return token === this.generation;
}
}