提交
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
//
|
||||
// ConferenceSession.swift
|
||||
// TUIRoomKit
|
||||
//
|
||||
// Created by janejntang on 2024/3/6.
|
||||
//
|
||||
|
||||
import RTCRoomEngine
|
||||
|
||||
class ConferenceOptions {
|
||||
|
||||
static func quickStart(startConferenceParams: StartConferenceParams,
|
||||
onSuccess: TUIRoomInfoBlock? = nil,
|
||||
onError: TUIErrorBlock? = nil) {
|
||||
let roomInfo = createRoomInfo(startConferenceParams: startConferenceParams)
|
||||
quickStartConference(roomInfo: roomInfo,
|
||||
enableAudio: startConferenceParams.isOpenMicrophone,
|
||||
enableVideo: startConferenceParams.isOpenCamera,
|
||||
isSoundOnSpeaker: startConferenceParams.isOpenSpeaker,
|
||||
onSuccess: onSuccess,
|
||||
onError: onError)
|
||||
}
|
||||
|
||||
private static func quickStartConference(roomInfo: TUIRoomInfo,
|
||||
enableAudio: Bool,
|
||||
enableVideo: Bool,
|
||||
isSoundOnSpeaker: Bool,
|
||||
onSuccess: TUIRoomInfoBlock?,
|
||||
onError: TUIErrorBlock?) {
|
||||
EngineManager.shared.createRoom(roomInfo: roomInfo) {
|
||||
EngineManager.shared.enterRoom(roomId: roomInfo.roomId,
|
||||
enableAudio: enableAudio,
|
||||
enableVideo: enableVideo,
|
||||
isSoundOnSpeaker: isSoundOnSpeaker) { roomInfo in
|
||||
onSuccess?(roomInfo)
|
||||
} onError: { code, message in
|
||||
onError?(code, message)
|
||||
}
|
||||
} onError: { code, message in
|
||||
onError?(code, message)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static func join(joinConferenParams: JoinConferenceParams,
|
||||
onSuccess: TUIRoomInfoBlock? = nil,
|
||||
onError: TUIErrorBlock? = nil) {
|
||||
var options:TUIEnterRoomOptions?
|
||||
if let password = joinConferenParams.password, password.count > 0 {
|
||||
options = TUIEnterRoomOptions()
|
||||
options?.password = password
|
||||
}
|
||||
EngineManager.shared.enterRoom(roomId: joinConferenParams.roomId,
|
||||
options: options,
|
||||
enableAudio: joinConferenParams.isOpenMicrophone,
|
||||
enableVideo: joinConferenParams.isOpenCamera,
|
||||
isSoundOnSpeaker: joinConferenParams.isOpenSpeaker) { roomInfo in
|
||||
onSuccess?(roomInfo)
|
||||
} onError: { code, message in
|
||||
onError?(code, message)
|
||||
}
|
||||
}
|
||||
|
||||
private static func createRoomInfo(startConferenceParams: StartConferenceParams) -> TUIRoomInfo {
|
||||
let roomInfo = TUIRoomInfo()
|
||||
roomInfo.roomId = startConferenceParams.roomId
|
||||
roomInfo.isMicrophoneDisableForAllUser = !startConferenceParams.isOpenMicrophone
|
||||
roomInfo.isCameraDisableForAllUser = !startConferenceParams.isOpenCamera
|
||||
roomInfo.isSeatEnabled = startConferenceParams.isSeatEnabled
|
||||
roomInfo.name = startConferenceParams.name ?? ""
|
||||
roomInfo.seatMode = .applyToTake
|
||||
return roomInfo
|
||||
}
|
||||
|
||||
deinit {
|
||||
debugPrint("deinit \(self)")
|
||||
}
|
||||
}
|
||||
25
TUIKit/TUIRoomKit/Source/Common/Utils/CoreExtension.swift
Normal file
25
TUIKit/TUIRoomKit/Source/Common/Utils/CoreExtension.swift
Normal file
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// CoreExtension.swift
|
||||
// TUIRoomKit
|
||||
//
|
||||
// Created by WesleyLei on 2022/9/23.
|
||||
// Copyright © 2022 Tencent. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import TUICore
|
||||
|
||||
let gRoomEngineKey = NSObject.getRoomEngineKey()
|
||||
// {roomId:roomId}
|
||||
let gRoomInfoKey = NSObject.getRoomInfoKey()
|
||||
// {roomId:roomId}
|
||||
let gLocalUserInfoKey = NSObject.getLocalUserInfoKey()
|
||||
// {roomId:roomId}
|
||||
let gTopViewKey = NSObject.getTopViewKey()
|
||||
// {roomId:roomId}
|
||||
let gBottomViewKey = NSObject.getBottomViewKey()
|
||||
// {roomId:roomId}
|
||||
let gUserListControllerKey = NSObject.getUserListControllerKey()
|
||||
// {roomEngine:roomEngineObj,currentUserInfo:currentUserInfoObj}
|
||||
let gExtensionControllerKey = NSObject.getExtensionControllerKey()
|
||||
// {roomEngine:roomEngineObj,currentUserInfo:currentUserInfoObj}
|
||||
53
TUIKit/TUIRoomKit/Source/Common/Utils/FetchRoomId.swift
Normal file
53
TUIKit/TUIRoomKit/Source/Common/Utils/FetchRoomId.swift
Normal file
@@ -0,0 +1,53 @@
|
||||
//
|
||||
// FetchRoomId.swift
|
||||
// TUIRoomKit
|
||||
//
|
||||
// Created by janejntang on 2024/1/29.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import TUICore
|
||||
|
||||
class FetchRoomId {
|
||||
class func getRoomId(onGetRoomId: @escaping (String)->()) {
|
||||
let roomId = getRandomRoomId(numberOfDigits: 6)
|
||||
checkIfRoomIdExists(roomId: roomId) {
|
||||
getRoomId(onGetRoomId: onGetRoomId)
|
||||
} onNotExist: {
|
||||
onGetRoomId(roomId)
|
||||
}
|
||||
}
|
||||
|
||||
class func getRandomRoomId(numberOfDigits: Int) -> String {
|
||||
var numberOfDigit = numberOfDigits > 0 ? numberOfDigits : 1
|
||||
numberOfDigit = numberOfDigit < 10 ? numberOfDigit : 9
|
||||
let minNumber = Int(truncating: NSDecimalNumber(decimal: pow(10, numberOfDigit - 1)))
|
||||
let maxNumber = Int(truncating: NSDecimalNumber(decimal: pow(10, numberOfDigit))) - 1
|
||||
let randomNumber = arc4random_uniform(UInt32(maxNumber - minNumber)) + UInt32(minNumber)
|
||||
return String(randomNumber)
|
||||
}
|
||||
|
||||
class func checkIfRoomIdExists(roomId: String, onExist: @escaping () -> (), onNotExist: @escaping () -> ()) {
|
||||
V2TIMManager.sharedInstance().getGroupsInfo([roomId]) { infoResult in
|
||||
if checkIfRoomIdExistsWithResultCode(infoResult?.first?.resultCode) {
|
||||
onExist()
|
||||
} else {
|
||||
onNotExist()
|
||||
}
|
||||
} fail: { code, message in
|
||||
onNotExist()
|
||||
}
|
||||
}
|
||||
|
||||
private class func checkIfRoomIdExistsWithResultCode(_ resultCode: Int32?) -> Bool {
|
||||
let kIMCodeGroupSuccess = 0
|
||||
let kIMCodeGroupInsufficientOperationAuthority = 10007
|
||||
if let resultCode = resultCode {
|
||||
return resultCode == kIMCodeGroupSuccess || resultCode == kIMCodeGroupInsufficientOperationAuthority
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
128
TUIKit/TUIRoomKit/Source/Common/Utils/RoomCommon.swift
Normal file
128
TUIKit/TUIRoomKit/Source/Common/Utils/RoomCommon.swift
Normal file
@@ -0,0 +1,128 @@
|
||||
//
|
||||
// RoomCommon.swift
|
||||
// TUIRoomKit
|
||||
//
|
||||
// Created by janejntang on 2023/6/26.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import AVFoundation
|
||||
import TUICore
|
||||
|
||||
var isRTL: Bool {
|
||||
TUIGlobalization.getRTLOption()
|
||||
}
|
||||
|
||||
var isLandscape: Bool {
|
||||
if #available(iOS 13, *) {
|
||||
return UIApplication.shared.windows.first?.windowScene?.interfaceOrientation.isLandscape == true
|
||||
} else {
|
||||
return UIApplication.shared.statusBarOrientation.isLandscape
|
||||
}
|
||||
}
|
||||
|
||||
class RoomCommon {
|
||||
enum AuthorizationDeniedType {
|
||||
case microphone
|
||||
case camera
|
||||
}
|
||||
class func checkAuthorMicStatusIsDenied() -> Bool {
|
||||
return AVCaptureDevice.authorizationStatus(for: .audio) == .authorized
|
||||
}
|
||||
class func checkAuthorCamaraStatusIsDenied() -> Bool {
|
||||
return AVCaptureDevice.authorizationStatus(for: .video) == .authorized
|
||||
}
|
||||
class func micStateActionWithPopCompletion(completion: @escaping (Bool) -> ()) {
|
||||
if AVCaptureDevice.authorizationStatus(for: .audio) == .notDetermined {
|
||||
AVCaptureDevice.requestAccess(for: .audio) { granted in
|
||||
completion(granted)
|
||||
}
|
||||
} else {
|
||||
showAuthorizationAlert(deniedType: .microphone)
|
||||
}
|
||||
}
|
||||
class func cameraStateActionWithPopCompletion(completion: @escaping (Bool) -> () ) {
|
||||
if AVCaptureDevice.authorizationStatus(for: .video) == .notDetermined {
|
||||
AVCaptureDevice.requestAccess(for: .video) { granted in
|
||||
completion(granted)
|
||||
}
|
||||
} else {
|
||||
showAuthorizationAlert(deniedType: .camera)
|
||||
}
|
||||
}
|
||||
|
||||
private class func showAuthorizationAlert(deniedType: AuthorizationDeniedType) {
|
||||
let laterMessage: String = .permissionLaterText
|
||||
let openSettingMessage: String = .permissionEnableText
|
||||
let title: String = deniedType == .microphone ? .microphonePermissionTitle : .cameraPermissionTitle
|
||||
let message: String = deniedType == .microphone ? .microphonePermissionTipsText : .cameraPermissionTipsText
|
||||
let alertVC = UIAlertController(title: title,
|
||||
message: message,
|
||||
preferredStyle: .alert)
|
||||
let declineAction = UIAlertAction(title: laterMessage, style: .cancel) { _ in
|
||||
|
||||
}
|
||||
let sureAction = UIAlertAction(title: openSettingMessage, style: .default) { _ in
|
||||
guard let url = URL(string: UIApplication.openSettingsURLString) else { return }
|
||||
if UIApplication.shared.canOpenURL(url) {
|
||||
if #available(iOS 10.0, *) {
|
||||
UIApplication.shared.open(url, options: [:], completionHandler: nil)
|
||||
} else {
|
||||
UIApplication.shared.openURL(url)
|
||||
}
|
||||
}
|
||||
}
|
||||
alertVC.addAction(declineAction)
|
||||
alertVC.addAction(sureAction)
|
||||
DispatchQueue.main.async {
|
||||
let vc = getCurrentWindowViewController()
|
||||
vc?.present(alertVC, animated: true)
|
||||
}
|
||||
}
|
||||
|
||||
class func getCurrentWindowViewController() -> UIViewController? {
|
||||
var keyWindow: UIWindow?
|
||||
for window in UIApplication.shared.windows {
|
||||
if window.isMember(of: UIWindow.self), window.isKeyWindow {
|
||||
keyWindow = window
|
||||
break
|
||||
}
|
||||
}
|
||||
guard let rootController = keyWindow?.rootViewController else {
|
||||
return nil
|
||||
}
|
||||
func findCurrentController(from vc: UIViewController?) -> UIViewController? {
|
||||
if let nav = vc as? UINavigationController {
|
||||
return findCurrentController(from: nav.topViewController)
|
||||
} else if let tabBar = vc as? UITabBarController {
|
||||
return findCurrentController(from: tabBar.selectedViewController)
|
||||
} else if let presented = vc?.presentedViewController {
|
||||
return findCurrentController(from: presented)
|
||||
}
|
||||
return vc
|
||||
}
|
||||
let viewController = findCurrentController(from: rootController)
|
||||
return viewController
|
||||
}
|
||||
}
|
||||
|
||||
private extension String {
|
||||
static var microphonePermissionTitle: String {
|
||||
localized("No access to microphone")
|
||||
}
|
||||
static var microphonePermissionTipsText: String {
|
||||
localized("Unable to use audio function, click \"Authorize Now\" to open the microphone permission.")
|
||||
}
|
||||
static var cameraPermissionTitle: String {
|
||||
localized("No access to camera")
|
||||
}
|
||||
static var cameraPermissionTipsText: String {
|
||||
localized("Unable to use the video function, click \"Authorize Now\" to open the camera permission.")
|
||||
}
|
||||
static var permissionLaterText: String {
|
||||
localized("Later")
|
||||
}
|
||||
static var permissionEnableText: String {
|
||||
localized("Authorize Now")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user