@caisual/kit 0.1.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/kit.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import type { DeviceReport } from '@caisual/contracts';
2
+ export type { DeviceReport } from '@caisual/contracts';
1
3
  export type JsonValue = null | boolean | number | string | JsonValue[] | {
2
4
  [key: string]: JsonValue;
3
5
  };
@@ -36,8 +38,91 @@ export type BoardOffline = {
36
38
  accepted: false;
37
39
  reason: 'offline';
38
40
  };
41
+ export type RoomStatus = 'lobby' | 'countdown' | 'playing' | 'ended';
42
+ export interface RoomPlayer {
43
+ id: string;
44
+ name: string;
45
+ guest: boolean;
46
+ role: string | null;
47
+ team: number | null;
48
+ ready: boolean;
49
+ connected: boolean;
50
+ }
51
+ export type VoiceMode = 'none' | 'room' | 'team' | 'proximity';
52
+ export type VoiceState = 'off' | 'joining' | 'on' | 'reconnecting';
53
+ export interface VoicePeer {
54
+ id: string;
55
+ mic: boolean;
56
+ muted: boolean;
57
+ speaking: boolean;
58
+ volume: number;
59
+ gain: number;
60
+ }
61
+ export interface Voice {
62
+ readonly mode: VoiceMode;
63
+ readonly state: VoiceState;
64
+ readonly mic: boolean;
65
+ readonly muted: boolean;
66
+ readonly speaking: boolean;
67
+ readonly peers: readonly VoicePeer[];
68
+ join(options?: {
69
+ mic?: boolean;
70
+ }): Promise<void>;
71
+ leave(): void;
72
+ mute(muted?: boolean): void;
73
+ setVolume(playerId: string, volume: number): void;
74
+ onPeers(listener: (peers: readonly VoicePeer[]) => void): () => void;
75
+ onState(listener: (state: VoiceState) => void): () => void;
76
+ }
77
+ export interface RoomInvite {
78
+ code: string;
79
+ url: string;
80
+ }
81
+ export interface Room {
82
+ readonly state: JsonValue;
83
+ readonly tick: number;
84
+ readonly seed: number;
85
+ readonly status: RoomStatus;
86
+ readonly players: readonly RoomPlayer[];
87
+ readonly you: string;
88
+ readonly host: string | null;
89
+ readonly code: string;
90
+ readonly result: JsonValue;
91
+ readonly voice: Voice;
92
+ invite(): RoomInvite;
93
+ onState(listener: (state: JsonValue, tick: number, serverTime: number) => void): () => void;
94
+ onPlayers(listener: (players: readonly RoomPlayer[]) => void): () => void;
95
+ onStatus(listener: (status: RoomStatus, result: JsonValue, at: number) => void): () => void;
96
+ onMessage(listener: (message: JsonValue) => void): () => void;
97
+ send(message: JsonValue): void;
98
+ ready(ready: boolean): void;
99
+ setRole(role: string): void;
100
+ setTeam(team: number): void;
101
+ start(): void;
102
+ leave(): void;
103
+ serverTime(): number;
104
+ }
105
+ export interface MatchOptions {
106
+ mode: string;
107
+ key: Record<string, string | number>;
108
+ signal?: AbortSignal;
109
+ onWaiting?(waiting: {
110
+ players: number;
111
+ min: number;
112
+ max: number;
113
+ }): void;
114
+ }
115
+ export interface Rooms {
116
+ readonly invited: string | null;
117
+ create(options: {
118
+ mode: string | null;
119
+ }): Promise<Room>;
120
+ join(code?: string): Promise<Room>;
121
+ match(options: MatchOptions): Promise<Room>;
122
+ }
39
123
  export interface CaisualConnection {
40
124
  connected: boolean;
125
+ device: DeviceReport;
41
126
  player: Player;
42
127
  daily: {
43
128
  day: string;
@@ -63,6 +148,7 @@ export interface CaisualConnection {
63
148
  guests?: boolean;
64
149
  }): Promise<BoardTop>;
65
150
  };
151
+ room: Rooms;
66
152
  }
67
153
  export interface Caisual {
68
154
  connect(): Promise<CaisualConnection>;