Skip to content

Commit e2660d0

Browse files
committed
ios addition
1 parent a6f1c00 commit e2660d0

3 files changed

Lines changed: 20 additions & 17 deletions

File tree

ios/RCTWebRTC/Utils/AudioDeviceModule/AudioDeviceModule.swift

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -111,56 +111,56 @@ import WebRTC
111111
/// Tracks whether WebRTC is currently playing back audio.
112112
private let isPlayingSubject: CurrentValueSubject<Bool, Never>
113113
/// `true` while audio playout is active.
114-
var isPlaying: Bool { isPlayingSubject.value }
114+
@objc public var isPlaying: Bool { isPlayingSubject.value }
115115
/// Publisher that reflects playout activity changes.
116116
var isPlayingPublisher: AnyPublisher<Bool, Never> { isPlayingSubject.eraseToAnyPublisher() }
117117

118118
/// Tracks whether WebRTC is capturing microphone samples.
119119
private let isRecordingSubject: CurrentValueSubject<Bool, Never>
120120
/// `true` while audio capture is active.
121-
var isRecording: Bool { isRecordingSubject.value }
121+
@objc public var isRecording: Bool { isRecordingSubject.value }
122122
/// Publisher that reflects recording activity changes.
123123
var isRecordingPublisher: AnyPublisher<Bool, Never> { isRecordingSubject.eraseToAnyPublisher() }
124124

125125
/// Tracks whether the microphone is muted at the ADM layer.
126126
private let isMicrophoneMutedSubject: CurrentValueSubject<Bool, Never>
127127
/// `true` if the microphone is muted.
128-
var isMicrophoneMuted: Bool { isMicrophoneMutedSubject.value }
128+
@objc public var isMicrophoneMuted: Bool { isMicrophoneMutedSubject.value }
129129
/// Publisher that reflects microphone mute changes.
130130
var isMicrophoneMutedPublisher: AnyPublisher<Bool, Never> { isMicrophoneMutedSubject.eraseToAnyPublisher() }
131131

132132
/// Tracks whether stereo playout is configured.
133133
private let isStereoPlayoutEnabledSubject: CurrentValueSubject<Bool, Never>
134134
/// `true` if stereo playout is available and active.
135-
var isStereoPlayoutEnabled: Bool { isStereoPlayoutEnabledSubject.value }
135+
@objc public var isStereoPlayoutEnabled: Bool { isStereoPlayoutEnabledSubject.value }
136136
/// Publisher emitting stereo playout state.
137137
var isStereoPlayoutEnabledPublisher: AnyPublisher<Bool, Never> { isStereoPlayoutEnabledSubject.eraseToAnyPublisher() }
138138

139139
/// Tracks whether VP processing is currently bypassed.
140140
private let isVoiceProcessingBypassedSubject: CurrentValueSubject<Bool, Never>
141141
/// `true` if the voice processing unit is bypassed.
142-
var isVoiceProcessingBypassed: Bool { isVoiceProcessingBypassedSubject.value }
142+
@objc public var isVoiceProcessingBypassed: Bool { isVoiceProcessingBypassedSubject.value }
143143
/// Publisher emitting VP bypass changes.
144144
var isVoiceProcessingBypassedPublisher: AnyPublisher<Bool, Never> { isVoiceProcessingBypassedSubject.eraseToAnyPublisher() }
145145

146146
/// Tracks whether voice processing is enabled.
147147
private let isVoiceProcessingEnabledSubject: CurrentValueSubject<Bool, Never>
148148
/// `true` when Apple VP is active.
149-
var isVoiceProcessingEnabled: Bool { isVoiceProcessingEnabledSubject.value }
149+
@objc public var isVoiceProcessingEnabled: Bool { isVoiceProcessingEnabledSubject.value }
150150
/// Publisher emitting VP enablement changes.
151151
var isVoiceProcessingEnabledPublisher: AnyPublisher<Bool, Never> { isVoiceProcessingEnabledSubject.eraseToAnyPublisher() }
152152

153153
/// Tracks whether automatic gain control is enabled inside VP.
154154
private let isVoiceProcessingAGCEnabledSubject: CurrentValueSubject<Bool, Never>
155155
/// `true` while AGC is active.
156-
var isVoiceProcessingAGCEnabled: Bool { isVoiceProcessingAGCEnabledSubject.value }
156+
@objc public var isVoiceProcessingAGCEnabled: Bool { isVoiceProcessingAGCEnabledSubject.value }
157157
/// Publisher emitting AGC changes.
158158
var isVoiceProcessingAGCEnabledPublisher: AnyPublisher<Bool, Never> { isVoiceProcessingAGCEnabledSubject.eraseToAnyPublisher() }
159159

160160
/// Observes RMS audio levels (in dB) derived from the input tap.
161161
private let audioLevelSubject = CurrentValueSubject<Float, Never>(Constant.silenceDB) // default to silence
162162
/// Latest measured audio level.
163-
var audioLevel: Float { audioLevelSubject.value }
163+
@objc public var audioLevel: Float { audioLevelSubject.value }
164164
/// Publisher emitting audio level updates.
165165
var audioLevelPublisher: AnyPublisher<Float, Never> { audioLevelSubject.eraseToAnyPublisher() }
166166

