signaling

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const NostrSignalingEventKind = 20006

NostrSignalingEventKind is the Nostr ephemeral event kind for signaling messages.

Variables

This section is empty.

Functions

This section is empty.

Types

type BridgeMessageHandler

type BridgeMessageHandler func(payload []byte)

BridgeMessageHandler is called when a bridge_message is received.

type Client

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

Client connects to the peerclaw-server WebSocket signaling endpoint and exchanges SDP offers/answers and ICE candidates.

func NewClient

func NewClient(serverURL, agentID string, logger *slog.Logger) *Client

NewClient creates a new signaling client.

func (*Client) Close

func (c *Client) Close() error

Close closes the signaling connection.

func (*Client) Connect

func (c *Client) Connect(ctx context.Context) error

Connect establishes a WebSocket connection to the signaling server.

func (*Client) ICEServers

func (c *Client) ICEServers() []pcsignaling.ICEServerConfig

ICEServers returns the ICE server configurations received from the signaling server.

func (*Client) Receive

func (c *Client) Receive() <-chan pcsignaling.SignalMessage

Receive returns a channel of incoming signal messages.

func (*Client) Send

Send sends a signal message to the signaling server.

func (*Client) SetAgentID

func (c *Client) SetAgentID(id string)

SetAgentID sets the agent ID for the signaling client. Must be called before Connect().

func (*Client) SetBridgeHandler

func (c *Client) SetBridgeHandler(handler BridgeMessageHandler)

SetBridgeHandler registers a handler for bridge_message types.

type CompositeSignaling

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

CompositeSignaling wraps a primary (WebSocket) and fallback (Nostr) signaling client. It tries the primary first and falls back to Nostr if the primary fails.

func NewCompositeSignaling

func NewCompositeSignaling(primary, fallback SignalingClient, logger *slog.Logger) *CompositeSignaling

NewCompositeSignaling creates a composite signaling client.

func (*CompositeSignaling) Close

func (cs *CompositeSignaling) Close() error

Close closes both signaling clients.

func (*CompositeSignaling) Connect

func (cs *CompositeSignaling) Connect(ctx context.Context) error

Connect tries the primary signaling first, then falls back to Nostr.

func (*CompositeSignaling) ICEServers

func (cs *CompositeSignaling) ICEServers() []pcsignaling.ICEServerConfig

ICEServers returns ICE servers from the active client.

func (*CompositeSignaling) Receive

func (cs *CompositeSignaling) Receive() <-chan pcsignaling.SignalMessage

Receive returns the merged channel of incoming messages.

func (*CompositeSignaling) Send

Send sends via the active channel. Falls back on failure.

func (*CompositeSignaling) SetAgentID

func (cs *CompositeSignaling) SetAgentID(id string)

SetAgentID sets the agent ID on both signaling clients.

func (*CompositeSignaling) SetBridgeHandler

func (cs *CompositeSignaling) SetBridgeHandler(handler BridgeMessageHandler)

SetBridgeHandler sets the handler on both clients.

type NostrSignaling

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

NostrSignaling implements SignalingClient using Nostr ephemeral events. Uses event kind 20006, NIP-44 encryption, reusing the NostrTransport relay management pattern.

func NewNostrSignaling

func NewNostrSignaling(agentID string, relayURLs []string, iceServers []pcsignaling.ICEServerConfig, logger *slog.Logger) *NostrSignaling

NewNostrSignaling creates a new Nostr-based signaling client.

func (*NostrSignaling) Close

func (ns *NostrSignaling) Close() error

Close disconnects from all Nostr relays and shuts down subscriptions.

func (*NostrSignaling) Connect

func (ns *NostrSignaling) Connect(ctx context.Context) error

Connect establishes connections to Nostr relays and subscribes to signaling events.

func (*NostrSignaling) ConnectedRelays

func (ns *NostrSignaling) ConnectedRelays() int

ConnectedRelays returns the number of currently connected signaling relays.

func (*NostrSignaling) ICEServers

func (ns *NostrSignaling) ICEServers() []pcsignaling.ICEServerConfig

ICEServers returns the configured ICE server list.

func (*NostrSignaling) NostrPublicKeyHex

func (ns *NostrSignaling) NostrPublicKeyHex() string

NostrPublicKeyHex returns the Nostr public key hex for this signaling client. Returns an empty string if keys have not been initialized yet.

func (*NostrSignaling) Receive

func (ns *NostrSignaling) Receive() <-chan pcsignaling.SignalMessage

Receive returns a channel of incoming signaling messages.

func (*NostrSignaling) Send

Send publishes a signaling message as a Nostr ephemeral event.

func (*NostrSignaling) SetAgentID

func (ns *NostrSignaling) SetAgentID(id string)

SetAgentID sets the agent ID for the Nostr signaling client.

func (*NostrSignaling) SetBridgeHandler

func (ns *NostrSignaling) SetBridgeHandler(handler BridgeMessageHandler)

SetBridgeHandler registers a handler for bridge messages.

func (*NostrSignaling) SetNostrKeys

func (ns *NostrSignaling) SetNostrKeys(keys *transport.NostrKeypair)

SetNostrKeys sets the Nostr keypair for signing and encryption. If not called before Connect, a random keypair will be generated.

type SignalingClient

type SignalingClient interface {
	Connect(ctx context.Context) error
	Send(ctx context.Context, msg pcsignaling.SignalMessage) error
	Receive() <-chan pcsignaling.SignalMessage
	ICEServers() []pcsignaling.ICEServerConfig
	SetBridgeHandler(handler BridgeMessageHandler)
	SetAgentID(id string)
	Close() error
}

SignalingClient abstracts the signaling transport used for WebRTC negotiation. Implementations include Client (WebSocket to server), NostrSignaling (decentralized via Nostr relays), and CompositeSignaling (hybrid).

Jump to

Keyboard shortcuts

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