Skip to content

Commit

Permalink
Updated README.
Browse files Browse the repository at this point in the history
  • Loading branch information
HavenDV committed Jan 8, 2021
1 parent 6a142c6 commit 8acbc72
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,18 @@ client.DefaultNamespace = "my";
// or
// Connects to "my" namespace.
await client.ConnectAsync(new Uri(LocalCharServerUrl), cancellationToken, "my");
await client.ConnectAsync(new Uri(LocalCharServerUrl), namespaces: "my");
// Sends message to "my" namespace.
await client.Emit("message", "hello", "my", cancellationToken);
await client.Emit("message", "hello", "my");

```

### Custom arguments

```cs
await client.ConnectAsync(new Uri($"wss://socketio-chat-h9jt.herokuapp.com/?access_token={mAccessToken}"));
```

### Live Example

C# .NET Fiddle - https://dotnetfiddle.net/FWMpQ3 <br/>
Expand Down
10 changes: 8 additions & 2 deletions src/libs/H.Socket.IO/SocketIoClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -384,17 +384,23 @@ public async Task<bool> ConnectToNamespaceAsync(string customNamespace, Cancella
/// </summary>
/// <param name="uri"></param>
/// <param name="timeout"></param>
/// <param name="cancellationToken"></param>
/// <param name="namespaces"></param>
/// <exception cref="InvalidOperationException">if AfterError event occurs while wait connect message</exception>
/// <exception cref="ObjectDisposedException"></exception>
/// <exception cref="OperationCanceledException"></exception>
/// <exception cref="ArgumentNullException"></exception>
/// <returns></returns>
public async Task<bool> ConnectAsync(Uri uri, TimeSpan timeout, params string[] namespaces)
public async Task<bool> ConnectAsync(
Uri uri,
TimeSpan timeout,
CancellationToken cancellationToken = default,
params string[] namespaces)
{
uri = uri ?? throw new ArgumentNullException(nameof(uri));

using var cancellationSource = new CancellationTokenSource(timeout);
using var cancellationSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
cancellationSource.CancelAfter(timeout);

return await ConnectAsync(uri, cancellationSource.Token, namespaces).ConfigureAwait(false);
}
Expand Down

0 comments on commit 8acbc72

Please sign in to comment.