mancala/packages/core/src/rtmt/client/rtmt.ts

26 lines
1.2 KiB
TypeScript
Raw Normal View History

2024-06-17 17:25:40 +03:00
import { TinyEmitter } from "tiny-emitter"
import { AuthUser } from "../../models/AuthUser";
2022-09-02 00:01:55 +03:00
2024-06-17 17:25:40 +03:00
export type OnMessage = (message: Object) => any
2021-06-27 19:28:55 +03:00
2022-09-04 01:06:07 +03:00
export type ConnectionState = "none" | "connecting" | "error" | "connected" | "closed" | "reconnecting";
2022-09-02 00:01:55 +03:00
export type RtmtEventTypes = "open" | "close" | "connected" | "error" | "disconnected" | "message" | "connectionchange" | "authenticated";
2022-09-02 00:01:55 +03:00
2024-06-17 17:25:40 +03:00
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>;
2024-06-17 17:25:40 +03:00
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;
2022-09-02 00:01:55 +03:00
sendMessage: (channel: string, message: Object) => void;
2024-06-17 17:25:40 +03:00
addMessageListener(channel: string, callback: (message: any) => void): any;
removeMessageListener(channel: string, callback: (message: any) => void): any;
on(event: RtmtEventTypes, callback: (...value: any[]) => void): this;
2022-09-02 00:01:55 +03:00
off(event: RtmtEventTypes, callback: (...value: any[]) => void): this;
2024-06-17 17:25:40 +03:00
dispose(): any;
}