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
8 changes: 3 additions & 5 deletions ios/RCTWebRTC/Utils/AudioDeviceModule/AudioDeviceModule.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright © 2025 Stream.io Inc. All rights reserved.
// Copyright © 2026 Stream.io Inc. All rights reserved.
//

import AudioToolbox
Expand Down Expand Up @@ -92,7 +92,7 @@ import WebRTC
return ".willReleaseAudioEngine(\(engine))"

case .configureInputFromSource(let engine, let source, let destination, let format):
return ".configureInputFromSource(\(engine), source:\(source?.description ?? "nil"), destination:\(destination), format:\(format))"
return ".configureInputFromSource(\(engine), source:\(source), destination:\(destination), format:\(format))"

case .configureOutputFromSource(let engine, let source, let destination, let format):
return ".configureOutputFromSource(\(engine), source:\(source), destination:\(destination?.description ?? "nil"), format:\(format))"
Expand Down Expand Up @@ -221,9 +221,6 @@ import WebRTC

audioLevelsAdapter.subject = audioLevelSubject
source.observer = self

source.isVoiceProcessingBypassed = true
isVoiceProcessingBypassedSubject.send(true)
}

/// Objective-C compatible convenience initializer.
Expand Down Expand Up @@ -255,6 +252,7 @@ import WebRTC
/// sendAudio capability.
_ = source.setRecordingAlwaysPreparedMode(false)
source.prefersStereoPlayout = isPreferred
source.isVoiceProcessingBypassed = isPreferred
}

/// Starts or stops speaker playout on the ADM, retrying transient failures.
Expand Down
49 changes: 36 additions & 13 deletions ios/RCTWebRTC/WebRTCModule+RTCMediaStream.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,25 @@ - (void)setVideoEffectProcessor:(VideoEffectProcessor *)videoEffectProcessor
objc_setAssociatedObject(self, @selector(videoEffectProcessor), videoEffectProcessor, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

#pragma mark - Default Media Constraints

/**
* Returns common optional constraints for improved audio quality.
* Ported from stream-video-swift DefaultRTCMediaConstraints.
* https://github.com/GetStream/stream-video-swift/blob/develop/Sources/StreamVideo/WebRTC/DefaultRTCMediaConstraints.swift
*/
+ (NSDictionary *)commonOptionalConstraints {
return @{
@"DtlsSrtpKeyAgreement": kRTCMediaConstraintsValueTrue,
@"googAutoGainControl": kRTCMediaConstraintsValueTrue,
@"googNoiseSuppression": kRTCMediaConstraintsValueTrue,
@"googEchoCancellation": kRTCMediaConstraintsValueTrue,
@"googHighpassFilter": kRTCMediaConstraintsValueTrue,
@"googTypingNoiseDetection": kRTCMediaConstraintsValueTrue,
@"googAudioMirroring": kRTCMediaConstraintsValueFalse
};
}

#pragma mark - getUserMedia

- (NSString *)convertBoolToString:(id)value {
Expand All @@ -45,19 +64,23 @@ - (NSString *)convertBoolToString:(id)value {
- (RTCAudioTrack *)createAudioTrack:(NSDictionary *)constraints {
NSString *trackId = [[NSUUID UUID] UUIDString];
NSDictionary *audioConstraints = constraints[@"audio"];
NSMutableDictionary *optionalConstraints = [NSMutableDictionary dictionary];
optionalConstraints[@"googAutoGainControl"] = audioConstraints[@"autoGainControl"] != nil
? [self convertBoolToString:audioConstraints[@"autoGainControl"]]
: @"true";
optionalConstraints[@"googNoiseSuppression"] =
audioConstraints[@"noiseSuppression"] != nil ? [self convertBoolToString:audioConstraints[@"noiseSuppression"]]
: @"true";
optionalConstraints[@"googEchoCancellation"] =
audioConstraints[@"echoCancellation"] != nil ? [self convertBoolToString:audioConstraints[@"echoCancellation"]]
: @"true";
optionalConstraints[@"googHighpassFilter"] = audioConstraints[@"highpassFilter"] != nil
? [self convertBoolToString:audioConstraints[@"highpassFilter"]]
: @"true";

// Start with common optional constraints as defaults
NSMutableDictionary *optionalConstraints = [[[self class] commonOptionalConstraints] mutableCopy];

// Override with user-provided constraints if specified
if (audioConstraints[@"autoGainControl"] != nil) {
optionalConstraints[@"googAutoGainControl"] = [self convertBoolToString:audioConstraints[@"autoGainControl"]];
}
if (audioConstraints[@"noiseSuppression"] != nil) {
optionalConstraints[@"googNoiseSuppression"] = [self convertBoolToString:audioConstraints[@"noiseSuppression"]];
}
if (audioConstraints[@"echoCancellation"] != nil) {
optionalConstraints[@"googEchoCancellation"] = [self convertBoolToString:audioConstraints[@"echoCancellation"]];
}
if (audioConstraints[@"highpassFilter"] != nil) {
optionalConstraints[@"googHighpassFilter"] = [self convertBoolToString:audioConstraints[@"highpassFilter"]];
}

RTCMediaConstraints *mediaConstraints =
[[RTCMediaConstraints alloc] initWithMandatoryConstraints:nil optionalConstraints:optionalConstraints];
Expand Down