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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import AppDispatcher from 'dispatcher/app_dispatcher.jsx';
import EventEmitter from 'events';
import {WebrtcActionTypes} from 'utils/constants.jsx';
class WebrtcStoreClass extends EventEmitter {
constructor() {
super();
this.video_call_with = null;
}
setVideoCallWith(userId) {
this.video_call_with = userId;
this.emitBusy(userId !== null);
}
getVideoCallWith() {
return this.video_call_with;
}
isBusy() {
return this.video_call_with !== null;
}
emitInit(userId, isCaller) {
this.emit(WebrtcActionTypes.INITIALIZE, userId, isCaller);
}
addInitListener(callback) {
this.on(WebrtcActionTypes.INITIALIZE, callback);
}
removeInitListener(callback) {
this.removeListener(WebrtcActionTypes.INITIALIZE, callback);
}
emitBusy(isBusy) {
this.emit(WebrtcActionTypes.BUSY, isBusy);
}
addBusyListener(callback) {
this.on(WebrtcActionTypes.BUSY, callback);
}
removeBusyListener(callback) {
this.removeListener(WebrtcActionTypes.BUSY, callback);
}
emitNotify(message) {
this.emit(WebrtcActionTypes.NOTIFY, message);
}
addNotifyListener(callback) {
this.on(WebrtcActionTypes.NOTIFY, callback);
}
removeNotifyListener(callback) {
this.removeListener(WebrtcActionTypes.NOTIFY, callback);
}
emitChanged(message) {
this.emit(WebrtcActionTypes.CHANGED, message);
}
addChangedListener(callback) {
this.on(WebrtcActionTypes.CHANGED, callback);
}
removeChangedListener(callback) {
this.removeListener(WebrtcActionTypes.CHANGED, callback);
}
emitRhsChanged(isOpen) {
this.emit(WebrtcActionTypes.RHS, isOpen);
}
addRhsChangedListener(callback) {
this.on(WebrtcActionTypes.RHS, callback);
}
removeRhsChangedListener(callback) {
this.removeListener(WebrtcActionTypes.RHS, callback);
}
}
var WebrtcStore = new WebrtcStoreClass();
WebrtcStore.setMaxListeners(0);
WebrtcStore.dispatchToken = AppDispatcher.register((payload) => {
var action = payload.action;
switch (action.type) {
case WebrtcActionTypes.INITIALIZE:
WebrtcStore.emitInit(action.user_id, action.is_calling);
break;
case WebrtcActionTypes.NOTIFY:
WebrtcStore.emitNotify(action.message);
break;
default:
if (action.message) {
WebrtcStore.emitChanged(action.message);
}
break;
}
});
export default WebrtcStore;
|