Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 50 additions & 2 deletions ios/RCTWebRTC/WebRTCModule+RTCMediaStream.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#import <WebRTC/RTCMediaConstraints.h>
#import <WebRTC/RTCMediaStreamTrack.h>
#import <WebRTC/RTCVideoTrack.h>
#import <WebRTC/WebRTC.h>

#import "RTCMediaStreamTrack+React.h"
#import "WebRTCModuleOptions.h"
Expand Down Expand Up @@ -214,6 +215,7 @@ - (RTCVideoTrack *)createScreenCaptureVideoTrack {

if (constraints[@"audio"]) {
audioTrack = [self createAudioTrack:constraints];
[self ensureAudioSessionWithRecording];
}
if (constraints[@"video"]) {
videoTrack = [self createVideoTrack:constraints];
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion stream-react-native-webrtc.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Loading