@@ -14,6 +14,7 @@ @implementation FlutterWebRTCPlugin {
14
14
id _registry;
15
15
id _messenger;
16
16
id _textures;
17
+ BOOL _speakerOn;
17
18
}
18
19
19
20
@synthesize messenger = _messenger;
@@ -45,6 +46,7 @@ - (instancetype)initWithChannel:(FlutterMethodChannel *)channel
45
46
_registry = registrar;
46
47
_textures = textures;
47
48
_messenger = messenger;
49
+ _speakerOn = NO ;
48
50
self.viewController = viewController;
49
51
}
50
52
@@ -60,11 +62,31 @@ - (instancetype)initWithChannel:(FlutterMethodChannel *)channel
60
62
self.localStreams = [NSMutableDictionary new ];
61
63
self.localTracks = [NSMutableDictionary new ];
62
64
self.renders = [[NSMutableDictionary alloc ] init ];
65
+
66
+ [[NSNotificationCenter defaultCenter ] addObserver: self selector: @selector (didSessionRouteChange: ) name: AVAudioSessionRouteChangeNotification object: nil ];
67
+
63
68
return self;
64
69
}
65
70
71
+
72
+ - (void )didSessionRouteChange : (NSNotification *)notification {
73
+ NSDictionary *interuptionDict = notification.userInfo ;
74
+ NSInteger routeChangeReason = [[interuptionDict valueForKey: AVAudioSessionRouteChangeReasonKey] integerValue ];
75
+
76
+ switch (routeChangeReason) {
77
+ case AVAudioSessionRouteChangeReasonCategoryChange: {
78
+ NSError * error;
79
+ [[AVAudioSession sharedInstance ] overrideOutputAudioPort: _speakerOn? AVAudioSessionPortOverrideSpeaker : AVAudioSessionPortOverrideNone error: &error];
80
+ }
81
+ break ;
82
+
83
+ default :
84
+ break ;
85
+ }
86
+ }
87
+
66
88
- (void )handleMethodCall : (FlutterMethodCall*)call result : (FlutterResult) result {
67
-
89
+
68
90
if ([@" createPeerConnection" isEqualToString: call.method]) {
69
91
NSDictionary * argsMap = call.arguments ;
70
92
NSDictionary * configuration = argsMap[@" configuration" ];
@@ -466,9 +488,10 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult) result
466
488
} else if ([@" enableSpeakerphone" isEqualToString: call.method]) {
467
489
NSDictionary * argsMap = call.arguments ;
468
490
NSNumber * enable = argsMap[@" enable" ];
491
+ _speakerOn = enable.boolValue ;
469
492
AVAudioSession *audioSession = [AVAudioSession sharedInstance ];
470
493
[audioSession setCategory: AVAudioSessionCategoryPlayAndRecord
471
- withOptions: enable.boolValue ? AVAudioSessionCategoryOptionDefaultToSpeaker : 0
494
+ withOptions: _speakerOn ? AVAudioSessionCategoryOptionDefaultToSpeaker : 0
472
495
error: nil ];
473
496
[audioSession setActive: YES error: nil ];
474
497
result (nil );
0 commit comments