Skip to content

Commit

Permalink
Address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
ipavlidakis committed Apr 24, 2024
1 parent c3a93a7 commit c0f0df5
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,16 @@ private struct DemoMoreControlsViewModifier: ViewModifier {
Task {
do {
if isTranscribing {
try await viewModel.call?.stopTranscriptions()
try await viewModel.call?.stopTranscription()
} else {
try await viewModel.call?.startTranscriptions()
try await viewModel.call?.startTranscription()
}
} catch {
log.error(error)
}
}
},
label: isTranscribing ? "Disable Transcriptions" : "Transcriptions"
label: isTranscribing ? "Disable Transcription" : "Transcription"
) {
Image(
systemName: isTranscribing
Expand Down
83 changes: 42 additions & 41 deletions Sources/StreamVideo/Call.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,24 +62,8 @@ public class Call: @unchecked Sendable, WSEventsSubscriber {
)
self.callController.call = self
subscribeToLocalCallSettingsChanges()
executeOnMain { [weak self] in
guard let self else { return }
self
.state
.$settings
.map(\.?.audio.noiseCancellation)
.removeDuplicates()
.sink { [weak self] in self?.didUpdate($0) }
.store(in: &self.cancellables)

self
.state
.$settings
.map(\.?.transcription)
.removeDuplicates()
.sink { [weak self] in self?.didUpdate($0) }
.store(in: &self.cancellables)
}
subscribeToNoiseCancellationSettingsChanges()
subscribeToTranscriptionSettingsChanges()
}

internal convenience init(
Expand Down Expand Up @@ -906,7 +890,7 @@ public class Call: @unchecked Sendable, WSEventsSubscriber {
/// - Parameter transcriptionExternalStorage: The external storage location for the
/// transcription (optional).
@discardableResult
public func startTranscriptions(
public func startTranscription(
transcriptionExternalStorage: String? = nil
) async throws -> StartTranscriptionResponse {
try await coordinatorClient.startTranscription(
Expand All @@ -924,7 +908,7 @@ public class Call: @unchecked Sendable, WSEventsSubscriber {
/// - Returns: A StopTranscriptionResponse indicating whether the stop request was successful
/// or not.
@discardableResult
public func stopTranscriptions() async throws -> StopTranscriptionResponse {
public func stopTranscription() async throws -> StopTranscriptionResponse {
try await coordinatorClient.stopTranscription(
type: callType,
id: callId
Expand Down Expand Up @@ -1055,6 +1039,31 @@ public class Call: @unchecked Sendable, WSEventsSubscriber {
.store(in: &cancellables)
}

private func subscribeToNoiseCancellationSettingsChanges() {
executeOnMain { [weak self] in
guard let self else { return }
self
.state
.$settings
.map(\.?.audio.noiseCancellation)
.removeDuplicates()
.sink { [weak self] in self?.didUpdate($0) }
.store(in: &self.cancellables)
}
}

private func subscribeToTranscriptionSettingsChanges() {
executeOnMain {
self
.state
.$settings
.map(\.?.transcription)
.removeDuplicates()
.sink { [weak self] in self?.didUpdate($0) }
.store(in: &self.cancellables)
}
}

private func updateCallSettingsManagers(with callSettings: CallSettings) {
microphone.status = callSettings.audioOn ? .enabled : .disabled
camera.status = callSettings.videoOn ? .enabled : .disabled
Expand Down Expand Up @@ -1118,28 +1127,20 @@ public class Call: @unchecked Sendable, WSEventsSubscriber {
return
}

switch value.mode {
case .available:
log.debug("TranscriptionSettings updated with mode:\(value.mode).")
case .disabled:
/// Deactivate noiseCancellationFilter if mode is disabled and the noiseCancellation
/// audioFilter is currently active.
log.debug("TranscriptionSettings updated with mode:\(value.mode). Will deactivate transcriptions.")
Task {
do {
try await stopTranscriptions()
} catch {
log.error(error)
}
}
case .autoOn:
log.debug("TranscriptionSettings updated with mode:\(value.mode). Will activate transcriptions.")
Task {
do {
try await startTranscriptions()
} catch {
log.error(error)
Task { @MainActor in
do {
switch value.mode {
case .disabled where state.transcribing == true:
log.debug("TranscriptionSettings updated with mode:\(value.mode). Will deactivate transcriptions.")
try await stopTranscription()
case .autoOn where state.transcribing == false:
log.debug("TranscriptionSettings updated with mode:\(value.mode). Will activate transcriptions.")
try await startTranscription()
default:
log.debug("TranscriptionSettings updated with mode:\(value.mode). No action required.")
}
} catch {
log.error(error)
}
}
}
Expand Down
1 change: 1 addition & 0 deletions Sources/StreamVideo/Utils/Models+Sendable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ import Foundation

extension StartTranscriptionResponse: @unchecked Sendable {}
extension StopTranscriptionResponse: @unchecked Sendable {}
extension TranscriptionSettings: @unchecked Sendable {}

0 comments on commit c0f0df5

Please sign in to comment.