Skip to content

Commit 7eab1c3

Browse files
committed
ios: fix crash if device doesn't have a name
We have observed this crash: ~~~ Fatal Exception: NSInvalidArgumentException 0 CoreFoundation 0x19c404654 __exceptionPreprocess 1 libobjc.A.dylib 0x19c126bcc objc_exception_throw 2 CoreFoundation 0x19c45a280 -[__NSCFString characterAtIndex:].cold.1 3 CoreFoundation 0x19c4636e8 -[__NSPlaceholderDictionary initWithObjects:forKeys:count:].cold.5 4 CoreFoundation 0x19c2f20bc -[__NSPlaceholderDictionary initWithObjects:forKeys:count:] 5 CoreFoundation 0x19c2e40c4 +[NSDictionary dictionaryWithObjects:forKeys:count:] 6 JitsiMeet 0x104d58d20 -[WebRTCModule(RTCMediaStream) enumerateDevices:] + 145 (WebRTCModule+RTCMediaStream.m:145) ~~~
1 parent 268933f commit 7eab1c3

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

ios/RCTWebRTC/WebRTCModule+RTCMediaStream.m

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,17 +123,21 @@ - (RTCVideoTrack *)createVideoTrack:(NSDictionary *)constraints {
123123
mediaType:AVMediaTypeVideo
124124
position:AVCaptureDevicePositionUnspecified];
125125
for (AVCaptureDevice *device in videoevicesSession.devices) {
126-
NSString *position = @"";
126+
NSString *position = @"unknown";
127127
if (device.position == AVCaptureDevicePositionBack) {
128128
position = @"environment";
129129
} else if (device.position == AVCaptureDevicePositionFront) {
130130
position = @"front";
131131
}
132+
NSString *label = "Unknown video device";
133+
if (device.localizedName != nil) {
134+
label = device.localizedName;
135+
}
132136
[devices addObject:@{
133137
@"facing": position,
134138
@"deviceId": device.uniqueID,
135139
@"groupId": @"",
136-
@"label": device.localizedName,
140+
@"label": label,
137141
@"kind": @"videoinput",
138142
}];
139143
}
@@ -142,10 +146,14 @@ - (RTCVideoTrack *)createVideoTrack:(NSDictionary *)constraints {
142146
mediaType:AVMediaTypeAudio
143147
position:AVCaptureDevicePositionUnspecified];
144148
for (AVCaptureDevice *device in audioDevicesSession.devices) {
149+
NSString *label = "Unknown audio device";
150+
if (device.localizedName != nil) {
151+
label = device.localizedName;
152+
}
145153
[devices addObject:@{
146154
@"deviceId": device.uniqueID,
147155
@"groupId": @"",
148-
@"label": device.localizedName,
156+
@"label": label,
149157
@"kind": @"audioinput",
150158
}];
151159
}

0 commit comments

Comments
 (0)