RegisterDataChannelCreatedCallback();
}
+ private void UnregisterEvents()
+ {
+ UnregisterErrorOccurredCallback();
+ UnregisterStateChangedCallback();
+ UnregisterIceGatheringStateChangedCallback();
+ UnregisterSignalingStateChangedCallback();
+ UnregisterPeerConnectionStateChangedCallback();
+ UnregisterIceConnectionStateChangedCallback();
+ UnregisterNegotiationNeededCallback();
+ UnregisterIceCandidateCallback();
+ UnregisterTrackAddedCallback();
+ UnregisterDataChannelCreatedCallback();
+ }
+
private void RegisterErrorOccurredCallback()
{
_webRtcErrorOccurredCallback = (handle, error, state, _) =>
{
- Log.Info(WebRTCLog.Tag, $"{error}, {state}");
+ // Log.Info(WebRTCLog.Tag, $"{error}, {state}");
ErrorOccurred?.Invoke(this, new WebRTCErrorOccurredEventArgs((WebRTCError)error, state));
};
ThrowIfFailed("Failed to set error occurred callback.");
}
+ private void UnregisterErrorOccurredCallback()
+ {
+ NativeWebRTC.UnsetErrorOccurredCb(Handle).
+ ThrowIfFailed("Failed to unset error occurred callback.");
+ }
+
private void RegisterStateChangedCallback()
{
_webRtcStateChangedCallback = (handle, previous, current, _) =>
{
- Log.Info(WebRTCLog.Tag, $"{previous}, {current}");
+ // Log.Info(WebRTCLog.Tag, $"{previous}, {current}");
StateChanged?.Invoke(this, new WebRTCStateChangedEventArgs(previous, current));
};
ThrowIfFailed("Failed to set state changed callback.");
}
+ private void UnregisterStateChangedCallback()
+ {
+ NativeWebRTC.UnsetStateChangedCb(Handle).
+ ThrowIfFailed("Failed to unset state changed callback.");
+ }
+
private void RegisterIceGatheringStateChangedCallback()
{
_webRtcIceGatheringStateChangedCallback = (handle, state, _) =>
{
- Log.Info(WebRTCLog.Tag, $"Ice gathering state : {state}");
+ // Log.Info(WebRTCLog.Tag, $"Ice gathering state : {state}");
IceGatheringStateChanged?.Invoke(this, new WebRTCIceGatheringStateChangedEventArgs(state));
};
ThrowIfFailed("Failed to set Ice gathering state changed callback.");
}
+ private void UnregisterIceGatheringStateChangedCallback()
+ {
+ NativeWebRTC.UnsetIceGatheringStateChangedCb(Handle).
+ ThrowIfFailed("Failed to unset Ice gathering state changed callback.");
+ }
+
private void RegisterSignalingStateChangedCallback()
{
_webRtcSignalingStateChangedCallback = (handle, state, _) =>
{
- Log.Info(WebRTCLog.Tag, $"Signaling state : {state}");
+ // Log.Info(WebRTCLog.Tag, $"Signaling state : {state}");
SignalingStateChanged?.Invoke(this, new WebRTCSignalingStateChangedEventArgs(state));
};
ThrowIfFailed("Failed to set signaling state changed callback.");
}
+ private void UnregisterSignalingStateChangedCallback()
+ {
+ NativeWebRTC.UnsetSignalingStateChangedCb(Handle).
+ ThrowIfFailed("Failed to unset signaling state changed callback.");
+ }
+
private void RegisterPeerConnectionStateChangedCallback()
{
_webRtcPeerConnectionStateChangedCallback = (handle, state, _) =>
ThrowIfFailed("Failed to set peer connection state changed callback.");
}
+ private void UnregisterPeerConnectionStateChangedCallback()
+ {
+ NativeWebRTC.UnsetPeerConnectionStateChangedCb(Handle).
+ ThrowIfFailed("Failed to unset peer connection state changed callback.");
+ }
+
private void RegisterIceConnectionStateChangedCallback()
{
_webRtcIceConnectionStateChangedCallback = (handle, state, _) =>
{
- Log.Info(WebRTCLog.Tag, $"Ice connection state : {state}");
+ // Log.Info(WebRTCLog.Tag, $"Ice connection state : {state}");
IceConnectionStateChanged?.Invoke(this, new WebRTCIceConnectionStateChangedEventArgs(state));
};
ThrowIfFailed("Failed to set ICE connection state changed callback.");
}
+ private void UnregisterIceConnectionStateChangedCallback()
+ {
+ NativeWebRTC.UnsetIceConnectionStateChangedCb(Handle).
+ ThrowIfFailed("Failed to unset ICE connection state changed callback.");
+ }
+
private void RegisterNegotiationNeededCallback()
{
_webRtcNegotiationNeededCallback = (handle, _) =>
ThrowIfFailed("Failed to set negotiation needed callback.");
}
+ private void UnregisterNegotiationNeededCallback()
+ {
+ NativeWebRTC.UnsetNegotiationNeededCb(Handle).
+ ThrowIfFailed("Failed to unset negotiation needed callback.");
+ }
+
private void RegisterIceCandidateCallback()
{
_webRtcIceCandidateCallback = (handle, candidate, _) =>
ThrowIfFailed("Failed to set ice candidate callback.");
}
+ private void UnregisterIceCandidateCallback()
+ {
+ NativeWebRTC.UnsetIceCandidateCb(Handle).
+ ThrowIfFailed("Failed to unset ice candidate callback.");
+ }
+
private void RegisterTrackAddedCallback()
{
_webRtcTrackAddedCallback = (handle, type, id, _) =>
{
- Log.Info(WebRTCLog.Tag, $"Track type[{type}], id[{id}]");
+ // Log.Info(WebRTCLog.Tag, $"Track type[{type}], id[{id}]");
TrackAdded?.Invoke(this, new WebRTCTrackAddedEventArgs(new MediaStreamTrack(this, type, id)));
};
ThrowIfFailed("Failed to set track added callback.");
}
+ private void UnregisterTrackAddedCallback()
+ {
+ NativeWebRTC.UnsetTrackAddedCb(Handle).
+ ThrowIfFailed("Failed to unset track added callback.");
+ }
+
private void RegisterAudioFrameEncodedCallback()
{
_webRtcAudioFrameEncodedCallback = (handle, type, id, packet, _) =>
{
- Log.Info(WebRTCLog.Tag, $"Track type[{type}], id[{id}]");
+ // Log.Info(WebRTCLog.Tag, $"Track type[{type}], id[{id}]");
_audioFrameEncoded?.Invoke(this,
new WebRTCFrameEncodedEventArgs(new MediaStreamTrack(this, type, id), MediaPacket.From(packet)));
{
_webRtcVideoFrameEncodedCallback = (handle, type, id, packet, _) =>
{
- Log.Info(WebRTCLog.Tag, $"Track type[{type}], id[{id}]");
+ // Log.Info(WebRTCLog.Tag, $"Track type[{type}], id[{id}]");
_videoFrameEncoded?.Invoke(this,
new WebRTCFrameEncodedEventArgs(new MediaStreamTrack(this, type, id), MediaPacket.From(packet)));
{
_webRtcDataChannelCreatedCallback = (handle, dataChannelHandle, _) =>
{
- Log.Debug(WebRTCLog.Tag, "Invoked");
+ // Log.Debug(WebRTCLog.Tag, "Invoked");
DataChannel?.Invoke(this, new WebRTCDataChannelEventArgs(dataChannelHandle));
};
NativeDataChannel.SetCreatedByPeerCb(Handle, _webRtcDataChannelCreatedCallback).
ThrowIfFailed("Failed to set data channel created callback.");
}
+
+ private void UnregisterDataChannelCreatedCallback()
+ {
+ NativeDataChannel.UnsetCreatedByPeerCb(Handle).
+ ThrowIfFailed("Failed to unset data channel created callback.");
+ }
}
}
*/
using System;
-using System.Threading.Tasks;
using System.Collections.ObjectModel;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
+using System.Threading;
+using System.Threading.Tasks;
using Tizen.Applications;
using static Interop;
{
try
{
+ Log.Info(WebRTCLog.Tag, "Detach sources");
foreach (var source in _source)
{
+ source.ReplaceDisplay(null);
source.DetachFrom(this);
}
+ _source.Clear();
_source = null;
}
catch (Exception ex)
Log.Error(WebRTCLog.Tag, ex.ToString());
}
}
+
if (_handle != null)
{
+ UnregisterEvents();
_handle.Dispose();
_disposed = true;
}
/// <remarks>
/// The WebRTC must be in the <see cref="WebRTCState.Idle"/> state.<br/>
/// The WebRTC state will be <see cref="WebRTCState.Negotiating"/> state.<br/>
- /// <see cref="StateChanged"/> event will be invoked when the state is changed to <see cref="WebRTCState.Negotiating"/> internally.
+ /// The user should check whether <see cref="State" /> is changed to <see cref="WebRTCState.Negotiating"/> state or not.
/// </remarks>
/// <exception cref="InvalidOperationException">The WebRTC is not in the valid state.</exception>
/// <exception cref="ObjectDisposedException">The WebRTC has already been disposed.</exception>
}
/// <summary>
- /// Starts the WebRTC.
+ /// Starts the WebRTC asynchronously.
/// </summary>
/// <remarks>
/// The WebRTC must be in the <see cref="WebRTCState.Idle"/> state.<br/>
/// The WebRTC state will be <see cref="WebRTCState.Negotiating"/> state.<br/>
- /// This ensures that <see cref="StateChanged" /> event will be invoked with <see cref="WebRTCState.Negotiating"/> state.
+ /// This ensures that <see cref="State" /> is changed to <see cref="WebRTCState.Negotiating"/> state.
/// </remarks>
/// <exception cref="InvalidOperationException">The WebRTC is not in the valid state.</exception>
/// <exception cref="ObjectDisposedException">The WebRTC has already been disposed.</exception>
NativeWebRTC.Start(Handle).ThrowIfFailed("Failed to start the WebRTC");
- await tcs.Task;
+ await tcs.Task.ConfigureAwait(false);
+ await Task.Yield();
}
finally
{
/// </summary>
/// <remarks>
/// The WebRTC must be in the <see cref="WebRTCState.Negotiating"/> or <see cref="WebRTCState.Playing"/> state.<br/>
- /// The WebRTC state will be <see cref="WebRTCState.Idle"/> state.
+ /// The WebRTC state will be <see cref="WebRTCState.Idle"/> state.<br/>
+ /// The user should check whether <see cref="State" /> is changed to <see cref="WebRTCState.Idle"/> state or not.
/// </remarks>
/// <exception cref="InvalidOperationException">The WebRTC is not in the valid state.</exception>
/// <exception cref="ObjectDisposedException">The WebRTC has already been disposed.</exception>
ValidateWebRTCState(WebRTCState.Negotiating);
var bundle_ = bundle?.SafeBundleHandle ?? new SafeBundleHandle();
- NativeWebRTC.CreateSDPOffer(Handle, bundle_, out string offer).ThrowIfFailed("Failed to create offer");
+
+ NativeWebRTC.CreateSDPOffer(Handle, bundle_, out string offer).
+ ThrowIfFailed("Failed to create offer");
return offer;
}
var bundle_ = bundle?.SafeBundleHandle ?? new SafeBundleHandle();
- NativeWebRTC.CreateSDPAnswer(Handle, bundle_, out string answer).ThrowIfFailed("Failed to create answer");
+ NativeWebRTC.CreateSDPAnswer(Handle, bundle_, out string answer).
+ ThrowIfFailed("Failed to create answer");
return answer;
}