1
- import { RtcClient , IRtcPeer } from "@formant/realtime-sdk" ;
1
+ import { IRtcPeer , RtcClient } from "@formant/realtime-sdk" ;
2
+ import { defined } from "../../../common/defined" ;
3
+ import { delay } from "../../../common/delay" ;
4
+ import { createDevice } from "../api/createDevice" ;
5
+ import { createShareLink } from "../api/createShareLink" ;
6
+ import { disableDevice } from "../api/disableDevice" ;
7
+ import { eventsCounter } from "../api/eventsCounter" ;
8
+ import { getAnnotationCount } from "../api/getAnnotationCount" ;
9
+ import { getAnnotationCountByIntervals } from "../api/getAnnotationCountByIntervals" ;
10
+ import { getDevicesData } from "../api/getDevicesData" ;
11
+ import { getPeers } from "../api/getPeers" ;
12
+ import { getRealtimeSessions } from "../api/getRealtimeSessions" ;
13
+ import { getTelemetry } from "../api/getTelemetry" ;
14
+ import { patchDevice } from "../api/patchDevice" ;
15
+ import { queryDevicesData } from "../api/queryDevicesData" ;
16
+ import { queryEvents } from "../api/queryEvents" ;
2
17
import { getRtcClientPool } from "../AppRtcClientPools" ;
3
18
import { Authentication } from "../Authentication" ;
4
19
import { CaptureStream } from "../CaptureStream" ;
5
20
import { FORMANT_API_URL } from "../config" ;
6
- import { delay } from "../../../common/delay" ;
7
- import { defined } from "../../../common/defined" ;
8
- import { InterventionType } from "../model/InterventionType" ;
9
- import { IInterventionTypeMap } from "../model/IInterventionTypeMap" ;
10
- import { IInterventionResponse } from "../model/IInterventionResponse" ;
11
- import { IEventQuery } from "../model/IEventQuery" ;
12
21
import { AggregateLevel } from "../model/AggregateLevel" ;
13
22
import { EventType } from "../model/EventType" ;
23
+ import { IEvent } from "../model/IEvent" ;
24
+ import { IEventQuery } from "../model/IEventQuery" ;
25
+ import { IInterventionResponse } from "../model/IInterventionResponse" ;
26
+ import { IInterventionTypeMap } from "../model/IInterventionTypeMap" ;
27
+ import { InterventionType } from "../model/InterventionType" ;
14
28
import { IShare } from "../model/IShare" ;
29
+ import { ITags } from "../model/ITags" ;
15
30
import { SessionType } from "../model/SessionType" ;
31
+ import { TelemetryResult } from "../model/TelemetryResult" ;
16
32
import { isRtcPeer } from "../utils/isRtcPeer" ;
33
+ import { BaseDevice } from "./BaseDevice" ;
17
34
import {
18
35
Command ,
19
36
ConfigurationDocument ,
20
37
IStartRealtimeConnectionOptions ,
21
38
TelemetryStream ,
22
39
} from "./device.types" ;
23
- import { BaseDevice } from "./BaseDevice" ;
24
- import { ITags } from "../model/ITags" ;
25
- import { createShareLink } from "../api/createShareLink" ;
26
- import { eventsCounter } from "../api/eventsCounter" ;
27
- import { getAnnotationCount } from "../api/getAnnotationCount" ;
28
- import { getAnnotationCountByIntervals } from "../api/getAnnotationCountByIntervals" ;
29
- import { getTelemetry } from "../api/getTelemetry" ;
30
- import { getRealtimeSessions } from "../api/getRealtimeSessions" ;
31
- import { getPeers } from "../api/getPeers" ;
32
- import { createDevice } from "../api/createDevice" ;
33
- import { patchDevice } from "../api/patchDevice" ;
34
- import { getDevicesData } from "../api/getDevicesData" ;
35
- import { queryDevicesData } from "../api/queryDevicesData" ;
36
- import { disableDevice } from "../api/disableDevice" ;
37
- import { TelemetryResult } from "../model/TelemetryResult" ;
38
- import { IEvent } from "../model/IEvent" ;
39
- import { queryEvents } from "../api/queryEvents" ;
40
40
export class Device extends BaseDevice {
41
41
constructor (
42
42
public id : string ,
@@ -362,7 +362,7 @@ export class Device extends BaseDevice {
362
362
return false ;
363
363
}
364
364
365
- async getAvailableCommands ( ) : Promise < Command [ ] > {
365
+ async getAvailableCommands ( includeDisabled = true ) : Promise < Command [ ] > {
366
366
const result = await fetch (
367
367
`${ FORMANT_API_URL } /v1/admin/command-templates/` ,
368
368
{
@@ -384,17 +384,28 @@ export class Device extends BaseDevice {
384
384
parameterMeta : i . parameterMeta ,
385
385
enabled : i . enabled ,
386
386
tags : i . tags ,
387
- } ) ) ;
387
+ } ) ) . filter ( ( i : any ) => {
388
+ if ( includeDisabled ) {
389
+ return true ;
390
+ }
391
+ return i . enabled ;
392
+ } ) ;
388
393
}
389
394
390
395
async sendCommand (
391
396
name : string ,
392
397
data ?: string ,
393
398
time ?: Date ,
394
- metadata ?: { }
399
+ metadata ?: { } ,
400
+ id ?: string
395
401
) : Promise < Response > {
396
- const commands = await this . getAvailableCommands ( ) ;
397
- const command = commands . find ( ( _ ) => _ . name === name ) ;
402
+ const commands = await this . getAvailableCommands ( false ) ;
403
+ const command = commands . find ( ( _ ) => {
404
+ if ( id ) {
405
+ return _ . id === id
406
+ }
407
+ return _ . name === name
408
+ } ) ;
398
409
if ( ! command ) {
399
410
throw new Error ( `Could not find command with name "${ name } "` ) ;
400
411
}
0 commit comments