wire

package
v0.410.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 28, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package wire formats and parses the line-based JaWS WebSocket protocol.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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.

func ReadLoop

func ReadLoop(ctx context.Context, ccf context.CancelCauseFunc, doneCh <-chan struct{}, incomingMsgCh chan<- WsMsg, ws *websocket.Conn)

ReadLoop reads WebSocket text messages, parses them, and sends parsed messages on incomingMsgCh.

Closes incomingMsgCh on exit.

func WriteLoop

func WriteLoop(ctx context.Context, ccf context.CancelCauseFunc, doneCh <-chan struct{}, outboundMsgCh <-chan WsMsg, ws *websocket.Conn)

WriteLoop reads messages from outboundMsgCh, formats them, and writes them to the WebSocket.

Closes the WebSocket on exit.

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.

func (*Message) String

func (msg *Message) String() string

String returns the Message in a form suitable for debug output.

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

func Parse(txt []byte) (WsMsg, bool)

Parse parses an incoming text buffer into a message.

func (*WsMsg) Append

func (m *WsMsg) Append(b []byte) []byte

Append appends m in wire format to b and returns the extended buffer.

func (*WsMsg) FillAlert

func (m *WsMsg) FillAlert(err error)

FillAlert replaces m with an escaped danger alert for err.

func (*WsMsg) Format

func (m *WsMsg) Format() string

Format returns m in wire format.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL