Documentation ¶
Overview ¶
Package wsstream contains utilities for streaming content over WebSockets. The Conn type allows callers to multiplex multiple read/write channels over a single websocket. The Reader type allows an io.Reader to be copied over a websocket channel as binary content.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsWebSocketRequest ¶
IsWebSocketRequest returns true if the incoming request contains connection upgrade headers for WebSockets.
Types ¶
type ChannelType ¶
type ChannelType int
const ( IgnoreChannel ChannelType = iota ReadChannel WriteChannel ReadWriteChannel )
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn supports sending multiple binary channels over a websocket connection. Supports only the "channel.k8s.io" subprotocol.
func NewConn ¶
func NewConn(channels ...ChannelType) *Conn
NewConn creates a WebSocket connection that supports a set of channels. Channels begin each web socket message with a single byte indicating the channel number (0-N). 255 is reserved for future use. The channel types for each channel are passed as an array, supporting the different duplex modes. Read and Write refer to whether the channel can be used as a Reader or Writer.
func (*Conn) Open ¶
func (conn *Conn) Open(w http.ResponseWriter, req *http.Request) ([]io.ReadWriteCloser, error)
Open the connection and create channels for reading and writing.
func (*Conn) SetIdleTimeout ¶
SetIdleTimeout sets the interval for both reads and writes before timeout. If not specified, there is no timeout on the connection.
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader supports returning an arbitrary byte stream over a websocket channel. Supports the "binary.k8s.io" and "base64.binary.k8s.io" subprotocols.
func NewReader ¶
NewReader creates a WebSocket pipe that will copy the contents of r to a provided WebSocket connection. If ping is true, a zero length message will be sent to the client before the stream begins reading.
func (*Reader) Copy ¶
Copy the reader to the response. The created WebSocket is closed after this method completes.
func (*Reader) SetIdleTimeout ¶
SetIdleTimeout sets the interval for both reads and writes before timeout. If not specified, there is no timeout on the reader.