///<summary> 创建 IceSocket /// IceSocket 是可靠的TCP传输 ///</summary> ///<param name="rtcConfiguration"> 服务器地址</param> ///<param name="rtcIceParameters"> 可选的来源标识</param> ///<param name="isCaller"> 是否为主叫</param> ///<param name="observer"> 事件侦听器</param> static public IceSocket Connect(string rtcConfiguration, string rtcIceParameters, bool isCaller, RTCSocketObserver observer) { if (observer == null) { throw new ArgumentNullException(); } int index = 1; while (index < OBSERVERS.Length && OBSERVERS[index] != null) { ++index; } if (index == OBSERVERS.Length) { throw new OverflowException(); } OBSERVERS[index] = observer; IntPtr iface = JSEP._CreateIceSocket(rtcConfiguration, rtcIceParameters, isCaller, (IntPtr)index, IceSocketCallback); if (iface == IntPtr.Zero) { OBSERVERS[index] = null; throw new ArgumentException(); } IceSocket self = new IceSocket(); SOCKETS.Add(iface, self); self.iface = iface; return(self); }
///<summary> 创建 WebSocket 服务器并侦听客户的连接 /// WebSocket 是可靠的TCP传输 ///</summary> ///<param name="wsURL"> 服务器地址</param> ///<param name="rtcWebSocketInit"> 配置参数</param> ///<param name="observer"> 事件侦听器</param> static public WebSocket Listen(string wsURL, string rtcWebSocketInit, RTCSocketObserver observer) { if (observer == null) { throw new ArgumentNullException(); } int index = 1; while (index < OBSERVERS.Length && OBSERVERS[index] != null) { ++index; } if (index == OBSERVERS.Length) { throw new OverflowException(); } OBSERVERS[index] = observer; IntPtr iface = JSEP._CreateWebSocketServer(wsURL, rtcWebSocketInit, (IntPtr)index, WebSocketCallback); if (iface == IntPtr.Zero) { OBSERVERS[index] = null; throw new ArgumentException(); } WebSocket self = new WebSocket(); SOCKETS.Add(iface, self); self.iface = iface; return(self); }