attach(Attach a socket (call from the actor’sws,req?):Promise<void>
webSocket(ws, req)). If onConnect
is configured it runs first as a gate: throw or ctx.close() rejects the
connection (closed, never admitted as a watcher, no hello/state). On
accept, sends the state snapshot then hello, and handles inbound
call/ping frames.
The returned Promise settles once the socket is wired and the onConnect
gate has run — NOT necessarily once the connection is admitted. With an
authorize hook the bootstrap needs the client’s first frame, and the
Telnyx actor host delivers no frame until webSocket() has returned
(every frame is its own serialized turn, run after setup): so when no
frame has arrived yet, attach returns and the bootstrap runs later —
inside the first frame’s own turn (an attach frame is authorized with
its token; anything else as anonymous), or on the attachGraceMs timer
for a client that sends nothing. Awaiting attach from webSocket() is
therefore safe and is the documented shape. Nothing after the
await is ordered against admission: observe authorized connections
through onAttach (which runs just before admission), not by reading
watcherCount or broadcasting right after attach resolves.
If the initial snapshot can’t be read the connection is REJECTED (closed,
no hello) rather than admitted half-initialized — see sendSnapshot.
Parameters
Returns
Promise<void>
The Actor Entry
The actor’swebSocket(ws, req) entry calls attach() once per accepted connection. The Socket Server shows the listeners it registers.
AgentServerSocket
Thews-style socket surface the server drives, modeled structurally so
this module carries no ws dependency — anything with this shape works,
including the socket the platform hands an actor’s webSocket(ws, req).
Properties
CLOSED
ThereadonlyCLOSED:number
readyState value for a fully closed socket.
OPEN
ThereadonlyOPEN:number
readyState value for an open, writable socket.
readyState
The socket’s current state, compared againstreadonlyreadyState:number
OPEN / CLOSED.
Methods
close()
close(Close the socket with an optional close code and reason. Parameterscode?,reason?):void
Returns
void
on() Call Signature
on(Register a listener for inbound frames; it may return a promise a host can await. Parametersevent,listener):unknown
Returns
unknown
Call Signature
on(Register a listener for the socket closing. Parametersevent,listener):unknown
Returns
unknown
Call Signature
on(Register a listener for socket errors. Parametersevent,listener):unknown
Returns
unknown
send()
send(Send one text frame. Parametersdata):void
Returns
void