socket

package
v0.7.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2022 License: MPL-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrFailedToUpdateDevice    = errors.New("failed to update device last seen")
	ErrFailedToSendPongMessage = errors.New("failed to write pong message")
)

Functions

func BuildRoutes

func BuildRoutes(h *Hub, r *Repo, m *m.Middleware) http.Handler

func ListenHandler

func ListenHandler(hub *Hub, repo *Repo) http.HandlerFunc

func LoginHandler

func LoginHandler(hub *Hub, repo *Repo) http.HandlerFunc

func NewClient

func NewClient(conn WebSocketConnection, device *datastore.Device, events []string, deviceRepo datastore.DeviceRepository, eventDeliveryRepo datastore.EventDeliveryRepository)

Types

type AckEventDelivery

type AckEventDelivery struct {
	UID string `json:"uid"`
}

type CLIEvent

type CLIEvent struct {
	UID     string                `json:"uid"`
	Headers httpheader.HTTPHeader `json:"headers" bson:"headers"`
	Data    json.RawMessage       `json:"data"`

	// for filtering this event delivery
	EventType string `json:"-"`
	DeviceID  string `json:"-"`
	AppID     string `json:"-"`
	GroupID   string `json:"-"`
}

type Client

type Client struct {
	EventTypes []string
	Device     *datastore.Device
	// contains filtered or unexported fields
}

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

func (*Client) Close

func (c *Client) Close(unregister chan *Client)

func (*Client) GoOffline

func (c *Client) GoOffline()

func (*Client) HasEventType

func (c *Client) HasEventType(evType string) bool

func (*Client) IsOnline

func (c *Client) IsOnline() bool

func (*Client) ResendEventDeliveries

func (c *Client) ResendEventDeliveries(since time.Time, events chan *CLIEvent)

func (*Client) UpdateEventDeliveryStatus

func (c *Client) UpdateEventDeliveryStatus(id string)

type Hub

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

Hub maintains the set of active clients and broadcasts messages to the clients.

func NewHub

func NewHub() *Hub

func (*Hub) StartClientStatusWatcher

func (h *Hub) StartClientStatusWatcher()

func (*Hub) StartEventSender

func (h *Hub) StartEventSender()

func (*Hub) StartEventWatcher

func (h *Hub) StartEventWatcher()

func (*Hub) StartRegister

func (h *Hub) StartRegister()

func (*Hub) StartUnregister

func (h *Hub) StartUnregister()

func (*Hub) Stop

func (h *Hub) Stop()

type ListenRequest

type ListenRequest struct {
	HostName   string   `json:"host_name"`
	DeviceID   string   `json:"device_id"`
	SourceID   string   `json:"source_id"`
	EventTypes []string `json:"event_types"`
}

type LoginRequest

type LoginRequest struct {
	HostName string `json:"host_name"`
	DeviceID string `json:"device_id"`
}

type LoginResponse

type LoginResponse struct {
	Device *datastore.Device      `json:"device"`
	Group  *datastore.Group       `json:"group"`
	App    *datastore.Application `json:"app"`
}

type Repo

type Repo struct {
	DeviceRepo        datastore.DeviceRepository
	SourceRepo        datastore.SourceRepository
	AppRepo           datastore.ApplicationRepository
	SubscriptionRepo  datastore.SubscriptionRepository
	EventDeliveryRepo datastore.EventDeliveryRepository
}

type WatchCollectionFn

type WatchCollectionFn func(fn func(doc map[string]interface{}) error, collection string, stop chan struct{}) error

type WebSocketConnection

type WebSocketConnection interface {
	Close() error
	SetReadLimit(limit int64)
	SetPingHandler(h func(appData string) error)
	WriteMessage(messageType int, data []byte) error
	ReadMessage() (messageType int, p []byte, err error)
}

Jump to

Keyboard shortcuts

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