Documentation
¶
Overview ¶
Package wire formats and parses the line-based JaWS WebSocket protocol.
Each message is encoded as What<TAB>Jid<TAB>Data<LF>. Data for most commands is written by WsMsg.Append as a JSON-compatible quoted string (see appendJSONQuote) so the browser can decode it with JSON.parse; the server decodes it with Parse (strconv.Unquote, which accepts every escape appendJSONQuote emits). The string grammars of JSON and strconv.Unquote merely overlap rather than nest, but appendJSONQuote stays inside their intersection. The Set and Call commands carry path/function payloads directly, so callers must keep those payloads free of raw tabs and newlines; jaws.JsCall compacts JSON for that reason before it enters the wire layer.
Index ¶
- func AppendJSONQuote(b []byte, s string) []byte
- func PingLoop(ctx context.Context, ccf context.CancelCauseFunc, doneCh <-chan struct{}, ...)
- func ReadLoop(ctx context.Context, ccf context.CancelCauseFunc, doneCh <-chan struct{}, ...)
- func WriteLoop(ctx context.Context, ccf context.CancelCauseFunc, doneCh <-chan struct{}, ...)
- type Message
- type WsMsg
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendJSONQuote ¶ added in v0.500.0
AppendJSONQuote appends s to b as a double-quoted JSON string literal that the browser's JSON.parse accepts. Use it instead of strconv.AppendQuote when the quoted data is written into a WebSocket frame: strconv emits Go-only escapes (\xNN, \UXXXXXXXX) for control bytes, DEL and invalid UTF-8 that JSON.parse rejects. See appendJSONQuote for the exact behavior, which is pinned by Fuzz_appendJSONQuote.
func PingLoop ¶ added in v0.300.2
func PingLoop(ctx context.Context, ccf context.CancelCauseFunc, doneCh <-chan struct{}, interval, timeout time.Duration, ws *websocket.Conn)
PingLoop sends periodic WebSocket pings and reports ping errors through ccf.
Returns immediately when interval is non-positive.
Types ¶
type Message ¶
type Message struct {
Dest any // destination tag, HTML ID or *jaws.Element
What what.What // command to perform
Data string // payload, such as inner HTML content or a slice of tags
}
Message contains the elements of a message to be sent to requests.
type WsMsg ¶
type WsMsg struct {
Data string // data to send
Jid jid.Jid // Jid to send, or -1 if Data contains that already
What what.What // command
}
WsMsg is a message sent to or from a WebSocket.
func Parse ¶
Parse parses an incoming text buffer into a message.
The wire format mirrors WsMsg.Append. For commands other than what.Set and what.Call, if the Data field begins with a double quote it is decoded with strconv.Unquote and the message is rejected if that fails; data that does not begin with a double quote is taken verbatim. Set and Call data is always taken verbatim. In all cases the resulting data is sanitized with strings.ToValidUTF8.