websocket

package
v0.5.11 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Handle

func Handle(ctx context.Context, conn *websocket.Conn, h Handler)

Handle handles the given service.

func NewTestingEnv

func NewTestingEnv(t *testing.T, newHandler func() Handler) (*websocket.Conn, *websocket.Conn, func())

Creates a testing environement to unit test handlers and modules.

Types

type Handler

type Handler interface {
	// Handles a ping request.
	HandlePing(ctx context.Context, respond hwebsocket.ResponseSender, msg hwebsocket.Msg) error

	HandlePingResponse(ctx context.Context, respond hwebsocket.ResponseSender, msg hwebsocket.Msg) error

	// Handles a signed ping request.
	HandleSignedLatency(ctx context.Context, respond hwebsocket.ResponseSender, msg hwebsocket.Msg) error

	// Handles a client connection.
	HandleConnect(conn *websocket.Conn)

	// Handles a request to join a session.
	HandleParticipantJoin(ctx context.Context, handleFrame func(), sender hwebsocket.ResponseSender, msg hwebsocket.Msg) error

	// Handles a client's disconnection.
	HandleDisconnect(error)

	// Handles a request to create an entity.
	HandleEntityAdd(ctx context.Context, respond hwebsocket.ResponseSender, msg hwebsocket.Msg) error

	// Handles a request to delete an entity and its associated resources.
	HandleEntityDelete(ctx context.Context, respond hwebsocket.ResponseSender, msg hwebsocket.Msg) error

	// Handles an entity pose update.
	HandleEntityUpdatePose(ctx context.Context, msg hwebsocket.Msg) error

	// Handles a custom message.
	HandleCustomMessage(ctx context.Context, respond hwebsocket.ResponseSender, msg hwebsocket.Msg) error

	// Handles a request to add an entity component type.
	HandleEntityComponentTypeAdd(ctx context.Context, respond hwebsocket.ResponseSender, msg hwebsocket.Msg) error

	// Handles a request to get the name of an entity component.
	HandleEntityComponentGetName(ctx context.Context, respond hwebsocket.ResponseSender, msg hwebsocket.Msg) error

	// Handles a request to get the id of an entity component.
	HandleEntityComponentGetID(ctx context.Context, respond hwebsocket.ResponseSender, msg hwebsocket.Msg) error

	// handles a request to add an entity component.
	HandleEntityComponentAdd(ctx context.Context, respond hwebsocket.ResponseSender, msg hwebsocket.Msg) error

	// Handles a request to delete an entity component.
	HandleEntityComponentDelete(ctx context.Context, respond hwebsocket.ResponseSender, msg hwebsocket.Msg) error

	// Handles a request to update an entity component.
	HandleEntityComponentUpdate(ctx context.Context, msg hwebsocket.Msg) error

	// Handles a request to list entity components.
	HandleEntityComponentList(ctx context.Context, respond hwebsocket.ResponseSender, msg hwebsocket.Msg) error

	// Handles a request to subscribe to event related to a registered entity
	// component.
	HandleEntityComponentSubscribe(ctx context.Context, respond hwebsocket.ResponseSender, msg hwebsocket.Msg) error

	// Handles a request to unsubscribe to an entity component.
	HandleEntityComponentUnsubscribe(ctx context.Context, respond hwebsocket.ResponseSender, msg hwebsocket.Msg) error

	// Handles a request to pass the proof of work receipt to network credit service.
	HandleReceipt(ctx context.Context, respond hwebsocket.ResponseSender, msg hwebsocket.Msg) error

	// Handle a message with a module.
	HandleWithModule(ctx context.Context, module modules.Module, respond hwebsocket.ResponseSender, msg hwebsocket.Msg) error

	// Sends a sync clock message to the client.
	SendSyncClock(ctx context.Context, send hwebsocket.ResponseSender) error

	// Creates a message receiver used to receive incoming messages.
	Receiver() hwebsocket.Receiver

	// Creates a message sender passed in service methods in order to send
	// messages.
	Sender() hwebsocket.Sender

	// Closes the service and releases its allocated resources.
	Close()

	// The interval between each sync clock message sent to the connected
	// client.
	SyncClockInterval() time.Duration

	// The time a client is idle before being disconnected.
	IdleTimeout() time.Duration

	// Returns the session store.
	GetSessions() *models.SessionStore

	// Returns the modules.
	GetModules() []modules.Module

	// The currently joined session.
	CurrentSession() *models.Session

	// The current participant.
	CurrentParticipant() *models.Participant

	// Get ClientID
	GetClientID() string
}

Handler represents a hagall handler.

func HandlerWithLogs

func HandlerWithLogs(h Handler, summaryInterval time.Duration) Handler

func HandlerWithMetrics

func HandlerWithMetrics(h Handler, publicEndpoint string) Handler

type Logger

type Logger func(format string, v ...interface{})

type RealtimeHandler

type RealtimeHandler struct {
	// The interval between each sync clock message sent to the connected
	// client.
	ClientSyncClockInterval time.Duration

	// The time a client is idle before being disconnected.
	ClientIdleTimeout time.Duration

	// The duration of a frame.
	FrameDuration time.Duration

	// The store that contains all the server sessions.
	Sessions *models.SessionStore

	// The module that expand Hagall features.
	Modules []modules.Module

	FeatureFlags featureflag.FeatureFlag

	// channel for sending incoming receipts to ReceiptHandler goroutine
	ReceiptChan chan ncsclient.ReceiptPayload

	PrivateKey *ecdsa.PrivateKey
	// contains filtered or unexported fields
}

RealtimeHandler represents a service that manages multiple client connections and relays their actions in realtime.

func (*RealtimeHandler) Close

