Skip to content

Commit

Permalink
com.utilities.websockets 1.0.0-preview.2 (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenHodgson authored Aug 17, 2024
1 parent 7b0fc5c commit 4c79f99
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
18 changes: 16 additions & 2 deletions Samples~/WebsocketDemo/WebSocketBindings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using UnityEngine;
using UnityEngine.UIElements;

Expand Down Expand Up @@ -44,6 +45,11 @@ public class WebSocketBindings : MonoBehaviour
private WebSocket webSocket;

private readonly List<Tuple<LogType, string>> logs = new();
#if !UNITY_2022_3_OR_NEWER
// ReSharper disable once InconsistentNaming
private CancellationToken destroyCancellationToken => destroyCancellationTokenSource.Token;
private CancellationTokenSource destroyCancellationTokenSource = new CancellationTokenSource();
#endif

private void OnValidate()
{
Expand All @@ -58,7 +64,6 @@ private void Awake()
OnValidate();

var root = uiDocument.rootVisualElement;

statusLabel = root.Q<Label>("status-label");
fpsLabel = root.Q<Label>("fps-label");
addressTextField = root.Q<TextField>("address-text-field");
Expand Down Expand Up @@ -147,6 +152,15 @@ private void OnDisable()
clearLogsButton.clicked -= OnClearLogsClick;
}

private void OnDestroy()
{
#if !UNITY_2022_3_OR_NEWER
destroyCancellationTokenSource?.Cancel();
destroyCancellationTokenSource?.Dispose();
destroyCancellationTokenSource = null;
#endif
}

private async void OnConnectClick()
{
if (webSocket != null)
Expand Down Expand Up @@ -181,7 +195,7 @@ private async void OnDisconnectClick()

try
{
await webSocket.CloseAsync();
await webSocket.CloseAsync(cancellationToken: CancellationToken.None);
}
catch (Exception e)
{
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "Utilities.WebSockets",
"description": "A simple websocket package for Unity (UPM)",
"keywords": [],
"version": "1.0.0-preview.1",
"version": "1.0.0-preview.2",
"unity": "2021.3",
"documentationUrl": "https://github.com/RageAgainstThePixel/com.utilities.websockets#documentation",
"changelogUrl": "https://github.com/RageAgainstThePixel/com.utilities.websockets/releases",
Expand All @@ -17,7 +17,7 @@
"url": "https://github.com/StephenHodgson"
},
"dependencies": {
"com.utilities.async": "2.1.5"
"com.utilities.async": "2.1.7"
},
"samples": [
{
Expand Down

0 comments on commit 4c79f99

Please sign in to comment.