Skip to content
This repository was archived by the owner on May 26, 2019. It is now read-only.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ Switch the mic on/off

Checks if there are any active calls on the device and returns a promise with a boolean value (`true` if there're active calls, `false` otherwise).

### checkSpeaker

Checks if the device speaker is on and returns a promise with a boolean value (`true` if speaker is on, `false` otherwise).

## Events

### - didReceiveStartCallAction
Expand Down
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ export default class RNCallKit {
: 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;
Expand Down
11 changes: 11 additions & 0 deletions ios/RNCallKit/RNCallKit.m
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,17 @@ - (void)dealloc
resolve(@(self.callKitCallController.callObserver.calls.count > 0));
}

RCT_REMAP_METHOD(checkSpeaker,
checkSpeakerResolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)
{
#ifdef DEBUG
NSLog(@"[RNCallKit][checkSpeaker]");
#endif
NSString *output = [AVAudioSession sharedInstance].currentRoute.outputs.count > 0 ? [AVAudioSession sharedInstance].currentRoute.outputs[0].portType : nil;
resolve(@([output isEqualToString:@"Speaker"]));
}

#pragma mark - CXCallController call actions

// Display the incoming call to the user
Expand Down