From ae51fa2a6b296785348f12859bb5f7aad18ac09c Mon Sep 17 00:00:00 2001 From: ARKALYK AKASH Date: Fri, 6 Apr 2018 09:46:34 +0200 Subject: [PATCH 1/4] setMute method and event handler added. --- README.md | 24 ++++++++++++++++++++++-- index.js | 11 +++++++++++ ios/RNCallKit/RNCallKit.m | 25 ++++++++++++++++++++++++- 3 files changed, 57 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 01a3213..6ab3821 100644 --- a/README.md +++ b/README.md @@ -124,7 +124,7 @@ continueUserActivity:(NSUserActivity *)userActivity - **ringtoneSound**: string (optional) - If provided, it will be played when incoming calls received; the system will use the default ringtone if this is not provided -Initialise RNCallKit with options +Initialize RNCallKit with options ### displayIncomingCall @@ -159,6 +159,13 @@ Call when you make an outgoing call Call when you finish an incoming/outgoing call +### setMutedCall + +- **uuid**: string +- **muted**: boolean + +Switch the mic on/off + ## Events ### - didReceiveStartCallAction @@ -217,6 +224,12 @@ Callback for `RNCallKit.displayIncomingCall` **error**: string (optional) +### - didPerformSetMutedCallAction + +A call was muted by the system or the user: + +**muted**: boolean + ## Usage ```javascript @@ -228,7 +241,7 @@ import uuid from 'uuid'; class RNCallKitExample extends React.Component { constructor(props) { - // Initialise RNCallKit + // Initialize RNCallKit let options = { appName: 'RNCallKitExample', imageName: 'my_image_name_in_bundle', @@ -246,6 +259,7 @@ class RNCallKitExample extends React.Component { RNCallKit.addEventListener('endCall', this.onRNCallKitPerformEndCallAction); RNCallKit.addEventListener('didActivateAudioSession', this.onRNCallKitDidActivateAudioSession); RNCallKit.addEventListener('didDisplayIncomingCall', this.onRNCallKitDidDisplayIncomingCall); + RNCallKit.addEventListener('didPerformSetMutedCallAction', this.onRNCallKitDidPerformSetMutedCallAction); } onRNCallKitDidReceiveStartCallAction(data) { @@ -292,6 +306,12 @@ class RNCallKitExample extends React.Component { */ } + onRNCallKitDidPerformSetMutedCallAction(muted) { + /* You will get this event after the system or the user mutes a call + * You can use it to toggle the mic on your custom call UI + */ + } + // This is a fake function where you can receive incoming call notifications onIncomingCall() { // Store the generated uuid somewhere diff --git a/index.js b/index.js index 51fbf71..77f5208 100644 --- a/index.js +++ b/index.js @@ -16,6 +16,7 @@ const RNCallKitPerformAnswerCallAction = 'RNCallKitPerformAnswerCallAction'; const RNCallKitPerformEndCallAction = 'RNCallKitPerformEndCallAction'; const RNCallKitDidActivateAudioSession = 'RNCallKitDidActivateAudioSession'; const RNCallKitDidDisplayIncomingCall = 'RNCallKitDidDisplayIncomingCall'; +const RNCallKitDidPerformSetMutedCallAction = 'RNCallKitDidPerformSetMutedCallAction'; export default class RNCallKit { static addEventListener(type, handler) { @@ -47,6 +48,11 @@ export default class RNCallKit { RNCallKitDidDisplayIncomingCall, (data) => { handler(data.error); } ); + } else if (type === 'didPerformSetMutedCallAction') { + listener = _RNCallKitEmitter.addListener( + RNCallKitDidPerformSetMutedCallAction, + (data) => { handler(data.muted); } + ); } _callkitEventHandlers.set(handler, listener); @@ -98,6 +104,11 @@ export default class RNCallKit { _RNCallKit.endAllCalls(); } + static setMutedCAll(uuid, muted) { + if (Platform.OS !== 'ios') return; + _RNCallKit.setMutedCall(uuid, muted); + } + /* static setHeldCall(uuid, onHold) { if (Platform.OS !== 'ios') return; diff --git a/ios/RNCallKit/RNCallKit.m b/ios/RNCallKit/RNCallKit.m index ff8d78e..787182c 100644 --- a/ios/RNCallKit/RNCallKit.m +++ b/ios/RNCallKit/RNCallKit.m @@ -23,6 +23,7 @@ static NSString *const RNCallKitPerformEndCallAction = @"RNCallKitPerformEndCallAction"; static NSString *const RNCallKitDidActivateAudioSession = @"RNCallKitDidActivateAudioSession"; static NSString *const RNCallKitDidDisplayIncomingCall = @"RNCallKitDidDisplayIncomingCall"; +static NSString *const RNCallKitDidPerformSetMutedCallAction = @"RNCallKitDidPerformSetMutedCallAction"; @implementation RNCallKit { @@ -65,7 +66,8 @@ - (void)dealloc RNCallKitPerformAnswerCallAction, RNCallKitPerformEndCallAction, RNCallKitDidActivateAudioSession, - RNCallKitDidDisplayIncomingCall + RNCallKitDidDisplayIncomingCall, + RNCallKitDidPerformSetMutedCallAction ]; } @@ -185,6 +187,18 @@ - (void)dealloc [self.callKitProvider reportOutgoingCallWithUUID:uuid connectedAtDate:[NSDate date]]; } +RCT_EXPORT_METHOD(setMutedCall:(NSString *)uuidString muted:(BOOL)muted) +{ +#ifdef DEBUG + NSLog(@"[RNCallKit][setMutedCall] muted = %i", muted); +#endif + NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:uuidString]; + CXSetMutedCallAction *setMutedAction = [[CXSetMutedCallAction alloc] initWithCallUUID:uuid muted:muted]; + CXTransaction *transaction = [[CXTransaction alloc] init]; + [transaction addAction:setMutedAction]; + + [self requestTransaction:transaction]; +} - (void)requestTransaction:(CXTransaction *)transaction { @@ -440,4 +454,13 @@ - (void)provider:(CXProvider *)provider didDeactivateAudioSession:(AVAudioSessio #endif } +-(void)provider:(CXProvider *)provider performSetMutedCallAction:(CXSetMutedCallAction *)action +{ +#ifdef DEBUG + NSLog(@"[RNCallKit][CXProviderDelegate][provider:performSetMutedCallAction]"); +#endif + [self sendEventWithName:RNCallKitDidPerformSetMutedCallAction body:@{ @"muted": @(action.muted) }]; + [action fulfill]; +} + @end From 49ade6742d7a795d37351ef5b19590a4d7b882f4 Mon Sep 17 00:00:00 2001 From: ARKALYK AKASH Date: Fri, 6 Apr 2018 10:02:47 +0200 Subject: [PATCH 2/4] version bumped. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9cc4618..8eb61f0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-callkit", - "version": "1.3.3", + "version": "1.3.4", "description": "iOS 10 CallKit Framework For React Native", "main": "index.js", "scripts": { From eb986fc7505a06de871b3d200aaac3f51d185db8 Mon Sep 17 00:00:00 2001 From: ARKALYK AKASH Date: Fri, 6 Apr 2018 11:37:41 +0200 Subject: [PATCH 3/4] back to Brittish :) --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6ab3821..813a190 100644 --- a/README.md +++ b/README.md @@ -124,7 +124,7 @@ continueUserActivity:(NSUserActivity *)userActivity - **ringtoneSound**: string (optional) - If provided, it will be played when incoming calls received; the system will use the default ringtone if this is not provided -Initialize RNCallKit with options +Initialise RNCallKit with options ### displayIncomingCall @@ -241,7 +241,7 @@ import uuid from 'uuid'; class RNCallKitExample extends React.Component { constructor(props) { - // Initialize RNCallKit + // Initialise RNCallKit let options = { appName: 'RNCallKitExample', imageName: 'my_image_name_in_bundle', From 9408c8909a97f1356997cc9ac816e54403da9e7b Mon Sep 17 00:00:00 2001 From: ARKALYK AKASH Date: Mon, 16 Apr 2018 10:14:05 +0200 Subject: [PATCH 4/4] rolled back to 1.3.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8eb61f0..9cc4618 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-callkit", - "version": "1.3.4", + "version": "1.3.3", "description": "iOS 10 CallKit Framework For React Native", "main": "index.js", "scripts": {