-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathStringeeCall.js
More file actions
executable file
·153 lines (128 loc) · 4.26 KB
/
StringeeCall.js
File metadata and controls
executable file
·153 lines (128 loc) · 4.26 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
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import {Component} from 'react';
import PropTypes from 'prop-types';
import {NativeModules, NativeEventEmitter, Platform} from 'react-native';
import {callEvents} from './helpers/StringeeHelper';
import {each} from 'underscore';
import type {RNStringeeEventCallback} from './helpers/StringeeHelper';
const RNStringeeCall = NativeModules.RNStringeeCall;
export default class extends Component {
static propTypes = {
eventHandlers: PropTypes.object,
clientId: PropTypes.string,
};
constructor(props) {
super(props);
this._events = [];
this._subscriptions = [];
this._eventEmitter = new NativeEventEmitter(RNStringeeCall);
this.makeCall = this.makeCall.bind(this);
this.initAnswer = this.initAnswer.bind(this);
this.answer = this.answer.bind(this);
this.hangup = this.hangup.bind(this);
this.reject = this.reject.bind(this);
this.sendDTMF = this.sendDTMF.bind(this);
this.sendCallInfo = this.sendCallInfo.bind(this);
this.getCallStats = this.getCallStats.bind(this);
this.switchCamera = this.switchCamera.bind(this);
this.enableVideo = this.enableVideo.bind(this);
this.mute = this.mute.bind(this);
this.setSpeakerphoneOn = this.setSpeakerphoneOn.bind(this);
this.resumeVideo = this.resumeVideo.bind(this);
}
componentDidMount() {
this.sanitizeCallEvents(this.props.eventHandlers);
}
componentWillUnmount() {
this._unregisterEvents();
}
render() {
return null;
}
_unregisterEvents() {
this._subscriptions.forEach(e => e.remove());
this._subscriptions = [];
this._events.forEach(e => RNStringeeCall.removeNativeEvent(e));
this._events = [];
}
sanitizeCallEvents(events) {
if (typeof events !== 'object') {
return;
}
const platform = Platform.OS;
each(events, (handler, type) => {
const eventName = callEvents[platform][type];
if (eventName !== undefined) {
this._subscriptions.push(
this._eventEmitter.addListener(eventName, data => {
if (handler !== undefined) {
// const eventType = data.eventType;
// if (data.eventType === 'StringeeCall') {
handler(data);
// }
}
}),
);
this._events.push(eventName);
RNStringeeCall.setNativeEvent(eventName);
} else {
console.log(`${type} is not a supported event`);
}
});
}
makeCall(parameters: string, callback: RNStringeeEventCallback) {
RNStringeeCall.makeCall(this.props.clientId, parameters, callback);
}
initAnswer(callId: string, callback: RNStringeeEventCallback) {
RNStringeeCall.initAnswer(this.props.clientId, callId, callback);
}
answer(callId: string, callback: RNStringeeEventCallback) {
RNStringeeCall.answer(callId, callback);
}
hangup(callId: string, callback: RNStringeeEventCallback) {
RNStringeeCall.hangup(callId, callback);
}
reject(callId: string, callback: RNStringeeEventCallback) {
RNStringeeCall.reject(callId, callback);
}
sendDTMF(callId: string, dtmf: string, callback: RNStringeeEventCallback) {
RNStringeeCall.sendDTMF(callId, dtmf, callback);
}
sendCallInfo(
callId: string,
callInfo: string,
callback: RNStringeeEventCallback,
) {
RNStringeeCall.sendCallInfo(callId, callInfo, callback);
}
getCallStats(callId: string, callback: RNStringeeEventCallback) {
RNStringeeCall.getCallStats(this.props.clientId, callId, callback);
}
switchCamera(callId: string, callback: RNStringeeEventCallback) {
RNStringeeCall.switchCamera(callId, callback);
}
enableVideo(
callId: string,
enabled: boolean,
callback: RNStringeeEventCallback,
) {
RNStringeeCall.enableVideo(callId, enabled, callback);
}
mute(callId: string, mute: boolean, callback: RNStringeeEventCallback) {
RNStringeeCall.mute(callId, mute, callback);
}
setSpeakerphoneOn(
callId: string,
on: boolean,
callback: RNStringeeEventCallback,
) {
RNStringeeCall.setSpeakerphoneOn(callId, on, callback);
}
resumeVideo(callId: string, callback: RNStringeeEventCallback) {
const platform = Platform.OS;
if (platform === 'ios') {
console.log('this function only for android');
} else {
RNStringeeCall.resumeVideo(callId, callback);
}
}
}