Esempio n. 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();
            }
        }
            /// <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();
            }
Esempio n. 3
0
        /// <summary>
        /// 创建Offer
        /// </summary>
        /// <param name="ice_restart">ice restart</param>
        /// <param name="voice_activity_detection">voice activity detection</param>
        /// <param name="use_rtp_mux">use rtp mux</param>
        /// <returns>offer 字符串</returns>
        public async Task <string> CreateOffer(
            bool ice_restart = false,
            bool voice_activity_detection = true,
            bool use_rtp_mux = true)
        {
            var holder = new UnmanageHolder();

            try
            {
                return(await Promise <string> .Await((cs, ce) =>
                {
                    WebrtcUnityResult2Callback done = (type, sdp) =>
                    {
                        unsafe
                        {
                            //var strType = new string((sbyte*)type.ToPointer());
                            var strSdp = new string((sbyte *)sdp.ToPointer());
                            cs(strSdp);
                        }
                    };
                    WebrtcUnityResultCallback error = msg =>
                    {
                        unsafe
                        {
                            ce(new Exception(new string((sbyte *)msg.ToPointer())));
                        }
                    };
                    holder.Hold(done, error);
                    PeerConnection_CreateOffer(Handler,
                                               done,
                                               error,
                                               true,
                                               true,
                                               voice_activity_detection,
                                               ice_restart,
                                               use_rtp_mux);
                }));
            }
            finally
            {
                holder.Release();
            }
        }