Skip to content

Commit 9149cd5

Browse files
authored
Adding c# change for sample app
1 parent 072062c commit 9149cd5

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

specs/WebRtcPortConfiguration.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,46 @@ ScenarioWebRtcUdpPortConfiguration::~ScenarioWebRtcUdpPortConfiguration()
7474
CHECK_FAILURE(m_webView->remove_ContentLoading(m_contentLoadingToken));
7575
}
7676

77+
```
78+
### C# Sample
79+
```csharp
80+
using Microsoft.Web.WebView2.Core;
81+
using System;
82+
83+
class ScenarioWebRtcUdpPortConfiguration
84+
{
85+
private readonly AppWindow _appWindow;
86+
private readonly CoreWebView2 _webView;
87+
private readonly string _demoUri;
88+
private EventRegistrationToken _contentLoadingToken;
89+
90+
public ScenarioWebRtcUdpPortConfiguration(AppWindow appWindow)
91+
{
92+
_appWindow = appWindow;
93+
_webView = appWindow.GetWebView();
94+
95+
// Navigate to a demo page that will trigger WebRTC usage.
96+
_demoUri = "https://webrtc.github.io/samples/src/content/peerconnection/trickle-ice/";
97+
_webView.Navigate(_demoUri);
98+
99+
// If we navigate away from the demo page, turn off this scenario.
100+
_webView.ContentLoading += WebView_ContentLoading;
101+
}
102+
103+
private void WebView_ContentLoading(object? sender, CoreWebView2ContentLoadingEventArgs e)
104+
{
105+
var uri = _webView.Source;
106+
if (uri != _demoUri)
107+
{
108+
_appWindow.DeleteComponent(this);
109+
}
110+
}
111+
112+
~ScenarioWebRtcUdpPortConfiguration()
113+
{
114+
_webView.ContentLoading -= WebView_ContentLoading;
115+
}
116+
}
77117
```
78118

79119
# API Details

0 commit comments

Comments
 (0)