Documentation
¶
Overview ¶
Package wpstream is a hand-rolled Engine.IO v4 + Socket.IO v4 + socket.io-stream client. It ports the socket.io transport used by src/bin/vip-wp.js for the wpcliStrategy=websocket WP-CLI strategy.
engineio.go is the bottom layer: the Engine.IO v4 transport. It does the HTTP long-poll handshake, upgrades to WebSocket, answers server pings, and exposes a packet-level duplex to the Socket.IO codec above it.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a Socket.IO v4 namespace client over a transport.
func (*Client) Connect ¶
Connect sends the namespace CONNECT packet and waits for the server CONNECT ack, then starts the read loop in a background goroutine.
func (*Client) Emit ¶
Emit sends an event to the server. If ack is non-nil the packet carries an ack id and ack will be called when the server replies.
type DialOptions ¶
type DialOptions struct {
BaseURL string // e.g. https://api.wpvip.com (no trailing /socket.io/)
Header http.Header // extraHeaders carried on BOTH transports (Bearer token)
Client *http.Client
}
DialOptions configure the Engine.IO connection.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine is a connected Engine.IO transport (after the websocket upgrade). A background read loop dispatches incoming frames: pings are answered immediately, non-ping packets are queued on recvCh for Read callers.
func Dial ¶
func Dial(ctx context.Context, opts DialOptions) (*Engine, error)
Dial performs the polling handshake then upgrades to WebSocket.
func (*Engine) Read ¶
Read returns the next non-heartbeat packet. Blocks until a packet arrives, the context is cancelled, or the connection is closed.
func (*Engine) WriteBinary ¶
WriteBinary sends a raw binary attachment frame (EIO4: no type prefix).
type IOStream ¶
type IOStream struct {
// contains filtered or unexported fields
}
IOStream is a duplex stream over the socket.io-stream subprotocol. It implements io.ReadWriteCloser.
Flow control: reading triggers a $stream-read credit to the remote sender; the sender waits for that credit before flushing one chunk via $stream-write. Write blocks until a credit arrives (from the remote reader calling Read) and until the remote acknowledges receipt (ack from $stream-write handler).
Teardown: abort(err) closes the `closed` channel, unblocking all blocked Read/Write/deliver calls. deliverEOF() is a normal end-of-stream; it uses a separate sync.Once-guarded readEOF channel so buffered data can still drain.
func (*IOStream) Close ¶
Close implements io.Closer. Sends $stream-end exactly once and marks the stream closed. Idempotent.
func (*IOStream) Read ¶
Read implements io.Reader. On the first call (or after consuming a previous chunk) it sends a $stream-read credit to the remote, then blocks until a chunk, EOF, or error arrives. Also unblocks when the stream is aborted (I3).
func (*IOStream) Write ¶
Write implements io.Writer. Blocks until a read-credit arrives from the remote (i.e., the remote called Read, which sent $stream-read), then sends the chunk and blocks until the remote ACKs receipt. Both waits are escapable via the closed channel (I3). Emit errors are propagated (M1).
type Options ¶
type Options struct {
APIHost string
Token string
GUID string
InputToken string
Columns int
Rows int
IsTTY bool // CR→LF stdin normalization when true (vip-wp.js:51)
Stdin io.Reader
Stdout io.Writer
Stderr io.Writer
}
Options configure a single Run.
type Packet ¶
Packet is one Engine.IO packet. For text packets Type is the type char and Data is the payload after it. For raw binary frames (socket.io attachments) Binary is true, Type is eioMessage by convention, and Data holds the bytes.
type Result ¶
type Result struct {
ExitCode int
}
Result carries the terminal outcome (the caller maps ExitCode to os.Exit).
func Run ¶
Run connects and executes one WP-CLI command over socket.io. It implements the reconnect/offset loop: on disconnect (before an exit event arrives) it re-dials with exponential backoff and resumes from offset.
C1/C2 fix: the loop is entirely self-contained; every Engine is explicitly closed before the next attempt or before returning. No goroutine is launched that outlives its engine.
type StreamSocket ¶
type StreamSocket struct {
// contains filtered or unexported fields
}
StreamSocket wraps a Client to provide the socket.io-stream subprotocol. Port of socket.io-stream/lib/socket.js.
func NewStreamSocket ¶
func NewStreamSocket(ctx context.Context, cli *Client) *StreamSocket
func (*StreamSocket) CreateStream ¶
func (ss *StreamSocket) CreateStream() *IOStream