Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to await ConnectAsync() #117

Closed
Closed
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions TestClient/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -305,11 +305,11 @@ private void btnConnect_Click(object sender, EventArgs e)
{
if (!obs.IsConnected)
{
System.Threading.Tasks.Task.Run(() =>
System.Threading.Tasks.Task.Run(async () =>
{
try
{
obs.ConnectAsync(txtServerIP.Text, txtServerPassword.Text);
await obs.ConnectAsync(txtServerIP.Text, txtServerPassword.Text);
}
catch (Exception ex)
{
Expand Down
3 changes: 2 additions & 1 deletion obs-websocket-dotnet/IOBSWebsocket.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
using OBSWebsocketDotNet.Communication;
using OBSWebsocketDotNet.Types;
Expand Down Expand Up @@ -1050,7 +1051,7 @@ public interface IOBSWebsocket
/// </summary>
/// <param name="url">Server URL in standard URL format.</param>
/// <param name="password">Server password</param>
void ConnectAsync(string url, string password);
Task ConnectAsync(string url, string password);

/// <summary>
/// Disconnect this instance from the server
Expand Down
6 changes: 4 additions & 2 deletions obs-websocket-dotnet/OBSWebsocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ public void Connect(string url, string password)
/// </summary>
/// <param name="url">Server URL in standard URL format.</param>
/// <param name="password">Server password</param>
public void ConnectAsync(string url, string password)
/// <returns>Returns the awaitable Task from <see cref="WebsocketClient.StartOrFail"/>.
/// NOTE: After awaiting, the client is still not ready to work. Please subscribe to the Connected event to determine when the connection is actually fully established</returns>
public Task ConnectAsync(string url, string password)
{
if (!url.ToLower().StartsWith(WEBSOCKET_URL_PREFIX))
{
Expand All @@ -105,7 +107,7 @@ public void ConnectAsync(string url, string password)
wsConnection.DisconnectionHappened.Subscribe(d => Task.Run(() => OnWebsocketDisconnect(this, d)));

connectionPassword = password;
wsConnection.StartOrFail();
return wsConnection.StartOrFail();
}

/// <summary>
Expand Down