Exemplo n.º 1
0
        /// <summary>
        /// Sends a string data across the data channel to the remote peer.
        /// </summary>
        /// <param name="data">The string data to send</param>
        /// <exception cref="ObjectDisposedException">The WebRTCDataChannel has already been disposed.</exception>
        /// <since_tizen> 9 </since_tizen>
        public void Send(string data)
        {
            ValidateNotDisposed();

            NativeDataChannel.SendString(Handle, data).
            ThrowIfFailed("Failed to send string data");
        }
        private void RegisterDataChannelErrorOccurredCallback()
        {
            _webRtcDataChannelErrorOccurredCallback = (dataChannelHandle, error, _) =>
            {
                ErrorOccurred?.Invoke(this, new WebRTCDataChannelErrorOccurredEventArgs((WebRTCError)error));
            };

            NativeDataChannel.SetErrorOccurredCb(_handle, _webRtcDataChannelErrorOccurredCallback).
            ThrowIfFailed("Failed to set data channel error callback.");
        }
        private void RegisterDataChannelClosedCallback()
        {
            _webRtcDataChannelClosedCallback = (dataChannelHandle, _) =>
            {
                Closed?.Invoke(this, new EventArgs());
            };

            NativeDataChannel.SetClosedCb(_handle, _webRtcDataChannelClosedCallback).
            ThrowIfFailed("Failed to set data channel closed callback.");
        }
        private void RegisterDataChannelMsgRecvCallback()
        {
            _webRtcDataChannelMsgRecvCallback = (dataChannelHandle, type, message, _) =>
            {
                MessageReceived?.Invoke(this, new WebRTCDataChannelMessageReceivedEventArgs(type, message));
            };

            NativeDataChannel.SetMessageReceivedCb(_handle, _webRtcDataChannelMsgRecvCallback).
            ThrowIfFailed("Failed to set data channel message received callback.");
        }
Exemplo n.º 5
0
        /// <summary>
        /// Sends byte data across the data channel to the remote peer.
        /// </summary>
        /// <param name="data">The byte data to send</param>
        /// <exception cref="ObjectDisposedException">The WebRTCDataChannel has already been disposed.</exception>
        /// <since_tizen> 9 </since_tizen>
        public void Send(byte[] data)
        {
            ValidateNotDisposed();

            if (data == null)
            {
                throw new ArgumentNullException(nameof(data), "data is null");
            }

            NativeDataChannel.SendBytes(Handle, data, (uint)data.Length).
            ThrowIfFailed("Failed to send bytes data");
        }
Exemplo n.º 6
0
        private void RegisterDataChannelCreatedCallback()
        {
            _webRtcDataChannelCreatedCallback = (handle, dataChannelHandle, _) =>
            {
                Log.Debug(WebRTCLog.Tag, "Invoked");

                DataChannel?.Invoke(this, new WebRTCDataChannelEventArgs(dataChannelHandle));
            };

            NativeDataChannel.SetCreatedByPeerCb(Handle, _webRtcDataChannelCreatedCallback).
            ThrowIfFailed("Failed to set data channel created callback.");
        }
Exemplo n.º 7
0
        protected virtual void Dispose(bool disposing)
        {
            if (_disposed || !disposing)
            {
                return;
            }

            if (true)
            {
                NativeDataChannel.Destroy(_handle);
                _disposed = true;
            }
        }
Exemplo n.º 8
0
        private void RegisterDataChannelBufferedAmountLowThresholdCallback()
        {
            if (_webRtcDataChannelBufferedAmountLowThresholdCallback == null)
            {
                _webRtcDataChannelBufferedAmountLowThresholdCallback = (dataChannelHanel, _) =>
                {
                    _bufferedAmountLowThresholdOccurred?.Invoke(this, new EventArgs());
                };
            }

            NativeDataChannel.SetBufferedAmountLowThresholdCb(_handle, _bufferThreshold.Value,
                                                              _webRtcDataChannelBufferedAmountLowThresholdCallback).
            ThrowIfFailed("Failed to set buffered amount low threshold callback.");
        }
