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]Deeplink handling #163

Merged
merged 6 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
3 changes: 1 addition & 2 deletions DemoApp/Resources/Entitlements/DemoApp-Debug.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
<string>development</string>
<key>com.apple.developer.associated-domains</key>
<array>
<string>applinks:staging.getstream.io</string>
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't needed as the domain is the same and can be handled.

<string>applinks:getstream.io</string>
<string>applinks:getstream.io</string>
</array>
<key>com.apple.security.application-groups</key>
<array>
Expand Down
1 change: 0 additions & 1 deletion DemoApp/Resources/Entitlements/DemoApp.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<string>production</string>
<key>com.apple.developer.associated-domains</key>
<array>
<string>applinks:staging.getstream.io</string>
<string>applinks:getstream.io</string>
</array>
<key>com.apple.security.application-groups</key>
Expand Down
18 changes: 16 additions & 2 deletions DemoApp/Sources/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import UIKit
import GDPerformanceView_Swift

class AppDelegate: NSObject, UIApplicationDelegate, UNUserNotificationCenterDelegate {

@Injected(\.streamVideo) var streamVideo

func application(
Expand All @@ -21,6 +21,7 @@ class AppDelegate: NSObject, UIApplicationDelegate, UNUserNotificationCenterDele
return true
}

/// Method used to handle custom URL schemes
func application(
_ app: UIApplication,
open url: URL,
Expand All @@ -30,14 +31,27 @@ class AppDelegate: NSObject, UIApplicationDelegate, UNUserNotificationCenterDele
return true
}

/// Method used to handle universal deeplinks
func application(
_ application: UIApplication,
continue userActivity: NSUserActivity,
restorationHandler: @escaping ([UIUserActivityRestoring]?
) -> Void) -> Bool {
guard let url = userActivity.webpageURL else {
return false
}
Router.shared.handle(url: url)
return true
}

func application(
_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data
) {
let deviceToken = deviceToken.map { String(format: "%02x", $0) }.joined()
AppState.shared.pushToken = deviceToken
}

func userNotificationCenter(
_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
Expand Down
2 changes: 1 addition & 1 deletion DemoApp/Sources/Components/AppEnvironment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ extension AppEnvironment {
case .debug:
return [.staging, .pronto, .production]
case .test:
return [.staging]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update test environment to be able to process all available deeplinks

return [.staging, .pronto, .production]
case .release:
return [.production]
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// Copyright © 2023 Stream.io Inc. All rights reserved.
//

import Foundation
import StreamVideo
import OSLog

final class OSLogDestination: BaseLogDestination {

override func write(message: String) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This allows us to see our logs from the AppStore versions using the Console.app

os_log("%{public}s", message)
}
}
3 changes: 3 additions & 0 deletions DemoApp/Sources/Components/Router.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,17 @@ final class Router: ObservableObject {
// MARK: - Handle URL

func handle(url: URL) {
log.debug("Request to handle deeplink \(url)")
let (deeplinkInfo, _) = deeplinkAdapter.handle(url: url)

guard
deeplinkInfo != .empty
else {
log.warning("Request to handle deeplink \(url) denied ❌")
return
}

log.debug("Request to handle deeplink \(url) accepted ✅")
if streamVideoUI != nil {
appState.deeplinkInfo = deeplinkInfo
} else {
Expand Down
9 changes: 5 additions & 4 deletions DemoApp/Sources/Extensions/DemoApp+Sentry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ extension DemoApp {
}

LogConfig.destinationTypes = [
ConsoleLogDestination.self,
SentryLogDestination.self,
MemoryLogDestination.self
MemoryLogDestination.self,
OSLogDestination.self
]
} else {
LogConfig.level = .debug
LogConfig.destinationTypes = [
ConsoleLogDestination.self,
MemoryLogDestination.self
MemoryLogDestination.self,
OSLogDestination.self
]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import StreamVideoSwiftUI

struct DetailedCallingView: View {
@ObservedObject var viewModel: CallViewModel

@Injected(\.streamVideo) var streamVideo

private let imageSize: CGFloat = 32

@State private var callId = ""

@State private var callAction = CallAction.startCall

@State private var callFlow: CallFlow = .joinImmediately

var participants: [User] {
Expand All @@ -28,13 +28,13 @@ struct DetailedCallingView: View {
}
return participants
}

@State var selectedParticipants = [User]()
@State var incomingCallInfo: IncomingCall?
@State var logoutAlertShown = false

@ObservedObject var appState = AppState.shared

var body: some View {
NavigationView {
VStack {
Expand All @@ -53,7 +53,7 @@ struct DetailedCallingView: View {
Text("Call details")
.font(.title)
.padding()

HStack {
Spacer()
ZStack {
Expand All @@ -71,18 +71,18 @@ struct DetailedCallingView: View {
.padding()
}
}

Picker("Call action", selection: $callAction) {
Text(CallAction.startCall.rawValue).tag(CallAction.startCall)
Text(CallAction.joinCall.rawValue).tag(CallAction.joinCall)
}
.pickerStyle(.segmented)

TextField("Insert a call id", text: $callId)
.textFieldStyle(.roundedBorder)
.padding()
.accessibilityIdentifier("callId")

if callAction == .startCall {
startCallView
.transition(.opacity)
Expand All @@ -107,7 +107,7 @@ struct DetailedCallingView: View {
.alignedToReadableContentGuide()
}
.navigationViewStyle(StackNavigationViewStyle())
// .navigationBarHidden(true)
// .navigationBarHidden(true)
ipavlidakis marked this conversation as resolved.
Show resolved Hide resolved
.onAppear() {
CallService.shared.registerForIncomingCalls()
}
Expand Down Expand Up @@ -140,12 +140,16 @@ struct DetailedCallingView: View {
self.callId = callId
viewModel.joinCall(callType: .default, callId: callId)
}
.onReceive(appState.$deeplinkInfo) { deeplinkInfo in
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this one to align the DetailedCallingView with the SimpleView and allow us to perform the DeeplinkTests

self.callId = deeplinkInfo.callId
joinCallIfNeeded(with: deeplinkInfo.callId, callType: deeplinkInfo.callType)
}
}

private var makeCallEnabled: Bool {
callId.isEmpty || participants.isEmpty
}

var startCallView: some View {
Group {
HStack {
Expand All @@ -154,7 +158,7 @@ struct DetailedCallingView: View {
Spacer()
}
.padding(.horizontal)

List(participants) { participant in
Button {
if selectedParticipants.contains(participant) {
Expand All @@ -179,7 +183,7 @@ struct DetailedCallingView: View {
.frame(maxHeight: UIScreen.main.bounds.height / 4)
.listStyle(PlainListStyle())
.accessibility(identifier: "participantList")

Picker("Call flow", selection: $callFlow) {
Text(CallFlow.joinImmediately.rawValue)
.tag(CallFlow.joinImmediately)
Expand All @@ -192,7 +196,7 @@ struct DetailedCallingView: View {
.accessibility(identifier: CallFlow.lobby.rawValue)
}
.pickerStyle(.segmented)

Button {
resignFirstResponder()
if callFlow == .lobby {
Expand All @@ -216,7 +220,7 @@ struct DetailedCallingView: View {
.cornerRadius(16)
}
}

var members: [MemberRequest] {
var members: [MemberRequest] = selectedParticipants.map {
MemberRequest(custom: $0.customData, role: $0.role, userId: $0.id)
Expand All @@ -232,7 +236,19 @@ struct DetailedCallingView: View {
}
return members
}


private func joinCallIfNeeded(with callId: String, callType: String = .default) {
guard !callId.isEmpty, viewModel.callingState == .idle else {
return
}

Task {
try await streamVideo.connect()
await MainActor.run {
viewModel.joinCall(callType: callType, callId: callId)
}
}
}
}

enum CallAction: String {
Expand Down
10 changes: 10 additions & 0 deletions StreamVideo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@
409BFA402A9F79D2003341EF /* View+OptionalPublisher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 409BFA3F2A9F79D2003341EF /* View+OptionalPublisher.swift */; };
409BFA432A9F7BBB003341EF /* ReadableContentGuide.swift in Sources */ = {isa = PBXBuildFile; fileRef = 409BFA422A9F7BBB003341EF /* ReadableContentGuide.swift */; };
40AB31262A49838000C270E1 /* EventTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40AB31252A49838000C270E1 /* EventTests.swift */; };
40B499CA2AC1A5E100A53B60 /* OSLogDestination.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40B499C92AC1A5E100A53B60 /* OSLogDestination.swift */; };
40B499CC2AC1A90F00A53B60 /* DeeplinkTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40B499CB2AC1A90F00A53B60 /* DeeplinkTests.swift */; };
40B499CE2AC1AA0900A53B60 /* AppEnvironment.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4030E59F2A9DF5BD003E8CBA /* AppEnvironment.swift */; };
40B713692A275F1400D1FE67 /* AppState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8456E6C5287EB55F004E180E /* AppState.swift */; };
40D7E7962AB1C9590017095E /* ThermalStateViewModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40D7E7952AB1C9580017095E /* ThermalStateViewModifier.swift */; };
40D946412AA5ECEF00C8861B /* CodeScanner.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40D946402AA5ECEF00C8861B /* CodeScanner.swift */; };
Expand Down Expand Up @@ -894,6 +897,8 @@
409BFA3F2A9F79D2003341EF /* View+OptionalPublisher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "View+OptionalPublisher.swift"; sourceTree = "<group>"; };
409BFA422A9F7BBB003341EF /* ReadableContentGuide.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReadableContentGuide.swift; sourceTree = "<group>"; };
40AB31252A49838000C270E1 /* EventTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventTests.swift; sourceTree = "<group>"; };
40B499C92AC1A5E100A53B60 /* OSLogDestination.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OSLogDestination.swift; sourceTree = "<group>"; };
40B499CB2AC1A90F00A53B60 /* DeeplinkTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeeplinkTests.swift; sourceTree = "<group>"; };
40D7E7952AB1C9580017095E /* ThermalStateViewModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThermalStateViewModifier.swift; sourceTree = "<group>"; };
40D946402AA5ECEF00C8861B /* CodeScanner.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CodeScanner.swift; sourceTree = "<group>"; };
40D946422AA5F65300C8861B /* DemoQRCodeScannerButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DemoQRCodeScannerButton.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1772,6 +1777,7 @@
isa = PBXGroup;
children = (
409386192AA09E4A00FF5AF4 /* MemoryLogDestination.swift */,
40B499C92AC1A5E100A53B60 /* OSLogDestination.swift */,
4093861B2AA0A11500FF5AF4 /* LogQueue.swift */,
4093861E2AA0A21800FF5AF4 /* MemoryLogViewer.swift */,
);
Expand Down Expand Up @@ -2038,6 +2044,7 @@
82D858B729EDAE0A00CF9F8B /* ParticipantActionsTests.swift */,
824DBA9F29F6D77B005ACD09 /* ReconnectionTests.swift */,
82FB89362A702A9200AC16A1 /* Authentication_Tests.swift */,
40B499CB2AC1A90F00A53B60 /* DeeplinkTests.swift */,
);
path = Tests;
sourceTree = "<group>";
Expand Down Expand Up @@ -3694,6 +3701,7 @@
82C837E229A532C000CB6B0E /* LoginPage.swift in Sources */,
82392D542993C9E100941435 /* StreamTestCase.swift in Sources */,
82C837E029A531ED00CB6B0E /* CallPage.swift in Sources */,
40B499CE2AC1AA0900A53B60 /* AppEnvironment.swift in Sources */,
82B8C0FA29E80997001F816C /* RingProcessTests.swift in Sources */,
82392D6B2993CDF500941435 /* UserRobot.swift in Sources */,
82D858B829EDAE0A00CF9F8B /* ParticipantActionsTests.swift in Sources */,
Expand All @@ -3704,6 +3712,7 @@
82AD932529E6FCCF00D4D295 /* LobbyPage.swift in Sources */,
824DBAA029F6D77B005ACD09 /* ReconnectionTests.swift in Sources */,
828DE5BD299521EF00F93197 /* UserRobot+Asserts.swift in Sources */,
40B499CC2AC1A90F00A53B60 /* DeeplinkTests.swift in Sources */,
82B8C0FC29E80A2A001F816C /* CallLifecycleTests.swift in Sources */,
82392D71299403B200941435 /* CallViewsTests.swift in Sources */,
820221622A24BB7100F7BAED /* LaunchArgument.swift in Sources */,
Expand Down Expand Up @@ -3779,6 +3788,7 @@
847B47B52A249E7E000714CE /* Examples.swift in Sources */,
40F445F72A9E2AAC004BE3DA /* ReactionsViewModifier.swift in Sources */,
4093861F2AA0A21800FF5AF4 /* MemoryLogViewer.swift in Sources */,
40B499CA2AC1A5E100A53B60 /* OSLogDestination.swift in Sources */,
84D6493E29E7F75E002CA428 /* CallsViewModel.swift in Sources */,
401A64AB2A9DF7EC00534ED1 /* DemoChatAdapter.swift in Sources */,
4093861A2AA09E4A00FF5AF4 /* MemoryLogDestination.swift in Sources */,
Expand Down
Loading