/// <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"); }
/// <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(); } }
internal static extern void PeerConnection_CreateAnswer(IntPtr ptr, WebrtcUnityResult2Callback success, WebrtcUnityResultCallback failure, bool offer_to_receive_video, bool offer_to_receive_audio, bool voice_activity_detection, bool ice_restart, bool use_rtp_mux);
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> /// 创建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(); } }
/// <summary> /// C++ API:添加音频监听器 /// </summary> /// <param name="ptr">音频轨道指针</param> /// <param name="onDataReady">回调函数</param> /// <returns>新建的监听器指针</returns> [DllImport(UnityPluginDll)] internal static extern IntPtr AudioSource_AddSink(IntPtr ptr, WebrtcUnityResultCallback onDataReady);
/// <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);
/// <summary> /// C++ API:添加监听器 /// </summary> /// <param name="ptr">视频媒体轨道指针</param> /// <param name="onI420FrameReady">收到视频的回调函数</param> /// <returns>监听器指针</returns> [DllImport(UnityPluginDll)] internal static extern IntPtr VideoTrack_AddSink(IntPtr ptr, WebrtcUnityResultCallback onI420FrameReady);
internal static extern void PeerConnection_SetLocalDescription(IntPtr ptr, string type, string sdp, WebrtcUnityCallback success, WebrtcUnityResultCallback failure);