forked from react-native-webrtc/react-native-callkit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
137 lines (118 loc) · 4.61 KB
/
index.js
File metadata and controls
137 lines (118 loc) · 4.61 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
'use strict';
import {
NativeModules,
NativeEventEmitter,
Platform,
} from 'react-native';
const _RNCallKit = NativeModules.RNCallKit;
const _RNCallKitEmitter = new NativeEventEmitter(_RNCallKit);
const _callkitEventHandlers = new Map();
const RNCallKitDidReceiveStartCallAction = 'RNCallKitDidReceiveStartCallAction';
const RNCallKitPerformAnswerCallAction = 'RNCallKitPerformAnswerCallAction';
const RNCallKitPerformEndCallAction = 'RNCallKitPerformEndCallAction';
const RNCallKitDidActivateAudioSession = 'RNCallKitDidActivateAudioSession';
const RNCallKitDidDisplayIncomingCall = 'RNCallKitDidDisplayIncomingCall';
const RNCallKitDidPerformSetMutedCallAction = 'RNCallKitDidPerformSetMutedCallAction';
export default class RNCallKit {
static addEventListener(type, handler) {
if (Platform.OS !== 'ios') return;
var listener;
if (type === 'didReceiveStartCallAction') {
listener = _RNCallKitEmitter.addListener(
RNCallKitDidReceiveStartCallAction,
(data) => { handler(data);}
);
_RNCallKit._startCallActionEventListenerAdded();
} else if (type === 'answerCall') {
listener = _RNCallKitEmitter.addListener(
RNCallKitPerformAnswerCallAction,
(data) => { handler(data);}
);
} else if (type === 'endCall') {
listener = _RNCallKitEmitter.addListener(
RNCallKitPerformEndCallAction,
(data) => { handler(data); }
);
} else if (type === 'didActivateAudioSession') {
listener = _RNCallKitEmitter.addListener(
RNCallKitDidActivateAudioSession,
() => { handler(); }
);
} else if (type === 'didDisplayIncomingCall') {
listener = _RNCallKitEmitter.addListener(
RNCallKitDidDisplayIncomingCall,
(data) => { handler(data.error); }
);
} else if (type === 'didPerformSetMutedCallAction') {
listener = _RNCallKitEmitter.addListener(
RNCallKitDidPerformSetMutedCallAction,
(data) => { handler(data.muted); }
);
}
_callkitEventHandlers.set(handler, listener);
}
static removeEventListener(type, handler) {
if (Platform.OS !== 'ios') return;
var listener = _callkitEventHandlers.get(handler);
if (!listener) {
return;
}
listener.remove();
_callkitEventHandlers.delete(handler);
}
static setup(options) {
if (Platform.OS !== 'ios') return;
if (!options.appName) {
throw new Error('RNCallKit.setup: option "appName" is required');
}
if (typeof options.appName !== 'string') {
throw new Error('RNCallKit.setup: option "appName" should be of type "string"');
}
_RNCallKit.setup(options);
}
static displayIncomingCall(uuid, handle, handleType = 'number', hasVideo = false, localizedCallerName?: String) {
if (Platform.OS !== 'ios') return;
_RNCallKit.displayIncomingCall(uuid, handle, handleType, hasVideo, localizedCallerName);
}
static startCall(uuid, handle, handleType = 'number', hasVideo = false, contactIdentifier?: String) {
if (Platform.OS !== 'ios') return;
_RNCallKit.startCall(uuid, handle, handleType, hasVideo, contactIdentifier);
}
static reportConnectedOutgoingCallWithUUID(uuid) {
if (Platform.OS !== 'ios') return;
_RNCallKit.reportConnectedOutgoingCallWithUUID(uuid);
}
static endCall(uuid) {
if (Platform.OS !== 'ios') return;
_RNCallKit.endCall(uuid);
}
static endAllCalls() {
if (Platform.OS !== 'ios') return;
_RNCallKit.endAllCalls();
}
static checkIfInCall(uuid) {
return Platform.OS === 'ios' ?
_RNCallKit.checkIfInCall(uuid) :
Promise.reject('RNCallKit.checkIfInCall was called from unsupported OS');
}
static setMutedCAll(uuid, muted) {
if (Platform.OS !== 'ios') return;
_RNCallKit.setMutedCall(uuid, muted);
}
static checkIfBusy() {
return Platform.OS === 'ios'
? _RNCallKit.checkIfBusy()
: Promise.reject('RNCallKit.checkIfBusy was called from unsupported OS');
};
static checkSpeaker() {
return Platform.OS === 'ios'
? _RNCallKit.checkSpeaker()
: Promise.reject('RNCallKit.checkSpeaker was called from unsupported OS');
}
/*
static setHeldCall(uuid, onHold) {
if (Platform.OS !== 'ios') return;
_RNCallKit.setHeldCall(uuid, onHold);
}
*/
}