[WebRTC] Fix DataChannel event bug (#6392)
authorHaesu Gwon <haesu.gwon@samsung.com>
Wed, 2 Oct 2024 09:33:09 +0000 (18:33 +0900)
committerGitHub <noreply@github.com>
Wed, 2 Oct 2024 09:33:09 +0000 (18:33 +0900)
* [WebRTC] Fix DataChannel event(BufferedAmountLow) bug

src/Tizen.Multimedia.Remoting/WebRTC/WebRTCDataChannel.Events.cs
src/Tizen.Multimedia.Remoting/WebRTC/WebRTCDataChannel.cs

index b998669d9620c8be193050984eba1017eb43433f..d6cb3c031553bbde279f528baf8caa9630c64e00 100755 (executable)
@@ -136,13 +136,18 @@ namespace Tizen.Multimedia.Remoting
 
         /// <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.
+        /// If <see cref="BufferedAmountLowThreshold"/> is not set, this event will not be registered.
         /// </summary>
         /// <since_tizen> 10 </since_tizen>
         public event EventHandler<EventArgs> BufferedAmountLow
         {
             add
             {
+                if (!_bufferThreshold.HasValue)
+                {
+                    return;
+                }
+
                 if (_bufferedAmountLowThresholdOccurred == null)
                 {
                     RegisterDataChannelBufferedAmountLowThresholdCallback();
@@ -151,6 +156,11 @@ namespace Tizen.Multimedia.Remoting
             }
             remove
             {
+                if (!_bufferThreshold.HasValue)
+                {
+                    return;
+                }
+
                 _bufferedAmountLowThresholdOccurred -= value;
                 if (_bufferedAmountLowThresholdOccurred == null)
                 {
@@ -229,16 +239,12 @@ namespace Tizen.Multimedia.Remoting
 
         private void RegisterDataChannelBufferedAmountLowThresholdCallback()
         {
-            if (_webRtcDataChannelBufferedAmountLowThresholdCallback == null)
+            _webRtcDataChannelBufferedAmountLowThresholdCallback = (dataChannelHanel, _) =>
             {
-                _webRtcDataChannelBufferedAmountLowThresholdCallback = (dataChannelHanel, _) =>
-                {
-                    _bufferedAmountLowThresholdOccurred?.Invoke(this, new EventArgs());
-                };
-            }
+                _bufferedAmountLowThresholdOccurred?.Invoke(this, new EventArgs());
+            };
 
-            NativeDataChannel.SetBufferedAmountLowThresholdCb(_handle, _bufferThreshold.Value,
-                _webRtcDataChannelBufferedAmountLowThresholdCallback).
+            NativeDataChannel.SetBufferedAmountLowThresholdCb(_handle, _bufferThreshold.Value, _webRtcDataChannelBufferedAmountLowThresholdCallback).
                 ThrowIfFailed("Failed to set buffered amount low threshold callback.");
         }
 
index fcb1dc7de8eed6848ec260e438c4b42fb7670595..21a77d49ea974b76a3151cb8565cac2d7869ef21 100755 (executable)
@@ -161,8 +161,6 @@ namespace Tizen.Multimedia.Remoting
                 ValidateNotDisposed();
 
                 _bufferThreshold = value;
-
-                RegisterDataChannelBufferedAmountLowThresholdCallback();
             }
         }