Documentation
¶
Index ¶
- type Device
- type DeviceManager
- func (dm *DeviceManager) AddDevice(w http.ResponseWriter, r *http.Request, session string, userID int64, ...)
- func (dm *DeviceManager) Broadcast(message string)
- func (dm *DeviceManager) KickDevice(userID int64, deviceID string)
- 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 Operator
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
Click to show internal directories.
Click to hide internal directories.