@@ -177,10 +177,10 @@ import WebRTC
177177
let publisher: AnyPublisher<Event, Never>
178178

179179
/// Strong reference to the current engine so we can introspect it if needed.
180-
private var engine: AVAudioEngine?
180+
@objc public var engine: AVAudioEngine?
181181

182182
/// Textual diagnostics for logging and debugging.
183-
public override var description: String {
183+
@objc public override var description: String {
184184
"{ " +
185185
"isPlaying:\(isPlaying)" +
186186
", isRecording:\(isRecording)" +
@@ -235,14 +235,14 @@ import WebRTC
235235
// MARK: - Recording
236236

237237
/// Reinitializes the ADM, clearing its internal audio graph state.
238-
func reset() {
238+
@objc public func reset() {
239239
_ = source.reset()
240240
}
241241

242242
/// Switches between stereo and mono playout while keeping the recording
243243
/// state consistent across reinitializations.
244244
/// - Parameter isPreferred: `true` when stereo output should be used.
245-
func setStereoPlayoutPreference(_ isPreferred: Bool) {
245+
@objc public func setStereoPlayoutPreference(_ isPreferred: Bool) {
246246
/// - Important: `.voiceProcessing` requires VP to be enabled in order to mute and
247247
/// `.restartEngine` rebuilds the whole graph. Each of them has different issues:
248248
/// - `.voiceProcessing`: as it requires VP to be enabled in order to mute/unmute that
@@ -259,7 +259,7 @@ import WebRTC
259259
/// Starts or stops speaker playout on the ADM, retrying transient failures.
260260
/// - Parameter isActive: `true` to start playout, `false` to stop.
261261
/// - Throws: `AudioDeviceError` when WebRTC returns a non-zero status.
262-
func setPlayout(_ isActive: Bool) throws {
262+
@objc public func setPlayout(_ isActive: Bool) throws {
263263
guard isActive != isPlaying else {
264264
return
265265
}
@@ -283,7 +283,7 @@ import WebRTC
283283
/// Enables or disables recording on the wrapped audio device module.
284284
/// - Parameter isEnabled: When `true` recording starts, otherwise stops.
285285
/// - Throws: `AudioDeviceError` when the underlying module reports a failure.
286-
func setRecording(_ isEnabled: Bool) throws {
286+
@objc public func setRecording(_ isEnabled: Bool) throws {
287287
guard isEnabled != isRecording else {
288288
return
289289
}
@@ -309,7 +309,7 @@ import WebRTC
309309
/// Updates the muted state of the microphone for the wrapped module.
310310
/// - Parameter isMuted: `true` to mute the microphone, `false` to unmute.
311311
/// - Throws: `AudioDeviceError` when the underlying module reports a failure.
312-
func setMuted(_ isMuted: Bool) throws {
312+
@objc public func setMuted(_ isMuted: Bool) throws {
313313
guard isMuted != source.isMicrophoneMuted else {
314314
return
315315
}
@@ -326,7 +326,7 @@ import WebRTC
326326
}
327327

328328
/// Forces the ADM to recompute whether stereo output is supported.
329-
func refreshStereoPlayoutState() {
329+
@objc public func refreshStereoPlayoutState() {
330330
source.refreshStereoPlayoutState()
331331
}
332332

ios/RCTWebRTC/WebRTCModule.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,16 @@ static NSString *const kEventMediaStreamTrackEnded = @"mediaStreamTrackEnded";
2323
static NSString *const kEventPeerConnectionOnRemoveTrack = @"peerConnectionOnRemoveTrack";
2424
static NSString *const kEventPeerConnectionOnTrack = @"peerConnectionOnTrack";
2525

26+
@class AudioDeviceModule;
27+
2628
@interface WebRTCModule : RCTEventEmitter<RCTBridgeModule>
2729

2830
@property(nonatomic, strong) dispatch_queue_t workerQueue;
2931

3032
@property(nonatomic, strong) RTCPeerConnectionFactory *peerConnectionFactory;
3133
@property(nonatomic, strong) id<RTCVideoDecoderFactory> decoderFactory;
3234
@property(nonatomic, strong) id<RTCVideoEncoderFactory> encoderFactory;
35+
@property(nonatomic, strong) AudioDeviceModule *audioDeviceModule;
3336

3437
@property(nonatomic, strong) NSMutableDictionary<NSNumber *, RTCPeerConnection *> *peerConnections;
3538
@property(nonatomic, strong) NSMutableDictionary<NSString *, RTCMediaStream *> *localStreams;

ios/RCTWebRTC/WebRTCModule.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ - (instancetype)init {
100100
audioProcessingModule:nil];
101101
}
102102

103-
_peerConnectionFactory.audioDeviceModule = [[AudioDeviceModule alloc] initWithSource:_peerConnectionFactory.audioDeviceModule];
103+
_audioDeviceModule = [[AudioDeviceModule alloc] initWithSource:_peerConnectionFactory.audioDeviceModule];
104104

105105
_peerConnections = [NSMutableDictionary new];
106106
_localStreams = [NSMutableDictionary new];

0 commit comments

Comments
 (0)