socket

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2023 License: MPL-2.0 Imports: 21 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(r *Repo) http.Handler

func ListenHandler

func ListenHandler(repo *Repo) http.HandlerFunc

func LoginHandler

func LoginHandler(repo *Repo) http.HandlerFunc

func NewClient

func NewClient(ctx context.Context, conn WebSocketConnection, device *datastore.Device, sourceID 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:"-"`
	EndpointID string `json:"-"`
	SourceID   string `json:"-"`
	ProjectID  string `json:"-"`
}

type Client

type Client struct {
	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(ctx context.Context)

func (*Client) IsOnline

func (c *Client) IsOnline() bool

func (*Client) ResendEventDeliveries

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

func (*Client) UpdateEventDeliveryStatus

func (c *Client) UpdateEventDeliveryStatus(ctx context.Context, id, projectId string)

type EndpointError added in v0.9.0

type EndpointError struct {
	Err error
	// contains filtered or unexported fields
}

func (*EndpointError) Delay added in v0.9.0

func (e *EndpointError) Delay() time.Duration

func (*EndpointError) Error added in v0.9.0

func (e *EndpointError) Error() string

type EventDelivery added in v0.9.0

type EventDelivery struct {
	EventDeliveryID string
	ProjectID       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) EventDeliveryCLiHandler added in v0.9.0

func (h *Hub) EventDeliveryCLiHandler(r *Repo) func(context.Context, *asynq.Task) error

func (*Hub) Start added in v0.8.2

func (h *Hub) Start(ctx context.Context)

func (*Hub) StartClientStatusWatcher

func (h *Hub) StartClientStatusWatcher(ctx context.Context)

func (*Hub) StartEventSender

func (h *Hub) StartEventSender(ctx context.Context)

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" valid:"required~please provide a hostname"`
	ProjectID  string `json:"project_id" valid:"required~please provide a project id"`
	DeviceID   string `json:"device_id" valid:"required~please provide a device id"`
	SourceID   string `json:"-"`
	SourceName string `json:"source_name"`
}

type LoginRequest

type LoginRequest struct {
	HostName string `json:"host_name" valid:"required~please provide a hostname"`
}

type LoginResponse

type LoginResponse struct {
	Projects []ProjectDevice `json:"projects"`
	UserName string          `json:"user_name"`
}

type ProjectDevice added in v0.8.2

type ProjectDevice struct {
	Project *datastore.Project `json:"project"`
	Device  *datastore.Device  `json:"device"`
}

type Repo

type Repo struct {
	OrgMemberRepository datastore.OrganisationMemberRepository
	ProjectRepo         datastore.ProjectRepository
	DeviceRepo          datastore.DeviceRepository
	SourceRepo          datastore.SourceRepository
	EndpointRepo        datastore.EndpointRepository
	SubscriptionRepo    datastore.SubscriptionRepository
	EventDeliveryRepo   datastore.EventDeliveryRepository
	Queue               queue.Queuer
}

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