1. 增加状态池初始化
2. 把状态池注入需要的地方
This commit is contained in:
@@ -75,15 +75,24 @@ type WebSocketService struct {
|
||||
|
||||
// deviceRepo 设备仓库
|
||||
deviceRepo repository.DeviceRepo
|
||||
|
||||
// deviceStatusPool 设备状态池
|
||||
deviceStatusPool *DeviceStatusPool
|
||||
}
|
||||
|
||||
// SetDeviceStatusPool 设置设备状态池
|
||||
func (ws *WebSocketService) SetDeviceStatusPool(pool *DeviceStatusPool) {
|
||||
ws.deviceStatusPool = pool
|
||||
}
|
||||
|
||||
// NewWebSocketService 创建WebSocket服务实例
|
||||
func NewWebSocketService(deviceRepo repository.DeviceRepo) *WebSocketService {
|
||||
return &WebSocketService{
|
||||
connections: make(map[string]*DeviceConnection),
|
||||
logger: logs.NewLogger(),
|
||||
defaultTimeout: 5, // 默认5秒超时
|
||||
deviceRepo: deviceRepo,
|
||||
connections: make(map[string]*DeviceConnection),
|
||||
logger: logs.NewLogger(),
|
||||
defaultTimeout: 5, // 默认5秒超时
|
||||
deviceRepo: deviceRepo,
|
||||
deviceStatusPool: NewDeviceStatusPool(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user