-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchannels.js
40 lines (36 loc) · 994 Bytes
/
channels.js
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
// CHANNELS
const CHANNEL_DATA_SUBSCRIBE = 'subscribe';
const CHANNEL_DATA_UNSUBSCRIBE = 'unsubscribe';
export default class Channels {
contructor() {
this._channels = {};
}
setupChannels(channelSetup) {
for (let remote of channelSetup.remote_channels) {
if (channelSetup.action === CHANNEL_DATA_SUBSCRIBE) {
this.addRemoteChannel(remote, channelSetup.local_channel);
}
if (channelSetup.action === CHANNEL_DATA_UNSUBSCRIBE) {
this.removeRemoteChannel(remote, channelSetup.local_channel);
}
}
}
addRemoteChannel(remote, local) {
if (remote in _channels) {
for (let remote_chan of this._channels) {
if (remote_chan === local) {
return;
}
}
this._channels[remote].push(local);
} else {
this._channels[remote] = [local];
}
}
removeRemoteChannel(remote) {
delete this._channels[remote];
}
getLocalChannels(remote) {
return this._channels[remote];
}
}