device

package
v1.0.11 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConnectionRecords

type ConnectionRecords struct {
	CurrentContinuousDays   int64
	HistoryContinuousDays   int64
	LongestSingleConnection int64
}

ConnectionRecords represents device connection statistics

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(logger log.Logger, 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) error

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) GetUserDeviceStatistics

func (dm *DeviceManager) GetUserDeviceStatistics(userID int64) (*DeviceStatistics, error)

GetUserDeviceStatistics gets device usage statistics for API

func (*DeviceManager) GetUserDevices

func (dm *DeviceManager) GetUserDevices(userID int64) ([]*UserDeviceInfo, error)

GetUserDevices gets user device list for API

func (*DeviceManager) KickDevice

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

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

func (*DeviceManager) RemoveDevice

func (dm *DeviceManager) RemoveDevice(userID int64, deviceID int64) error

RemoveDevice removes a device for API

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 DeviceStatistics

type DeviceStatistics struct {
	WeeklyStats       []*WeeklyStat
	ConnectionRecords *ConnectionRecords
}

DeviceStatistics represents device usage statistics

type Operator

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

type UserDeviceInfo

type UserDeviceInfo struct {
	ID         int64
	IP         string
	Identifier string
	UserAgent  string
	Online     bool
	Enabled    bool
	CreatedAt  int64
	UpdatedAt  int64
}

UserDeviceInfo represents user device information for API responses

type WeeklyStat

type WeeklyStat struct {
	Day     int32
	DayName string
	Hours   float64
}

WeeklyStat represents weekly device usage statistics

Jump to

Keyboard shortcuts

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