Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/nuget-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/unity-upm-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions integrations/Unity/WebSocketWebGL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion integrations/Unity/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
Loading