Skip to content

Commit

Permalink
Add didFailProvisionalNavigation
Browse files Browse the repository at this point in the history
  • Loading branch information
SvenTiigi committed Oct 9, 2024
1 parent fe1c1ec commit 4de9cd9
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Sources/Models/YouTubePlayer+Error.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public extension YouTubePlayer {
enum Error: Swift.Error, Sendable {
/// Player setup failed with Error
case setupFailed(Swift.Error)
/// Did fail provisional navigation
case didFailProvisionalNavigation(Swift.Error)
/// The web views underlying web content process was terminated
case webContentProcessDidTerminate
/// The YouTube iFrame API JavaScript failed to load
Expand Down
3 changes: 3 additions & 0 deletions Sources/WebView/YouTubePlayerWebView+Event.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import WebKit

// MARK: - YouTubePlayerWebView+Event

Expand All @@ -10,6 +11,8 @@ extension YouTubePlayerWebView {
case receivedJavaScriptEvent(YouTubePlayer.JavaScriptEvent)
/// The frame of the YouTubePlayerWebView changed
case frameChanged(CGRect)
/// Did fail provisional navigation
case didFailProvisionalNavigation(Error)
/// Web content process did terminate
case webContentProcessDidTerminate
}
Expand Down
15 changes: 15 additions & 0 deletions Sources/WebView/YouTubePlayerWebView+WKNavigationDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@ import WebKit

extension YouTubePlayerWebView: WKNavigationDelegate {

/// WebView did fail provisional navigation
/// - Parameters:
/// - webView: The web view.
/// - navigation: The navigation.
/// - error: The error.
func webView(
_ webView: WKWebView,
didFailProvisionalNavigation navigation: WKNavigation!,
withError error: Error
) {
self.eventSubject.send(
.didFailProvisionalNavigation(error)
)
}

/// WebView decide policy for NavigationAction
/// - Parameters:
/// - webView: The WKWebView
Expand Down
7 changes: 7 additions & 0 deletions Sources/YouTubePlayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,13 @@ private extension YouTubePlayer {
self.webView.evaluate(
javaScript: .init("setYouTubePlayerSize(\(parameters));")
)
case .didFailProvisionalNavigation(let error):
// Send object will change event
self.objectWillChange.send()
// Send web content process did terminate error
self.playerStateSubject.send(
.error(.didFailProvisionalNavigation(error))
)
case .webContentProcessDidTerminate:
// Send object will change event
self.objectWillChange.send()
Expand Down

0 comments on commit 4de9cd9

Please sign in to comment.