From 5442f1fd4f27388341c2719fa28fe3c40b34c77c Mon Sep 17 00:00:00 2001 From: Pallab Gain <122030825+pallab-gain-tt@users.noreply.github.com> Date: Thu, 28 Dec 2023 12:19:20 +0200 Subject: [PATCH] SDK v0.8.2 (#409) --- NinchatSDKSwift.podspec | 2 +- .../UIKit/Video View/JitsiVideoWebView.swift | 34 +++++++++++------- .../NINGroupChatViewController.swift | 35 ++++++++++++------- 3 files changed, 44 insertions(+), 27 deletions(-) diff --git a/NinchatSDKSwift.podspec b/NinchatSDKSwift.podspec index d2b9b8e1..505b19ad 100644 --- a/NinchatSDKSwift.podspec +++ b/NinchatSDKSwift.podspec @@ -2,7 +2,7 @@ Pod::Spec.new do |s| s.name = "NinchatSDKSwift" - s.version = "0.8.1" + s.version = "0.8.2" s.summary = "iOS SDK for Ninchat, Swift version" s.description = "For building iOS applications using Ninchat messaging." s.homepage = "https://ninchat.com/" diff --git a/NinchatSDKSwift/Implementations/View/UIKit/Video View/JitsiVideoWebView.swift b/NinchatSDKSwift/Implementations/View/UIKit/Video View/JitsiVideoWebView.swift index 34287092..950a92e2 100644 --- a/NinchatSDKSwift/Implementations/View/UIKit/Video View/JitsiVideoWebView.swift +++ b/NinchatSDKSwift/Implementations/View/UIKit/Video View/JitsiVideoWebView.swift @@ -15,23 +15,23 @@ protocol JitsiVideoWebViewEventsDelegate: AnyObject { class JitsiVideoWebView: UIView { // MARK: - PROPERTIES - + // MARK: - Web view private var webView: WKWebView! - + // MARK: - Delegate var eventsDelegate: JitsiVideoWebViewEventsDelegate? - + // MARK: - Debug mode private var isDebugMode = false - + // MARK: - INITIALIZERS override init(frame: CGRect) { super.init(frame: frame) self.backgroundColor = .clear self.addWebView() } - + required init?(coder: NSCoder) { super.init(coder: coder) self.backgroundColor = .clear @@ -50,27 +50,28 @@ extension JitsiVideoWebView { webConfig.defaultWebpagePreferences.preferredContentMode = .mobile // this setting is necessary for iPad } // webConfig.preferences.setValue(true, forKey: "developerExtrasEnabled") // uncomment this if you want to debug using the web inspector - + // Enable JavaScript messaging let contentController = WKUserContentController() contentController.add(self, name: "videoConferenceJoined") contentController.add(self, name: "videoConferenceLeft") webConfig.userContentController = contentController - + self.webView = WKWebView(frame: .zero, configuration: webConfig) - + // Use black background for the web view while it loads Jitsy video webView.backgroundColor = .black webView.isOpaque = false webView.scrollView.backgroundColor = .black webView.scrollView.isScrollEnabled = false - + webView.uiDelegate = self + // Set a custom non-iPhone user agent, otherwise Jitsi might not load webView.customUserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36" - + // Set navigation delegate webView.navigationDelegate = self - + // Add web view webView.translatesAutoresizingMaskIntoConstraints = false self.addSubview(webView) @@ -109,6 +110,13 @@ extension JitsiVideoWebView: WKNavigationDelegate { } } +extension JitsiVideoWebView: WKUIDelegate { + @available(iOS 15.0, *) + func webView(_ webView: WKWebView, requestMediaCapturePermissionFor origin: WKSecurityOrigin, initiatedByFrame frame: WKFrameInfo, type: WKMediaCaptureType, decisionHandler: @escaping (WKPermissionDecision) -> Void) { + decisionHandler(.grant) + } +} + // MARK: - WKScriptMessageHandler extension JitsiVideoWebView: WKScriptMessageHandler { func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) { @@ -130,7 +138,7 @@ extension JitsiVideoWebView { let roomName = components.queryItems?.first(where: { $0.name == "roomName" })?.value ?? "" let jwt = components.queryItems?.first(where: { $0.name == "jwt" })?.value ?? "" let lang = components.queryItems?.first(where: { $0.name == "lang" })?.value ?? "en" - + let htmlContent = """ @@ -187,7 +195,7 @@ extension JitsiVideoWebView { """ - + return htmlContent } } diff --git a/NinchatSDKSwift/Implementations/View/ViewController/NINGroupChatViewController.swift b/NinchatSDKSwift/Implementations/View/ViewController/NINGroupChatViewController.swift index 9438e8c5..d706f09b 100644 --- a/NinchatSDKSwift/Implementations/View/ViewController/NINGroupChatViewController.swift +++ b/NinchatSDKSwift/Implementations/View/ViewController/NINGroupChatViewController.swift @@ -16,7 +16,7 @@ final class NINGroupChatViewController: UIViewController, DeallocatableViewContr // MARK: - Injected var viewModel: NINGroupChatViewModel! - + var onChatClosed: (() -> Void)? var onBackToQueue: (() -> Void)? var onOpenGallery: ((UIImagePickerController.SourceType) -> Void)? @@ -330,15 +330,24 @@ final class NINGroupChatViewController: UIViewController, DeallocatableViewContr // MARK: - Video Call @IBAction func onJoinVideoCallDidTap(_ sender: Any) { - view.endEditing(true) - viewModel.joinVideoCall(inside: videoViewContainer) { [weak self] error in - if error != nil { - // TODO: Jitsi - localize error - debugger("Jitsi: join video error: \(error)") - Toast.show(message: .error("Failed to join video meeting")) - } else { - self?.moveVideoContainerToFront() - self?.toggleChatButton.isHidden = false + self.viewModel.grantVideoCallPermissions { error in + if error as? PermissionError != nil { + /// 1. Show toast to notify the user + Toast.show(message: .error("\("Permission denied".localized)\n\("Update Settings".localized)")) + return + } + DispatchQueue.main.async { + self.view.endEditing(true) + self.viewModel.joinVideoCall(inside: self.videoViewContainer) { [weak self] error in + if error != nil { + // TODO: Jitsi - localize error + debugger("Jitsi: join video error: \(error)") + Toast.show(message: .error("Failed to join video meeting")) + } else { + self?.moveVideoContainerToFront() + self?.toggleChatButton.isHidden = false + } + } } } } @@ -509,7 +518,7 @@ extension NINGroupChatViewController { jitsiVideoWebView.trailingAnchor.constraint(equalTo: videoViewContainer.trailingAnchor) ]) } - + private func markVideoCallAsFinished() { moveVideoContainerToBack() markChatButton(hasUnreadMessages: false) @@ -629,7 +638,7 @@ extension NINGroupChatViewController { titlebar.map(view.bringSubviewToFront) view.bringSubviewToFront(chatControlsContainer) } - + private func addTapOverlayView() { let tapOverlayView = UIView() tapOverlayView.backgroundColor = UIColor.clear @@ -650,7 +659,7 @@ extension NINGroupChatViewController { self.tapOverlayView?.removeFromSuperview() self.tapOverlayView = nil } - + @objc private func handleTapGesture() { didTapOnVideoContainer() }