Example #1
0
        /// <summary>
        /// 设置本地描述
        /// </summary>
        /// <param name="type">描述类型</param>
        /// <param name="sdp">描述</param>
        /// <returns></returns>
        public async Task SetLocalDescription(string type, string sdp)
        {
            var holder = new UnmanageHolder();

            try
            {
                await Promise.Await((cs, ce) =>
                {
                    WebrtcUnityCallback done        = () => cs();
                    WebrtcUnityResultCallback error = msg =>
                    {
                        unsafe
                        {
                            ce(new Exception(new string((sbyte *)msg.ToPointer())));
                        }
                    };
                    holder.Hold(done, error);
                    PeerConnection_SetLocalDescription(Handler,
                                                       type,
                                                       sdp,
                                                       done,
                                                       error);
                });
            }
            finally
            {
                holder.Release();
            }
        }
Example #2
0
 /// <summary>
 /// 持有一个数据通道
 /// </summary>
 /// <param name="handler">数据通道指针</param>
 internal protected RTCDataChannel(IntPtr handler) : base(handler)
 {
     _stateChange         = () => this.OnStateChange();
     _message             = buffer => this.OnMessage(buffer);
     _bufferedAmoutChange = state => this.OnBufferedAmoutChange(state);
     this.observer        = new WebrtcObjectRef(RTCDataChannel_RegisterObserver(handler, _stateChange, _message, _bufferedAmoutChange), "RTCDataChannel Observer");
 }
Example #3
0
 internal static extern IntPtr PeerConnectionObserver_new(WebrtcUnityStateCallback SignalingChange,
                                                          WebrtcUnityResultCallback DataChannel,
                                                          WebrtcUnityCallback RenegotiationNeeded,
                                                          WebrtcUnityStateCallback IceConnectionChange,
                                                          WebrtcUnityStateCallback StandardizedIceConnectionChange,
                                                          WebrtcUnityStateCallback ConnectionChange,
                                                          WebrtcUnityStateCallback IceGatheringChange,
                                                          WebrtcUnityResultCallback IceCandidate,
                                                          WebrtcUnityResultCallback IceCandidatesRemoved,
                                                          WebrtcUnityStateCallback IceConnectionReceivingChange,
                                                          WebrtcUnityResultCallback AddTrack,
                                                          WebrtcUnityResultCallback RemoveTrack,
                                                          WebrtcUnityStateCallback InterestingUsage);
            /// <summary>
            /// 执行
            /// </summary>
            /// <param name="action">要执行的方法</param>
            public void Invoke(Action action)
            {
                if (factory.Handler == IntPtr.Zero)
                {
                    return;
                }
                WebrtcUnityCallback native = () => action();
                var holder = new UnmanageHolder();

                holder.Hold(native);
                PeerConnectionFactory_SignalingThreadInvoke(factory.Handler, native);
                holder.StillHere();
            }
Example #5
0
 /// <summary>
 /// 注册事件响应
 /// </summary>
 /// <param name="ptr">数据通道指针</param>
 /// <param name="stateChange">状态变化回调</param>
 /// <param name="message">收到消息回调</param>
 /// <param name="bufferedAmountChange">buffered amout change</param>
 /// <returns>响应器指针</returns>
 [DllImport(UnityPluginDll)] internal static extern IntPtr RTCDataChannel_RegisterObserver(IntPtr ptr, WebrtcUnityCallback stateChange, WebrtcUnityResultCallback message, WebrtcUnityResultCallback bufferedAmountChange);
Example #6
0
 internal static extern void PeerConnection_SetLocalDescription(IntPtr ptr,
                                                                string type,
                                                                string sdp,
                                                                WebrtcUnityCallback success,
                                                                WebrtcUnityResultCallback failure);
Example #7
0
 /// <summary>
 /// C++ API:在信令线程上执行
 /// </summary>
 /// <param name="ptr">创建器指针</param>
 /// <param name="callback">要执行的方法</param>
 [DllImport(UnityPluginDll)] internal static extern void PeerConnectionFactory_SignalingThreadInvoke(IntPtr ptr, WebrtcUnityCallback callback);