Skip to content
Snippets Groups Projects
Commit f00120d1 authored by Georgios Diamantopoulos's avatar Georgios Diamantopoulos
Browse files

allow starting new sessions

parent d29593e2
Branches
Tags
No related merge requests found
...@@ -3,6 +3,11 @@ namespace MasterDevs.ChromeDevTools ...@@ -3,6 +3,11 @@ namespace MasterDevs.ChromeDevTools
{ {
public class ChromeSessionFactory : IChromeSessionFactory public class ChromeSessionFactory : IChromeSessionFactory
{ {
public IChromeSession Create(ChromeSessionInfo sessionInfo)
{
return Create(sessionInfo.WebSocketDebuggerUrl);
}
public IChromeSession Create(string endpointUrl) public IChromeSession Create(string endpointUrl)
{ {
// Sometimes binding to localhost might resolve wrong AddressFamily, force IPv4 // Sometimes binding to localhost might resolve wrong AddressFamily, force IPv4
......
...@@ -5,7 +5,9 @@ namespace MasterDevs.ChromeDevTools ...@@ -5,7 +5,9 @@ namespace MasterDevs.ChromeDevTools
{ {
public interface IChromeProcess : IDisposable public interface IChromeProcess : IDisposable
{ {
Task<ChromeSessionInfo[]> GetSessions(); Task<ChromeSessionInfo[]> GetSessionInfo();
Task<ChromeSessionInfo> StartNewSession();
Uri RemoteDebuggingUri { get; } Uri RemoteDebuggingUri { get; }
} }
......
...@@ -20,6 +20,8 @@ namespace MasterDevs.ChromeDevTools ...@@ -20,6 +20,8 @@ namespace MasterDevs.ChromeDevTools
public override void Dispose() public override void Dispose()
{ {
base.Dispose();
Process.Kill(); Process.Kill();
try try
{ {
......
...@@ -7,29 +7,41 @@ namespace MasterDevs.ChromeDevTools ...@@ -7,29 +7,41 @@ namespace MasterDevs.ChromeDevTools
{ {
public class RemoteChromeProcess : IChromeProcess public class RemoteChromeProcess : IChromeProcess
{ {
private readonly HttpClient http;
public RemoteChromeProcess(string remoteDebuggingUri)
: this(new Uri(remoteDebuggingUri))
{
}
public RemoteChromeProcess(Uri remoteDebuggingUri) public RemoteChromeProcess(Uri remoteDebuggingUri)
{ {
RemoteDebuggingUri = remoteDebuggingUri; RemoteDebuggingUri = remoteDebuggingUri;
http = new HttpClient
{
BaseAddress = RemoteDebuggingUri
};
} }
public Uri RemoteDebuggingUri { get; } public Uri RemoteDebuggingUri { get; }
public virtual void Dispose() public virtual void Dispose()
{ {
http.Dispose();
} }
public async Task<ChromeSessionInfo[]> GetSessions() public async Task<ChromeSessionInfo[]> GetSessionInfo()
{ {
using (var http = new HttpClient string json = await http.GetStringAsync("/json");
{ return JsonConvert.DeserializeObject<ChromeSessionInfo[]>(json);
BaseAddress = RemoteDebuggingUri
})
{
string json = await http.GetStringAsync("/json");
return JsonConvert.DeserializeObject<ChromeSessionInfo[]>(json);
}
} }
public async Task<ChromeSessionInfo> StartNewSession()
{
string json = await http.GetStringAsync("/json");
return JsonConvert.DeserializeObject<ChromeSessionInfo>(json);
}
} }
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment