websocket

package
v0.74.2 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2026 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Rendered for js/wasm

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewJSInterface

func NewJSInterface(conn *Conn) js.Value

NewJSInterface creates a JavaScript object wrapping the WebSocket connection. It exposes: send(string|Uint8Array), close(), and callback properties onmessage, onclose, onerror.

Callback properties may be set from the JS thread while the read loop goroutine reads them. In WASM this is safe because Go and JS share a single thread, but the design would need synchronization on multi-threaded runtimes.

Types

type Conn

type Conn struct {
	// contains filtered or unexported fields
}

Conn wraps a WebSocket connection over a NetBird TCP connection.

func Dial

func Dial(ctx context.Context, client *netbird.Client, rawURL string, protocols []string) (*Conn, error)

Dial establishes a WebSocket connection to the given URL through the NetBird network. Optional protocols are sent via the Sec-WebSocket-Protocol header.

func (*Conn) Close

func (c *Conn) Close() error

Close sends a close frame with StatusNormalClosure and closes the underlying connection.

func (*Conn) ReadMessage

func (c *Conn) ReadMessage() (ws.OpCode, []byte, error)

ReadMessage reads the next WebSocket message, handling control frames automatically.

func (*Conn) WriteBinary

func (c *Conn) WriteBinary(data []byte) error

WriteBinary sends a binary WebSocket message.

func (*Conn) WriteText

func (c *Conn) WriteText(data []byte) error

WriteText sends a text WebSocket message.

Jump to

Keyboard shortcuts

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