From fbfa582a6c971da2e2be6482d22f07c7f5cae2f4 Mon Sep 17 00:00:00 2001 From: Ilias Pavlidakis Date: Thu, 29 Aug 2024 15:06:49 +0300 Subject: [PATCH] [Fix]Allow callSettings propagation to CallState (#497) --- CHANGELOG.md | 1 + Sources/StreamVideo/Call.swift | 11 ++++++++++- Sources/StreamVideo/StreamVideo.swift | 8 ++++++-- Sources/StreamVideoSwiftUI/CallViewModel.swift | 12 ++++++++++-- StreamVideoTests/Mock/MockStreamVideo.swift | 6 +++++- 5 files changed, 32 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 397b83705..ff2be3bf0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### ✅ Added - Participants (regular and anonymous) count, can be accessed - before or after joining a call - from the `Call.state.participantCount` & `Call.state.anonymousParticipantCount` respectively. [#496](https://github.com/GetStream/stream-video-swift/pull/496) +- You can now provide the `CallSettings` when you start a ringing call [#497](https://github.com/GetStream/stream-video-swift/pull/497) # [1.0.9](https://github.com/GetStream/stream-video-swift/releases/tag/1.0.9) _July 19, 2024_ diff --git a/Sources/StreamVideo/Call.swift b/Sources/StreamVideo/Call.swift index 54c1e12be..4f4fe3b09 100644 --- a/Sources/StreamVideo/Call.swift +++ b/Sources/StreamVideo/Call.swift @@ -43,7 +43,8 @@ public class Call: @unchecked Sendable, WSEventsSubscriber { callType: String, callId: String, coordinatorClient: DefaultAPI, - callController: CallController + callController: CallController, + callSettings: CallSettings? = nil ) { self.callId = callId self.callType = callType @@ -63,6 +64,14 @@ public class Call: @unchecked Sendable, WSEventsSubscriber { initialSpeakerStatus: .enabled, initialAudioOutputStatus: .enabled ) + + /// If we received a non-nil initial callSettings, we updated them here. + if let callSettings { + Task { @MainActor [weak self] in + self?.state.update(callSettings: callSettings) + } + } + self.callController.call = self // It's important to instantiate the stateMachine as soon as possible // to ensure it's uniqueness. diff --git a/Sources/StreamVideo/StreamVideo.swift b/Sources/StreamVideo/StreamVideo.swift index ee0c2b92e..94da6b3b6 100644 --- a/Sources/StreamVideo/StreamVideo.swift +++ b/Sources/StreamVideo/StreamVideo.swift @@ -215,10 +215,13 @@ public class StreamVideo: ObservableObject, @unchecked Sendable { /// - Parameters: /// - callType: the type of the call. /// - callId: the id of the all. + /// - callSettings: the initial CallSettings to use. If `nil` is provided, the default CallSettings + /// will be used. /// - Returns: `Call` object. public func call( callType: String, - callId: String + callId: String, + callSettings: CallSettings? = nil ) -> Call { callCache.call(for: callCid(from: callId, callType: callType)) { let callController = makeCallController(callType: callType, callId: callId) @@ -226,7 +229,8 @@ public class StreamVideo: ObservableObject, @unchecked Sendable { callType: callType, callId: callId, coordinatorClient: coordinatorClient, - callController: callController + callController: callController, + callSettings: callSettings ) eventsMiddleware.add(subscriber: call) return call diff --git a/Sources/StreamVideoSwiftUI/CallViewModel.swift b/Sources/StreamVideoSwiftUI/CallViewModel.swift index 825296f6e..6034593e1 100644 --- a/Sources/StreamVideoSwiftUI/CallViewModel.swift +++ b/Sources/StreamVideoSwiftUI/CallViewModel.swift @@ -351,7 +351,11 @@ open class CallViewModel: ObservableObject { backstage: backstage ) } else { - let call = streamVideo.call(callType: callType, callId: callId) + let call = streamVideo.call( + callType: callType, + callId: callId, + callSettings: callSettings + ) self.call = call Task { do { @@ -572,7 +576,11 @@ open class CallViewModel: ObservableObject { enteringCallTask = Task { do { log.debug("Starting call") - let call = call ?? streamVideo.call(callType: callType, callId: callId) + let call = call ?? streamVideo.call( + callType: callType, + callId: callId, + callSettings: callSettings + ) var settingsRequest: CallSettingsRequest? var limits: LimitsSettingsRequest? if maxDuration != nil || maxParticipants != nil { diff --git a/StreamVideoTests/Mock/MockStreamVideo.swift b/StreamVideoTests/Mock/MockStreamVideo.swift index 51a42837f..463d22e6d 100644 --- a/StreamVideoTests/Mock/MockStreamVideo.swift +++ b/StreamVideoTests/Mock/MockStreamVideo.swift @@ -60,7 +60,11 @@ final class MockStreamVideo: StreamVideo, Mockable { stubbedFunction[function] = value } - override func call(callType: String, callId: String) -> Call { + override func call( + callType: String, + callId: String, + callSettings: CallSettings? = nil + ) -> Call { stubbedFunction[.call] as! Call }