-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature]Disconnection timeout during call
- Loading branch information
1 parent
b7766ec
commit a7967ed
Showing
20 changed files
with
593 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
146 changes: 146 additions & 0 deletions
146
...ionTests/DocumentationTests/DocumentationTests/05-ui-cookbook/23-network-disruption.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
import StreamVideo | ||
import StreamVideoSwiftUI | ||
import SwiftUI | ||
import Combine | ||
|
||
@MainActor | ||
fileprivate func content() { | ||
container { | ||
let call = streamVideo.call(callType: "default", callId: callId) | ||
|
||
// Set the disconnection timeout to 60 seconds | ||
call.setDisconnectionTimeout(60) | ||
} | ||
|
||
container { | ||
struct DemoFeedbackView: View { | ||
|
||
@Environment(\.openURL) private var openURL | ||
@Injected(\.appearance) private var appearance | ||
|
||
@State private var email: String = "" | ||
@State private var comment: String = "" | ||
@State private var rating: Int = 5 | ||
@State private var isSubmitting = false | ||
@State private var toast: Toast? | ||
|
||
private weak var call: Call? | ||
private var dismiss: () -> Void | ||
private var isSubmitEnabled: Bool { !email.isEmpty && !isSubmitting } | ||
|
||
init(_ call: Call, dismiss: @escaping () -> Void) { | ||
self.call = call | ||
self.dismiss = dismiss | ||
} | ||
|
||
var body: some View { | ||
ScrollView { | ||
VStack(spacing: 32) { | ||
Image("feedbackLogo") | ||
|
||
VStack(spacing: 8) { | ||
Text("How is your call going?") | ||
.font(appearance.fonts.headline) | ||
.foregroundColor(appearance.colors.text) | ||
.lineLimit(1) | ||
|
||
Text("All feedback is celebrated!") | ||
.font(appearance.fonts.subheadline) | ||
.foregroundColor(.init(appearance.colors.textLowEmphasis)) | ||
.lineLimit(2) | ||
} | ||
.frame(maxWidth: .infinity, alignment: .center) | ||
.multilineTextAlignment(.center) | ||
|
||
VStack(spacing: 27) { | ||
VStack(spacing: 16) { | ||
TextField( | ||
"Email Address *", | ||
text: $email | ||
) | ||
.textFieldStyle(DemoTextfieldStyle()) | ||
|
||
DemoTextEditor(text: $comment, placeholder: "Message") | ||
} | ||
|
||
HStack { | ||
Text("Rate Quality") | ||
.font(appearance.fonts.body) | ||
.foregroundColor(.init(appearance.colors.textLowEmphasis)) | ||
.frame(maxWidth: .infinity, alignment: .leading) | ||
|
||
DemoStarRatingView(rating: $rating) | ||
} | ||
} | ||
|
||
HStack { | ||
Button { | ||
resignFirstResponder() | ||
openURL(.init(string: "https://getstream.io/video/#contact")!) | ||
} label: { | ||
Text("Contact Us") | ||
} | ||
.frame(maxWidth: .infinity) | ||
.foregroundColor(appearance.colors.text) | ||
.padding(.vertical, 4) | ||
.clipShape(Capsule()) | ||
.overlay(Capsule().stroke(Color(appearance.colors.textLowEmphasis), lineWidth: 1)) | ||
|
||
Button { | ||
resignFirstResponder() | ||
isSubmitting = true | ||
Task { | ||
do { | ||
try await call?.collectUserFeedback( | ||
rating: rating, | ||
reason: """ | ||
\(email) | ||
\(comment) | ||
""" | ||
) | ||
Task { @MainActor in | ||
dismiss() | ||
} | ||
isSubmitting = false | ||
} catch { | ||
log.error(error) | ||
dismiss() | ||
isSubmitting = false | ||
} | ||
} | ||
} label: { | ||
if isSubmitting { | ||
ProgressView() | ||
} else { | ||
Text("Submit") | ||
} | ||
} | ||
.frame(maxWidth: .infinity) | ||
.foregroundColor(appearance.colors.text) | ||
.padding(.vertical, 4) | ||
.background(isSubmitEnabled ? appearance.colors.accentBlue : appearance.colors.lightGray) | ||
.disabled(!isSubmitEnabled) | ||
.clipShape(Capsule()) | ||
} | ||
|
||
Spacer() | ||
} | ||
.padding(.horizontal) | ||
} | ||
.toastView(toast: $toast) | ||
.onAppear { checkIfDisconnectionErrorIsAvailable() } | ||
} | ||
|
||
// MARK: - Private helpers | ||
|
||
func checkIfDisconnectionErrorIsAvailable() { | ||
if call?.state.disconnectionError is ClientError.NetworkNotAvailable { | ||
toast = .init( | ||
style: .error, | ||
message: "Your call was ended because it seems your internet connection is down." | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.