Exemplo n.º 9
0
        internal WebRTCDataChannel(IntPtr dataChannelHandle)
        {
            if (dataChannelHandle == IntPtr.Zero)
            {
                throw new ArgumentNullException(nameof(dataChannelHandle),
                                                "WebRTC is not created successfully in native");
            }

            _handle = dataChannelHandle;

            NativeDataChannel.GetLabel(_handle, out string label).
            ThrowIfFailed("Failed to get label");

            Label = label;
        }
        internal WebRTCDataChannelMessageReceivedEventArgs(DataChannelType type, IntPtr message)
        {
            Type = type;

            if (type == DataChannelType.Strings)
            {
                Message = Marshal.PtrToStringAnsi(message);
            }
            else
            {
                NativeDataChannel.GetData(message, out IntPtr data, out ulong size).
                ThrowIfFailed("Failed to get data");

                Data = new byte[(int)size];
                Marshal.Copy(data, Data, 0, (int)size);
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WebRTCDataChannel"/> class.
        /// </summary>
        /// <remarks>
        /// The bundle is similar format as the RTCDataChannelInit members outlined https://www.w3.org/TR/webrtc/#dom-rtcdatachannelinit.<br/>
        /// The following attributes can be set to options by using <see cref="Bundle"/> API:<br/>
        /// 'ordered' of type bool            : Whether the channel will send data with guaranteed ordering. The default value is true.<br/>
        /// 'max-packet-lifetime' of type int : The time in milliseconds to attempt transmitting unacknowledged data. -1 for unset. The default value is -1.<br/>
        /// 'max-retransmits' of type int     : The number of times data will be attempted to be transmitted without acknowledgement before dropping. The default value is -1.<br/>
        /// 'protocol' of type string         : The subprotocol used by this channel. The default value is NULL.<br/>
        /// 'id' of type int                  : Override the default identifier selection of this channel. The default value is -1.<br/>
        /// 'priority' of type int            : The priority to use for this channel(1:very low, 2:low, 3:medium, 4:high). The default value is 2.<br/>
        /// </remarks>
        /// <param name="webRtc">The owner of this WebRTCDataChannel.</param>
        /// <param name="label">The name of this data channel.</param>
        /// <param name="bundle">The data channel option.</param>
        /// <exception cref="ArgumentNullException">The webRtc or label is null.</exception>
        /// <since_tizen> 9 </since_tizen>
        public WebRTCDataChannel(WebRTC webRtc, string label, Bundle bundle)
        {
            if (webRtc == null)
            {
                throw new ArgumentNullException(nameof(webRtc), "WebRTC is not created successfully.");
            }

            if (string.IsNullOrEmpty(label))
            {
                throw new ArgumentNullException(nameof(label), "label is null.");
            }

            var bundle_ = bundle?.SafeBundleHandle ?? new SafeBundleHandle();

            NativeDataChannel.Create(webRtc.Handle, label, bundle_, out _handle).
            ThrowIfFailed("Failed to create webrtc data channel");

            Debug.Assert(_handle != null);

            Label = label;
        }
Exemplo n.º 12
0
 private void UnregisterDataChannelCreatedCallback()
 {
     NativeDataChannel.UnsetCreatedByPeerCb(Handle).
     ThrowIfFailed("Failed to unset data channel created callback.");
 }
Exemplo n.º 13
0
 private void UnregisterDataChannelErrorOccurredCallback()
 {
     NativeDataChannel.UnsetErrorOccurredCb(_handle).
     ThrowIfFailed("Failed to unset data channel error callback.");
 }
Exemplo n.º 14
0
 private void UnregisterDataChannelMessageReceivedCallback()
 {
     NativeDataChannel.UnsetMessageReceivedCb(_handle).
     ThrowIfFailed("Failed to unset data channel message received callback.");
 }
Exemplo n.º 15
0
 private void UnregisterDataChannelClosedCallback()
 {
     NativeDataChannel.UnsetClosedCb(_handle).
     ThrowIfFailed("Failed to unset data channel closed callback.");
 }
Exemplo n.º 16
0
 private void UnregisterDataChannelBufferedAmountLowThresholdCallback()
 {
     NativeDataChannel.UnsetBufferedAmountLowThresholdCb(_handle).
     ThrowIfFailed("Failed to unset buffered amount low threshold callback.");
 }