Skip to content
Draft
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
2 changes: 1 addition & 1 deletion DemoApp/Sources/Components/AppEnvironment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ extension AppEnvironment {
#if targetEnvironment(simulator)
return .simple
#else
return .simple
return .detailed
#endif
case .release:
return .simple
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ struct DetailedCallingView<Factory: ViewFactory>: View {
callType: callType,
callId: text,
members: members,
ring: callFlow == .ringEvents,
ring: false,//callFlow == .ringEvents,
video: viewModel.callSettings.videoOn
)
}
Expand All @@ -189,6 +189,18 @@ struct DetailedCallingView<Factory: ViewFactory>: View {
self.callAction = currentUser?.type == .regular ? callAction : .joinCall
self.callFlow = currentUser?.type == .regular ? callFlow : .joinImmediately
}
.onChange(of: viewModel.callingState) { state in
if state == .inCall && !hasRang {
hasRang = true
viewModel.ring(
callType: callType,
callId: text,
members: members,
video: true,
showOutgoingScreen: true
)
}
}
}

@ViewBuilder
Expand Down Expand Up @@ -244,3 +256,6 @@ struct DetailedCallingView<Factory: ViewFactory>: View {
)
}
}

//TODO: temp for testing.
var hasRang = false
10 changes: 10 additions & 0 deletions Sources/StreamVideo/Call.swift
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,16 @@ public class Call: @unchecked Sendable, WSEventsSubscriber {
}
return response.call
}

@discardableResult
public func ring(request: RingCallRequest) async throws -> RingCallResponse {
let response = try await coordinatorClient.ringCall(
type: callType,
id: callId,
ringCallRequest: request
)
return response
}

/// Updates an existing call with the specified parameters.
/// - Parameters:
Expand Down
47 changes: 46 additions & 1 deletion Sources/StreamVideoSwiftUI/CallViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ open class CallViewModel: ObservableObject {
private(set) var localCallSettingsChange = false

private var hasAcceptedCall = false
private var skipCallStateUpdates = false

public var participants: [CallParticipant] {
let updateParticipants = call?.state.participants ?? []
Expand Down Expand Up @@ -431,6 +432,46 @@ open class CallViewModel: ObservableObject {
customData: customData
)
}

public func ring(
callType: String,
callId: String,
members: [Member],
video: Bool? = nil,
showOutgoingScreen: Bool = false
) {
outgoingCallMembers = members
if showOutgoingScreen {
skipCallStateUpdates = true
setCallingState(.outgoing)
}
if self.call == nil || (call?.id != callId && call?.callType != callType) {
let callSettings = localCallSettingsChange ? callSettings : nil
let call = streamVideo.call(
callType: callType,
callId: callId,
callSettings: callSettings
)
self.call = call
}
guard let call else { return }
Task(disposableBag: disposableBag, priority: .userInitiated) { [weak self] in
guard let self else { return }
do {
try await call.ring(
request: .init(membersIds: members.map(\.id).filter { $0 != self.streamVideo.user.id }, video: video)
)
if let autoCancelTimeout = call.state.settings?.ring.autoCancelTimeoutMs {
let timeoutSeconds = TimeInterval(autoCancelTimeout / 1000)
startTimer(timeout: timeoutSeconds)
}
} catch {
self.error = error
setCallingState(.idle)
self.call = nil
}
}
}

/// Enters into a lobby before joining a call.
/// - Parameters:
Expand Down Expand Up @@ -593,7 +634,9 @@ open class CallViewModel: ObservableObject {
lineNumber: line
)
if let call, (callingState != .inCall || self.call?.cId != call.cId) {
setCallingState(.inCall)
if !skipCallStateUpdates {
setCallingState(.inCall)
}
self.call = call
} else if call == nil, callingState != .idle {
setCallingState(.idle)
Expand Down Expand Up @@ -887,6 +930,7 @@ open class CallViewModel: ObservableObject {
setActiveCall(call)
}
case .outgoing where call?.cId == event.callCid:
skipCallStateUpdates = false
enterCall(
call: call,
callType: event.type,
Expand Down Expand Up @@ -942,6 +986,7 @@ open class CallViewModel: ObservableObject {
}

private func updateCallStateIfNeeded() {
guard !skipCallStateUpdates else { return }
if callingState == .outgoing {
if !callParticipants.isEmpty {
setCallingState(.inCall)
Expand Down
Loading