@spinajs/http-socket-common
v3.0.29
Published
Wire protocol shared by the spinajs WebSocket server and client: envelopes, error codes, protocol version and contract typing helpers
Maintainers
Readme
@spinajs/http-socket-common
The wire protocol shared by @spinajs/http-socket (server) and @spinajs/http-socket-client. It has no dependencies and runs in browsers and Node. Both packages re-export it, so apps rarely import it directly.
PROTOCOL_VERSION(1) and the wire event namesWIRE_EVENTS:- commands:
cmd - events in both directions:
evt - stream frames, server to client:
chunk,end,fail - client to server:
credit,cancel
- commands:
SYSTEM_EVENTS:sys.shutdown,sys.disconnect.- The envelopes (types):
HandshakeCommandRequest(id,name,payload,deadline,traceparent, andcreditsfor streams)CommandReply:CommandResultReply,CommandStreamReplyorCommandErrorReplyEventFrame,ShutdownNotice,DisconnectNotice- the stream frames
Chunk,StreamEnd,StreamFail,StreamCredit, andCancelFrame
- Guards for them:
isCommandRequest,isEventFrame,isCancelFrame,isChunk,isStreamEnd,isStreamFail,isStreamCredit. - Names and ids:
isName/NAME_PATTERN/MAX_NAME_LENGTHandisId/ID_PATTERN/MAX_ID_LENGTH. - Keys:
isKey/MAX_KEY_LENGTH(the rule forCommandRequest.idempotencyKeyandafter, which are reserved for durable commands). - The 13 error codes:
ErrorCode,ERROR_CODES,DEFAULT_RETRYABLE,isErrorCode- the wire shape
SocketErrorand its guardisSocketError SocketException, a throwableSocketErrorwithtoWire()/fromWire()
- Typed contracts:
defineContract<C>(),ContractShape,SocketContractand the helper typesCommandName,CommandPayload,CommandResult,EventName,EventPayload,ClientEventName,ClientEventPayload,ContractOf.
Full documentation: docs/http-socket-common, covering the wire protocol, the handshake, frame guards, error codes, custom socket exceptions, typed contracts and the contract helper types.
See @spinajs/http-socket for the server, @spinajs/http-socket-client for the client and packages/http-socket-example for a runnable example.
