Skip to content

Commit 8b0a6ae

Browse files
committed
Add logs + replace try/catch block with error logging (exceptions are disabled by default in IOS Unity builds)
1 parent b569bf0 commit 8b0a6ae

File tree

1 file changed

+69
-66
lines changed
  • Assets/Samples/Stream Video & Audio Chat SDK/0.7.0/Video & Audio Chat Example Project/Plugins/iOS

1 file changed

+69
-66
lines changed

Assets/Samples/Stream Video & Audio Chat SDK/0.7.0/Video & Audio Chat Example Project/Plugins/iOS/AudioSessionMonitor.mm

Lines changed: 69 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,26 @@ - (void)prepareAudioSessionForRecording {
4141

4242
if(@available(iOS 10.0, *)){
4343
options |= AVAudioSessionCategoryOptionAllowBluetoothA2DP;
44+
} else {
45+
NSLog(@"[Stream] Add option AVAudioSessionCategoryOptionAllowBluetoothA2DP");
4446
}
4547

4648
BOOL success = [audioSession setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:options error:&error];
4749

4850
if(!success){
49-
NSLog(@"Error setting audio session category: %@", error.localizedDescription);
51+
NSLog(@"[Stream] Error setting audio session category: %@", error.localizedDescription);
52+
} else {
53+
NSLog(@"[Stream] Success in setCategory");
5054
}
5155

5256
// Set audio session mode
5357
if(@available(iOS 5.0, *)){
5458
success = [audioSession setMode:AVAudioSessionModeVideoChat error:&error];
5559

5660
if(!success){
57-
NSLog(@"Error setting audio session category: %@", error.localizedDescription);
61+
NSLog(@"[Stream] Error setting audio session category: %@", error.localizedDescription);
62+
} else {
63+
NSLog(@"[Stream] Success in setMod:AVAudioSessionModeVideoChate");
5864
}
5965
}
6066

@@ -63,22 +69,22 @@ - (void)prepareAudioSessionForRecording {
6369
success = [audioSession setPreferredSampleRate:16000 error:&error];
6470

6571
if(!success){
66-
NSLog(@"Error setting audio session category: %@", error.localizedDescription);
72+
NSLog(@"[Stream] Error setting audio session category: %@", error.localizedDescription);
6773
}
6874

6975
success = [audioSession setPreferredIOBufferDuration:0.01 error:&error];
7076

7177
if(!success){
72-
NSLog(@"Error setting audio session category: %@", error.localizedDescription);
78+
NSLog(@"[Stream] Error setting audio session category: %@", error.localizedDescription);
7379
}
7480
}
7581

7682
// Activate the audio session
7783
success = [audioSession setActive:YES error:&error];
7884
if(!success) {
79-
NSLog(@"Error setting audio session category: %@", error.localizedDescription);
85+
NSLog(@"[Stream] Error setting audio session category: %@", error.localizedDescription);
8086
} else {
81-
NSLog(@"Audio Session prepared sucessfully for recording with low latency.");
87+
NSLog(@"[Stream] Audio Session prepared sucessfully for recording with low latency.");
8288
}
8389

8490
}
@@ -87,83 +93,80 @@ - (void)prepareAudioSessionForRecording {
8793
- (NSDictionary *)getCurrentAudioSettings {
8894
AVAudioSession *session = [AVAudioSession sharedInstance];
8995
NSMutableDictionary *settings = [NSMutableDictionary dictionary];
90-
91-
@try {
92-
// Basic session properties
93-
settings[@"category"] = session.category ?: @"Unknown";
94-
settings[@"mode"] = session.mode ?: @"Unknown";
95-
96-
// Category options
97-
AVAudioSessionCategoryOptions options = session.categoryOptions;
98-
settings[@"categoryOptions"] = @{
99-
@"allowBluetooth": @(((options & AVAudioSessionCategoryOptionAllowBluetooth) != 0)),
100-
@"allowBluetoothA2DP": @(((options & AVAudioSessionCategoryOptionAllowBluetoothA2DP) != 0)),
101-
@"allowAirPlay": @(((options & AVAudioSessionCategoryOptionAllowAirPlay) != 0)),
102-
@"defaultToSpeaker": @(((options & AVAudioSessionCategoryOptionDefaultToSpeaker) != 0)),
103-
@"mixWithOthers": @(((options & AVAudioSessionCategoryOptionMixWithOthers) != 0)),
104-
@"interruptSpokenAudioAndMixWithOthers": @(((options & AVAudioSessionCategoryOptionInterruptSpokenAudioAndMixWithOthers) != 0)),
105-
};
106-
107-
// Routing information
108-
AVAudioSessionRouteDescription *route = session.currentRoute;
96+
97+
// Basic session properties
98+
settings[@"category"] = session.category ?: @"Unknown";
99+
settings[@"mode"] = session.mode ?: @"Unknown";
100+
101+
// Category options
102+
AVAudioSessionCategoryOptions options = session.categoryOptions;
103+
settings[@"categoryOptions"] = @{
104+
@"allowBluetooth": @(((options & AVAudioSessionCategoryOptionAllowBluetooth) != 0)),
105+
@"allowBluetoothA2DP": @(((options & AVAudioSessionCategoryOptionAllowBluetoothA2DP) != 0)),
106+
@"allowAirPlay": @(((options & AVAudioSessionCategoryOptionAllowAirPlay) != 0)),
107+
@"defaultToSpeaker": @(((options & AVAudioSessionCategoryOptionDefaultToSpeaker) != 0)),
108+
@"mixWithOthers": @(((options & AVAudioSessionCategoryOptionMixWithOthers) != 0)),
109+
@"interruptSpokenAudioAndMixWithOthers": @(((options & AVAudioSessionCategoryOptionInterruptSpokenAudioAndMixWithOthers) != 0)),
110+
};
111+
112+
// Routing information
113+
AVAudioSessionRouteDescription *route = session.currentRoute;
114+
if (route) {
109115
NSMutableArray *inputs = [NSMutableArray array];
110116
NSMutableArray *outputs = [NSMutableArray array];
111-
117+
112118
for (AVAudioSessionPortDescription *port in route.inputs) {
113119
[inputs addObject:@{
114-
@"portType": port.portType,
115-
@"portName": port.portName,
120+
@"portType": port.portType ?: @"Unknown",
121+
@"portName": port.portName ?: @"Unknown",
116122
@"channels": @(port.channels.count),
117-
//@"isBuiltIn": @(port.isBuiltInMicrophone) <- prop doesn't exit
118123
}];
119124
}
120-
125+
121126
for (AVAudioSessionPortDescription *port in route.outputs) {
122127
[outputs addObject:@{
123-
@"portType": port.portType,
124-
@"portName": port.portName,
128+
@"portType": port.portType ?: @"Unknown",
129+
@"portName": port.portName ?: @"Unknown",
125130
@"channels": @(port.channels.count),
126131
}];
127132
}
128-
133+
129134
settings[@"routing"] = @{
130135
@"inputs": inputs,
131136
@"outputs": outputs
132137
};
133-
134-
// Technical settings
135-
settings[@"sampleRate"] = @{
136-
@"preffered": @(session.preferredSampleRate),
137-
@"current": @(session.sampleRate)
138-
};
139-
140-
settings[@"IOBufferDuration"] = @{
141-
@"preffered": @(session.preferredIOBufferDuration),
142-
@"current": @(session.IOBufferDuration)
143-
};
144-
145-
settings[@"latency"] = @{
146-
@"input": @(session.inputLatency),
147-
@"output": @(session.outputLatency)
148-
};
149-
150-
// Hardware status
151-
settings[@"hardware"] = @{
152-
@"inputAvailable": @(session.inputAvailable),
153-
@"otherAudioPlaying": @(session.otherAudioPlaying),
154-
@"inputGain": @(session.inputGain),
155-
@"outputVolume": @(session.outputVolume),
156-
};
157-
158-
159-
} @catch (NSException *exception) {
160-
NSLog(@"Error getting audio settings: %@", exception);
161-
settings[@"error"] = exception.description;
138+
} else {
139+
settings[@"routing"] = @{@"error": @"No route available"};
162140
}
163-
141+
142+
// Technical settings
143+
settings[@"sampleRate"] = @{
144+
@"preferred": @(session.preferredSampleRate),
145+
@"current": @(session.sampleRate)
146+
};
147+
148+
settings[@"IOBufferDuration"] = @{
149+
@"preferred": @(session.preferredIOBufferDuration),
150+
@"current": @(session.IOBufferDuration)
151+
};
152+
153+
settings[@"latency"] = @{
154+
@"input": @(session.inputLatency),
155+
@"output": @(session.outputLatency)
156+
};
157+
158+
// Hardware status
159+
settings[@"hardware"] = @{
160+
@"inputAvailable": @(session.isInputAvailable),
161+
@"otherAudioPlaying": @(session.isOtherAudioPlaying),
162+
@"inputGain": @(session.inputGain),
163+
@"outputVolume": @(session.outputVolume),
164+
};
165+
164166
return settings;
165167
}
166168

169+
167170
- (void)startMonitoring{
168171
[self registerNotifications];
169172
}
@@ -179,7 +182,7 @@ - (void)registerNotifications{
179182
object:nil
180183
queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notification) {
181184
NSDictionary *settings = [self getCurrentAudioSettings];
182-
NSLog(@"Audio Route Changed: %@", settings);
185+
NSLog(@"[Stream] Audio Route Changed: %@", settings);
183186

184187
NSDictionary *eventInfo = @{
185188
@"type": @"routeChange",
@@ -197,7 +200,7 @@ - (void)registerNotifications{
197200

198201
[center addObserverForName:AVAudioSessionInterruptionNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notification) {
199202
NSInteger type = [notification.userInfo[AVAudioSessionInterruptionTypeKey] integerValue];
200-
NSLog(@"Audio Session Interrupted: %ld", (long)type);
203+
NSLog(@"[Stream] Audio Session Interrupted: %ld", (long)type);
201204

202205
NSDictionary *eventInfo = @{
203206
@"type": @"interruption",
@@ -213,7 +216,7 @@ - (void)registerNotifications{
213216
}];
214217

215218
[center addObserverForName:AVAudioSessionMediaServicesWereResetNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notification) {
216-
NSLog(@"Audio Session Media Services Reset");
219+
NSLog(@"[Stream] Audio Session Media Services Reset");
217220

218221
NSDictionary *eventInfo = @{
219222
@"type": @"reset",

0 commit comments

Comments
 (0)