|
|
@@ -18,12 +18,13 @@ import { QueryDeepPartialEntity } from 'typeorm/query-builder/QueryPartialEntity
|
|
|
import { TaskService } from '../task/task.service'
|
|
|
import { OperatorConfigService } from '../operator_config/operator_config.service'
|
|
|
import { Interval } from '@nestjs/schedule'
|
|
|
-import { EventsGateway } from 'src/events/events.gateway'
|
|
|
+import { EventsGateway } from '../events/events.gateway'
|
|
|
import { DeviceTask, DeviceTaskStatus } from './entities/device-task.entity'
|
|
|
import { DeviceTaskItem, DeviceTaskItemStatus } from './entities/device-task-item.entity'
|
|
|
import PQueue from 'p-queue'
|
|
|
import { randomUUID } from 'crypto'
|
|
|
import { setTimeout } from 'timers/promises'
|
|
|
+import { SendMessageDto } from './dtos/send-message.dto'
|
|
|
|
|
|
@Injectable()
|
|
|
export class DeviceService implements OnModuleInit {
|
|
|
@@ -332,24 +333,14 @@ export class DeviceService implements OnModuleInit {
|
|
|
return device
|
|
|
}
|
|
|
|
|
|
- async sendToDeviceWithAck(socketId: string, action: string, data: any) {
|
|
|
+ async sendMessage(deviceId: string, message: SendMessageDto) {
|
|
|
+ const device = await this.findOnelineDevice(deviceId)
|
|
|
return await this.eventsGateway.sendForResult(
|
|
|
{
|
|
|
id: randomUUID(),
|
|
|
- action,
|
|
|
- data
|
|
|
+ ...message
|
|
|
},
|
|
|
- socketId
|
|
|
+ device.socketId
|
|
|
)
|
|
|
}
|
|
|
-
|
|
|
- async installApk(deviceId: string, apkUrl: string) {
|
|
|
- const device = await this.findOnelineDevice(deviceId)
|
|
|
- return await this.sendToDeviceWithAck(device.socketId, 'installApk', { apkUrl })
|
|
|
- }
|
|
|
-
|
|
|
- async runScript(deviceId: string, script: string) {
|
|
|
- const device = await this.findOnelineDevice(deviceId)
|
|
|
- return await this.sendToDeviceWithAck(device.socketId, 'runScript', { script })
|
|
|
- }
|
|
|
}
|