diff --git a/.github/workflows/nuget-publish.yml b/.github/workflows/nuget-publish.yml index f93244c..bf34e1f 100644 --- a/.github/workflows/nuget-publish.yml +++ b/.github/workflows/nuget-publish.yml @@ -30,7 +30,7 @@ jobs: name: Publish to NuGet runs-on: ubuntu-latest needs: [build] - # TODO: revert to: if: github.event_name == 'push' && github.ref == 'refs/heads/master' + if: github.event_name == 'push' && github.ref == 'refs/heads/master' steps: - uses: actions/checkout@v4 with: diff --git a/.github/workflows/unity-upm-release.yml b/.github/workflows/unity-upm-release.yml index 8733ab6..acbe4bd 100644 --- a/.github/workflows/unity-upm-release.yml +++ b/.github/workflows/unity-upm-release.yml @@ -31,7 +31,7 @@ jobs: name: Update UPM branch runs-on: ubuntu-latest needs: [checkSemver] - if: needs.checkSemver.outputs.semver-updated == 'true' + if: github.event_name == 'push' && needs.checkSemver.outputs.semver-updated == 'true' steps: - uses: actions/checkout@v4 @@ -171,7 +171,7 @@ jobs: name: Create Unity Package and Release runs-on: ubuntu-latest needs: [checkSemver] - if: needs.checkSemver.outputs.semver-updated == 'true' + if: github.event_name == 'push' && needs.checkSemver.outputs.semver-updated == 'true' steps: - name: Checkout Code uses: actions/checkout@v4 diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ea2fa8..00e1302 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this project are documented in this file. This changelog starts at 2.0.5 — see the [GitHub Releases](https://github.com/endel/NativeWebSocket/releases) page for earlier versions. +## 2.0.8 - 2026-10-26 + +### Fixed + +- **WebGL: `CancelConnection()` no longer throws on an open socket.** Browsers only accept 1000 or 3000-4999 in `close()`, so closing with 1006 threw. It now closes with 1000 and still reports `Abnormal` (1006) to `OnClose`, like the other platforms. + ## 2.0.7 - 2026-08-06 ### Fixed diff --git a/integrations/Unity/WebSocketWebGL.cs b/integrations/Unity/WebSocketWebGL.cs index 4033501..e523861 100644 --- a/integrations/Unity/WebSocketWebGL.cs +++ b/integrations/Unity/WebSocketWebGL.cs @@ -30,6 +30,9 @@ public class WebSocket : IWebSocket protected int instanceId; + // CancelConnection() was called: OnClose reports Abnormal, like the native socket + private bool cancelled; + public event WebSocketOpenEventHandler OnOpen; public event WebSocketMessageEventHandler OnMessage; public event WebSocketErrorEventHandler OnError; @@ -104,7 +107,11 @@ public Task Connect() public void CancelConnection() { if (State == WebSocketState.Open) - Close(WebSocketCloseCode.Abnormal); + { + // browsers only accept 1000 or 3000-4999 in close(): 1006 would throw + cancelled = true; + Close(WebSocketCloseCode.Normal); + } } public Task Close(WebSocketCloseCode code = WebSocketCloseCode.Normal, string reason = null) @@ -183,7 +190,7 @@ public void DelegateOnErrorEvent(string errorMsg) public void DelegateOnCloseEvent(int closeCode) { - this.OnClose?.Invoke(WebSocketHelpers.ParseCloseCodeEnum(closeCode)); + this.OnClose?.Invoke(cancelled ? WebSocketCloseCode.Abnormal : WebSocketHelpers.ParseCloseCodeEnum(closeCode)); } } } diff --git a/integrations/Unity/package.json b/integrations/Unity/package.json index 27d5b16..884d1a3 100644 --- a/integrations/Unity/package.json +++ b/integrations/Unity/package.json @@ -1,6 +1,6 @@ { "name": "com.endel.nativewebsocket", - "version": "2.0.7", + "version": "2.0.8", "description": "WebSocket client for Unity - with no external dependencies (WebGL, Native, Android, iOS, UWP). Events auto-dispatch to the main thread via SynchronizationContext.", "license": "MIT", "repository": {