ws

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MessageTypeAnswer    = "answer"
	MessageTypeCandidate = "candidate"
	MessageTypeOffer     = "offer"
	MessageTypeInfo      = "info"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {

	// Buffered channel of outbound messages.
	Send chan []byte

	// webRTC peer connection
	PeerConnection *webrtc.PeerConnection
	// contains filtered or unexported fields
}

Client is a middleman between the websocket connection and the hub.

func NewClient

func NewClient(hub *Hub, conn *websocket.Conn, webrtcConn *webrtc.PeerConnection) *Client

func (*Client) ReadLoop

func (c *Client) ReadLoop()

ReadLoop pumps messages from the websocket connection to the hub.

The application runs ReadLoop in a per-connection goroutine. The application ensures that there is at most one reader on a connection by executing all reads from this goroutine.

func (*Client) WriteLoop

func (c *Client) WriteLoop()

WriteLoop pumps messages from the hub to the websocket connection.

A goroutine running WriteLoop is started for each connection. The application ensures that there is at most one writer to a connection by executing all writes from this goroutine.

type Hub

type Hub struct {
	// Registered Clients.
	Clients map[*Client]struct{}

	// Broadcast messages to all Clients.
	Broadcast chan []byte

	// Register a new client to the hub.
	Register chan *Client

	// Unregister a client from the hub.
	Unregister chan *Client

	// lock to prevent write to closed channel
	sync.RWMutex
}

func NewHub

func NewHub() *Hub

func (*Hub) GetInfo

func (h *Hub) GetInfo() Info

func (*Hub) NoClients

func (h *Hub) NoClients() int

NoClients returns the number of Clients registered

func (*Hub) Run

func (h *Hub) Run()

Run is the main hub event loop handling register, unregister and broadcast events.

func (*Hub) SendInfo

func (h *Hub) SendInfo(info Info)

SendInfo broadcasts hub statistics to all Clients.

type Info

type Info struct {
	NoConnections int `json:"no_connections"`
}

type WebsocketMessage

type WebsocketMessage struct {
	Event string          `json:"event"`
	Data  json.RawMessage `json:"data"`
}

Jump to

Keyboard shortcuts

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