Intel® Collaboration Suite for WebRTC
Community support and discussions on the Intel® Collaboration Suite for WebRTC (Intel® CS for WebRTC).
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
1151 Discussions

Has anyone try to package delegates with Rx? (ios 4.2SDK)

JJ_Lin
Beginner
426 Views

I was trying to extend OWTConferenceClientDelegate to rx DelegateProxy but I keep got nil while setCurrentDelegate.
The error said that "mutex lock failed: Invalid argument" in libc++.tbd

Is there anyway to solve this?
Is this error means that the thread which static lib runs in are private or unsafe?

 

請問是否有人嘗試將ios sdk裡的delegates事件封裝成rx的delegateProxy? 在封裝之後調用rx的delegateProxy事件例如OWTConferenceClientDelegate的conferenceClient:didAddStream: 時會產生mutex lock failed: Invalid argument錯誤

想詢問有人成功將delegates封裝成rx嗎?



import RxSwift
import RxCocoa

private class RxOWTConferenceClientDelegateProxy: DelegateProxy<OWTConferenceClient, OWTConferenceClientDelegate>, DelegateProxyType, OWTConferenceClientDelegate {

    public weak private (set) var controller: OWTConferenceClient?

    public init(controller: ParentObject) {
        self.controller = controller
        super.init(parentObject: controller, delegateProxy: RxOWTConferenceClientDelegateProxy.self)
    }

    static func registerKnownImplementations() {
        self.register { RxOWTConferenceClientDelegateProxy(controller: $0) }
    }
    
    static func currentDelegate(for object: OWTConferenceClient) -> OWTConferenceClientDelegate? {
        return object.delegate
    }

    static func setCurrentDelegate(_ delegate: OWTConferenceClientDelegate?, to object: OWTConferenceClient) {
        object.delegate = delegate     <<<<<<< ERROR happens to this line.
    }
}


extension Reactive where Base: OWTConferenceClient {

    public var delegate: DelegateProxy<OWTConferenceClient, OWTConferenceClientDelegate> {
        return RxOWTConferenceClientDelegateProxy.proxy(for: base)
    }

    func join(token: String) -> Single<OWTConferenceInfo> {
        return Single<OWTConferenceInfo>.create { single in
            self.base.join(withToken: token,
                      onSuccess: { (info) in
                        single(.success(info))
                        return
            },
                      onFailure: { (error) in
                        single(.error(error))
                        return
            })

            return Disposables.create()
        }
    }

    func doPublish(constraints: OWTStreamConstraints) -> Single<OWTConferencePublication> {
        return Single<OWTConferencePublication>.create { single in
            var err: NSError?
            let localStream = OWTLocalStream(constratins: constraints, error: &err)
            if err != nil { single(.error(err!)) }

            self.base.publish(localStream,
                              with: nil,
                              onSuccess: { single(.success($0))
            },
                              onFailure: { single(.error($0))
            })

            return Disposables.create()
        }
    }

    func leave() -> Single<Void> {
        return Single<Void>.create { single in
            self.base.leaveWith(
                onSuccess: { single(.success(()))
            },
                onFailure: { single(.error($0))
            })

            return Disposables.create()
        }
    }

    public var didAddStream: Observable<OWTRemoteStream> {
        return delegate.methodInvoked(#selector(OWTConferenceClientDelegate.conferenceClient(_:didAdd:) as ((OWTConferenceClientDelegate) -> (OWTConferenceClient, OWTRemoteStream) -> Void)?))
            .observeOn(MainScheduler.instance)
            .map { $0[1] as! OWTRemoteStream }
    }
    
    public var didAddParticipant: Observable<OWTConferenceParticipant> {
        return delegate.methodInvoked(#selector(OWTConferenceClientDelegate.conferenceClient(_:didAdd:) as ((OWTConferenceClientDelegate) -> (OWTConferenceClient, OWTConferenceParticipant) -> Void)?))
            .observeOn(MainScheduler.instance)
            .map { $0[1] as! OWTConferenceParticipant }
    }
}

 

0 Kudos
0 Replies
Reply