Skip to content

Commit 41d5f51

Browse files
committed
[Demo]Enable proximity policies on every active call
1 parent 2308527 commit 41d5f51

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

DemoApp/Sources/Components/AppState.swift

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import SwiftUI
99

1010
@MainActor
1111
final class AppState: ObservableObject {
12-
12+
1313
@Injected(\.callKitPushNotificationAdapter) private var callKitPushNotificationAdapter
1414
@Injected(\.callKitAdapter) private var callKitAdapter
1515
@Injected(\.gleap) private var gleap
@@ -35,7 +35,10 @@ final class AppState: ObservableObject {
3535
}
3636

3737
@Published var loading = false
38-
@Published var activeCall: Call?
38+
@Published var activeCall: Call? {
39+
didSet { didUpdate(activeCall: activeCall) }
40+
}
41+
3942
@Published var activeAnonymousCallId: String = ""
4043
@Published var voIPPushToken: String? {
4144
didSet {
@@ -110,7 +113,7 @@ final class AppState: ObservableObject {
110113
.receive(on: DispatchQueue.main)
111114
.sink { [weak self] in self?.voIPPushToken = $0 }
112115
}
113-
116+
114117
// MARK: - Actions
115118

116119
func connectUser() {
@@ -127,7 +130,7 @@ final class AppState: ObservableObject {
127130
}
128131
}
129132
}
130-
133+
131134
func logout() async {
132135
if let voipPushToken = unsecureRepository.currentVoIPPushToken() {
133136
do {
@@ -180,7 +183,7 @@ final class AppState: ObservableObject {
180183
log.debug("Clearing up VOIP push notification token.")
181184
}
182185
}
183-
186+
184187
private func didUpdate(pushToken: String?) {
185188
if let pushToken, let streamVideo {
186189
Task {
@@ -206,6 +209,19 @@ final class AppState: ObservableObject {
206209
private func didUpdate(videoFilter: VideoFilter?) {
207210
activeCall?.setVideoFilter(videoFilter)
208211
}
212+
213+
private func didUpdate(activeCall: Call?) {
214+
guard
215+
!AppEnvironment.proximityPolicies.isEmpty,
216+
let activeCall
217+
else {
218+
return
219+
}
220+
221+
AppEnvironment
222+
.proximityPolicies
223+
.forEach { try? activeCall.addProximityPolicy($0.value) }
224+
}
209225
}
210226

211227
// MARK: - UserListProvider

DemoApp/Sources/Views/CallView/CallingView/SimpleCallingView.swift

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -188,15 +188,6 @@ struct SimpleCallingView: View {
188188
await call.updateAudioSessionPolicy(AppEnvironment.audioSessionPolicy.value)
189189
}
190190

191-
private func setProximityPolicies(for callId: String) throws {
192-
let policies = AppEnvironment.proximityPolicies.map(\.value)
193-
guard !policies.isEmpty else {
194-
return
195-
}
196-
let call = streamVideo.call(callType: callType, callId: callId)
197-
try policies.forEach { try call.addProximityPolicy($0) }
198-
}
199-
200191
private func setClientCapabilities(for callId: String) async {
201192
guard let clientCapabilities = AppEnvironment.clientCapabilities else {
202193
return
@@ -241,7 +232,6 @@ struct SimpleCallingView: View {
241232
case .lobby:
242233
await setPreferredVideoCodec(for: text)
243234
try? await setAudioSessionPolicyOverride(for: text)
244-
try? setProximityPolicies(for: text)
245235
await setClientCapabilities(for: text)
246236
viewModel.enterLobby(
247237
callType: callType,
@@ -251,13 +241,11 @@ struct SimpleCallingView: View {
251241
case .join:
252242
await setPreferredVideoCodec(for: text)
253243
try? await setAudioSessionPolicyOverride(for: text)
254-
try? setProximityPolicies(for: text)
255244
await setClientCapabilities(for: text)
256245
viewModel.joinCall(callType: callType, callId: text)
257246
case let .start(callId):
258247
await setPreferredVideoCodec(for: callId)
259248
try? await setAudioSessionPolicyOverride(for: callId)
260-
try? setProximityPolicies(for: callId)
261249
await setClientCapabilities(for: callId)
262250
viewModel.startCall(
263251
callType: callType,

0 commit comments

Comments
 (0)