Skip to content

Commit 00ae0a4

Browse files
authored
[Fix]Call event overflow (#889)
1 parent 60b5701 commit 00ae0a4

File tree

2 files changed

+55
-14
lines changed

2 files changed

+55
-14
lines changed

Sources/StreamVideoSwiftUI/CallViewModel.swift

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,6 @@ open class CallViewModel: ObservableObject {
211211
}
212212
}
213213

214-
/// A simple value, signalling that the viewModel has been subscribed to receive callEvents from
215-
/// `StreamVideo`.
216-
private(set) var isSubscribedToCallEvents: Bool = false
217-
218214
public init(
219215
participantsLayout: ParticipantsLayout = .grid,
220216
callSettings: CallSettings? = nil
@@ -589,7 +585,9 @@ open class CallViewModel: ObservableObject {
589585
self.call = call
590586
} else if call == nil, callingState != .idle {
591587
setCallingState(.idle)
592-
self.call = nil
588+
Task { @MainActor in
589+
self.call = nil
590+
}
593591
}
594592
}
595593

@@ -817,10 +815,13 @@ open class CallViewModel: ObservableObject {
817815
handleAcceptedEvent(callEvent)
818816
case .rejected:
819817
handleRejectedEvent(callEvent)
820-
case .ended:
818+
case let .ended(event) where event.callCid == call?.cId:
821819
Task { @MainActor [weak self] in
822820
self?.leaveCall()
823821
}
822+
case .ended:
823+
// Another call ended. No action is required.
824+
break
824825
case let .userBlocked(callEventInfo):
825826
if
826827
callEventInfo.user?.id == streamVideo.user.id,

StreamVideoSwiftUITests/CallViewModel_Tests.swift

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Copyright © 2025 Stream.io Inc. All rights reserved.
33
//
44

5-
#if swift(>=6.0)
65
@testable import StreamVideo
76
@testable import StreamVideoSwiftUI
87
import StreamWebRTC
@@ -32,9 +31,7 @@ final class CallViewModel_Tests: XCTestCase, @unchecked Sendable {
3231
thirdUser = nil
3332
secondUser = nil
3433
firstUser = nil
35-
mockResponseBuilder = nil
36-
peerConnectionFactory = nil
37-
super.tearDown()
34+
try await super.tearDown()
3835
}
3936

4037
@MainActor
@@ -554,6 +551,46 @@ final class CallViewModel_Tests: XCTestCase, @unchecked Sendable {
554551
await fulfilmentInMainActor { self.subject.participantEvent == nil }
555552
}
556553

554+
func test_inCall_ringingCallEnds_activeCallRemainsJoined() async throws {
555+
// Given
556+
await prepare()
557+
subject.startCall(callType: callType, callId: callId, members: participants)
558+
await assertCallingState(.inCall)
559+
560+
let newCallId = String.unique
561+
let cid = callCid(from: newCallId, callType: .default)
562+
// When
563+
streamVideo.process(
564+
.coordinatorEvent(
565+
.typeCallRingEvent(
566+
.init(
567+
call: .dummy(cid: cid),
568+
callCid: cid,
569+
createdAt: .init(),
570+
members: [],
571+
sessionId: .unique,
572+
user: .dummy(),
573+
video: true
574+
)
575+
)
576+
)
577+
)
578+
streamVideo.process(
579+
.coordinatorEvent(
580+
.typeCallEndedEvent(
581+
.init(
582+
call: .dummy(cid: cid),
583+
callCid: cid,
584+
createdAt: .init()
585+
)
586+
)
587+
)
588+
)
589+
590+
// Then
591+
await assertCallingState(.inCall)
592+
}
593+
557594
func test_inCall_participantJoinedAndLeft() async throws {
558595
// Given
559596
await prepare()
@@ -968,9 +1005,6 @@ final class CallViewModel_Tests: XCTestCase, @unchecked Sendable {
9681005
streamVideo.state.user = firstUser.user
9691006

9701007
subject = .init()
971-
await fulfilmentInMainActor(file: file, line: line) {
972-
self.subject.isSubscribedToCallEvents
973-
}
9741008
}
9751009

9761010
private func prepareIncomingCallScenario(
@@ -1110,11 +1144,18 @@ final class CallViewModel_Tests: XCTestCase, @unchecked Sendable {
11101144
if let delay {
11111145
await wait(for: delay)
11121146
}
1147+
#if compiler(>=6.0)
11131148
await fulfilmentInMainActor(
11141149
"CallViewModel.callingState expected:\(expected) actual: \(subject.callingState)",
11151150
file: file,
11161151
line: line
11171152
) { self.subject.callingState == expected }
1153+
#else
1154+
await fulfilmentInMainActor(
1155+
file: file,
1156+
line: line
1157+
) { self.subject.callingState == expected }
1158+
#endif
11181159
}
11191160
}
11201161

@@ -1138,4 +1179,3 @@ extension User {
11381179
extension Member {
11391180
var userId: String { id }
11401181
}
1141-
#endif

0 commit comments

Comments
 (0)