-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.ts
70 lines (56 loc) · 1.46 KB
/
example.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
import { makeSocketRoomConnector } from "./client";
const initialState = {
happy: 4,
people: [] as string[]
};
const initalSocketData = {
name: ""
}
const receiver = {
setRole: (role: string) => {
},
update: () => {
}
};
const a = makeSocketRoomConnector(
receiver,
(manager) => ({
getRole: (callback: (role: string) => void) => {
const { people } = manager.getState();
const newPerson = "someone else";
manager.setElement("people", [...people, newPerson]);
callback(newPerson);
manager.toSender("update");
manager.setSenderData({
name: "Role"
});
},
init: (x: number) => {
manager.toSender("update");
//manager.setState("")
},
onJoin: () => {
const { people } = manager.getState();
manager.setSenderData({ name: people[0] });
manager.toSender("setRole", "captain");
manager.toRoomExcludingSender();
}
}),
initialState,
initalSocketData
);
a.startRoom("secret123", (code) => {
a.getRoomState().people;
console.log(code);
});
a.toRoomManager("getRole", (role: string) => {
});
a.joinRoom("334", "secret123", (state) => {
if (!state.success) {
// handler error
return;
}
const { value } = state;
})
a.toRoomManager("init", 4);
const role = await a.toRoomManagerAsync("getRole");