device

package
v0.0.0-...-f0a2dc7 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2025 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Device

type Device struct {
	Session      string
	DeviceID     string
	Conn         *websocket.Conn
	CreatedAt    time.Time
	LastPingTime time.Time
}

Device represents a device structure

type DeviceManager

type DeviceManager struct {

	// event callbacks
	OnDeviceOnline  func(userID int64, deviceID, session string)
	OnDeviceOffline func(userID int64, deviceID, session string, createAt time.Time)
	OnDeviceKicked  func(userID int64, deviceID, session string, operator Operator)
	OnMessage       func(userID int64, deviceID, session string, message string)
	// contains filtered or unexported fields
}

DeviceManager manages devices

func NewDeviceManager

func NewDeviceManager(heartbeatTimeout, checkInterval int) *DeviceManager

NewDeviceManager creates a new device manager

func (*DeviceManager) AddDevice

func (dm *DeviceManager) AddDevice(w http.ResponseWriter, r *http.Request, session string, userID int64, deviceID string, maxDevices int)

AddDevice **Add: Device connects WebSocket and is added to the manager**

func (*DeviceManager) Broadcast

func (dm *DeviceManager) Broadcast(message string)

Broadcast sends a message to all devices

func (*DeviceManager) KickDevice

func (dm *DeviceManager) KickDevice(userID int64, deviceID string)

KickDevice kicks a device (supports individual device or entire user)

func (*DeviceManager) SendToDevice

func (dm *DeviceManager) SendToDevice(userID int64, deviceID string, message string) error

SendToDevice sends a message to a specific device

func (*DeviceManager) Shutdown

func (dm *DeviceManager) Shutdown(ctx context.Context)

Gracefully shut down all WebSocket connections

func (*DeviceManager) StartHeartbeatCheck

func (dm *DeviceManager) StartHeartbeatCheck()

StartHeartbeatCheck periodically checks for heartbeat timeout devices

func (*DeviceManager) UpdateHeartbeat

func (dm *DeviceManager) UpdateHeartbeat(userID int64, deviceID string)

UpdateHeartbeat updates device heartbeat

type Operator

type Operator int
const (
	MaxDevices Operator = iota
	Admin
	SubscribeUpdate = "subscribe_update"
)

Jump to

Keyboard shortcuts

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