Documentation / @super-line/server / Conn
Class: Conn<Ev, Ctx, Role, Data>
Defined in: conn.ts:20
A single client connection, passed to handlers as the third argument.
Node-local: conn objects live on the node that accepted the upgrade, so don't stash one to reach a user later — cross-node delivery goes through the Adapter (use a per-user room instead). Generic over the events it may emit (scoped by role), its ctx, and its role.
Type Parameters
Ev
Ev = Record<string, ServerMessageDef>
Ctx
Ctx = unknown
Role
Role extends string = string
Data
Data = unknown
Constructors
Constructor
new Conn<
Ev,Ctx,Role,Data>(ws,id,role,ctx,serializer,backpressure?):Conn<Ev,Ctx,Role,Data>
Defined in: conn.ts:40
Parameters
ws
WebSocket
The underlying ws socket. conn.ws.terminate() simulates a drop in tests.
id
string
Server-assigned unique id for this connection (stable for its lifetime).
role
Role
This connection's role (the literal resolved by authenticate).
ctx
Ctx
The context authenticate returned for this connection.
serializer
backpressure?
Returns
Conn<Ev, Ctx, Role, Data>
Properties
channels
readonlychannels:Set<string>
Defined in: conn.ts:27
Namespaced channels (rooms + topics) this connection belongs to.
connectedAt
readonlyconnectedAt:number
Defined in: conn.ts:32
When this connection was accepted (Date.now() at the upgrade).
ctx
readonlyctx:Ctx
Defined in: conn.ts:48
The context authenticate returned for this connection.
data
data:
Data
Defined in: conn.ts:29
Mutable per-connection scratch state, typed per role by the contract's data schema.
id
readonlyid:string
Defined in: conn.ts:44
Server-assigned unique id for this connection (stable for its lifetime).
lastPingAt?
optionallastPingAt?:number
Defined in: conn.ts:34
When the server last sent a heartbeat ping to this connection (managed by the server).
lastPongAt?
optionallastPongAt?:number
Defined in: conn.ts:36
When a heartbeat pong was last received — liveness signal (managed by the server).
missedPongs
missedPongs:
number=0
Defined in: conn.ts:38
Pings sent since the last pong; drives reaping (managed by the server).
role
readonlyrole:Role
Defined in: conn.ts:46
This connection's role (the literal resolved by authenticate).
ws
readonlyws:WebSocket
Defined in: conn.ts:42
The underlying ws socket. conn.ws.terminate() simulates a drop in tests.
Methods
close()
close():
void
Defined in: conn.ts:83
Close the underlying socket.
Returns
void
emit()
emit<
E>(event,data):void
Defined in: conn.ts:78
Push an event to THIS connection (node-local). Scoped to the role's events.
Type Parameters
E
E extends string | number | symbol
Parameters
event
E
data
EmitData<Ev[E]>
Returns
void
send()
send(
frame):void
Defined in: conn.ts:66
Encode and send a frame (unicast, e.g. req/res).
Parameters
frame
Returns
void
sendRaw()
sendRaw(
payload):void
Defined in: conn.ts:72
Forward an already-encoded frame (fan-out path; encoded once at the source).
Parameters
payload
string | Uint8Array<ArrayBufferLike>
Returns
void