diff --git a/ios/RCTWebRTC/WebRTCModule+RTCMediaStream.m b/ios/RCTWebRTC/WebRTCModule+RTCMediaStream.m index 49e922987..eafae4394 100644 --- a/ios/RCTWebRTC/WebRTCModule+RTCMediaStream.m +++ b/ios/RCTWebRTC/WebRTCModule+RTCMediaStream.m @@ -4,6 +4,7 @@ #import #import #import +#import #import "RTCMediaStreamTrack+React.h" #import "WebRTCModuleOptions.h" @@ -214,6 +215,7 @@ - (RTCVideoTrack *)createScreenCaptureVideoTrack { if (constraints[@"audio"]) { audioTrack = [self createAudioTrack:constraints]; + [self ensureAudioSessionWithRecording]; } if (constraints[@"video"]) { videoTrack = [self createVideoTrack:constraints]; @@ -408,15 +410,32 @@ - (RTCVideoTrack *)createScreenCaptureVideoTrack { NSString *trackUUID = [[NSUUID UUID] UUIDString]; if ([originalTrack.kind isEqualToString:@"audio"]) { RTCAudioTrack *audioTrack = [self.peerConnectionFactory audioTrackWithTrackId:trackUUID]; + audioTrack.isEnabled = originalTrack.isEnabled; [self.localTracks setObject:audioTrack forKey:trackUUID]; - return trackUUID; + for (NSString* streamId in self.localStreams) { + RTCMediaStream* stream = [self.localStreams objectForKey:streamId]; + for (RTCAudioTrack* track in stream.audioTracks) { + if ([trackID isEqualToString:track.trackId]) { + [stream addAudioTrack:audioTrack]; + } + } + } } else { RTCVideoTrack *originalVideoTrack = (RTCVideoTrack *)originalTrack; RTCVideoSource *videoSource = originalVideoTrack.source; RTCVideoTrack *videoTrack = [self.peerConnectionFactory videoTrackWithSource:videoSource trackId:trackUUID]; + videoTrack.isEnabled = originalTrack.isEnabled; [self.localTracks setObject:videoTrack forKey:trackUUID]; - return trackUUID; + for (NSString* streamId in self.localStreams) { + RTCMediaStream* stream = [self.localStreams objectForKey:streamId]; + for (RTCVideoTrack* track in stream.videoTracks) { + if ([trackID isEqualToString:track.trackId]) { + [stream addVideoTrack:videoTrack]; + } + } + } } + return trackUUID; } return @""; #endif @@ -518,4 +537,33 @@ - (RTCMediaStreamTrack *)trackForId:(nonnull NSString *)trackId pcId:(nonnull NS return peerConnection.remoteTracks[trackId]; } +- (void)ensureAudioSessionWithRecording { + RTCAudioSession* session = [RTCAudioSession sharedInstance]; + + // we also need to set default WebRTC audio configuration, since it may be activated after + // this method is called + RTCAudioSessionConfiguration* config = [RTCAudioSessionConfiguration webRTCConfiguration]; + // require audio session to be either PlayAndRecord or MultiRoute + if (session.category != AVAudioSessionCategoryPlayAndRecord) { + [session lockForConfiguration]; + config.category = AVAudioSessionCategoryPlayAndRecord; + config.categoryOptions = + AVAudioSessionCategoryOptionAllowAirPlay| + AVAudioSessionCategoryOptionAllowBluetooth| + AVAudioSessionCategoryOptionAllowBluetoothA2DP| + AVAudioSessionCategoryOptionDefaultToSpeaker; + config.mode = AVAudioSessionModeVideoChat; + NSError* error = nil; + bool success = [session setCategory:config.category withOptions:config.categoryOptions error:&error]; + if (!success) { + NSLog(@"ensureAudioSessionWithRecording: setCategory failed due to: %@", [error localizedDescription]); + } + success = [session setMode:config.mode error:&error]; + if (!success) { + NSLog(@"ensureAudioSessionWithRecording: Error setting category: %@", [error localizedDescription]); + } + [session unlockForConfiguration]; + } +} + @end diff --git a/package-lock.json b/package-lock.json index 6d0e61834..0638cea27 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@stream-io/react-native-webrtc", - "version": "125.0.3", + "version": "125.0.4-rc.3", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@stream-io/react-native-webrtc", - "version": "125.0.3", + "version": "125.0.4-rc.3", "license": "MIT", "dependencies": { "base64-js": "1.5.1", diff --git a/package.json b/package.json index eb4b396c9..7ad273cec 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@stream-io/react-native-webrtc", - "version": "125.0.3", + "version": "125.0.4-rc.3", "repository": { "type": "git", "url": "git+https://github.com/GetStream/react-native-webrtc.git" diff --git a/stream-react-native-webrtc.podspec b/stream-react-native-webrtc.podspec index 4697f58ef..c6b495dd8 100644 --- a/stream-react-native-webrtc.podspec +++ b/stream-react-native-webrtc.podspec @@ -19,7 +19,7 @@ Pod::Spec.new do |s| s.libraries = 'c', 'sqlite3', 'stdc++' s.framework = 'AudioToolbox','AVFoundation', 'CoreAudio', 'CoreGraphics', 'CoreVideo', 'GLKit', 'VideoToolbox' s.dependency 'React-Core' - s.dependency 'WebRTC-SDK', '~>125.6422.05' + s.dependency 'WebRTC-SDK', '~>125.6422.07' # Swift/Objective-C compatibility #https://blog.cocoapods.org/CocoaPods-1.5.0/ s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES'