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

Feature/jitsi in webview #399

Merged
merged 13 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
17 changes: 0 additions & 17 deletions JitsiMeetSDK.podspec

This file was deleted.

4 changes: 2 additions & 2 deletions 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.7.0"
s.version = "0.7.1"
s.summary = "iOS SDK for Ninchat, Swift version"
s.description = "For building iOS applications using Ninchat messaging."
s.homepage = "https://ninchat.com/"
Expand Down Expand Up @@ -40,7 +40,7 @@ Pod::Spec.new do |s|
}

# Cocoapods dependencies
s.dependency "JitsiMeetSDK", "~> 0.7.0"
s.dependency "JitsiWebRTC", "106.0.0"
s.dependency 'AnyCodable-FlightSchool', '~> 0.2.3'
s.dependency "AutoLayoutSwift", "4.0.0"
s.dependency "NinchatLowLevelClient", "~> 0.6.0"
Expand Down
8 changes: 5 additions & 3 deletions NinchatSDKSwift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 51;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
Expand All @@ -17,6 +17,7 @@
5C7A2AF227D20AF90067F2F1 /* QuestionnaireCellForm.xib in Resources */ = {isa = PBXBuildFile; fileRef = 5C7A2AF127D20AF90067F2F1 /* QuestionnaireCellForm.xib */; };
5CD4F1C82540CAAF009856AC /* Notification+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CD4F1C62540CAAF009856AC /* Notification+Extension.swift */; };
5CD4F1C92540CAAF009856AC /* KeyboardHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CD4F1C72540CAAF009856AC /* KeyboardHandler.swift */; };
75990FEF2AD7E95500EBC306 /* JitsiVideoWebView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75990FEE2AD7E95500EBC306 /* JitsiVideoWebView.swift */; };
7C44F1A84C25C4445CF3B955 /* Pods_NinchatSDKSwift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 495ADA60487CD354EDC07332 /* Pods_NinchatSDKSwift.framework */; };
851E359923B1214E000FA966 /* AutolayouTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 851E359823B1214E000FA966 /* AutolayouTests.swift */; };
851ECF6423969297006D332F /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = 851ECF6323969297006D332F /* README.md */; };
Expand Down Expand Up @@ -265,6 +266,7 @@
5CD4F1C62540CAAF009856AC /* Notification+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Notification+Extension.swift"; sourceTree = "<group>"; };
5CD4F1C72540CAAF009856AC /* KeyboardHandler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeyboardHandler.swift; sourceTree = "<group>"; };
62C8D99D572F0DB4B5E6D255 /* Pods-NinchatSDKSwiftUITests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-NinchatSDKSwiftUITests.release.xcconfig"; path = "Target Support Files/Pods-NinchatSDKSwiftUITests/Pods-NinchatSDKSwiftUITests.release.xcconfig"; sourceTree = "<group>"; };
75990FEE2AD7E95500EBC306 /* JitsiVideoWebView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JitsiVideoWebView.swift; sourceTree = "<group>"; };
7B50C1E321841F3749D5D05A /* Pods-NinchatSDKSwiftServerTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-NinchatSDKSwiftServerTests.release.xcconfig"; path = "Target Support Files/Pods-NinchatSDKSwiftServerTests/Pods-NinchatSDKSwiftServerTests.release.xcconfig"; sourceTree = "<group>"; };
832BEC3E467C0EEE45282F1B /* Pods-NinchatSDKSwiftTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-NinchatSDKSwiftTests.debug.xcconfig"; path = "Target Support Files/Pods-NinchatSDKSwiftTests/Pods-NinchatSDKSwiftTests.debug.xcconfig"; sourceTree = "<group>"; };
851E359823B1214E000FA966 /* AutolayouTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AutolayouTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -481,7 +483,6 @@
FA026FE8299BAC6100C4D3E4 /* JoinVideoButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JoinVideoButton.swift; sourceTree = "<group>"; };
FA026FEA299BAC7A00C4D3E4 /* NINGroupChatViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NINGroupChatViewController.swift; sourceTree = "<group>"; };
FA026FEC299BAC8C00C4D3E4 /* NINGroupChatViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NINGroupChatViewModel.swift; sourceTree = "<group>"; };
FA7958B329FBB821006527A7 /* JitsiMeetSDK.podspec */ = {isa = PBXFileReference; lastKnownFileType = text; path = JitsiMeetSDK.podspec; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -611,6 +612,7 @@
8530EC8223AD405200BAA52A /* Video View */ = {
isa = PBXGroup;
children = (
75990FEE2AD7E95500EBC306 /* JitsiVideoWebView.swift */,
8530EC8423AD405200BAA52A /* VideoView.swift */,
8530EC8323AD405200BAA52A /* VideoView.xib */,
);
Expand Down Expand Up @@ -675,7 +677,6 @@
children = (
855B9F9D238ED9DC0081A9C6 /* Podfile */,
852751D8238EE67000B6A44A /* NinchatSDKSwift.podspec */,
FA7958B329FBB821006527A7 /* JitsiMeetSDK.podspec */,
852751DA238EE67800B6A44A /* BUILDING.md */,
851ECF6323969297006D332F /* README.md */,
855B9F13238ECDB30081A9C6 /* NinchatSDKSwift */,
Expand Down Expand Up @@ -1548,6 +1549,7 @@
91A16D46F4A792C00EC23086 /* ComposeMessage.swift in Sources */,
91A165F76F51AC329049D95E /* Dictionary+Extension.swift in Sources */,
91A1637BC9B1BCF029EE608F /* Queue.swift in Sources */,
75990FEF2AD7E95500EBC306 /* JitsiVideoWebView.swift in Sources */,
91A166157BBD01A10A8A6520 /* WebRTCServerInfo.swift in Sources */,
91A161BA5B39C92B92F6B56B /* RTCSessionDescription+Extension.swift in Sources */,
91A164EF2633C3EEEC657848 /* RTCIceCandidate+Extension.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ extension NINLowLevelClientProps: NINLowLevelSessionProps {
}

func setAction(_ action: NINLowLevelClientActions) {
debugger("set action: \(action)")
self.set(value: action.rawValue, forKey: "action")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ extension NINChatWebRTCClientImpl {
@objc
private func didSessionRouteChange(_ notification: Notification) {
if let userInfo = notification.userInfo, let reasonKey = userInfo[AVAudioSessionRouteChangeReasonKey] as? UInt, let reason = AVAudioSession.RouteChangeReason(rawValue: reasonKey) {
print("Route Changed: \(userInfo)")
debugger("Route Changed: \(userInfo)")

/// Force Speaker in case the app tries to use earning as the output
if RTCAudioSession.sharedInstance().currentRoute.outputs.first?.portType.rawValue ?? "" == "Receiver" || AVAudioSession.sharedInstance().currentRoute.outputs.first?.portType.rawValue ?? "" == "Receiver" {
Expand Down
121 changes: 43 additions & 78 deletions NinchatSDKSwift/Implementations/View Model/NINGroupChatViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
// license that can be found in the LICENSE file.
//

import Foundation
import JitsiMeetSDK
import UIKit

protocol NINGroupChatViewModel: AnyObject, NINChatStateProtocol, NINChatMessageProtocol, NINChatPermissionsProtocol, NINChatAttachmentProtocol {
var hasJoinedVideo: Bool { get }
Expand All @@ -22,16 +21,16 @@ protocol NINGroupChatViewModel: AnyObject, NINChatStateProtocol, NINChatMessageP
func leaveVideoCall()
}

final class NINGroupChatViewModelImpl: NSObject, NINGroupChatViewModel, JitsiMeetViewDelegate {
final class NINGroupChatViewModelImpl: NSObject, NINGroupChatViewModel {
private weak var sessionManager: NINChatSessionManager?
private var pipViewCoordinator: PiPViewCoordinator?
private var jitsiView: JitsiMeetView?
private var jitsiVideoWebView: JitsiVideoWebView?
private var typingStatus = false
private var typingStatusQueue: DispatchWorkItem?
private var isSelectingMedia = false

var hasJoinedVideo: Bool {
jitsiView?.delegate != nil
jitsiVideoWebView != nil
// jitsiView?.delegate != nil
}

var backlogMessages: String? {
Expand Down Expand Up @@ -114,6 +113,7 @@ final class NINGroupChatViewModelImpl: NSObject, NINGroupChatViewModel, JitsiMee
case let .failure(error):
completion(error)
case let .success(credentials):
// Configure url request
let avatarConfig = AvatarConfig(forUser: sessionManager)
let user = sessionManager.myUser
let iconURL = avatarConfig.imageOverrideURL ?? user?.iconURL
Expand All @@ -128,74 +128,38 @@ final class NINGroupChatViewModelImpl: NSObject, NINGroupChatViewModel, JitsiMee
serverAddress.removeSubrange(serverAddress.startIndex ..< endIdx)
}
let jitsiServerAddress = "https://jitsi-www." + serverAddress
let options = JitsiMeetConferenceOptions.fromBuilder {
$0.serverURL = URL(string: jitsiServerAddress)
$0.userInfo = .init(
displayName: userName,
andEmail: nil,
andAvatar: iconURL.flatMap { URL(string: $0) }
)
$0.room = credentials.room
$0.token = credentials.token

$0.setFeatureFlag("add-people.enabled", withBoolean: false)
$0.setFeatureFlag("audio-mute.enabled", withBoolean: true)
$0.setFeatureFlag("calendar.enabled", withBoolean: false)
$0.setFeatureFlag("call-integration.enabled", withBoolean: true) // android: false
$0.setFeatureFlag("car-mode.enabled", withBoolean: false)
$0.setFeatureFlag("close-captions.enabled", withBoolean: false)
$0.setFeatureFlag("conference-timer.enabled", withBoolean: true)
$0.setFeatureFlag("chat.enabled", withBoolean: false)
$0.setFeatureFlag("filmstrip.enabled", withBoolean: true)
$0.setFeatureFlag("fullscreen.enabled", withBoolean: true)
$0.setFeatureFlag("invite.enabled", withBoolean: false)
$0.setFeatureFlag("ios.screensharing.enabled", withBoolean: false)
$0.setFeatureFlag("speakerstats.enabled", withBoolean: false)
$0.setFeatureFlag("kick-out.enabled", withBoolean: false)
$0.setFeatureFlag("live-streaming.enabled", withBoolean: false)
$0.setFeatureFlag("meeting-name.enabled", withBoolean: false)
$0.setFeatureFlag("meeting-password.enabled", withBoolean: false)
$0.setFeatureFlag("notifications.enabled", withBoolean: false)
$0.setFeatureFlag("overflow-menu.enabled", withBoolean: true)
$0.setFeatureFlag("pip.enabled", withBoolean: false)
$0.setFeatureFlag("pip-while-screen-sharing.enabled", withBoolean: false)
$0.setFeatureFlag("prejoinpage.enabled", withBoolean: true)
$0.setFeatureFlag("prejoinpage.hide-display-name.enabled", withBoolean: true)
$0.setFeatureFlag("raise-hand.enabled", withBoolean: false)
$0.setFeatureFlag("recording.enabled", withBoolean: false)
$0.setFeatureFlag("server-url-change.enabled", withBoolean: false)
$0.setFeatureFlag("settings.enabled", withBoolean: true)
$0.setFeatureFlag("tile-view.enabled", withBoolean: true)
$0.setFeatureFlag("toolbox.alwaysVisible", withBoolean: false)
$0.setFeatureFlag("toolbox.enabled", withBoolean: true)
$0.setFeatureFlag("video-mute.enabled", withBoolean: true)
$0.setFeatureFlag("video-share.enabled", withBoolean: false)
$0.setFeatureFlag("welcomepage.enabled", withBoolean: false)
$0.setFeatureFlag("help.enabled", withBoolean: false)
$0.setFeatureFlag("lobby-mode.enabled", withBoolean: false)
$0.setFeatureFlag("reactions.enabled", withBoolean: false)
$0.setFeatureFlag("security-options.enabled", withBoolean: true)
$0.setFeatureFlag("settings.profile-section.enabled", withBoolean: false)
$0.setFeatureFlag("settings.conference-section-only-self-view.enabled", withBoolean: true)
$0.setFeatureFlag("settings.links-section.enabled", withBoolean: false)
$0.setFeatureFlag("settings.build-info-section.enabled", withBoolean: false)
$0.setFeatureFlag("settings.advanced-section.enabled", withBoolean: false)
$0.setFeatureFlag("participants.enabled", withValue: false)
let domain = jitsiServerAddress.replacingOccurrences(of: "https://", with: "")
let room = credentials.room
let jwt = credentials.token
let displayName = userName
let avatarUrl = iconURL.flatMap { URL(string: $0) }

var language = "en"
switch Locale.current.languageCode {
case "fi":
language = "fi"
case "sv":
language = "sv"
default:
language = "en"
}
let jitsiMeetView = self.jitsiView ?? JitsiMeetView()
jitsiMeetView.delegate = self
jitsiMeetView.join(options)

if self.pipViewCoordinator == nil {
self.pipViewCoordinator = PiPViewCoordinator(withView: jitsiMeetView)

let urlString = "https://ninchat.com/new/jitsi-meet.html?jwt=\(jwt)&roomName=\(room)&domain=\(domain)&lang=\(language)"

guard let url = URL(string: urlString) else {
completion(NinchatError(type: "unknown", props: nil))
return
}
self.pipViewCoordinator?.configureAsStickyView(withParentView: parentView)

jitsiMeetView.alpha = 0

self.jitsiView = jitsiMeetView
self.pipViewCoordinator?.show()


let urlRequest = URLRequest(url: url)

// Add JitsiVideoWebView
let jitsiVideoWebView = parentView.subviews.filter { $0 is JitsiVideoWebView }.first as? JitsiVideoWebView
self.jitsiVideoWebView = jitsiVideoWebView
jitsiVideoWebView?.eventsDelegate = self

// Load url request
jitsiVideoWebView?.loadJitsiMeeting(for: urlRequest)
completion(nil)
}
}
Expand All @@ -212,11 +176,12 @@ final class NINGroupChatViewModelImpl: NSObject, NINGroupChatViewModel, JitsiMee
guard hasJoinedVideo else {
return
}
pipViewCoordinator?.hide()

if force {
jitsiView?.hangUp()
jitsiVideoWebView?.hangUp()
}
jitsiView?.delegate = nil
self.jitsiVideoWebView?.eventsDelegate = nil
self.jitsiVideoWebView = nil
}
}

Expand Down Expand Up @@ -379,10 +344,10 @@ extension NINGroupChatViewModelImpl {
}
}

// MARK: - Jitsi Delegate
// MARK: - JitsiVideoWebViewDelegate

extension NINGroupChatViewModelImpl {
func ready(toClose data: [AnyHashable : Any]!) {
extension NINGroupChatViewModelImpl: JitsiVideoWebViewEventsDelegate {
func readyToClose() {
leaveVideoCall(force: false)
onGroupVideoReadyToClose?()
}
Expand Down
Loading
Loading