wsjs

package
v0.0.0-...-4507b72 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2025 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	//EnableBlobStreaming allows the browser provided Websocket's streaming
	// interface to be used, if supported.
	EnableBlobStreaming bool = true

	//ErrWebsocketClosed is returned when operations are performed on a closed Websocket
	ErrWebsocketClosed = errors.New("WebSocket: Web socket is closed")
)

Functions

func Dial

func Dial(network, address string) (net.Conn, error)

Dial is a standard legacy network dialer that returns a websocket-based connection. See: DialContext for details on the network and address.

func DialContext

func DialContext(ctx context.Context, network, address string) (net.Conn, error)

DialContext is a standard context-aware network dialer that returns a websocket-based connection. The address is a URL that should be in the form of "ws://host/path..." for unsecured websockets and "wss://host/path..." for secured websockets. If tunnel a TLS based protocol over a "wss://..." websocket you will get TLS twice, once on the websocket using the browsers TLS stack and another using the Go (or other compiled) TLS stack.

func GRPCDialer

func GRPCDialer(ctx context.Context, address string) (net.Conn, error)

GRPCDialer is a helper that can be used with grpc.WithContextDialer to call DialContext. The address provided to the calling grpc.Dial should be in the form "passthrough:///"+websocketURL where websocketURL matches the description in DialContext.

Types

type WebSocket

type WebSocket struct {
	URL string
	// contains filtered or unexported fields
}

WebSocket is a Go struct that wraps the web browser's JavaScript websocket object and provides a net.Conn interface

func New

func New(dialCtx context.Context, URL string) (*WebSocket, error)

New returns a new WebSocket using the provided dial context and websocket URL. The URL should be in the form of "ws://host/path..." for unsecured websockets and "wss://host/path..." for secured websockets. If tunnel a TLS based protocol over a "wss://..." websocket you will get TLS twice, once on the websocket using the browsers TLS stack and another using the Go (or other compiled) TLS stack.

func (*WebSocket) Close

func (ws *WebSocket) Close() error

Close shuts the websocket down

func (*WebSocket) LocalAddr

func (ws *WebSocket) LocalAddr() net.Addr

LocalAddr returns a dummy websocket address to satisfy net.Conn, see: wsAddr

func (*WebSocket) Read

func (ws *WebSocket) Read(buf []byte) (int, error)

Read implements the standard io.Reader interface (typical semantics)

func (*WebSocket) RemoteAddr

func (ws *WebSocket) RemoteAddr() net.Addr

RemoteAddr returns a dummy websocket address to satisfy net.Conn, see: wsAddr

func (*WebSocket) SetDeadline

func (ws *WebSocket) SetDeadline(future time.Time) (err error)

func (*WebSocket) SetReadDeadline

func (ws *WebSocket) SetReadDeadline(future time.Time) error

SetReadDeadline implements the Conn SetReadDeadline method

func (*WebSocket) SetWriteDeadline

func (ws *WebSocket) SetWriteDeadline(future time.Time) error

SetWriteDeadline implements the Conn SetWriteDeadline method

func (*WebSocket) Write

func (ws *WebSocket) Write(buf []byte) (n int, err error)

Write implements the standard io.Writer interface. Due to the JavaScript writes being internally buffered it will never block and a write timeout from a previous write may not surface until a subsequent write.

Jump to

Keyboard shortcuts

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