WebRTC for UWP, new RTCPeerConnection() doesn't complete execution

261 views
Skip to first unread message

Lillemor Blom

unread,
Apr 11, 2017, 5:58:01 AM4/11/17
to discuss-webrtc

I’m trying to create a Universal Windows Platform application that uses WebRTC, but my code never executes past the first new RTCPeerConnection.


I have been looking at the open source project WebRTC for UWP (blog post with links to the git repos) and managed to build and run the ChatterBox VoIP client example. Since I am new to both UWP programming and WebRTC (and .NET, C# and Windows programming in general) the examples I have been looking at in the repos mentioned above have been much too complex for me to follow.


To start with something simpler, I want to recreate the WebRTC.org minimalistic codelab exercise for beginners (link to the complete code) as a UWP application written in C#. The original HTML/javascript creates a webpage with two video streams, one that is the local videostream and one that is sent over WebRTC. But, my UWP code doesn’t even get past creating the first RTCPeerConnection.


I am using Visual Studio 2015 and have installed the in the project.


My code, first version


using Org.WebRtc
//+ other using statements

public sealed partial class MainPage : Page
   
{
       
RTCPeerConnection _pc1;
       
public MainPage()
       
{
           
this.InitializeComponent();
       
}

       
// Code that is executed when ‘Call’ button is clicked
       
private async void uxCall_Click(object sender, RoutedEventArgs e)
       
{
           
/* GetDefaultList() returns List<RTCIceServer>, with Stun/Turn-servers borrowed from the ChatterBox-example */
           
var config = new RTCConfiguration() { IceServers = GetDefaultList() };
            _pc1
= new RTCPeerConnection(config);
           
Debug.WriteLine(“Never reaches this point”);
       
}
   
}


Debugging and debug printouts shows that the statement after the creation of the new RTCPeerConnection is never reached. I thought that maybe creating a new RTCPeerConnection couldn’t be done on the main thread without blocking it, so I updated the code to run that code on another thread.


My code, second version


 using Org.WebRtc
 
public sealed partial class MainPage : Page
   
{
       
RTCPeerConnection _pc1;
       
public MainPage()
       
{
             
this.InitializeComponent();
       
}

       
// Code that is executed when ‘Call’ button is clicked
       
private async void uxCall_Click(object sender, RoutedEventArgs e)
       
{
             
var config = new RTCConfiguration() { IceServers = GetDefaultList() };
             _pc1
= await Task.Run(() => {
               
//A thread for the anonymous function has been created here
               
return new RTCPeerConnection(config);
               
Debug.WriteLine(“Never reaches this point...”);
             
});
             
Debug.WriteLine(“...or this point”);
       
}
   
}



Debug printouts show that the code doesn’t reach the line after the creation of the new RTCPeerConnection. Debugging shows that the thread created for the anonymous inner function is never destroyed. I have also tried to use an empty RTCConfiguration like in the codelab exercise, but it makes no difference.


My inexperience with WebRTC, UWP and asynchronous/thread programming in UWP makes it difficult for me to begin to understand if the error is with WebRTC, the threading or something else. Any help would be greatly appreciated.

Lillemor Blom

unread,
Apr 12, 2017, 2:51:54 AM4/12/17
to discuss-webrtc

I found the problem at last, and the solution is semi-embarassing not to have found earlier :)


There is a static method Initialize(CoreDispatcher dispatcher) that initializes WebRTC with dispatcher and worker thread (link to definition in the UWP WebRTC wrapper). The following statement before creating a new RTCPeerConnection solved the problem:


WebRTC.Initialize(this.Dispatcher);


According to the ChatterBox example it can take null instead of a dispatcher as a parameter (use in code example) in Windows 10.

jac...@microsoft.com

unread,
Apr 18, 2017, 4:08:34 AM4/18/17
to discuss-webrtc
Hello,

Glad you found the issue, I think we could do a better job of throwing an intelligible error in that case and will make a note of it.  If you need any other help with WebRTC for UWP just let me know!

Thanks,
James

Chen Cong

unread,
Apr 26, 2017, 3:22:07 AM4/26/17
to discuss-webrtc
Hi,

I have a problem that I can  not figure out  how to play the video. I can create a video source from a video track , but I don`t  know how to use the "Renderer" in "ChatterBox" sample .  Is there a easy way I can renderer the video , I`m not familiar with Windows  platform development and I can not  find other references.  Can you help me ?  :)
 在 2017年4月18日星期二 UTC+8下午4:08:34,jac...@microsoft.com写道:
Reply all
Reply to author
Forward
0 new messages