forked from hpi-sam/digital-fuesim-manv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
socket-types.ts
42 lines (37 loc) · 1.17 KB
/
socket-types.ts
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
import type { ExerciseState } from '../state';
import type { ExerciseAction } from '../store';
import type { UUID } from '../utils';
export interface ServerToClientEvents {
performAction: (action: ExerciseAction) => 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: (
exerciseId: string,
clientName: string,
callback: (response: SocketResponse<UUID>) => void
) => void;
proposeAction: (
action: ExerciseAction,
callback: (response: SocketResponse) => void
) => void;
getState: (
callback: (response: SocketResponse<ExerciseState>) => void
) => void;
}
export interface InterServerEvents {}
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;
};