|
@@ -20,6 +20,9 @@
|
20
|
20
|
#import <React/RCTLog.h>
|
21
|
21
|
|
22
|
22
|
@interface AudioMode : NSObject<RCTBridgeModule>
|
|
23
|
+
|
|
24
|
+@property(nonatomic, strong) dispatch_queue_t workerQueue;
|
|
25
|
+
|
23
|
26
|
@end
|
24
|
27
|
|
25
|
28
|
@implementation AudioMode {
|
|
@@ -52,15 +55,18 @@ typedef enum {
|
52
|
55
|
if (self) {
|
53
|
56
|
_category = nil;
|
54
|
57
|
_mode = nil;
|
|
58
|
+
|
|
59
|
+ dispatch_queue_attr_t attributes =
|
|
60
|
+ dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL,
|
|
61
|
+ QOS_CLASS_USER_INITIATED, -1);
|
|
62
|
+ _workerQueue = dispatch_queue_create("WebRTCModule.queue", attributes);
|
55
|
63
|
}
|
56
|
64
|
return self;
|
57
|
65
|
}
|
58
|
66
|
|
59
|
67
|
- (dispatch_queue_t)methodQueue {
|
60
|
|
- // Make sure all our methods run in the main thread. The route change
|
61
|
|
- // notification runs there so this will make sure it will only be fired
|
62
|
|
- // after our changes have been applied (when we cause them, that is).
|
63
|
|
- return dispatch_get_main_queue();
|
|
68
|
+ // Use a dedicated queue for audio mode operations.
|
|
69
|
+ return _workerQueue;
|
64
|
70
|
}
|
65
|
71
|
|
66
|
72
|
- (void)routeChanged:(NSNotification*)notification {
|
|
@@ -70,12 +76,15 @@ typedef enum {
|
70
|
76
|
integerValue];
|
71
|
77
|
|
72
|
78
|
switch (reason) {
|
73
|
|
- case AVAudioSessionRouteChangeReasonCategoryChange:
|
|
79
|
+ case AVAudioSessionRouteChangeReasonCategoryChange: {
|
74
|
80
|
// The category has changed. Check if it's the one we want and adjust as
|
75
|
|
- // needed.
|
76
|
|
- [self setCategory:_category mode:_mode error:nil];
|
|
81
|
+ // needed. This notification is posted on a secondary thread, so make
|
|
82
|
+ // sure we switch to our worker thread.
|
|
83
|
+ dispatch_async(_workerQueue, ^{
|
|
84
|
+ [self setCategory:_category mode:_mode error:nil];
|
|
85
|
+ });
|
77
|
86
|
break;
|
78
|
|
-
|
|
87
|
+ }
|
79
|
88
|
default:
|
80
|
89
|
// Do nothing.
|
81
|
90
|
break;
|