Skip to content

Commit

Permalink
SDK v0.8.2 (#409)
Browse files Browse the repository at this point in the history
  • Loading branch information
pallab-gain-tt authored Dec 28, 2023
1 parent 778d769 commit 5442f1f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 27 deletions.
2 changes: 1 addition & 1 deletion NinchatSDKSwift.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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) {
Expand All @@ -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 = """
<!DOCTYPE html>
<html>
Expand Down Expand Up @@ -187,7 +195,7 @@ extension JitsiVideoWebView {
</body>
</html>
"""

return htmlContent
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)?
Expand Down Expand Up @@ -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
}
}
}
}
}
Expand Down Expand Up @@ -509,7 +518,7 @@ extension NINGroupChatViewController {
jitsiVideoWebView.trailingAnchor.constraint(equalTo: videoViewContainer.trailingAnchor)
])
}

private func markVideoCallAsFinished() {
moveVideoContainerToBack()
markChatButton(hasUnreadMessages: false)
Expand Down Expand Up @@ -629,7 +638,7 @@ extension NINGroupChatViewController {
titlebar.map(view.bringSubviewToFront)
view.bringSubviewToFront(chatControlsContainer)
}

private func addTapOverlayView() {
let tapOverlayView = UIView()
tapOverlayView.backgroundColor = UIColor.clear
Expand All @@ -650,7 +659,7 @@ extension NINGroupChatViewController {
self.tapOverlayView?.removeFromSuperview()
self.tapOverlayView = nil
}

@objc private func handleTapGesture() {
didTapOnVideoContainer()
}
Expand Down

0 comments on commit 5442f1f

Please sign in to comment.