SvelteWebSocketServer 2.5.2
dotnet add package SvelteWebSocketServer --version 2.5.2
NuGet\Install-Package SvelteWebSocketServer -Version 2.5.2
<PackageReference Include="SvelteWebSocketServer" Version="2.5.2" />
<PackageVersion Include="SvelteWebSocketServer" Version="2.5.2" />
<PackageReference Include="SvelteWebSocketServer" />
paket add SvelteWebSocketServer --version 2.5.2
#r "nuget: SvelteWebSocketServer, 2.5.2"
#:package SvelteWebSocketServer@2.5.2
#addin nuget:?package=SvelteWebSocketServer&version=2.5.2
#tool nuget:?package=SvelteWebSocketServer&version=2.5.2
SvelteWebSocketServer
Basic C# implementation of a WebSocket server for use with svelte-websocket-stores
Usage
Basic Initialization
using EmbedIO;
using SvelteWebSocketServer;
var wsw = new WebSocketWrapper(); // Main entry-point
var ws = new WebServer().WithModule(webSocketWrapper);
Initialization using the WebSocketWrapperListener for easy event handling
using EmbedIO;
using SvelteWebSocketServer;
var wsw = new WebSocketWrapper(); // Main entry-point
var ws = new WebServer().WithModule(webSocketWrapper);
var wswListener = new WebSocketWrapperListener(wsw);
Basic event handling
wsw.OnJsonSet += (scope, id, value) => ...
Event handling using WebSocketWrapperListener
// Raw JSON value with exact ID match
wswListener.AddHandler("some.state", (scope, id, value) => ... );
// Typed value with exact ID match
wswListener.AddHandler<float>("some.state", (scope, match, value) => ... );
// These regex handlers are now deprecated. Please just use wsw.OnJsonSet instead.
// Raw JSON value with regex match
wswListener.AddHandler(new Regex("some\\.(.+?)\\.state"), (scope, id, value) => ... );
// Typed value with regex match
wswListener.AddHandler<float>(new Regex("some\\.(.+?)\\.state"), (scope, match, value) => ... );
WebSocket Message Format
All communication between a client and this library is over WebSocket.
All WebSocket messages are interpreted as JSON objects.
The message object is defined as:
type Json = boolean | number | string | { [key: string]: Json } | Json[] | null;
type Message = {
scope: string;
id: string;
value: Json;
}
The field scope identifies the scope of the client it comes from and limits which clients receive it when coming from the server.
The field id is the primary identifier and determines where the value field is stored.
Server
Client Connected
- Send the client messages for all the variables currently stored values
Message Received
- The incoming text data is parsed as JSON.
- The variable is indexed by the object's
scopeandidfields from the dictionary holding the respectively typed variables. - The variable's value is assigned to the object's
valuefield. - Send all clients a message for the new value.
- Handle any events.
Client [^1]
Message Received
- The incoming text data is parsed as JSON.
- The object's
scopefield is checked if it is global ("global") or matches the client's local scope (for example "tp1"). If it does not match, the message is discarded. - The local Svelte store is indexed by the object's
idfield from the dictionary holding the respectively typed stores. - The store's value is assigned to the object's
valuefield.
[^1]: This is the behavior expected by this WebSocket server
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- EmbedIO (>= 3.5.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2.5.2 | 224 | 4/22/2025 |
| 2.5.1 | 201 | 4/22/2025 |
| 2.5.0 | 192 | 4/21/2025 |
| 2.4.2 | 164 | 3/21/2025 |
| 2.4.1 | 144 | 3/21/2025 |
| 2.4.0 | 180 | 3/20/2025 |
| 2.3.3 | 446 | 3/19/2025 |
| 2.3.2 | 352 | 3/18/2025 |
| 2.2.0 | 160 | 11/21/2024 |
| 2.1.0 | 151 | 10/9/2024 |
| 2.0.2 | 164 | 8/29/2024 |
| 2.0.1 | 152 | 7/22/2024 |
| 1.0.2 | 158 | 7/8/2024 |
| 1.0.0.1 | 163 | 7/2/2024 |
| 1.0.0 | 156 | 7/1/2024 |