func (h *RealtimeHandler) Close()

func (*RealtimeHandler) CurrentParticipant

func (h *RealtimeHandler) CurrentParticipant() *models.Participant

func (*RealtimeHandler) CurrentSession

func (h *RealtimeHandler) CurrentSession() *models.Session

func (*RealtimeHandler) GetClientID

func (h *RealtimeHandler) GetClientID() string

func (*RealtimeHandler) GetModules

func (h *RealtimeHandler) GetModules() []modules.Module

func (*RealtimeHandler) GetSessions

func (h *RealtimeHandler) GetSessions() *models.SessionStore

func (*RealtimeHandler) HandleConnect

func (h *RealtimeHandler) HandleConnect(conn *websocket.Conn)

func (*RealtimeHandler) HandleCustomMessage

func (h *RealtimeHandler) HandleCustomMessage(ctx context.Context, respond hwebsocket.ResponseSender, msg hwebsocket.Msg) error

func (*RealtimeHandler) HandleDisconnect

func (h *RealtimeHandler) HandleDisconnect(_ error)

func (*RealtimeHandler) HandleEntityAdd

func (h *RealtimeHandler) HandleEntityAdd(ctx context.Context, respond hwebsocket.ResponseSender, msg hwebsocket.Msg) error

func (*RealtimeHandler) HandleEntityComponentAdd

func (h *RealtimeHandler) HandleEntityComponentAdd(ctx context.Context, respond hwebsocket.ResponseSender, msg hwebsocket.Msg) error

func (*RealtimeHandler) HandleEntityComponentDelete

func (h *RealtimeHandler) HandleEntityComponentDelete(ctx context.Context, respond hwebsocket.ResponseSender, msg hwebsocket.Msg) error

func (*RealtimeHandler) HandleEntityComponentGetID

func (h *RealtimeHandler) HandleEntityComponentGetID(ctx context.Context, respond hwebsocket.ResponseSender, msg hwebsocket.Msg) error

func (*RealtimeHandler) HandleEntityComponentGetName

func (h *RealtimeHandler) HandleEntityComponentGetName(ctx context.Context, respond hwebsocket.ResponseSender, msg hwebsocket.Msg) error

func (*RealtimeHandler) HandleEntityComponentList

func (h *RealtimeHandler) HandleEntityComponentList(ctx context.Context, respond hwebsocket.ResponseSender, msg hwebsocket.Msg) error

func (*RealtimeHandler) HandleEntityComponentSubscribe

func (h *RealtimeHandler) HandleEntityComponentSubscribe(ctx context.Context, respond hwebsocket.ResponseSender, msg hwebsocket.Msg) error

func (*RealtimeHandler) HandleEntityComponentTypeAdd

func (h *RealtimeHandler) HandleEntityComponentTypeAdd(ctx context.Context, respond hwebsocket.ResponseSender, msg hwebsocket.Msg) error

func (*RealtimeHandler) HandleEntityComponentUnsubscribe

func (h *RealtimeHandler) HandleEntityComponentUnsubscribe(ctx context.Context, respond hwebsocket.ResponseSender, msg hwebsocket.Msg) error

func (*RealtimeHandler) HandleEntityComponentUpdate

func (h *RealtimeHandler) HandleEntityComponentUpdate(ctx context.Context, msg hwebsocket.Msg) error

func (*RealtimeHandler) HandleEntityDelete

func (h *RealtimeHandler) HandleEntityDelete(ctx context.Context, respond hwebsocket.ResponseSender, msg hwebsocket.Msg) error

func (*RealtimeHandler) HandleEntityUpdatePose

func (h *RealtimeHandler) HandleEntityUpdatePose(ctx context.Context, msg hwebsocket.Msg) error

func (*RealtimeHandler) HandleParticipantJoin

func (h *RealtimeHandler) HandleParticipantJoin(ctx context.Context, handleFrame func(), respond hwebsocket.ResponseSender, msg hwebsocket.Msg) error

func (*RealtimeHandler) HandlePing

func (h *RealtimeHandler) HandlePing(ctx context.Context, respond hwebsocket.ResponseSender, msg hwebsocket.Msg) error

func (*RealtimeHandler) HandlePingResponse added in v0.5.8

func (h *RealtimeHandler) HandlePingResponse(ctx context.Context, respond hwebsocket.ResponseSender, msg hwebsocket.Msg) error

func (*RealtimeHandler) HandleReceipt

func (h *RealtimeHandler) HandleReceipt(ctx context.Context, respond hwebsocket.ResponseSender, msg hwebsocket.Msg) error

func (*RealtimeHandler) HandleSignedLatency added in v0.5.8

func (h *RealtimeHandler) HandleSignedLatency(ctx context.Context, respond hwebsocket.ResponseSender, msg hwebsocket.Msg) error

func (*RealtimeHandler) HandleWithModule

func (h *RealtimeHandler) HandleWithModule(ctx context.Context, m modules.Module, respond hwebsocket.ResponseSender, msg hwebsocket.Msg) error

func (*RealtimeHandler) IdleTimeout

func (h *RealtimeHandler) IdleTimeout() time.Duration

func (*RealtimeHandler) Receiver

func (h *RealtimeHandler) Receiver() hwebsocket.Receiver

func (*RealtimeHandler) SendSyncClock

func (h *RealtimeHandler) SendSyncClock(ctx context.Context, respond hwebsocket.ResponseSender) error

func (*RealtimeHandler) Sender

func (h *RealtimeHandler) Sender() hwebsocket.Sender

func (*RealtimeHandler) SyncClockInterval

func (h *RealtimeHandler) SyncClockInterval() time.Duration

type TestResponseSender

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

Jump to

Keyboard shortcuts

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