Skip to content

Commit c6f3761

Browse files
authored
[Enhancement]Allow deeplinks from new domain (#785)
1 parent e32dd86 commit c6f3761

File tree

9 files changed

+193
-82
lines changed

9 files changed

+193
-82
lines changed

DemoApp/Sources/Components/AppEnvironment.swift

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ extension AppEnvironment {
4141
case demo
4242
case legacy
4343
case prontoFrankfurtC2
44+
case livestream
4445
case custom(baseURL: BaseURL, apiKey: String, token: String)
4546

4647
var url: URL {
@@ -55,6 +56,8 @@ extension AppEnvironment {
5556
URL(string: "https://getstream.io")!
5657
case .legacy:
5758
URL(string: "https://stream-calls-dogfood.vercel.app")!
59+
case .livestream:
60+
URL(string: "https://livestream-react-demo.vercel.app")!
5861
case let .custom(baseURL, _, _):
5962
baseURL.url
6063
}
@@ -72,6 +75,8 @@ extension AppEnvironment {
7275
return "Staging"
7376
case .legacy:
7477
return "Legacy"
78+
case .livestream:
79+
return "Livestream"
7580
case .demo:
7681
return "Demo"
7782
case let .custom(_, apiKey, _):
@@ -94,6 +99,9 @@ extension AppEnvironment {
9499
.appendingPathComponent("join")
95100
.appendingPathComponent(callId)
96101
.addQueryParameter("type", value: callType)
102+
case .livestream:
103+
return url
104+
.appending(.init(name: "id", value: callId))
97105
default:
98106
return url
99107
.appendingPathComponent("join")
@@ -107,7 +115,8 @@ extension AppEnvironment {
107115
.prontoStaging,
108116
.staging,
109117
.demo,
110-
.legacy
118+
.legacy,
119+
.livestream
111120
]
112121
}
113122

@@ -258,6 +267,7 @@ extension AppEnvironment {
258267
case staging
259268
case demo
260269
case legacy
270+
case livestream
261271

262272
var deeplinkURL: URL {
263273
switch self {
@@ -269,6 +279,8 @@ extension AppEnvironment {
269279
return BaseURL.demo.url
270280
case .legacy:
271281
return BaseURL.legacy.url
282+
case .livestream:
283+
return BaseURL.livestream.url
272284
}
273285
}
274286

@@ -282,18 +294,20 @@ extension AppEnvironment {
282294
return "Demo"
283295
case .legacy:
284296
return "Legacy"
297+
case .livestream:
298+
return "Livestream"
285299
}
286300
}
287301
}
288302

289303
static var supportedDeeplinks: [SupportedDeeplink] = {
290304
switch configuration {
291305
case .debug:
292-
return [.pronto, .demo, .staging, .legacy]
306+
return [.pronto, .demo, .staging, .legacy, .livestream]
293307
case .test:
294308
return [.pronto, .demo, .staging, .legacy]
295309
case .release:
296-
return [.demo]
310+
return [.demo, .livestream]
297311
}
298312
}()
299313
}

DemoApp/Sources/Components/Authentication/AuthenticationProvider.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ enum AuthenticationProvider {
4646
return "demo"
4747
case .prontoFrankfurtC2:
4848
return "pronto-fra-c2"
49+
case .livestream:
50+
return "demo"
4951
case .custom:
5052
return ""
5153
}

DemoApp/Sources/Components/Deeplinks/DeeplinkAdapter.swift

Lines changed: 53 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -37,51 +37,65 @@ struct DeeplinkAdapter {
3737
guard canHandle(url: url) else {
3838
return (.empty, nil)
3939
}
40-
41-
let pathComponentsCount = url.pathComponents.endIndex
4240

43-
// Fetch the callId from the path components
44-
// e.g https://getstream.io/join/path-call-id
45-
let callPathId: String? = {
41+
if
42+
url.host == AppEnvironment.BaseURL.livestream.url.host,
43+
let callId = url.queryParameters["id"] ?? url.queryParameters["view"] {
44+
return (
45+
DeeplinkInfo(
46+
url: url,
47+
callId: callId,
48+
callType: .livestream,
49+
baseURL: AppEnvironment.BaseURL.livestream
50+
),
51+
nil
52+
)
53+
} else {
54+
let pathComponentsCount = url.pathComponents.endIndex
55+
56+
// Fetch the callId from the path components
57+
// e.g https://getstream.io/join/path-call-id
58+
let callPathId: String? = {
59+
guard
60+
pathComponentsCount >= 2,
61+
url.pathComponents[pathComponentsCount - 2] == "join",
62+
let callId = url.pathComponents.last
63+
else {
64+
return nil
65+
}
66+
return callId
67+
}()
68+
69+
// Fetch the callId from the query parameters
70+
// e.g https://getstream.io/video/demos?id=parameter-call-id
71+
let callParameterId = url.queryParameters["id"]
72+
4673
guard
47-
pathComponentsCount >= 2,
48-
url.pathComponents[pathComponentsCount - 2] == "join",
49-
let callId = url.pathComponents.last
74+
// Use the the callPathId with higher priority if it's available.
75+
let callId = callPathId ?? callParameterId
5076
else {
51-
return nil
77+
log.warning("Unable to handle deeplink because id was missing.")
78+
return (.empty, nil)
5279
}
53-
return callId
54-
}()
55-
56-
// Fetch the callId from the query parameters
57-
// e.g https://getstream.io/video/demos?id=parameter-call-id
58-
let callParameterId = url.queryParameters["id"]
5980

60-
guard
61-
// Use the the callPathId with higher priority if it's available.
62-
let callId = callPathId ?? callParameterId
63-
else {
64-
log.warning("Unable to handle deeplink because id was missing.")
65-
return (.empty, nil)
66-
}
81+
let callType = url.queryParameters["type"] ?? "default"
6782

68-
let callType = url.queryParameters["type"] ?? "default"
83+
log.debug("Deeplink handled was: \(url)")
84+
let host = url.host
85+
let baseURL: AppEnvironment.BaseURL = AppEnvironment
86+
.BaseURL
87+
.allCases
88+
.first { $0.url.host == host } ?? AppEnvironment.baseURL
6989

70-
log.debug("Deeplink handled was: \(url)")
71-
let host = url.host
72-
let baseURL: AppEnvironment.BaseURL = AppEnvironment
73-
.BaseURL
74-
.allCases
75-
.first { $0.url.host == host } ?? AppEnvironment.baseURL
76-
77-
return (
78-
DeeplinkInfo(
79-
url: url,
80-
callId: callId,
81-
callType: callType,
82-
baseURL: baseURL
83-
),
84-
nil
85-
)
90+
return (
91+
DeeplinkInfo(
92+
url: url,
93+
callId: callId,
94+
callType: callType,
95+
baseURL: baseURL
96+
),
97+
nil
98+
)
99+
}
86100
}
87101
}

DemoApp/Sources/ViewModifiers/CallModifier/DemoCallModifier.swift

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import SwiftUI
99

1010
struct DemoCallModifier<Factory: ViewFactory>: ViewModifier {
1111

12+
@Injected(\.appearance) private var appearance
13+
1214
var viewFactory: Factory
1315
var viewModel: CallViewModel
1416
var chatViewModel: DemoChatViewModel
@@ -27,32 +29,16 @@ struct DemoCallModifier<Factory: ViewFactory>: ViewModifier {
2729

2830
func body(content: Content) -> some View {
2931
contentView(content)
32+
.modifier(ThermalStateViewModifier())
3033
}
3134

3235
@MainActor
3336
@ViewBuilder
3437
private func contentView(_ rootView: Content) -> some View {
35-
if
36-
let call = viewModel.call,
37-
call.callType == .livestream {
38-
ZStack {
39-
rootView
40-
LivestreamPlayer(
41-
viewFactory: viewFactory,
42-
type: call.callType,
43-
id: call.callId,
44-
joinPolicy: .none,
45-
showsLeaveCallButton: true,
46-
onFullScreenStateChange: { [weak viewModel] in viewModel?.hideUIElements = $0 }
47-
)
48-
}
49-
} else {
50-
VideoViewOverlay(
51-
rootView: rootView,
52-
viewFactory: viewFactory,
53-
viewModel: viewModel
54-
)
55-
.modifier(ThermalStateViewModifier())
56-
}
38+
DemoVideoViewOverlay(
39+
rootView: rootView,
40+
viewFactory: viewFactory,
41+
viewModel: viewModel
42+
)
5743
}
5844
}

DemoApp/Sources/Views/CallTopView/DemoCallTopView.swift

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,27 @@ struct DemoCallTopView: View {
2222

2323
var body: some View {
2424
HStack(spacing: 0) {
25-
HStack {
26-
if viewModel.callParticipants.count > 1, !hideLayoutMenu {
27-
LayoutMenuView(viewModel: viewModel)
28-
.accessibility(identifier: "viewMenu")
29-
}
25+
if !isCallLivestream {
26+
HStack {
27+
if viewModel.callParticipants.count > 1, !hideLayoutMenu {
28+
LayoutMenuView(viewModel: viewModel)
29+
.accessibility(identifier: "viewMenu")
30+
}
3031

31-
ToggleCameraIconView(viewModel: viewModel)
32+
ToggleCameraIconView(viewModel: viewModel)
3233

33-
Spacer()
34+
Spacer()
35+
}
36+
.frame(maxWidth: .infinity)
3437
}
35-
.frame(maxWidth: .infinity)
3638

37-
HStack(alignment: .center) {
38-
CallDurationView(viewModel)
39+
if !isCallLivestream {
40+
HStack(alignment: .center) {
41+
CallDurationView(viewModel)
42+
}
43+
.frame(height: 44)
44+
.frame(maxWidth: .infinity)
3945
}
40-
.frame(height: 44)
41-
.frame(maxWidth: .infinity)
4246

4347
HStack {
4448
Spacer()
@@ -61,6 +65,11 @@ struct DemoCallTopView: View {
6165
)
6266
}
6367

68+
private var isCallLivestream: Bool {
69+
guard let call = viewModel.call else { return false }
70+
return call.callType == .livestream
71+
}
72+
6473
private var hideLayoutMenu: Bool {
6574
viewModel.call?.state.screenSharingSession != nil
6675
&& viewModel.call?.state.isCurrentUserScreensharing == false

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@ struct DemoCallingViewModifier: ViewModifier {
2020

2121
private var isAnonymous: Bool { appState.currentUser == .anonymous }
2222

23-
private var callType: String {
23+
@State private var callType: String =
2424
!AppState.shared.deeplinkInfo.callType.isEmpty
2525
? AppState.shared.deeplinkInfo.callType
2626
: AppEnvironment.preferredCallType ?? .default
27-
}
2827

2928
init(
3029
text: Binding<String>,
@@ -49,14 +48,15 @@ struct DemoCallingViewModifier: ViewModifier {
4948
// deeplink.
5049

5150
if deeplinkInfo.callId.isEmpty {
52-
joinCallIfNeeded(with: self.text.wrappedValue, callType: callType)
51+
joinCallIfNeeded(with: self.text.wrappedValue, callType: deeplinkInfo.callType)
5352
} else {
5453
self.text.wrappedValue = deeplinkInfo.callId
5554
joinCallIfNeeded(
5655
with: self.text.wrappedValue,
57-
callType: callType
56+
callType: deeplinkInfo.callType
5857
)
5958
}
59+
callType = deeplinkInfo.callType
6060
}
6161
.onChange(of: viewModel.callingState) { callingState in
6262
switch callingState {

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,9 @@ struct SimpleCallingView: View {
156156
return
157157
}
158158

159-
if deeplinkInfo.baseURL == AppEnvironment
160-
.baseURL || (deeplinkInfo.baseURL == .legacy && AppEnvironment.baseURL == .pronto) {
159+
if
160+
deeplinkInfo.baseURL == AppEnvironment.baseURL || (deeplinkInfo.baseURL == .legacy && AppEnvironment.baseURL == .pronto)
161+
{
161162
if !Set(AppEnvironment.availableCallTypes).contains(deeplinkInfo.callType) {
162163
AppEnvironment.availableCallTypes.append(deeplinkInfo.callType)
163164
}

0 commit comments

Comments
 (0)