import { Server } from "https://deno.land/x/wocket@v1.0.0/src/server.ts";
A class to create a websocket server, handling clients connecting, and being able to handle messages from them, and send messages to them
Constructors
new
Server(options: IOptions)Properties
Methods
broadcast()
channelName: string,
message: Record<string, unknown>,
id: number,
Broadcast to other clients in a channel excluding the one passed in
close(): Promise<void>
Close the server, stopping all resources and breaking all connections to clients
on<CustomProps extends Record<string, unknown> | string | Uint8Array, ChannelName extends string = any>(channelName: ChannelName, cb: OnChannelCallback<CustomProps, ChannelName>): void
Do the following:
1. Create a channel (if it does not already exist).
2. Add a callback to that channel. This callback will be executed when
events are sent to the channel.
3. Store the callback in the list of callbacks that the channel has.
run(): void
Run the sever.
to(): void
channelName: string,
message: Record<string, unknown> | string,
onlySendTo?: number,
Send a message to the channel, so clients listening on that channel will receive this message