forked from stringeecom/stringee-react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringeeCall.js
More file actions
executable file
·123 lines (100 loc) · 3.05 KB
/
StringeeCall.js
File metadata and controls
executable file
·123 lines (100 loc) · 3.05 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
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";
const RNStringeeCall = NativeModules.RNStringeeCall;
export default class extends Component {
static propTypes = {
eventHandlers: PropTypes.object
};
constructor(props) {
super(props);
this._events = [];
this._subscriptions = [];
this._eventEmitter = new NativeEventEmitter(RNStringeeCall);
}
componentWillMount() {
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 => {
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(parameters, callback);
}
initAnswer(callId: string, callback: RNStringeeEventCallback) {
RNStringeeCall.initAnswer(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(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);
}
}