[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void ClosedCallback(IntPtr dataChanndelHandle, IntPtr userData);
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal delegate void BufferedAmountLowThresholdCallback(IntPtr dataChanndelHandle, IntPtr userData);
+
[DllImport(Libraries.WebRTC, EntryPoint = "webrtc_create_data_channel")]
internal static extern WebRTCErrorCode Create(IntPtr handle, string label, SafeBundleHandle bundle, out IntPtr dataChanndelHandle);
[DllImport(Libraries.WebRTC, EntryPoint = "webrtc_get_data")]
internal static extern WebRTCErrorCode GetData(IntPtr byteDataHandle, out IntPtr data, out ulong size);
+ [DllImport(Libraries.WebRTC, EntryPoint = "webrtc_data_channel_get_buffered_amount")]
+ internal static extern WebRTCErrorCode GetBufferedAmount(IntPtr handle, out uint amount);
+
+ [DllImport(Libraries.WebRTC, EntryPoint = "webrtc_data_channel_get_buffered_amount_low_threshold")]
+ internal static extern WebRTCErrorCode GetBufferedAmountLowThreshold(IntPtr handle, out uint threshold);
+
[DllImport(Libraries.WebRTC, EntryPoint = "webrtc_set_data_channel_cb")]
internal static extern WebRTCErrorCode SetCreatedByPeerCb(IntPtr handle, CreatedCallback callback, IntPtr userData = default);
[DllImport(Libraries.WebRTC, EntryPoint = "webrtc_data_channel_unset_close_cb")]
internal static extern WebRTCErrorCode UnsetClosedCb(IntPtr handle);
+
+ [DllImport(Libraries.WebRTC, EntryPoint = "webrtc_data_channel_set_buffered_amount_low_cb")]
+ internal static extern WebRTCErrorCode SetBufferedAmountLowThresholdCb(IntPtr handle, uint threshold, BufferedAmountLowThresholdCallback callback,
+ IntPtr userData = default);
+
+ [DllImport(Libraries.WebRTC, EntryPoint = "webrtc_data_channel_unset_buffered_amount_low_cb")]
+ internal static extern WebRTCErrorCode UnsetBufferedAmountLowThresholdCb(IntPtr handle);
}
}
\ No newline at end of file
private NativeDataChannel.ClosedCallback _webRtcDataChannelClosedCallback;
private NativeDataChannel.MessageReceivedCallback _webRtcDataChannelMsgRecvCallback;
private NativeDataChannel.ErrorOccurredCallback _webRtcDataChannelErrorOccurredCallback;
+ private NativeDataChannel.BufferedAmountLowThresholdCallback _webRtcDataChannelBufferedAmountLowThresholdCallback;
private event EventHandler<EventArgs> _opened;
private event EventHandler<EventArgs> _closed;
private event EventHandler<WebRTCDataChannelMessageReceivedEventArgs> _messageReceived;
private event EventHandler<WebRTCDataChannelErrorOccurredEventArgs> _errorOccurred;
+ private event EventHandler<EventArgs> _bufferedAmountLowThresholdOccurred;
/// <summary>
/// Occurs when the data channel's underlying data transport is established.
}
}
+ /// <summary>
+ /// Occurs when the buffered data amount is lower than <see cref="BufferedAmountLowThreshold"/>.<br/>
+ /// If <see cref="BufferedAmountLowThreshold"/> is not set, this event will not be raised.
+ /// </summary>
+ /// <since_tizen> 10 </since_tizen>
+ public event EventHandler<EventArgs> BufferedAmountLow
+ {
+ add
+ {
+ if (_bufferedAmountLowThresholdOccurred == null)
+ {
+ RegisterDataChannelBufferedAmountLowThresholdCallback();
+ }
+ _bufferedAmountLowThresholdOccurred += value;
+ }
+ remove
+ {
+ _bufferedAmountLowThresholdOccurred -= value;
+ if (_bufferedAmountLowThresholdOccurred == null)
+ {
+ UnregisterDataChannelBufferedAmountLowThresholdCallback();
+ }
+ }
+ }
+
private void RegisterDataChannelOpenedCallback()
{
_webRtcDataChannelOpenedCallback = (dataChannelHandle, _) =>
NativeDataChannel.UnsetErrorOccurredCb(_handle).
ThrowIfFailed("Failed to unset data channel error callback.");
}
+
+ 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.");
+ }
+
+ private void UnregisterDataChannelBufferedAmountLowThresholdCallback()
+ {
+ NativeDataChannel.UnsetBufferedAmountLowThresholdCb(_handle).
+ ThrowIfFailed("Failed to unset buffered amount low threshold callback.");
+ }
}
}
\ No newline at end of file
public string Label { get; }
/// <summary>
+ /// Gets the amount of buffered data.
+ /// </summary>
+ /// <value>The buffered amount in bytes.</value>
+ /// <since_tizen> 10 </since_tizen>
+ public uint BufferedAmount
+ {
+ get
+ {
+ ValidateNotDisposed();
+
+ NativeDataChannel.GetBufferedAmount(Handle, out uint amount).
+ ThrowIfFailed("Failed to get buffered amount");
+
+ return amount;
+ }
+ }
+
+ private uint? _bufferThreshold;
+ /// <summary>
+ /// Gets or sets the threshold of data channel buffered amount.<br/>
+ /// If the amount of buffered data is lower than threshold value, <see cref="BufferedAmountLow"/> will be occurred.<br/>
+ /// The default value is 0, which means <see cref="BufferedAmountLow"/> is disabled and will not be raised.
+ /// </summary>
+ /// <since_tizen> 10 </since_tizen>
+ public uint BufferedAmountLowThreshold
+ {
+ get
+ {
+ ValidateNotDisposed();
+
+ if (!_bufferThreshold.HasValue)
+ {
+ NativeDataChannel.GetBufferedAmountLowThreshold(Handle, out uint threshold).
+ ThrowIfFailed("Failed to get buffer threshold value");
+
+ _bufferThreshold = threshold;
+ }
+
+ return _bufferThreshold.Value;
+ }
+ set
+ {
+ ValidateNotDisposed();
+
+ _bufferThreshold = value;
+
+ RegisterDataChannelBufferedAmountLowThresholdCallback();
+ }
+ }
+
+ /// <summary>
/// Sends a string data across the data channel to the remote peer.
/// </summary>
/// <param name="data">The string data to send</param>