Skip to content

Commit

Permalink
[dotnet] implement chrome and edge support for casting to devices
Browse files Browse the repository at this point in the history
  • Loading branch information
titusfortner committed Sep 29, 2021
1 parent 604c23b commit ab6a867
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 1 deletion.
5 changes: 5 additions & 0 deletions dotnet/src/webdriver/Chrome/ChromeDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ public ChromeDriver(ChromeDriverService service, ChromeOptions options, TimeSpan
: base(service, options, commandTimeout)
{
this.AddCustomChromeCommand(ExecuteCdp, HttpCommandInfo.PostCommand, "/session/{sessionId}/goog/cdp/execute");
this.AddCustomChromeCommand(GetCastSinksCommand, HttpCommandInfo.GetCommand, "/session/{sessionId}/goog/cast/get_sinks");
this.AddCustomChromeCommand(SelectCastSinkCommand, HttpCommandInfo.PostCommand, "/session/{sessionId}/goog/cast/set_sink_to_use");
this.AddCustomChromeCommand(StartCastTabMirroringCommand, HttpCommandInfo.PostCommand, "/session/{sessionId}/goog/cast/start_tab_mirroring");
this.AddCustomChromeCommand(GetCastIssueMessageCommand, HttpCommandInfo.GetCommand, "/session/{sessionId}/goog/cast/get_issue_message");
this.AddCustomChromeCommand(StopCastingCommand, HttpCommandInfo.PostCommand, "/session/{sessionId}/goog/cast/stop_casting");
}

}
Expand Down
75 changes: 74 additions & 1 deletion dotnet/src/webdriver/Chromium/ChromiumDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,17 @@ public abstract class ChromiumDriver : WebDriver, ISupportsLogs, IDevTools
/// </summary>
public static readonly bool AcceptUntrustedCertificates = true;

protected const string ExecuteCdp = "executeCdpCommand";
protected const string GetCastSinksCommand = "getCastSinks";
protected const string SelectCastSinkCommand = "selectCastSink";
protected const string StartCastTabMirroringCommand = "startCastTabMirroring";
protected const string GetCastIssueMessageCommand = "getCastIssueMessage";
protected const string StopCastingCommand = "stopCasting";
private const string GetNetworkConditionsCommand = "getNetworkConditions";
private const string SetNetworkConditionsCommand = "setNetworkConditions";
private const string DeleteNetworkConditionsCommand = "deleteNetworkConditions";
private const string SendChromeCommand = "sendChromeCommand";
private const string SendChromeCommandWithResult = "sendChromeCommandWithResult";
protected const string ExecuteCdp = "executeCdpCommand";

private readonly string optionsCapabilityName;
private DevToolsSession devToolsSession;
Expand Down Expand Up @@ -234,6 +239,74 @@ public void CloseDevToolsSession()
}
}

/// <summary>
/// Returns the list of cast sinks (Cast devices) available to the Chrome media router.
/// </summary>
/// <returns>An object representing the list of available sinks.</returns>
public object GetCastSinks()
{
Response response = this.Execute(GetCastSinksCommand, null);
return response.Value;
}

/// <summary>
/// Selects a cast sink (Cast device) as the recipient of media router intents (connect or play).
/// </summary>
/// <param name="deviceName">Name of the target sink (device).</param>
public void SelectCastSink(string deviceName)
{
if (deviceName == null)
{
throw new ArgumentNullException("deviceName", "deviceName must not be null");
}

Dictionary<string, object> parameters = new Dictionary<string, object>();
parameters["sinkName"] = deviceName;
this.Execute(SelectCastSinkCommand, parameters);
}

/// <summary>
/// Initiates tab mirroring for the current browser tab on the specified device.
/// </summary>
/// <param name="deviceName">Name of the target sink (device).</param>
public void StartTabMirroring(string deviceName)
{
if (deviceName == null)
{
throw new ArgumentNullException("deviceName", "deviceName must not be null");
}

Dictionary<string, object> parameters = new Dictionary<string, object>();
parameters["sinkName"] = deviceName;
this.Execute(StartCastTabMirroringCommand, parameters);
}

/// <summary>
/// Returns the error message if there is any issue in a Cast session.
/// </summary>
/// <returns>An error message.</returns>
public String GetCastIssueMessage()
{
Response response = this.Execute(GetCastIssueMessageCommand, null);
return (string)response.Value;
}

/// <summary>
/// Stops casting from media router to the specified device, if connected.
/// </summary>
/// <param name="deviceName">Name of the target sink (device).</param>
public void StopCasting(string deviceName)
{
if (deviceName == null)
{
throw new ArgumentNullException("deviceName", "deviceName must not be null");
}

Dictionary<string, object> parameters = new Dictionary<string, object>();
parameters["sinkName"] = deviceName;
this.Execute(StopCastingCommand, parameters);
}

protected override void Dispose(bool disposing)
{
if (disposing)
Expand Down
5 changes: 5 additions & 0 deletions dotnet/src/webdriver/Edge/EdgeDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ public EdgeDriver(EdgeDriverService service, EdgeOptions options, TimeSpan comma
: base(service, options, commandTimeout)
{
this.AddCustomChromeCommand(ExecuteCdp, HttpCommandInfo.PostCommand, "/session/{sessionId}/ms/cdp/execute");
this.AddCustomChromeCommand(GetCastSinksCommand, HttpCommandInfo.GetCommand, "/session/{sessionId}/ms/cast/get_sinks");
this.AddCustomChromeCommand(SelectCastSinkCommand, HttpCommandInfo.PostCommand, "/session/{sessionId}/ms/cast/set_sink_to_use");
this.AddCustomChromeCommand(StartCastTabMirroringCommand, HttpCommandInfo.PostCommand, "/session/{sessionId}/ms/cast/start_tab_mirroring");
this.AddCustomChromeCommand(GetCastIssueMessageCommand, HttpCommandInfo.GetCommand, "/session/{sessionId}/ms/cast/get_issue_message");
this.AddCustomChromeCommand(StopCastingCommand, HttpCommandInfo.PostCommand, "/session/{sessionId}/ms/cast/stop_casting");
}
}
}

0 comments on commit ab6a867

Please sign in to comment.