websocket

package
v0.0.0-...-e19e394 Latest Latest
Warning

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

Go to latest
Published: May 31, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrDeviceNotConnected = errors.New("Device is currently connected, can not start session")
View Source
var ErrQuestionContainsInvalidChar = errors.New("Question contains a invalid character")
View Source
var ErrQuestionToLong = errors.New("Question length exteeds 80 characters")

Functions

func GenerateSecureToken

func GenerateSecureToken(n int) (string, error)

func SendMessage

func SendMessage(ws *websocket.Conn, msg any) error

Types

type WebsocketHandler

type WebsocketHandler struct {
	Connections map[uint]*websocketConnection // connection id -> connection

	ConnectedDevices map[uint]uint // device id -> connection id
	// contains filtered or unexported fields
}

func NewWebsocketHandler

func NewWebsocketHandler(cfg *config.Config, db *gorm.DB) *WebsocketHandler

func (*WebsocketHandler) InitialiseWebsocket

func (h *WebsocketHandler) InitialiseWebsocket(w http.ResponseWriter, r *http.Request)

InitialiseWebsocket

@Summary Open a connection to the device websocket API @Description Open a websocket connection used by devices to communicate with the server. @Description Devices get notified about session changes and send votes via this connection. @Tags device_websocket @Accept json @Produce json @Success 101 {string} string "Switching Protocols (WebSocket Upgrade)" @Failure 400 {string} string "Bad Request" @Router /ws [get]

func (*WebsocketHandler) RegisterWithPin

func (h *WebsocketHandler) RegisterWithPin(pin uint, device *models.Device) (*models.Device, error)

func (*WebsocketHandler) StartSession

func (h *WebsocketHandler) StartSession(userID uint, deviceID uint, questionStr string) (*models.Session, error)

func (*WebsocketHandler) StopSession

func (h *WebsocketHandler) StopSession(session *models.Session) error

Jump to

Keyboard shortcuts

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