socio
Version:
A WebSocket Real-Time Communication (RTC) API framework.
39 lines (38 loc) • 1.45 kB
TypeScript
import type { ClientID, ServerMessageDataObj } from "./types.d.ts";
import type { SocioSession } from "./core-session.js";
export type User = {
client_id: ClientID;
username?: string;
};
export type ChatRoomMessage = {
user: User;
ts: number;
text: string;
};
type ServerInterfaceFunction = (client_ids: string[], data: object) => void;
type ClientInterfaceFunction = (data: any) => void;
export declare class ServerChatRoom {
#private;
history_length: number;
server_interface: ServerInterfaceFunction;
constructor(ServerSendToClients: ServerInterfaceFunction, message_history_length?: number);
CloseRoom(): void;
get room_id(): number;
static get room_ids(): Set<number>;
Join(client_id: ClientID): void;
Leave(client_id: ClientID): void;
Post(client_id: ClientID, text: string): void;
}
export declare class ChatRoomClient {
#private;
serv: ClientInterfaceFunction;
msg_hook: (msg: Set<ChatRoomMessage>) => void;
constructor(ClientSendToServer: ClientInterfaceFunction, msg_hook: (msg: Set<ChatRoomMessage>) => void);
Join(room_id: number): void;
Leave(): void;
Post(text: string): void;
Receive(msgs: Set<ChatRoomMessage>): void;
}
export declare function HandleChatRoomServ(client: SocioSession, data: ServerMessageDataObj, chat_rooms: ServerChatRoom[]): void;
export declare function HandleChatRoomCMD(data: any, chat: ChatRoomClient): void;
export {};