Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimized code #30

Open
wants to merge 1 commit 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
40 changes: 34 additions & 6 deletions ios/Classes/FlutterCallKitPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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;

Expand Down
16 changes: 8 additions & 8 deletions lib/flutter_call_kit.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'dart:async';
import 'dart:io';

import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
Expand Down Expand Up @@ -195,8 +194,8 @@ class FlutterCallKit {
if (_onProviderReset == null) {
return null;
}
return _onProviderReset!();
case "performAnswerCallAction":
return _onProviderReset();
case "onPerformAnswerCallAction":
if (_performAnswerCallAction == null) {
return null;
}
Expand Down Expand Up @@ -301,9 +300,6 @@ class FlutterCallKit {
}

Future<void> reportConnectingOutgoingCallWithUUID(String uuid) async {
if (!Platform.isIOS) {
return;
}
await _channel.invokeMethod<void>(
'reportConnectingOutgoingCallWithUUID', uuid);
}
Expand Down Expand Up @@ -374,7 +370,7 @@ class FlutterCallKit {
}
await _channel.invokeMethod<void>('setMutedCall', {
'uuid': uuid,
'mute': mute,
'muted': mute,
});
}

Expand Down Expand Up @@ -426,7 +422,7 @@ class FlutterCallKit {
if (!Platform.isIOS) {
return;
}
await _channel.invokeMethod<void>('setMutedCall', {
await _channel.invokeMethod<void>('setOnHoldCall', {
'uuid': uuid,
'hold': hold,
});
Expand All @@ -439,6 +435,10 @@ class FlutterCallKit {
await _channel.invokeMethod<void>('setReachable');
}

Future<void> enableSpeaker(bool enable) async {
await _channel.invokeMethod<void>('enableSpeaker', {'enable': enable});
}

static String handleTypeToString(HandleType handleType) {
switch (handleType) {
case HandleType.generic:
Expand Down