diff --git a/ios/Classes/FlutterCallKitPlugin.m b/ios/Classes/FlutterCallKitPlugin.m index 7ec8213e..156f6629 100644 --- a/ios/Classes/FlutterCallKitPlugin.m +++ b/ios/Classes/FlutterCallKitPlugin.m @@ -10,7 +10,7 @@ static NSString *const kHandleStartCallNotification = @"handleStartCallNotification"; static NSString *const kDidReceiveStartCallAction = @"didReceiveStartCallAction"; -static NSString *const kPerformAnswerCallAction = @"performAnswerCallAction"; +static NSString *const kPerformAnswerCallAction = @"onPerformAnswerCallAction"; static NSString *const kPerformEndCallAction = @"performEndCallAction"; static NSString *const kDidActivateAudioSession = @"didActivateAudioSession"; static NSString *const kDidDeactivateAudioSession = @"didDeactivateAudioSession"; @@ -117,8 +117,10 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result { [self setMutedCall:call.arguments result:result]; }else if ([@"updateDisplay" isEqualToString:method]) { [self updateDisplay:call.arguments result:result]; - }else if ([@"setOnHold" isEqualToString:method]) { + }if ([@"setOnHoldCall" isEqualToString:method]) { [self setOnHold:call.arguments result:result]; + }if ([@"enableSpeaker" isEqualToString:method]) { + [self enableSpeaker:call.arguments result:result]; }else { result(FlutterMethodNotImplemented); } @@ -224,6 +226,32 @@ - (void)setOnHold:(NSDictionary *)arguments result:(FlutterResult)result [self requestTransaction:transaction result:result]; } +- (void)enableSpeaker:(NSDictionary *)arguments result:(FlutterResult)result +{ + NSNumber* enable = arguments[@"enable"]; +#ifdef DEBUG + NSLog(@"[FlutterCallKitPlugin][enableSpeaker] enableSpeaker = %d", [enable boolValue]); +#endif + AVAudioSession* audioSession = [AVAudioSession sharedInstance]; + [audioSession setCategory:AVAudioSessionCategoryPlayAndRecord withOptions: + AVAudioSessionCategoryOptionAllowBluetooth| + AVAudioSessionCategoryOptionAllowBluetoothA2DP error:nil]; + [audioSession setMode:AVAudioSessionModeVoiceChat error:nil]; + + double sampleRate = 44100.0; + [audioSession setPreferredSampleRate:sampleRate error:nil]; + + NSTimeInterval bufferDuration = .005; + [audioSession setPreferredIOBufferDuration:bufferDuration error:nil]; + + NSError* error; + [audioSession overrideOutputAudioPort:enable.boolValue ? AVAudioSessionPortOverrideSpeaker : AVAudioSessionPortOverrideNone error:&error]; + if(error != nil){ + NSLog(@"[FlutterCallKitPlugin][enableSpeaker] error = %@",error ); + } + [audioSession setActive:TRUE error:nil]; +} + - (void)reportConnectingOutgoingCallWithUUID:(NSString *)uuidString result:(FlutterResult)result { NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:uuidString]; @@ -512,10 +540,10 @@ + (void)reportNewIncomingCall:(NSString *)uuidString NSLog(@"[FlutterCallKitPlugin][reportNewIncomingCall] uuid = %@", uuid ); CXCallUpdate *callUpdate = [[CXCallUpdate alloc] init]; callUpdate.remoteHandle = [[CXHandle alloc] initWithType:_handleType value:handle]; - callUpdate.supportsDTMF = YES; - callUpdate.supportsHolding = YES; - callUpdate.supportsGrouping = YES; - callUpdate.supportsUngrouping = YES; + callUpdate.supportsDTMF = NO; + callUpdate.supportsHolding = NO; + callUpdate.supportsGrouping = NO; + callUpdate.supportsUngrouping = NO; callUpdate.hasVideo = hasVideo; callUpdate.localizedCallerName = localizedCallerName; diff --git a/lib/flutter_call_kit.dart b/lib/flutter_call_kit.dart index f1ebc0ce..805d7a4f 100644 --- a/lib/flutter_call_kit.dart +++ b/lib/flutter_call_kit.dart @@ -1,5 +1,4 @@ import 'dart:async'; -import 'dart:io'; import 'package:flutter/services.dart'; import 'package:flutter/widgets.dart'; @@ -195,8 +194,8 @@ class FlutterCallKit { if (_onProviderReset == null) { return null; } - return _onProviderReset!(); - case "performAnswerCallAction": + return _onProviderReset(); + case "onPerformAnswerCallAction": if (_performAnswerCallAction == null) { return null; } @@ -301,9 +300,6 @@ class FlutterCallKit { } Future reportConnectingOutgoingCallWithUUID(String uuid) async { - if (!Platform.isIOS) { - return; - } await _channel.invokeMethod( 'reportConnectingOutgoingCallWithUUID', uuid); } @@ -374,7 +370,7 @@ class FlutterCallKit { } await _channel.invokeMethod('setMutedCall', { 'uuid': uuid, - 'mute': mute, + 'muted': mute, }); } @@ -426,7 +422,7 @@ class FlutterCallKit { if (!Platform.isIOS) { return; } - await _channel.invokeMethod('setMutedCall', { + await _channel.invokeMethod('setOnHoldCall', { 'uuid': uuid, 'hold': hold, }); @@ -439,6 +435,10 @@ class FlutterCallKit { await _channel.invokeMethod('setReachable'); } + Future enableSpeaker(bool enable) async { + await _channel.invokeMethod('enableSpeaker', {'enable': enable}); + } + static String handleTypeToString(HandleType handleType) { switch (handleType) { case HandleType.generic: