UNPKG

spacesvr-websessions

Version:

A standardized reality for future of the 3D Web

22 lines (21 loc) 813 B
import { DataConnection } from "peerjs"; export declare type Message<Data = any> = { conn?: DataConnection; id: string; data: Data; }; export declare type Reducer<Data = any, State = any> = (message: Message<Data>, state: State) => void; export interface Channel<Data = any, State = any> { id: string; state: State; send: (data: Data) => void; receive: (message: Message<Data>) => void; } declare type ChannelType = "stream" | "sync"; export declare type Channels = { receive: (message: Message) => void; greet: (conn: DataConnection) => void; useChannel: <Data = any, State = any>(id: string, type: ChannelType, reducer: Reducer<Data, State>) => Channel<Data, State>; }; export declare const useChannels: (connections: Map<string, DataConnection>) => Channels; export {};