/// <summary> /// Creates SDP answer asynchronously with option to an offer received from a remote peer. /// </summary> /// <remarks>The WebRTC must be in the <see cref="WebRTCState.Negotiating"/></remarks> /// <returns>The SDP answer.</returns> /// <exception cref="InvalidOperationException">The WebRTC is not in the valid state.</exception> /// <exception cref="ObjectDisposedException">The WebRTC has already been disposed.</exception> /// <seealso cref="CreateOfferAsync()"/> /// <since_tizen> 9 </since_tizen> public async Task <string> CreateAnswerAsync() { ValidateWebRTCState(WebRTCState.Negotiating); var tcsSdpCreated = new TaskCompletionSource <string>(); NativeWebRTC.SdpCreatedCallback cb = (handle, sdp, _) => { tcsSdpCreated.TrySetResult(sdp); }; string answer = null; using (var cbKeeper = ObjectKeeper.Get(cb)) { NativeWebRTC.CreateSDPAnswerAsync(Handle, new SafeBundleHandle(), cb, IntPtr.Zero). ThrowIfFailed("Failed to create answer asynchronously"); answer = await tcsSdpCreated.Task.ConfigureAwait(false); await Task.Yield(); } return(answer); }
/// <summary> /// Creates SDP offer asynchronously to start a new WebRTC connection to a remote peer. /// </summary> /// <remarks>The WebRTC must be in the <see cref="WebRTCState.Negotiating"/></remarks> /// <returns>The SDP offer.</returns> /// <exception cref="InvalidOperationException">The WebRTC is not in the valid state.</exception> /// <exception cref="ObjectDisposedException">The WebRTC has already been disposed.</exception> /// <seealso cref="CreateAnswerAsync()"/> /// <since_tizen> 9 </since_tizen> public async Task <string> CreateOfferAsync() { ValidateWebRTCState(WebRTCState.Negotiating); var tcsSdpCreated = new TaskCompletionSource <string>(); NativeWebRTC.SdpCreatedCallback cb = (handle, sdp, _) => { tcsSdpCreated.TrySetResult(sdp); }; NativeWebRTC.CreateSDPOfferAsync(Handle, new SafeBundleHandle(), cb, IntPtr.Zero). ThrowIfFailed("Failed to create offer asynchronously"); var offer = await tcsSdpCreated.Task.ConfigureAwait(false); await Task.Yield(); return(offer); }