-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathStringeeCall2.js
More file actions
117 lines (96 loc) · 3.2 KB
/
StringeeCall2.js
File metadata and controls
117 lines (96 loc) · 3.2 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
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 RNStringeeCall2 = NativeModules.RNStringeeCall2;
const iOS = Platform.OS === "ios" ? true : false;
export default class extends Component {
static propTypes = {
eventHandlers: PropTypes.object
};
constructor(props) {
super(props);
this._events = [];
this._subscriptions = [];
this._eventEmitter = new NativeEventEmitter(RNStringeeCall2);
this.sanitizeCallEvents(this.props.eventHandlers);
}
componentWillUnmount() {
this._unregisterEvents();
}
render() {
return null;
}
_unregisterEvents() {
this._subscriptions.forEach(e => e.remove());
this._subscriptions = [];
this._events.forEach(e => RNStringeeCall2.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);
RNStringeeCall2.setNativeEvent(eventName);
} else {
console.log(`${type} is not a supported event`);
}
});
}
makeCall(parameters: string, callback: RNStringeeEventCallback) {
RNStringeeCall2.makeCall(parameters, callback);
}
initAnswer(callId: string, callback: RNStringeeEventCallback) {
RNStringeeCall2.initAnswer(callId, callback);
}
answer(callId: string, callback: RNStringeeEventCallback) {
RNStringeeCall2.answer(callId, callback);
}
hangup(callId: string, callback: RNStringeeEventCallback) {
RNStringeeCall2.hangup(callId, callback);
}
reject(callId: string, callback: RNStringeeEventCallback) {
RNStringeeCall2.reject(callId, callback);
}
switchCamera(callId: string, callback: RNStringeeEventCallback) {
RNStringeeCall2.switchCamera(callId, callback);
}
enableVideo(
callId: string,
enabled: boolean,
callback: RNStringeeEventCallback
) {
RNStringeeCall2.enableVideo(callId, enabled, callback);
}
mute(callId: string, mute: boolean, callback: RNStringeeEventCallback) {
RNStringeeCall2.mute(callId, mute, callback);
}
setSpeakerphoneOn(
callId: string,
on: boolean,
callback: RNStringeeEventCallback
) {
RNStringeeCall2.setSpeakerphoneOn(callId, on, callback);
}
resumeVideo(
callId: string,
callback: RNStringeeEventCallback
) {
if (iOS) {
console.log('this function only for android');
} else {
RNStringeeCall2.resumeVideo(callId, callback);
}
}
}