- First visit logs in as a new guest through Keycloak without a form; the session, including an offline refresh token, is kept in local storage - Account menu on the home page: guests can log in or sign up, users can log out (which starts a new guest session) - The WebSocket client in core authenticates with the access token after connecting, reports "connected" once the server accepts it, and re-sends renewed tokens on the open connection - Game page shows player names; guests appear as "Guest 4F2A" - Auth channels, AuthUser and player names in UserConnectionInfo move to core and the backend uses them from there - Mobile keeps using userKey login for now
26 lines
1.2 KiB
TypeScript
26 lines
1.2 KiB
TypeScript
import { TinyEmitter } from "tiny-emitter"
|
|
import { AuthUser } from "../../models/AuthUser";
|
|
|
|
export type OnMessage = (message: Object) => any
|
|
|
|
export type ConnectionState = "none" | "connecting" | "error" | "connected" | "closed" | "reconnecting";
|
|
|
|
export type RtmtEventTypes = "open" | "close" | "connected" | "error" | "disconnected" | "message" | "connectionchange" | "authenticated";
|
|
|
|
export const RTMT_WS_PING_INTERVAL = 1000, RTMT_WS_PING_INTERVAL_BUFFER_TIME = 2000;
|
|
|
|
// Supplies a current access token; called on every (re)connect.
|
|
export type TokenProvider = () => Promise<string>;
|
|
|
|
export interface RTMT extends TinyEmitter {
|
|
get connectionState(): ConnectionState;
|
|
// The user the server authenticated this connection as, once connected with a token.
|
|
get user(): AuthUser | undefined;
|
|
sendMessage: (channel: string, message: Object) => void;
|
|
addMessageListener(channel: string, callback: (message: any) => void): any;
|
|
removeMessageListener(channel: string, callback: (message: any) => void): any;
|
|
on(event: RtmtEventTypes, callback: (...value: any[]) => void): this;
|
|
off(event: RtmtEventTypes, callback: (...value: any[]) => void): this;
|
|
dispose(): any;
|
|
}
|