@4players/odin-common
Version:
Commonly used type definitions and utility functions across ODIN web projects
172 lines (171 loc) • 4.8 kB
TypeScript
import { type ZodString, type ZodType } from 'zod';
import type { MediaId } from './media.ts';
import type { Peer, PeerId } from './peer.ts';
import type { JsonValue } from '../serialization.ts';
export type RoomId = string;
export declare const RoomIdSchema: ZodString;
export declare namespace RoomV1 {
type Room = {
id: RoomId;
customer: string;
user_data: Uint8Array;
peers: Peer[];
};
const RoomSchema: ZodType<Room>;
type RoomUpdate = {
kind: 'Joined';
room: Room;
media_ids: MediaId[];
own_peer_id: PeerId;
} | {
kind: 'Left';
reason: 'RoomClosing' | 'ServerClosing' | 'PeerKicked';
} | {
kind: 'PeerJoined';
peer: Peer;
} | {
kind: 'PeerLeft';
peer_id: PeerId;
} | {
kind: 'UserDataChanged';
user_data?: Uint8Array;
};
const RoomUpdateSchema: ZodType<RoomUpdate>;
type RoomUpdates = {
updates: RoomUpdate[];
};
const RoomUpdatesSchema: ZodType<RoomUpdates>;
type RoomStatus = 'Joining' | 'Joined' | 'Closed';
const RoomStatusSchema: ZodType<RoomStatus>;
type RoomStatusChanged = {
status: RoomStatus;
message?: string;
};
const RoomStatusChangedSchema: ZodType<RoomStatusChanged>;
}
export declare namespace RoomV2 {
type Parameters = Record<string, JsonValue>;
const ParametersSchema: ZodType<Parameters>;
type ChannelPosition = {
x: number;
y: number;
z: number;
channel: number;
};
const PositionSchema: ZodType<ChannelPosition>;
type ChannelMask = bigint;
const ChannelMaskSchema: ZodType<ChannelMask>;
type HelloRoom = {
token: string;
room_id?: RoomId;
user_data?: Uint8Array;
parameters?: Parameters;
channel_masks?: Array<[number, ChannelMask]>;
positions?: ChannelPosition[];
};
const HelloRoomSchema: ZodType<HelloRoom>;
type ClientHello = {
Room: HelloRoom;
};
const ClientHelloSchema: ZodType<ClientHello>;
type ServerHello = {
Ok: Record<string, never>;
} | {
Rejected: {
message: string;
};
};
const ServerHelloSchema: ZodType<ServerHello>;
type PeerProperties = {
user_data?: Uint8Array;
tags?: string[];
parameters?: Record<string, JsonValue>;
};
const PeerPropertiesSchema: ZodType<PeerProperties>;
type Ping = {
Ping: {
id: number;
};
};
const PingSchema: ZodType<Ping>;
type ChangeSelf = {
ChangeSelf: Omit<PeerProperties, 'tags'>;
};
const ChangeSelfSchema: ZodType<ChangeSelf>;
type SetAudioMask = {
SetAudioMask: {
peer_id: number;
mask: bigint;
};
};
const SetAudioMaskSchema: ZodType<SetAudioMask>;
type SendMessage = {
SendMessage: {
peer_ids: number[];
message: Uint8Array;
};
};
const SendMessageSchema: ZodType<SendMessage>;
type Call = Ping | ChangeSelf | SetAudioMask | SendMessage;
const CallSchema: ZodType<Call>;
type Pong = {
Pong: {
id: number;
};
};
const PongSchema: ZodType<Pong>;
type Joined = {
Joined: {
own_peer_id: number;
room_id: string;
customer: string;
};
};
const JoinedSchema: ZodType<Joined>;
type Left = {
Left: {
reason: 'room_closing' | 'server_closing' | 'peer_kicked';
};
};
const LeftSchema: ZodType<Left>;
type PeerJoined = {
PeerJoined: PeerProperties & {
peer_id: number;
user_id: string;
};
};
const PeerJoinedSchema: ZodType<PeerJoined>;
type PeerLeft = {
PeerLeft: {
peer_id: number;
};
};
const PeerLeftSchema: ZodType<PeerLeft>;
type PeerChanged = {
PeerChanged: PeerProperties & {
peer_id: number;
};
};
const PeerChangedSchema: ZodType<PeerChanged>;
type NewReconnectToken = {
NewReconnectToken: {
token: string;
};
};
const NewReconnectTokenSchema: ZodType<NewReconnectToken>;
type MessageReceived = {
MessageReceived: {
sender_peer_id: number;
message: Uint8Array;
};
};
const MessageReceivedSchema: ZodType<MessageReceived>;
type ServerError = {
Error: {
message: string;
};
};
const ServerErrorSchema: ZodType<ServerError>;
type Event = Pong | Joined | Left | PeerJoined | PeerLeft | PeerChanged | NewReconnectToken | MessageReceived | ServerError;
const EventSchema: ZodType<Event>;
}