增加换肤功能
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
//
|
||||
// NSObject+TUIRoomMessageExtensionObserver.h
|
||||
// TUIRoomKit
|
||||
//
|
||||
// Created by janejntang on 2023/5/8.
|
||||
// Copyright © 2023 Tencent. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface NSObject (TUIRoomMessageExtensionObserver)
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -0,0 +1,20 @@
|
||||
//
|
||||
// NSObject+TUIRoomMessageExtensionObserver.m
|
||||
// TUIRoomKit
|
||||
//
|
||||
// Created by janejntang on 2023/5/8.
|
||||
// Copyright © 2023 Tencent. All rights reserved.
|
||||
//
|
||||
|
||||
#import "NSObject+TUIRoomMessageExtensionObserver.h"
|
||||
#import "TUICore.h"
|
||||
|
||||
@implementation NSObject (TUIRoomMessageExtensionObserver)
|
||||
|
||||
+ (void) load {
|
||||
if ([self respondsToSelector:@selector(tuiRoomKitExtensionLoad)]) {
|
||||
[self performSelector:@selector(tuiRoomKitExtensionLoad)];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,111 @@
|
||||
//
|
||||
// ServiceInitializer.swift
|
||||
// TUILiveKit
|
||||
//
|
||||
// Created by WesleyLei on 2023/10/19.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import TUICore
|
||||
import RTCRoomEngine
|
||||
|
||||
extension NSObject {
|
||||
@objc class func liveKitExtensionLoad() {
|
||||
ServiceInitializer.shared.registerObserver()
|
||||
}
|
||||
}
|
||||
|
||||
class ServiceInitializer {
|
||||
|
||||
private var isLoginEngine: Bool = false
|
||||
static let shared = ServiceInitializer()
|
||||
private var invitationManager: TUIConferenceInvitationManager?
|
||||
private var invitationObserver: InvitationObserverService?
|
||||
|
||||
private init() {
|
||||
}
|
||||
|
||||
func registerObserver() {
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(logoutSuccess(_:)),
|
||||
name: NSNotification.Name(rawValue: NSNotification.Name.TUILogoutSuccess.rawValue),
|
||||
object: nil)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(loginSuccess(_:)),
|
||||
name: NSNotification.Name(rawValue: NSNotification.Name.TUILoginSuccess.rawValue),
|
||||
object: nil)
|
||||
}
|
||||
|
||||
@objc private func logoutSuccess(_ notification: Notification) {
|
||||
logout(onSuccess: nil, onError: nil)
|
||||
removeInvitationObserver()
|
||||
}
|
||||
|
||||
@objc private func loginSuccess(_ notification: Notification) {
|
||||
login(onSuccess: nil, onError: nil)
|
||||
addInvitationObserver()
|
||||
}
|
||||
|
||||
private func addInvitationObserver() {
|
||||
invitationObserver = InvitationObserverService.shared
|
||||
invitationManager = TUIRoomEngine.sharedInstance().getExtension(extensionType: .conferenceInvitationManager) as? TUIConferenceInvitationManager
|
||||
guard let invitationObserver = invitationObserver else { return }
|
||||
invitationManager?.addObserver(invitationObserver)
|
||||
}
|
||||
|
||||
private func removeInvitationObserver() {
|
||||
guard let invitationObserver = invitationObserver else { return }
|
||||
invitationManager?.removeObserver(invitationObserver)
|
||||
}
|
||||
|
||||
func login(onSuccess: TUISuccessBlock?, onError: TUIErrorBlock?) {
|
||||
if isLoginEngine {
|
||||
onSuccess?()
|
||||
} else {
|
||||
let sdkAppId = Int(TUILogin.getSdkAppID())
|
||||
let userId = TUILogin.getUserID() ?? ""
|
||||
let userSig = TUILogin.getUserSig() ?? ""
|
||||
ServiceInitializer.login(sdkAppId: sdkAppId, userId: userId, userSig: userSig) { [weak self] in
|
||||
guard let self = self else { return }
|
||||
self.isLoginEngine = true
|
||||
onSuccess?()
|
||||
} onError: { code, message in
|
||||
onError?(code, message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func logout(onSuccess: TUISuccessBlock?, onError: TUIErrorBlock?) {
|
||||
if isLoginEngine {
|
||||
ServiceInitializer.logout {
|
||||
onSuccess?()
|
||||
} onError: { code, message in
|
||||
onError?(code, message)
|
||||
}
|
||||
self.isLoginEngine = false
|
||||
} else {
|
||||
onSuccess?()
|
||||
}
|
||||
}
|
||||
|
||||
deinit {
|
||||
NotificationCenter.default.removeObserver(self)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
extension ServiceInitializer {
|
||||
static func login(sdkAppId:Int,userId:String,userSig:String,onSuccess: @escaping TUISuccessBlock, onError: @escaping TUIErrorBlock) {
|
||||
TUIRoomEngine.login(sdkAppId: sdkAppId, userId: userId, userSig: userSig) {
|
||||
onSuccess()
|
||||
} onError: { code, message in
|
||||
onError(code, message)
|
||||
}
|
||||
}
|
||||
|
||||
static func logout(onSuccess: @escaping TUISuccessBlock, onError: @escaping TUIErrorBlock) {
|
||||
TUIRoomEngine.logout {
|
||||
onSuccess()
|
||||
} onError: { code, message in
|
||||
onError(code, message)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
//
|
||||
// TUIRoomMessageExtensionObserver.swift
|
||||
// TUIRoomKit
|
||||
//
|
||||
// Created by janejntang on 2023/5/8.
|
||||
// Copyright © 2023 Tencent. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import TUICore
|
||||
|
||||
extension NSObject {
|
||||
@objc class func tuiRoomKitExtensionLoad() {
|
||||
TUICore.registerExtension(TUICore_TUIChatExtension_InputViewMoreItem_ClassicExtensionID, object: RoomMessageExtensionObserver.shared)
|
||||
TUICore.registerService(TUICore_TUIRoomImAccessService, object: TUIRoomImAccessService.shared)
|
||||
TUICore.registerObjectFactory(TUICore_TUIRoomImAccessFactory, objectFactory: TUIRoomImAccessFactory.shared)
|
||||
TUICore.registerExtension(TUICore_TUIContactExtension_MeSettingMenu_ClassicExtensionID, object: RoomMessageExtensionObserver.shared)
|
||||
ServiceInitializer.shared.registerObserver()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user