You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+85-1Lines changed: 85 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,7 +27,7 @@ Used in [Colyseus Unity SDK](https://github.com/colyseus/colyseus-unity-sdk).
27
27
3. Click Add Package From Git URL
28
28
4. Enter URL: `https://github.com/endel/NativeWebSocket.git#upm-2.0`
29
29
30
-
If you need the old 1.x package instead, use `https://github.com/endel/NativeWebSocket.git#upm-1.x` in UPM, or check out the repository sources from the `1.x` branch.
30
+
If you need the previous 1.x package instead, use `https://github.com/endel/NativeWebSocket.git#upm-1.x` in UPM, or check out the repository sources from the [`1.x` branch](https://github.com/endel/NativeWebSocket/tree/1.x).
31
31
32
32
**Via .unitypackage:**
33
33
1. Download `NativeWebSocket.unitypackage` from the [Releases](https://github.com/endel/NativeWebSocket/releases) page
@@ -265,6 +265,90 @@ new WebSocket(string url, List<string> subprotocols)
265
265
266
266
---
267
267
268
+
# Migrating from 1.x
269
+
270
+
## Breaking changes
271
+
272
+
### Universal .NET library
273
+
274
+
The core library no longer depends on `UnityEngine`. It targets `netstandard2.0` and `net6.0`, and works across Unity, MonoGame, Godot, and any .NET project. Unity-specific code (WebGL) has been moved to separate integration files.
275
+
276
+
### `MainThreadUtil`, `WaitForUpdate`, and `WaitForBackgroundThread` removed
277
+
278
+
These Unity-specific classes have been removed. Event dispatching is now handled automatically via `SynchronizationContext`. Remove any references to these classes from your code.
279
+
280
+
```csharp
281
+
// 1.x — these no longer exist in 2.x
282
+
MainThreadUtil.Instance
283
+
MainThreadUtil.synchronizationContext
284
+
newWaitForUpdate()
285
+
newWaitForBackgroundThread()
286
+
```
287
+
288
+
### Automatic event dispatching — no more `Update()` dispatch loop
289
+
290
+
In 1.x, you had to call `DispatchMessageQueue()` every frame from `Update()`:
291
+
292
+
```csharp
293
+
// 1.x — REQUIRED in Update()
294
+
voidUpdate() {
295
+
websocket.DispatchMessageQueue();
296
+
}
297
+
```
298
+
299
+
In 2.x, events are automatically dispatched to the main thread via `SynchronizationContext` in Unity, Godot, and MonoGame (with `WebSocketGameComponent`). **Remove the `Update()` dispatch call.**`DispatchMessageQueue()` is only needed in environments without a `SynchronizationContext` (e.g. console apps).
Existing `Close()` calls without arguments still compile. However, if you implemented the `IWebSocket` interface directly, you must update your implementation to match the new signature.
312
+
313
+
### `IWebSocket` interface expanded
314
+
315
+
The interface now declares methods in addition to events and state:
Any custom `IWebSocket` implementation must now include these methods.
336
+
337
+
### Source files cannot be copied directly
338
+
339
+
In 1.x, you could copy `NativeWebSocket/Assets/WebSocket/WebSocket.cs` into your Unity project. In 2.x, the core source lives in `src/NativeWebSocket/` and requires a build-time transformation to add WebGL conditional compilation guards. Use UPM or the `.unitypackage` instead of copying raw files.
340
+
341
+
## Migration checklist
342
+
343
+
| What changed | Action required |
344
+
|---|---|
345
+
|`MainThreadUtil` / `WaitForUpdate` / `WaitForBackgroundThread` removed | Delete any code using these classes |
0 commit comments