Skip to content

Documentation / @super-line/server / Conn

Class: Conn<Ev, Ctx, Role, Data>

Defined in: conn.ts:11

A single client connection, passed to handlers as the third argument.

Node-local: conn objects live on the node that accepted the connection, 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>(raw, id, role, ctx, serializer, onEmit?): Conn<Ev, Ctx, Role, Data>

Defined in: conn.ts:35

Parameters

raw

RawConn

The underlying transport connection. conn.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

Serializer

onEmit?

(event, data) => void

Optional inspector tap: called with each emit so the server can mirror it to inspectors.

Returns

Conn<Ev, Ctx, Role, Data>

Properties

channels

readonly channels: Set<string>

Defined in: conn.ts:18

Namespaced channels (rooms + topics) this connection belongs to.


connectedAt

readonly connectedAt: number

Defined in: conn.ts:27

When this connection was accepted (Date.now()).


ctx

readonly ctx: Ctx

Defined in: conn.ts:43

The context authenticate returned for this connection.


data

data: Data

Defined in: conn.ts:20

Mutable per-connection scratch state, typed per role by the contract's data schema.


id

readonly id: string

Defined in: conn.ts:39

Server-assigned unique id for this connection (stable for its lifetime).


lastPingAt?

optional lastPingAt?: number

Defined in: conn.ts:29

When the server last sent a heartbeat ping to this connection (managed by the server).


lastPongAt?

optional lastPongAt?: number

Defined in: conn.ts:31

When a heartbeat pong was last received — liveness signal (managed by the server).


missedPongs

missedPongs: number = 0

Defined in: conn.ts:33

Pings sent since the last pong; drives reaping (managed by the server).


principal?

optional principal?: string

Defined in: conn.ts:24

ACL identity for stores: identify(conn) ?? conn.id, set by the server at accept (always defined there).


raw

readonly raw: RawConn

Defined in: conn.ts:37

The underlying transport connection. conn.terminate() simulates a drop in tests.


role

readonly role: Role

Defined in: conn.ts:41

This connection's role (the literal resolved by authenticate).


transport?

optional transport?: string

Defined in: conn.ts:22

The client↔server transport (wire) this connection was accepted on (set by the server at accept).

Methods

close()

close(): void

Defined in: conn.ts:68

Graceful close of the underlying transport connection.

Returns

void


emit()

emit<E>(event, data): void

Defined in: conn.ts:62

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:50

Encode and send a frame (unicast, e.g. req/res).

Parameters

frame

ServerFrame

Returns

void


sendRaw()

sendRaw(payload): void

Defined in: conn.ts:56

Forward an already-encoded frame (fan-out path; encoded once at the source).

Parameters

payload

string | Uint8Array<ArrayBufferLike>

Returns

void


terminate()

terminate(): void

Defined in: conn.ts:73

Hard close with no handshake — used by heartbeat reaping.

Returns

void

Released under the MIT License.