Documentation
¶
Index ¶
- type ConnectionRecords
- type Device
- type DeviceManager
- func (dm *DeviceManager) AddDevice(w http.ResponseWriter, r *http.Request, session string, userID int64, ...) error
- func (dm *DeviceManager) Broadcast(message string)
- func (dm *DeviceManager) GetUserDeviceStatistics(userID int64) (*DeviceStatistics, error)
- func (dm *DeviceManager) GetUserDevices(userID int64) ([]*UserDeviceInfo, error)
- func (dm *DeviceManager) KickDevice(userID int64, deviceID string)
- func (dm *DeviceManager) RemoveDevice(userID int64, deviceID int64) error
- func (dm *DeviceManager) SendToDevice(userID int64, deviceID string, message string) error
- func (dm *DeviceManager) Shutdown(ctx context.Context)
- func (dm *DeviceManager) StartHeartbeatCheck()
- func (dm *DeviceManager) UpdateHeartbeat(userID int64, deviceID string)
- type DeviceStatistics
- type Operator
- type UserDeviceInfo
- type WeeklyStat
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 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 ¶
WeeklyStat represents weekly device usage statistics