forked from react-native-webrtc/react-native-callkit
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
90 lines (79 loc) · 2.93 KB
/
index.js
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
'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';
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,
() => { handler();}
);
} else if (type === 'endCall') {
listener = _RNCallKitEmitter.addListener(
RNCallKitPerformEndCallAction,
() => { handler(); }
);
} else if (type === 'didActivateAudioSession') {
listener = _RNCallKitEmitter.addListener(
RNCallKitDidActivateAudioSession,
() => { handler(); }
);
}
_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) {
if (Platform.OS !== 'ios') return;
_RNCallKit.displayIncomingCall(uuid, handle, handleType, hasVideo);
}
static startCall(uuid, handle, handleType = 'number', hasVideo = false) {
if (Platform.OS !== 'ios') return;
_RNCallKit.startCall(uuid, handle, handleType, hasVideo);
}
static endCall(uuid) {
if (Platform.OS !== 'ios') return;
_RNCallKit.endCall(uuid);
}
/*
static setHeldCall(uuid, onHold) {
if (Platform.OS !== 'ios') return;
_RNCallKit.setHeldCall(uuid, onHold);
}
*/
}