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

[Fix]Accepting call on another device will sync state with CallViewModel #640

Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

### 🐞 Fixed
- Fix an issue that was causing the video capturer to no be cleaned up when the call was ended, causing the camera access system indicator to remain on while the `CallEnded` screen is visible. [#636](https://github.com/GetStream/stream-video-swift/pull/636)
- Fix an issue which was not dismissing incoming call screen if the call was accepted on another device. [#640](https://github.com/GetStream/stream-video-swift/pull/640)

# [1.15.0](https://github.com/GetStream/stream-video-swift/releases/tag/1.15.0)
_January 14, 2025_
Expand Down
2 changes: 1 addition & 1 deletion Sources/StreamVideoSwiftUI/CallViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ open class CallViewModel: ObservableObject {

switch callingState {
case .incoming where event.user?.id == streamVideo.user.id:
break
rejectCall(callType: event.type, callId: event.callId)
ipavlidakis marked this conversation as resolved.
Show resolved Hide resolved
case .outgoing where call?.cId == event.callCid:
enterCall(
call: call,
Expand Down
206 changes: 205 additions & 1 deletion StreamVideoSwiftUITests/CallViewModel_Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,211 @@ final class CallViewModel_Tests: StreamVideoTestCase {
callViewModel.callingState == .inCall
}
}


@MainActor
func test_incomingCall_acceptedFromSameUserElsewhere_callingStateChangesToIdle() async throws {
// Given
let callViewModel = CallViewModel()
await fulfillment { callViewModel.isSubscribedToCallEvents }

// When
let event = CallRingEvent(
call: mockResponseBuilder.makeCallResponse(cid: cId),
callCid: cId,
createdAt: Date(),
members: [],
sessionId: "123",
user: UserResponse(
blockedUserIds: [],
createdAt: Date(),
custom: [:],
id: secondUser.userId,
language: "",
role: "user",
teams: [],
updatedAt: Date()
),
video: true
)

let wrapped = WrappedEvent.coordinatorEvent(.typeCallRingEvent(event))
let eventNotificationCenter = try XCTUnwrap(eventNotificationCenter)
eventNotificationCenter.process(wrapped)

await fulfillment {
if case .incoming = callViewModel.callingState {
return true
} else {
return false
}
}

// Then
guard case let .incoming(call) = callViewModel.callingState else {
XCTFail()
return
}
XCTAssert(call.id == callId)

// When we receive an accept even it means we accepted somewhere else
eventNotificationCenter.process(
.coordinatorEvent(
.typeCallAcceptedEvent(
.dummy(
callCid: cId,
user: firstUser.user.toUserResponse()
)
)
)
)

// Then
let callingState = callViewModel.callingState
await fulfillment("CallViewModel.callingState expected:.inCall actual: \(callingState)") {
callViewModel.callingState == .idle
}
}

@MainActor
func test_incomingCall_anotherUserAcceptedThisCall_callingStateShouldRemainIncoming() async throws {
// Given
let callViewModel = CallViewModel()
await fulfillment { callViewModel.isSubscribedToCallEvents }

// When
let event = CallRingEvent(
call: mockResponseBuilder.makeCallResponse(cid: cId),
callCid: cId,
createdAt: Date(),
members: [],
sessionId: "123",
user: UserResponse(
blockedUserIds: [],
createdAt: Date(),
custom: [:],
id: secondUser.userId,
language: "",
role: "user",
teams: [],
updatedAt: Date()
),
video: true
)

let wrapped = WrappedEvent.coordinatorEvent(.typeCallRingEvent(event))
let eventNotificationCenter = try XCTUnwrap(eventNotificationCenter)
eventNotificationCenter.process(wrapped)

await fulfillment {
if case .incoming = callViewModel.callingState {
return true
} else {
return false
}
}

// Then
guard case let .incoming(call) = callViewModel.callingState else {
XCTFail()
return
}
XCTAssert(call.id == callId)

// When we receive an accept even it means we accepted somewhere else
eventNotificationCenter.process(
.coordinatorEvent(
.typeCallAcceptedEvent(
.dummy(
callCid: cId,
user: secondUser.user.toUserResponse()
)
)
)
)

// Then
try await XCTAssertWithDelay(
{
switch callViewModel.callingState {
case .incoming:
return true
default:
return false
}
}()
)
}

@MainActor
func test_incomingCall_acceptedAnotherCallElsewhere_callingStateShouldRemainInCall() async throws {
// Given
let callViewModel = CallViewModel()
await fulfillment { callViewModel.isSubscribedToCallEvents }

// When
let event = CallRingEvent(
call: mockResponseBuilder.makeCallResponse(cid: cId),
callCid: cId,
createdAt: Date(),
members: [],
sessionId: "123",
user: UserResponse(
blockedUserIds: [],
createdAt: Date(),
custom: [:],
id: secondUser.userId,
language: "",
role: "user",
teams: [],
updatedAt: Date()
),
video: true
)

let wrapped = WrappedEvent.coordinatorEvent(.typeCallRingEvent(event))
let eventNotificationCenter = try XCTUnwrap(eventNotificationCenter)
eventNotificationCenter.process(wrapped)

await fulfillment {
if case .incoming = callViewModel.callingState {
return true
} else {
return false
}
}

// Then
guard case let .incoming(call) = callViewModel.callingState else {
XCTFail()
return
}
XCTAssert(call.id == callId)

// When we receive an accept even it means we accepted somewhere else
eventNotificationCenter.process(
.coordinatorEvent(
.typeCallAcceptedEvent(
.dummy(
callCid: "default:\(String.unique)",
user: secondUser.user.toUserResponse()
)
)
)
)

// Then
try await XCTAssertWithDelay(
{
switch callViewModel.callingState {
case .incoming:
return true
default:
return false
}
}()
)
}

@MainActor
func test_incomingCall_rejectCall() async throws {
// Given
Expand Down