Skip to content
This repository has been archived by the owner on May 26, 2019. It is now read-only.

If applied, this commit will add a function check if device in call #65

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 50 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,59 @@

import {
NativeModules,
NativeEventEmitter,
Platform,
} from 'react-native';

import { listeners } from './actions'

const _RNCallKit = NativeModules.RNCallKit;
const _RNCallKitEmitter = new NativeEventEmitter(_RNCallKit);

const _callkitEventHandlers = new Map();

export default class RNCallKit {
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;
const listener = listeners[type](handler)
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);
}

Expand Down Expand Up @@ -65,6 +104,13 @@ export default class RNCallKit {
_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);
Expand Down
35 changes: 34 additions & 1 deletion ios/RNCallKit/RNCallKit.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
static NSString *const RNCallKitDidActivateAudioSession = @"RNCallKitDidActivateAudioSession";
static NSString *const RNCallKitDidDisplayIncomingCall = @"RNCallKitDidDisplayIncomingCall";
static NSString *const RNCallKitDidPerformSetMutedCallAction = @"RNCallKitDidPerformSetMutedCallAction";
static NSString *const RNCallKitCheckIfInCallAction = @"RNCallKitCheckIfInCallAction";

@implementation RNCallKit
{
Expand Down Expand Up @@ -67,7 +68,8 @@ - (void)dealloc
RNCallKitPerformEndCallAction,
RNCallKitDidActivateAudioSession,
RNCallKitDidDisplayIncomingCall,
RNCallKitDidPerformSetMutedCallAction
RNCallKitDidPerformSetMutedCallAction,
RNCallKitCheckIfInCallAction
];
}

Expand Down Expand Up @@ -184,6 +186,37 @@ - (void)dealloc
}
}


// check If In Call
RCT_EXPORT_METHOD(checkIfInCall:(NSString *)uuidString
checkIfInCallWithResolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)
{
int flag = 0;
@try {
for (CXCall *call in self.callKitCallController.callObserver.calls) {
NSString *callUid = [call.UUID UUIDString];
NSLog(@"[RNCallKit][checkIfInCall] call UUID = %@", call.UUID);
NSLog(@"[RNCallKit][checkIfInCall] call Ended = %d", call.hasEnded);
NSLog(@"[RNCallKit][checkIfInCall] My Call %d", [uuidString isEqualToString:callUid]);
if (call.hasEnded == false && ![uuidString isEqualToString:callUid]) {
flag = 1;
break;
}
}
if(flag == 1) {
resolve(@{@"inCall": @YES});
} else {
resolve(@{@"inCall": @NO});
}
}
@catch (NSException *exception) {
NSLog(@"[RNCallKit][checkIfInCall] exception %@", exception.reason);
}
}
//


RCT_EXPORT_METHOD(setHeldCall:(NSString *)uuidString onHold:(BOOL)onHold)
{
#ifdef DEBUG
Expand Down