forked from sendbird/sendbird-javascript-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSendBirdEvent.js
More file actions
52 lines (47 loc) · 1.27 KB
/
Copy pathSendBirdEvent.js
File metadata and controls
52 lines (47 loc) · 1.27 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
import SendBird from 'sendbird';
import { uuid4 } from './utils';
class SendBirdEvent {
constructor() {
this.sb = SendBird.getInstance();
this.key = uuid4();
this._createChannelHandler();
this.onChannelChanged = null;
this.onUserJoined = null;
this.onUserLeft = null;
this.onChannelHidden = null;
this.onUserEntered = null;
}
_createChannelHandler() {
const handler = new this.sb.ChannelHandler();
handler.onChannelChanged = channel => {
if (this.onChannelChanged) {
this.onChannelChanged(channel);
}
};
handler.onUserJoined = (groupChannel, user) => {
if (this.onUserJoined) {
this.onUserJoined(groupChannel, user);
}
};
handler.onUserLeft = (groupChannel, user) => {
if (this.onUserLeft) {
this.onUserLeft(groupChannel, user);
}
};
handler.onChannelHidden = groupChannel => {
if (this.onChannelHidden) {
this.onChannelHidden(groupChannel);
}
};
handler.onUserEntered = (openChannel, user) => {
if (this.onUserEntered) {
this.onUserEntered(openChannel, user);
}
};
this.sb.addChannelHandler(this.key, handler);
}
remove() {
this.sb.removeChannelHandler(this.key);
}
}
export { SendBirdEvent };