-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathpubsub.ts
28 lines (22 loc) · 814 Bytes
/
pubsub.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
import { nrp } from "./data";
import { StreamMessage } from "./proto/randomPackage/StreamMessage";
import { User } from "./proto/randomPackage/User";
const REDIS_CHANNELS = {
mainRoom: "MAIN_ROOM",
userChange: "USER_CHAHNGE",
};
const emitMainRoomChatUpdate = (msg: StreamMessage) =>
nrp.emit(REDIS_CHANNELS.mainRoom, JSON.stringify(msg));
const listenMainRoomChatUpdate = (
fn: (data: string, channel: string) => void
) => nrp.on(REDIS_CHANNELS.mainRoom, fn);
const emitUserUpdateEvent = (user: User) =>
nrp.emit(REDIS_CHANNELS.userChange, JSON.stringify(user));
const listenUserUpdateEvent = (fn: (data: string, channel: string) => void) =>
nrp.on(REDIS_CHANNELS.userChange, fn);
export {
emitMainRoomChatUpdate,
listenMainRoomChatUpdate,
emitUserUpdateEvent,
listenUserUpdateEvent,
};