Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#R Connecting state issue fixes #796

Merged
merged 1 commit into from
Oct 12, 2023
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
15 changes: 14 additions & 1 deletion GliaWidgets/Sources/ViewModel/Call/CallViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,20 @@ class CallViewModel: EngagementViewModel, ViewModel {
super.start()

update(for: call.kind.value)
update(for: interactor.state)

// In the case when SDK is configured once and then
// visitor has several Audio/Video engagements in a raw,
// after ending each of them, `interactor.state` has `.ended` value,
// which causes calling `call.end()` on the start of the next
// Audio/Video engagement. That `call.end()` breaks the flow and SDK does not
// handle `connected` state properly. So we need to skip handling `.ended` state
// on the start of a new engagement.
switch interactor.state {
case .ended:
break
default:
update(for: interactor.state)
}

switch startWith {
case .engagement(let mediaType):
Expand Down
10 changes: 6 additions & 4 deletions GliaWidgets/Sources/ViewModel/EngagementViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class EngagementViewModel: CommonEngagementModel {
let alertConfiguration: AlertConfiguration
let environment: Environment
let screenShareHandler: ScreenShareHandler
// Need to keep strong reference of `activeEngagement`,
// to be able to fetch survey after ending engagement
var activeEngagement: CoreSdkClient.Engagement?

private(set) var isViewActive = ObservableValue<Bool>(with: false)
Expand Down Expand Up @@ -225,10 +227,10 @@ class EngagementViewModel: CommonEngagementModel {
}

func endSession() {
interactor.endSession {
self.engagementDelegate?(.finished)
} failure: { _ in
self.engagementDelegate?(.finished)
interactor.endSession { [weak self] in
self?.engagementDelegate?(.finished)
} failure: { [weak self] _ in
self?.engagementDelegate?(.finished)
}
self.screenShareHandler.stop(nil)
}
Expand Down
12 changes: 12 additions & 0 deletions GliaWidgetsTests/Sources/CallViewModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -335,4 +335,16 @@ class CallViewModelTests: XCTestCase {

XCTAssertEqual(call.kind.value, .audio)
}

func test_startMethodDoesNotHandleInteractorStateEnded() {
let interactor: Interactor = .mock()
interactor.state = .ended(.byOperator)
let call: Call = .mock()
let viewModel: CallViewModel = .mock(interactor: interactor, call: call)

XCTAssertEqual(call.state.value, .none)
viewModel.start()

XCTAssertEqual(call.state.value, .none)
}
}
Loading