Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions dotnet/src/webdriver/BiDi/BiDi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,12 @@ private BiDi() { }

public Emulation.IEmulationModule Emulation => AsModule<Emulation.EmulationModule>();

public static async Task<IBiDi> ConnectAsync(string url, BiDiOptions? options = null, CancellationToken cancellationToken = default)
public static async Task<IBiDi> ConnectAsync(string url, Action<BiDiOptionsBuilder>? configure = null, CancellationToken cancellationToken = default)
{
var transport = await WebSocketTransport.ConnectAsync(new Uri(url), cancellationToken).ConfigureAwait(false);
BiDiOptionsBuilder builder = new();
configure?.Invoke(builder);

var transport = await WebSocketTransport.ConnectAsync(new Uri(url), builder.WebSocketConfigure, cancellationToken).ConfigureAwait(false);

BiDi bidi = new();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// <copyright file="BiDiOptions.cs" company="Selenium Committers">
// <copyright file="BiDiOptionsBuilder.cs" company="Selenium Committers">
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
Expand All @@ -17,8 +17,17 @@
// under the License.
// </copyright>

using System.Net.WebSockets;

namespace OpenQA.Selenium.BiDi;

public sealed class BiDiOptions
public sealed class BiDiOptionsBuilder
{
internal Action<ClientWebSocketOptions>? WebSocketConfigure { get; private set; }

public BiDiOptionsBuilder UseWebSocket(Action<ClientWebSocketOptions> configure)
{
WebSocketConfigure = configure;
return this;
}
}
4 changes: 2 additions & 2 deletions dotnet/src/webdriver/BiDi/WebDriver.Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace OpenQA.Selenium.BiDi;

public static class WebDriverExtensions
{
Comment thread
nvborisenko marked this conversation as resolved.
public static async Task<IBiDi> AsBiDiAsync(this IWebDriver webDriver, BiDiOptions? options = null, CancellationToken cancellationToken = default)
public static async Task<IBiDi> AsBiDiAsync(this IWebDriver webDriver, Action<BiDiOptionsBuilder>? configure = null, CancellationToken cancellationToken = default)
{
if (webDriver is null) throw new ArgumentNullException(nameof(webDriver));

Expand All @@ -34,7 +34,7 @@ public static async Task<IBiDi> AsBiDiAsync(this IWebDriver webDriver, BiDiOptio

if (webSocketUrl is null) throw new BiDiException("The driver is not compatible with bidirectional protocol or \"webSocketUrl\" not enabled in driver options.");

var bidi = await BiDi.ConnectAsync(webSocketUrl, options, cancellationToken).ConfigureAwait(false);
var bidi = await BiDi.ConnectAsync(webSocketUrl, configure, cancellationToken).ConfigureAwait(false);

return bidi;
}
Expand Down
4 changes: 3 additions & 1 deletion dotnet/src/webdriver/BiDi/WebSocketTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ sealed class WebSocketTransport(ClientWebSocket webSocket) : ITransport
private readonly SemaphoreSlim _socketSendSemaphoreSlim = new(1, 1);
private readonly MemoryStream _sharedMemoryStream = new();

public static async Task<WebSocketTransport> ConnectAsync(Uri uri, CancellationToken cancellationToken)
public static async Task<WebSocketTransport> ConnectAsync(Uri uri, Action<ClientWebSocketOptions>? configure, CancellationToken cancellationToken)
{
ClientWebSocket webSocket = new();

configure?.Invoke(webSocket.Options);

try
{
Comment thread
nvborisenko marked this conversation as resolved.
Outdated
await webSocket.ConnectAsync(uri, cancellationToken).ConfigureAwait(false);
Expand Down
Loading