UNPKG

@4players/odin

Version:

A cross-platform SDK enabling developers to integrate real-time VoIP chat technology into their projects

225 lines (224 loc) 8.23 kB
interface FieldSchema<Type extends keyof FieldSchemas> { type: Type; } interface ObjectSchema { type: 'Object'; fields: Record<string, Schema>; } interface ArraySchema { array?: true | false; } interface OptionalSchema { optional?: true | false; } export type Schema = (ObjectSchema | FieldSchema<keyof FieldSchemas>) & ArraySchema & OptionalSchema; interface FieldSchemas { String: string; Number: number; Bigint: bigint; Boolean: boolean; U8: Uint8Array; } type UnwrapFieldType<Type extends keyof FieldSchemas> = FieldSchemas[Type]; type UnwrapObjectType<T extends Schema> = T extends ObjectSchema ? { [N in keyof T['fields']]: Unwrap<T['fields'][N]>; } : T['type'] extends keyof FieldSchemas ? UnwrapFieldType<T['type']> : never; type UnwrapArray<T extends Schema> = T['array'] extends true ? Array<UnwrapObjectType<T>> : UnwrapObjectType<T>; type UnwrapOptional<T extends Schema> = T['optional'] extends true ? UnwrapArray<T> | undefined | null : UnwrapArray<T>; export type Unwrap<T extends Schema> = UnwrapOptional<T>; export type EventSchemas = { [P in string]: Schema; }; type EventHandler<T extends Schema, I> = (e: Unwrap<T>, instance: I) => void; export type EventHandlers<T extends EventSchemas, I> = { [Method in keyof T]: EventHandler<T[Method], I>; }; export type EventSchemaByMethod<Method extends keyof typeof EVENT_SCHEMAS> = Unwrap<(typeof EVENT_SCHEMAS)[Method]>; export type RoomUpdatedSchemaType = EventSchemaByMethod<'RoomUpdated'>['updates'][number]; export type PeerUpdatedSchemaType = EventSchemaByMethod<'PeerUpdated'>; export type MessageReceivedSchemaType = EventSchemaByMethod<'MessageReceived'>; export declare const EVENT_SCHEMAS: { RoomUpdated: { type: "Object"; fields: { updates: { type: "Object"; array: true; fields: { kind: { type: "String"; }; media_ids: { array: true; type: "Number"; optional: true; }; own_peer_id: { type: "Number"; optional: true; }; room: { type: "Object"; fields: { customer: { type: "String"; }; id: { type: "String"; }; peers: { array: true; type: "Object"; fields: { id: { type: "Number"; }; medias: { array: true; type: "Object"; fields: { id: { type: "Number"; }; paused: { type: "Boolean"; optional: true; }; properties: { type: "Object"; fields: { kind: { type: "String"; optional: true; }; }; }; }; }; user_data: { type: "U8"; }; user_id: { type: "String"; }; }; }; user_data: { type: "U8"; }; }; optional: true; }; peer: { type: "Object"; fields: { id: { type: "Number"; }; medias: { array: true; type: "Object"; fields: { id: { type: "Number"; }; paused: { type: "Boolean"; optional: true; }; properties: { type: "Object"; fields: { kind: { type: "String"; optional: true; }; }; }; }; }; user_data: { type: "U8"; }; user_id: { type: "String"; }; }; optional: true; }; user_data: { type: "U8"; optional: true; }; peer_id: { type: "Number"; optional: true; }; }; }; }; }; PeerUpdated: { type: "Object"; fields: { kind: { type: "String"; }; peer_id: { type: "Number"; }; media: { type: "Object"; optional: true; fields: { id: { type: "Number"; }; paused: { type: "Boolean"; optional: true; }; properties: { type: "Object"; fields: { kind: { type: "String"; optional: true; }; }; }; }; }; properties: { type: "Object"; fields: { kind: { type: "String"; optional: true; }; }; optional: true; }; media_id: { type: "Number"; optional: true; }; user_data: { type: "U8"; optional: true; }; }; }; MessageReceived: { type: "Object"; fields: { sender_peer_id: { type: "Number"; }; message: { type: "U8"; }; }; }; }; export {};