websocket

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DialSignaling

func DialSignaling(ctx context.Context, wsURL string, headers http.Header, dialer Dialer) (*websocket.Conn, error)

DialSignaling opens a bounded signaling socket with an optional custom dialer.

func ReadSignaling

func ReadSignaling(conn *websocket.Conn, route func(signaling.Message)) error

ReadSignaling reads text frames until a transport or decoding error occurs.

func WriteSignaling

func WriteSignaling(ctx context.Context, conn *websocket.Conn, message signaling.Message) error

WriteSignaling sends one JSON frame with a context-sensitive write deadline.

Types

type Dialer

type Dialer interface {
	DialContext(ctx context.Context, wsURL string, headers http.Header) (*websocket.Conn, *http.Response, error)
}

Dialer allows tests and callers to substitute a WebSocket transport.

type EventConnection

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

EventConnection owns the transport, read loop, and event queue.

func OpenEvents

func OpenEvents(ctx context.Context, wsURL, token, hardwareID string) (*EventConnection, error)

OpenEvents connects the account event stream and starts its read loop.

func OpenEventsWithDialer added in v0.5.0

func OpenEventsWithDialer(
	ctx context.Context,
	wsURL, token, hardwareID string,
	dialer Dialer,
) (*EventConnection, error)

OpenEventsWithDialer connects the account event stream using the supplied dialer. A nil dialer uses Gorilla's default dialer with a bounded handshake timeout.

func (*EventConnection) Close

func (ec *EventConnection) Close() error

Close closes the event connection.

func (*EventConnection) Receive

func (ec *EventConnection) Receive() (map[string]interface{}, error)

Receive receives events in wire order before a terminal read error. Concurrent callers are serialized to preserve that ordering.

func (*EventConnection) ReceiveFrame added in v0.5.0

ReceiveFrame returns the schema-generated event projection and its full raw payload.

type LiveNegotiation

type LiveNegotiation struct {
	SignalID  string
	RIID      string
	AnswerSDP string
	ControlID string
	Heartbeat time.Duration
}

LiveNegotiation contains the identities and timing returned by signaling.

func AwaitLiveAnswer

func AwaitLiveAnswer(
	ctx context.Context,
	parentDone <-chan struct{},
	parentErr func() error,
	events <-chan signaling.Message,
	deviceID int64,
	deadlineError func() error,
) (LiveNegotiation, error)

AwaitLiveAnswer pairs session_created with the SDP answer and validates their identities.

type SignalingWriter

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

SignalingWriter bounds outgoing frames and prioritizes close, heartbeat, and PTZ stop.

func NewSignalingWriter

func NewSignalingWriter(
	done <-chan struct{},
	write func(context.Context, signaling.Message) error,
	onFailure func(error),
) *SignalingWriter

NewSignalingWriter constructs a writer that stops when done closes.

func (*SignalingWriter) Finished

func (w *SignalingWriter) Finished() <-chan struct{}

Finished closes after Run drains queued requests.

func (*SignalingWriter) Run

func (w *SignalingWriter) Run()

Run services the writer queue until done closes.

func (*SignalingWriter) Send

func (w *SignalingWriter) Send(ctx context.Context, message signaling.Message) error

Send queues one frame and waits for the write or cancellation.

Jump to

Keyboard shortcuts

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