hub

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	Name       SwitchEvent `json:"name,omitempty"`
	DeviceName string      `json:"device_name,omitempty"`
	Device     sw.Device   `json:"device,omitempty"` //only used for updates
}

type Hub

type Hub struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Hub is a struct which makes a switch available through http.

func NewHub

func NewHub(switches ...sw.Switcher) (*Hub, error)

NewHub returns the pointer to an initialized Hub object.

func (*Hub) AddSwitch

func (hub *Hub) AddSwitch(r sw.Switcher) error

AddSwitch adds / registers a Switch. The switch's name must be unique.

func (*Hub) Broadcast

func (hub *Hub) Broadcast(dev sw.Device)

Broadcast sends a rotator Status struct to all connected clients

func (*Hub) BroadcastToWsClients

func (hub *Hub) BroadcastToWsClients(event Event) error

BroadcastToWsClients will send a rotator.Status struct to all clients connected through a Websocket

func (*Hub) ListenHTTP

func (hub *Hub) ListenHTTP(host string, port int, errorCh chan<- struct{})

ListenHTTP starts a HTTP Server on a given network adapter / port and sets a HTTP and Websocket handler. Since this function contains an endless loop, it should be executed in a go routine. If the listener can not be initialized, it will close the errorCh channel.

func (*Hub) RemoveSwitch

func (hub *Hub) RemoveSwitch(r sw.Switcher)

RemoveSwitch deletes / de-registers a switch.

func (*Hub) Switch

func (hub *Hub) Switch(name string) (sw.Switcher, bool)

Switch returns a particular Switch stored from the hub. If no Switch exists with that name, (nil, false) will be returned.

func (*Hub) Switches

func (hub *Hub) Switches() []sw.Switcher

Switches returns a slice of all registered Switches.

type SwitchEvent

type SwitchEvent string
const (
	AddSwitch    SwitchEvent = "add"
	RemoveSwitch SwitchEvent = "remove"
	UpdateSwitch SwitchEvent = "update"
)

type WsClient

type WsClient struct {
	*websocket.Conn
}

WsClient is a wrapper for clients connected through a Websocket

Jump to

Keyboard shortcuts

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