Repository navigation
Expand file tree
/
Copy pathsocket-types.ts
More file actions
89 lines (84 loc) · 3.02 KB
/
Copy pathsocket-types.ts
File metadata and controls
89 lines (84 loc) · 3.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import type { z } from 'zod';
import type { ExerciseState } from '../state.js';
import type {
JoinParallelExerciseResponseData,
UpdateParallelExerciseResponseData,
} from '../interfaces/parallel-exercise.js';
import type { ExerciseKey } from '../exercise-keys.js';
import type { JoinExerciseResponseDataInput } from '../interfaces/exercise.js';
import type { ExerciseAction } from '../store/action-reducers/action-reducers.js';
import type { UUID } from '../utils/uuid.js';
import type { CollectionEntityId } from '../marketplace/models/versioned-id-schema.js';
import type { Marketplace } from '../interfaces/collections.js';
export interface ServerToClientEvents {
performAction: (action: ExerciseAction) => void;
updateExerciseInstances: (data: UpdateParallelExerciseResponseData) => void;
collectionUpdate: (
data: z.input<typeof Marketplace.Collection.Events.SSEvent.schema>
) => void;
}
// The last argument is always expected to be the callback function. (To be able to use it in advanced typings)
export interface ClientToServerEvents {
joinExercise: (
payload: {
exerciseKey: ExerciseKey;
/** Present on fresh join; absent on reconnect. */
clientName?: string;
/** Present on reconnect attempt; absent on fresh join. */
clientId?: UUID;
},
callback: (
response: SocketResponse<JoinExerciseResponseDataInput>
) => void
) => void;
proposeAction: (
action: ExerciseAction,
callback: (response: SocketResponse) => void
) => void;
getState: (
callback: (response: SocketResponse<ExerciseState>) => void
) => void;
joinParallelExercise: (
id: UUID,
callback: (
response: SocketResponse<JoinParallelExerciseResponseData>
) => void
) => void;
controlParallelExercise: (
action: 'pause' | 'start',
callback: (response: SocketResponse) => void
) => void;
registerCollectionListenerClient: (
callback: (response: SocketResponse) => void
) => void;
joinCollectionRoom: (
collectionEntityId: CollectionEntityId,
callback: (
response: SocketResponse<
typeof Marketplace.Collection.Events.InitialData.InputType
>
) => void
) => void;
leaveCollectionRoom: (
collectionEntityId: CollectionEntityId,
callback: (response: SocketResponse) => void
) => void;
}
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
export interface InterServerEvents {}
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
export interface SocketData {}
export type SocketResponse<T = undefined> =
| (T extends undefined
? {
readonly success: true;
}
: {
readonly success: true;
readonly payload: T;
})
| {
readonly success: false;
readonly message: string;
readonly expected: boolean;
};