react-together
Version:
A library to seamlessly add real-time multi-user interaction to your React app!
52 lines (50 loc) • 1.82 kB
TypeScript
import { ReactModel, ViewInfo } from '@croquet/react';
import { UseStateTogetherWithPerUserValuesOptions } from '../hooks/useStateTogetherWithPerUserValues';
import { default as ChatModel } from './ChatModel';
interface setStateArgs<T> {
rtKey: string;
value: T | undefined;
}
interface SetStatePerUserArgs<T> {
rtKey: string;
userId: string;
value: T | undefined;
}
interface ReactTogetherModelOptions extends Record<string, unknown> {
}
interface FunctionTogetherArgs {
rtKey: string;
args: unknown[];
}
interface CreateChatArgs {
rtKey: string;
}
interface ConfigureStatePerUserArgs {
rtKey: string;
userId: string;
options: UseStateTogetherWithPerUserValuesOptions;
}
interface StatePerUserConfig {
keepValues?: boolean;
}
export default class ReactTogetherModel extends ReactModel {
state: Map<string, unknown>;
statePerUser: Map<string, Map<string, unknown>>;
statePerUserConfig: Map<string, StatePerUserConfig>;
chats: Map<string, ChatModel>;
viewIdUserIdMapping: Map<string, string>;
userIdCount: Map<string, number>;
init(options: ReactTogetherModelOptions): void;
handleViewJoin(viewId: string, viewInfo: ViewInfo<{
userId?: string;
}>): void;
handleViewExit(viewId: string): void;
setState<T>({ rtKey, value }: setStateArgs<T>): void;
setStatePerUser<T>({ rtKey, userId, value }: SetStatePerUserArgs<T>): void;
configureStatePerUser({ rtKey, options }: ConfigureStatePerUserArgs): void;
functionTogether({ rtKey, args }: FunctionTogetherArgs): void;
createChat({ rtKey }: CreateChatArgs): void;
}
export declare function getUserId(model: ReactTogetherModel, viewId: string): string;
export declare function getChat(model: ReactTogetherModel, rtKey: string): ChatModel | undefined;
export {};