-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
89 lines (77 loc) · 1.96 KB
/
index.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
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 usePartyHost from './host'
import usePartyGuest from './guest'
import { withRandom, shuffle } from './random'
import { withSecret } from './secret'
export type PeerId = string
export type Args = any
export type State = any
export type Secret = string
export type ConnectionStatus = boolean
export interface SimpleMoveArgs {
state: State
args: Args
callerId: PeerId
hostId: PeerId
}
export type RandomNumberGenerator = () => number
export interface RandomArgsMixin {
random: RandomNumberGenerator
}
export interface RandomMoveArgs extends SimpleMoveArgs, RandomArgsMixin {}
export type RevealSecretFunction = (
contextId: PeerId,
extractionFunction: (state: State) => State
) => any
export interface SecretArgsMixin {
contextId: PeerId
revealSecret: RevealSecretFunction
}
export interface SecretMoveArgs extends SimpleMoveArgs, SecretArgsMixin {}
export interface RandomSecretMoveArgs
extends SimpleMoveArgs,
SecretArgsMixin,
RandomArgsMixin {}
export type SimpleMove = {
_isSecret?: false
_isRandom?: false
(args: SimpleMoveArgs): State
}
export type SecretMove = {
_isSecret: true
_isRandom?: false
(args: SecretMoveArgs): State
}
export type RandomMove = {
_isSecret?: false
_isRandom: true
(args: RandomMoveArgs): State
}
export type RandomSecretMove = {
_isSecret: true
_isRandom: true
(args: RandomSecretMoveArgs): State
}
export type Move = SimpleMove | SecretMove | RandomMove | RandomSecretMove
export type Moves = { [key: string]: Move }
export type Game = Moves
export interface UsePartyHostArgs {
roomId: PeerId
game: Game
secret?: Secret
}
export interface UsePartyHostReturn {
state: State
moves: Moves | null
connections: PeerId[]
}
export interface UsePartyGuestArgs {
roomId: PeerId
game: Game
}
export interface UsePartyGuestReturn {
connectionId: PeerId
connected: ConnectionStatus
state: State
moves: Moves | null
}
export { usePartyHost, usePartyGuest, withRandom, shuffle, withSecret }