@dronedeploy/rocos-js-sdk 3.0.1-alpha.19 → 3.0.1-alpha.20
Sign up to get free protection for your applications and to get access to all the features.
- package/cjs/IRocosSDK.d.ts +2 -2
- package/cjs/RocosSDK.d.ts +6 -1
- package/cjs/RocosSDK.js +10 -0
- package/cjs/constants/api.d.ts +1 -0
- package/cjs/constants/api.js +2 -1
- package/cjs/helpers/websandbox/connection.d.ts +2 -1
- package/cjs/helpers/websandbox/connection.js +6 -5
- package/cjs/helpers/websandbox/frame/frame.js +4 -1
- package/cjs/helpers/websandbox/frame/frame.source.js +1 -1
- package/cjs/helpers/websandbox/frame/worker/manager.d.ts +8 -4
- package/cjs/helpers/websandbox/frame/worker/manager.js +32 -14
- package/cjs/helpers/websandbox/frame/worker/worker.source.js +1 -1
- package/cjs/helpers/websandbox/sandbox.d.ts +1 -1
- package/cjs/helpers/websandbox/sandbox.js +7 -7
- package/cjs/models/RocosError.d.ts +1 -0
- package/cjs/models/RocosError.js +1 -0
- package/cjs/models/ServiceEnum.d.ts +19 -18
- package/cjs/models/ServiceEnum.js +19 -18
- package/cjs/models/graph/Position.d.ts +6 -0
- package/cjs/models/graph/Position.js +2 -0
- package/cjs/models/graph/Quaternion.d.ts +6 -0
- package/cjs/models/graph/Quaternion.js +2 -0
- package/cjs/models/graph/Vector3.d.ts +5 -0
- package/cjs/models/graph/Vector3.js +2 -0
- package/cjs/models/graph/index.d.ts +3 -0
- package/cjs/models/graph/index.js +19 -0
- package/cjs/models/index.d.ts +1 -0
- package/cjs/models/index.js +1 -0
- package/cjs/models/maps/Panorama.d.ts +1 -17
- package/cjs/models/target/Target.d.ts +27 -0
- package/cjs/models/target/Target.js +2 -0
- package/cjs/node/RocosSDKNode.d.ts +1 -6
- package/cjs/node/RocosSDKNode.js +3 -9
- package/cjs/services/EvaluatorService.js +1 -1
- package/cjs/services/TargetService.d.ts +11 -0
- package/cjs/services/TargetService.js +31 -0
- package/cjs/services/index.d.ts +9 -8
- package/cjs/services/index.js +9 -8
- package/esm/IRocosSDK.d.ts +2 -2
- package/esm/RocosSDK.d.ts +6 -1
- package/esm/RocosSDK.js +11 -1
- package/esm/constants/api.d.ts +1 -0
- package/esm/constants/api.js +1 -0
- package/esm/helpers/websandbox/connection.d.ts +2 -1
- package/esm/helpers/websandbox/connection.js +6 -5
- package/esm/helpers/websandbox/frame/frame.js +4 -1
- package/esm/helpers/websandbox/frame/frame.source.js +1 -1
- package/esm/helpers/websandbox/frame/worker/manager.d.ts +8 -4
- package/esm/helpers/websandbox/frame/worker/manager.js +32 -14
- package/esm/helpers/websandbox/frame/worker/worker.source.js +1 -1
- package/esm/helpers/websandbox/sandbox.d.ts +1 -1
- package/esm/helpers/websandbox/sandbox.js +7 -7
- package/esm/models/RocosError.d.ts +1 -0
- package/esm/models/RocosError.js +1 -0
- package/esm/models/ServiceEnum.d.ts +19 -18
- package/esm/models/ServiceEnum.js +19 -18
- package/esm/models/graph/Position.d.ts +6 -0
- package/esm/models/graph/Position.js +1 -0
- package/esm/models/graph/Quaternion.d.ts +6 -0
- package/esm/models/graph/Quaternion.js +1 -0
- package/esm/models/graph/Vector3.d.ts +5 -0
- package/esm/models/graph/Vector3.js +1 -0
- package/esm/models/graph/index.d.ts +3 -0
- package/esm/models/graph/index.js +3 -0
- package/esm/models/index.d.ts +1 -0
- package/esm/models/index.js +1 -0
- package/esm/models/maps/Panorama.d.ts +1 -17
- package/esm/models/target/Target.d.ts +27 -0
- package/esm/models/target/Target.js +1 -0
- package/esm/node/RocosSDKNode.d.ts +1 -6
- package/esm/node/RocosSDKNode.js +4 -10
- package/esm/services/BaseServiceAbstract.js +1 -1
- package/esm/services/EvaluatorService.js +1 -1
- package/esm/services/TargetService.d.ts +11 -0
- package/esm/services/TargetService.js +27 -0
- package/esm/services/index.d.ts +9 -8
- package/esm/services/index.js +9 -8
- package/package.json +1 -1
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import { EvaluatorService } from '../services';
|
2
2
|
import { IBaseService, ServiceEnum } from '../models';
|
3
3
|
import { CallerServiceNode } from '../services/CallerServiceNode';
|
4
4
|
import { CommandServiceNode } from '../services/CommandServiceNode';
|
@@ -13,10 +13,6 @@ export declare class RocosSDKNode extends RocosSDK {
|
|
13
13
|
* Gets the telemetry service.
|
14
14
|
*/
|
15
15
|
getTelemetryService(): TelemetryServiceNode;
|
16
|
-
/**
|
17
|
-
* Gets the scheduler service.
|
18
|
-
*/
|
19
|
-
getSchedulerService(): ScheduleService;
|
20
16
|
/**
|
21
17
|
* Gets the service call service.
|
22
18
|
*/
|
@@ -48,5 +44,4 @@ export declare class RocosSDKNode extends RocosSDK {
|
|
48
44
|
* @deprecated Not supported in Node.js
|
49
45
|
*/
|
50
46
|
getRTPWebRTCService(): never;
|
51
|
-
getDeviceCredentialsService(): DeviceCredentialsService;
|
52
47
|
}
|
package/cjs/node/RocosSDKNode.js
CHANGED
@@ -84,6 +84,9 @@ class RocosSDKNode extends RocosSDK_1.RocosSDK {
|
|
84
84
|
case models_1.ServiceEnum.DEVICE_CREDENTIALS:
|
85
85
|
this.services[name] = new services_1.DeviceCredentialsService(config);
|
86
86
|
break;
|
87
|
+
case models_1.ServiceEnum.TARGET:
|
88
|
+
this.services[name] = new services_1.TargetService(config);
|
89
|
+
break;
|
87
90
|
}
|
88
91
|
}
|
89
92
|
this.logger.debug(`Found service ${name}.`);
|
@@ -95,12 +98,6 @@ class RocosSDKNode extends RocosSDK_1.RocosSDK {
|
|
95
98
|
getTelemetryService() {
|
96
99
|
return this.getService(models_1.ServiceEnum.TELEMETRY);
|
97
100
|
}
|
98
|
-
/**
|
99
|
-
* Gets the scheduler service.
|
100
|
-
*/
|
101
|
-
getSchedulerService() {
|
102
|
-
return this.getService(models_1.ServiceEnum.SCHEDULE);
|
103
|
-
}
|
104
101
|
/**
|
105
102
|
* Gets the service call service.
|
106
103
|
*/
|
@@ -146,8 +143,5 @@ class RocosSDKNode extends RocosSDK_1.RocosSDK {
|
|
146
143
|
getRTPWebRTCService() {
|
147
144
|
throw new Error('WebRTC service is not supported in NodeJS');
|
148
145
|
}
|
149
|
-
getDeviceCredentialsService() {
|
150
|
-
return this.getService(models_1.ServiceEnum.DEVICE_CREDENTIALS);
|
151
|
-
}
|
152
146
|
}
|
153
147
|
exports.RocosSDKNode = RocosSDKNode;
|
@@ -22,7 +22,7 @@ class EvaluatorService extends BaseServiceAbstract_1.BaseServiceAbstract {
|
|
22
22
|
}
|
23
23
|
async teardown() {
|
24
24
|
const sandbox = await this.sandbox;
|
25
|
-
sandbox.destroy();
|
25
|
+
sandbox.destroy('evaluator service torn down');
|
26
26
|
}
|
27
27
|
async execute(code, context, options) {
|
28
28
|
const sandbox = await this.sandbox;
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import { IBaseService, IRocosSDKConfig, RocosError, Target } from '../models';
|
2
|
+
import { BaseServiceAbstract } from './BaseServiceAbstract';
|
3
|
+
/**
|
4
|
+
* Service for managing targets (such as assets, PoI's, or FLOCS) on DroneDeploy
|
5
|
+
*/
|
6
|
+
export declare class TargetService extends BaseServiceAbstract implements IBaseService {
|
7
|
+
constructor(config: IRocosSDKConfig);
|
8
|
+
getStatus(): boolean;
|
9
|
+
protected getError(e: Error): RocosError;
|
10
|
+
list(projectId: string, frameID?: string): Promise<Target[]>;
|
11
|
+
}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.TargetService = void 0;
|
4
|
+
const models_1 = require("../models");
|
5
|
+
const api_1 = require("../constants/api");
|
6
|
+
const BaseServiceAbstract_1 = require("./BaseServiceAbstract");
|
7
|
+
const RocosLogger_1 = require("../logger/RocosLogger");
|
8
|
+
const formatServiceUrl_1 = require("../helpers/formatServiceUrl");
|
9
|
+
/**
|
10
|
+
* Service for managing targets (such as assets, PoI's, or FLOCS) on DroneDeploy
|
11
|
+
*/
|
12
|
+
class TargetService extends BaseServiceAbstract_1.BaseServiceAbstract {
|
13
|
+
constructor(config) {
|
14
|
+
super(config);
|
15
|
+
this.logger = RocosLogger_1.RocosLogger.getInstance(`TargetService(${this.config.url})`);
|
16
|
+
}
|
17
|
+
getStatus() {
|
18
|
+
return true;
|
19
|
+
}
|
20
|
+
getError(e) {
|
21
|
+
return new models_1.RocosError(e, models_1.errorCodes.TARGET_SERVICE_ERROR);
|
22
|
+
}
|
23
|
+
async list(projectId, frameID = 'seed') {
|
24
|
+
const resp = await this.callGet((0, formatServiceUrl_1.formatServiceUrl)(api_1.API_TARGETS_URL, {
|
25
|
+
url: this.config.url,
|
26
|
+
projectId,
|
27
|
+
}, this.config.insecure), 'Failed to list targets', { frameID });
|
28
|
+
return resp;
|
29
|
+
}
|
30
|
+
}
|
31
|
+
exports.TargetService = TargetService;
|
package/cjs/services/index.d.ts
CHANGED
@@ -6,23 +6,24 @@ export * from './ConfigGroupService';
|
|
6
6
|
export * from './ControlService';
|
7
7
|
export * from './DashboardService';
|
8
8
|
export * from './DeviceCredentialsService';
|
9
|
+
export * from './EvaluatorService';
|
9
10
|
export * from './EventService';
|
10
11
|
export * from './FileAccessorService';
|
11
12
|
export * from './IntegrationService';
|
13
|
+
export * from './MapService';
|
14
|
+
export * from './PlatformTimeService';
|
12
15
|
export * from './ProfileService';
|
13
16
|
export * from './ProjectService';
|
17
|
+
export * from './RTPWebRTCService';
|
14
18
|
export * from './RobotService';
|
19
|
+
export * from './ScheduleService';
|
15
20
|
export * from './SearchService';
|
21
|
+
export * from './SpotProvisioningService';
|
22
|
+
export * from './SpotProvisioningServiceNode';
|
16
23
|
export * from './StreamService';
|
24
|
+
export * from './TargetService';
|
17
25
|
export * from './TelemetryService';
|
26
|
+
export * from './TimeSyncerService';
|
18
27
|
export * from './UserService';
|
19
28
|
export * from './WebRTCSignallingService';
|
20
29
|
export * from './WorkflowService';
|
21
|
-
export * from './ScheduleService';
|
22
|
-
export * from './TimeSyncerService';
|
23
|
-
export * from './PlatformTimeService';
|
24
|
-
export * from './SpotProvisioningService';
|
25
|
-
export * from './SpotProvisioningServiceNode';
|
26
|
-
export * from './MapService';
|
27
|
-
export * from './EvaluatorService';
|
28
|
-
export * from './RTPWebRTCService';
|
package/cjs/services/index.js
CHANGED
@@ -22,23 +22,24 @@ __exportStar(require("./ConfigGroupService"), exports);
|
|
22
22
|
__exportStar(require("./ControlService"), exports);
|
23
23
|
__exportStar(require("./DashboardService"), exports);
|
24
24
|
__exportStar(require("./DeviceCredentialsService"), exports);
|
25
|
+
__exportStar(require("./EvaluatorService"), exports);
|
25
26
|
__exportStar(require("./EventService"), exports);
|
26
27
|
__exportStar(require("./FileAccessorService"), exports);
|
27
28
|
__exportStar(require("./IntegrationService"), exports);
|
29
|
+
__exportStar(require("./MapService"), exports);
|
30
|
+
__exportStar(require("./PlatformTimeService"), exports);
|
28
31
|
__exportStar(require("./ProfileService"), exports);
|
29
32
|
__exportStar(require("./ProjectService"), exports);
|
33
|
+
__exportStar(require("./RTPWebRTCService"), exports);
|
30
34
|
__exportStar(require("./RobotService"), exports);
|
35
|
+
__exportStar(require("./ScheduleService"), exports);
|
31
36
|
__exportStar(require("./SearchService"), exports);
|
37
|
+
__exportStar(require("./SpotProvisioningService"), exports);
|
38
|
+
__exportStar(require("./SpotProvisioningServiceNode"), exports);
|
32
39
|
__exportStar(require("./StreamService"), exports);
|
40
|
+
__exportStar(require("./TargetService"), exports);
|
33
41
|
__exportStar(require("./TelemetryService"), exports);
|
42
|
+
__exportStar(require("./TimeSyncerService"), exports);
|
34
43
|
__exportStar(require("./UserService"), exports);
|
35
44
|
__exportStar(require("./WebRTCSignallingService"), exports);
|
36
45
|
__exportStar(require("./WorkflowService"), exports);
|
37
|
-
__exportStar(require("./ScheduleService"), exports);
|
38
|
-
__exportStar(require("./TimeSyncerService"), exports);
|
39
|
-
__exportStar(require("./PlatformTimeService"), exports);
|
40
|
-
__exportStar(require("./SpotProvisioningService"), exports);
|
41
|
-
__exportStar(require("./SpotProvisioningServiceNode"), exports);
|
42
|
-
__exportStar(require("./MapService"), exports);
|
43
|
-
__exportStar(require("./EvaluatorService"), exports);
|
44
|
-
__exportStar(require("./RTPWebRTCService"), exports);
|
package/esm/IRocosSDK.d.ts
CHANGED
@@ -1,6 +1,5 @@
|
|
1
|
-
import { AssetStorageService, AuthService, CallerService, CommandService, ConfigGroupService, ControlService, DashboardService, DeviceCredentialsService, EvaluatorService, EventService, FileAccessorService, IntegrationService, MapService, ProfileService, ProjectService, RobotService, SearchService, SpotProvisioningService, SpotProvisioningServiceNode, StreamService, TelemetryService, TimeSyncerService, UserService, WebRTCSignallingService, WorkflowService } from './services';
|
1
|
+
import { AssetStorageService, AuthService, CallerService, CommandService, ConfigGroupService, ControlService, DashboardService, DeviceCredentialsService, EvaluatorService, EventService, FileAccessorService, IntegrationService, MapService, ProfileService, ProjectService, RTPWebRTCService, RobotService, SearchService, SpotProvisioningService, SpotProvisioningServiceNode, StreamService, TargetService, TelemetryService, TimeSyncerService, UserService, WebRTCSignallingService, WorkflowService } from './services';
|
2
2
|
import { IBaseService, IDebugLevel, ServiceEnum } from './models';
|
3
|
-
import { RTPWebRTCService } from './services/RTPWebRTCService';
|
4
3
|
export declare abstract class IRocosSDK {
|
5
4
|
abstract getService<T extends IBaseService>(name: ServiceEnum): T;
|
6
5
|
abstract getAuthService(): AuthService;
|
@@ -28,6 +27,7 @@ export declare abstract class IRocosSDK {
|
|
28
27
|
abstract getIntegrationService(): IntegrationService;
|
29
28
|
abstract getEvaluatorService(): EvaluatorService;
|
30
29
|
abstract getDeviceCredentialsService(): DeviceCredentialsService;
|
30
|
+
abstract getTargetService(): TargetService;
|
31
31
|
abstract cleanup(): Promise<boolean>;
|
32
32
|
abstract enableDebugMode(on: boolean): void;
|
33
33
|
abstract setDebugLevel(level: IDebugLevel): void;
|
package/esm/RocosSDK.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { AssetStorageService, AuthService, CallerService, CommandService, ConfigGroupService, ControlService, DashboardService, DeviceCredentialsService, EvaluatorService, EventService, FileAccessorService, IntegrationService, MapService, ProfileService, ProjectService, RTPWebRTCService, RobotService, ScheduleService, SearchService, SpotProvisioningService, StreamService, TelemetryService, TimeSyncerService, UserService, WebRTCSignallingService, WorkflowService } from './services';
|
1
|
+
import { AssetStorageService, AuthService, CallerService, CommandService, ConfigGroupService, ControlService, DashboardService, DeviceCredentialsService, EvaluatorService, EventService, FileAccessorService, IntegrationService, MapService, ProfileService, ProjectService, RTPWebRTCService, RobotService, ScheduleService, SearchService, SpotProvisioningService, StreamService, TargetService, TelemetryService, TimeSyncerService, UserService, WebRTCSignallingService, WorkflowService } from './services';
|
2
2
|
import { AuthorisedConfig, IBaseService, IDebugLevel, IRocosSDKConfig, ServiceEnum } from './models';
|
3
3
|
import { IRocosSDK } from './IRocosSDK';
|
4
4
|
import { Logger } from 'loglevel';
|
@@ -131,6 +131,11 @@ export declare class RocosSDK implements IRocosSDK {
|
|
131
131
|
* @returns DeviceCredentialsService
|
132
132
|
*/
|
133
133
|
getDeviceCredentialsService(): DeviceCredentialsService;
|
134
|
+
/**
|
135
|
+
* Gets the asset service.
|
136
|
+
* @returns AssetService
|
137
|
+
*/
|
138
|
+
getTargetService(): TargetService;
|
134
139
|
get platformTimeOffset(): number;
|
135
140
|
get platformTime(): number;
|
136
141
|
/**
|
package/esm/RocosSDK.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { AssetStorageService, AuthService, CallerService, CommandService, ConfigGroupService, ControlService, DashboardService, DeviceCredentialsService, EvaluatorService, EventService, FileAccessorService, IntegrationService, MapService, PlatFormTimeService, ProfileService, ProjectService, RTPWebRTCService, RobotService, ScheduleService, SearchService, SpotProvisioningService, StreamService, TelemetryService, TimeSyncerService, UserService, WebRTCSignallingService, WorkflowService, } from './services';
|
1
|
+
import { AssetStorageService, AuthService, CallerService, CommandService, ConfigGroupService, ControlService, DashboardService, DeviceCredentialsService, EvaluatorService, EventService, FileAccessorService, IntegrationService, MapService, PlatFormTimeService, ProfileService, ProjectService, RTPWebRTCService, RobotService, ScheduleService, SearchService, SpotProvisioningService, StreamService, TargetService, TelemetryService, TimeSyncerService, UserService, WebRTCSignallingService, WorkflowService, } from './services';
|
2
2
|
import { ServiceEnum } from './models';
|
3
3
|
import { RocosLogger } from './logger/RocosLogger';
|
4
4
|
import { RocosStore } from './store/RocosStore';
|
@@ -104,6 +104,9 @@ export class RocosSDK {
|
|
104
104
|
case ServiceEnum.DEVICE_CREDENTIALS:
|
105
105
|
this.services[name] = new DeviceCredentialsService(config);
|
106
106
|
break;
|
107
|
+
case ServiceEnum.TARGET:
|
108
|
+
this.services[name] = new TargetService(config);
|
109
|
+
break;
|
107
110
|
}
|
108
111
|
}
|
109
112
|
this.logger.debug(`Found service ${name}.`);
|
@@ -274,6 +277,13 @@ export class RocosSDK {
|
|
274
277
|
getDeviceCredentialsService() {
|
275
278
|
return this.getService(ServiceEnum.DEVICE_CREDENTIALS);
|
276
279
|
}
|
280
|
+
/**
|
281
|
+
* Gets the asset service.
|
282
|
+
* @returns AssetService
|
283
|
+
*/
|
284
|
+
getTargetService() {
|
285
|
+
return this.getService(ServiceEnum.TARGET);
|
286
|
+
}
|
277
287
|
get platformTimeOffset() {
|
278
288
|
return PlatFormTimeService.getInstance(this.getTimeSyncerService())?.platformTimeOffset;
|
279
289
|
}
|
package/esm/constants/api.d.ts
CHANGED
@@ -133,3 +133,4 @@ export declare const API_PROJECT_DEPLOYED_WORKFLOW_URL = "https://{url}/projects
|
|
133
133
|
export declare const API_LINKED_PROJECT_URL = "https://{url}/linked-projects/{linkedProjectId}";
|
134
134
|
export declare const API_DEVICE_CREDENTIALS_URL = "https://{url}/projects/{projectId}/callsigns/{callsign}/device-credentials";
|
135
135
|
export declare const API_DEVICE_CREDENTIALS_AUTH_URL = "https://{url}/device-credentials/auth";
|
136
|
+
export declare const API_TARGETS_URL = "https://{url}/projects/{projectId}/targets";
|
package/esm/constants/api.js
CHANGED
@@ -133,3 +133,4 @@ export const API_PROJECT_DEPLOYED_WORKFLOW_URL = 'https://{url}/projects/{projec
|
|
133
133
|
export const API_LINKED_PROJECT_URL = 'https://{url}/linked-projects/{linkedProjectId}';
|
134
134
|
export const API_DEVICE_CREDENTIALS_URL = 'https://{url}/projects/{projectId}/callsigns/{callsign}/device-credentials';
|
135
135
|
export const API_DEVICE_CREDENTIALS_AUTH_URL = 'https://{url}/device-credentials/auth';
|
136
|
+
export const API_TARGETS_URL = 'https://{url}/projects/{projectId}/targets';
|
@@ -39,6 +39,8 @@ export default class Connection<Local extends APIDeclaration<Local>, Remote exte
|
|
39
39
|
* @param args - arguments to pass to remote method
|
40
40
|
*/
|
41
41
|
callRemoteMethod<Method extends keyof Remote>(name: Method, ...args: Parameters<Remote[Method]>): Promise<ReturnType<Remote[Method]>>;
|
42
|
+
/** Log a message if debug mode is enabled */
|
43
|
+
log(...args: unknown[]): void;
|
42
44
|
private onMessageListener;
|
43
45
|
private callLocalMethod;
|
44
46
|
/** Respond to remote call
|
@@ -62,6 +64,5 @@ export default class Connection<Local extends APIDeclaration<Local>, Remote exte
|
|
62
64
|
*/
|
63
65
|
private popCallback;
|
64
66
|
private postMessage;
|
65
|
-
private log;
|
66
67
|
}
|
67
68
|
export {};
|
@@ -43,6 +43,12 @@ export default class Connection {
|
|
43
43
|
});
|
44
44
|
});
|
45
45
|
}
|
46
|
+
/** Log a message if debug mode is enabled */
|
47
|
+
log(...args) {
|
48
|
+
if (this.options.debugMode) {
|
49
|
+
console.debug(`[${this.name}]`, ...args);
|
50
|
+
}
|
51
|
+
}
|
46
52
|
onMessageListener(e) {
|
47
53
|
this.log('Received message', e);
|
48
54
|
const { data } = e;
|
@@ -125,9 +131,4 @@ export default class Connection {
|
|
125
131
|
this.log('sending message', { data, targetOrigin });
|
126
132
|
this.postMessageInternal(data, targetOrigin);
|
127
133
|
}
|
128
|
-
log(...args) {
|
129
|
-
if (this.options.debugMode) {
|
130
|
-
console.debug(`[${this.name}]`, ...args);
|
131
|
-
}
|
132
|
-
}
|
133
134
|
}
|
@@ -12,7 +12,10 @@ class Frame {
|
|
12
12
|
debugMode: isDebugMode,
|
13
13
|
});
|
14
14
|
void this.connection.callRemoteMethod('iframeInitialised');
|
15
|
-
|
15
|
+
// use roughly half the number of logical cores available clamped between 1 and 6
|
16
|
+
const workers = Math.min(Math.max(Math.ceil(navigator.hardwareConcurrency / 2), 1), 6);
|
17
|
+
this.connection.log(`Creating ${workers} workers`);
|
18
|
+
this.workerManager = new WorkerManager(workers);
|
16
19
|
}
|
17
20
|
async runCode(task) {
|
18
21
|
return this.workerManager.execute(task);
|
@@ -1,5 +1,5 @@
|
|
1
1
|
// Auto-generated file
|
2
2
|
/* eslint-disable */
|
3
3
|
import __WORKER_SOURCE__ from './worker/worker.source';
|
4
|
-
const source = `(()=>{"use strict";var e
|
4
|
+
const source = `(()=>{"use strict";var e;!function(e){e.RESPONSE="response",e.MESSAGE="message"}(e||(e={}));const s={allowedSenderOrigin:void 0,debugMode:!1};class t{constructor(e,t,r,n,o={}){this.callbacks=new Map,this.serviceMethods=new Map,this.name=e,this.options={...s,...o},this.log("Created connection w/ allowedOrigin:",this.options.allowedSenderOrigin),this.serviceMethods=new Map(Object.entries(r));const[i]=crypto.getRandomValues(new Uint32Array(1));this.incrementalID=i,this.postMessageInternal=t,n((e=>this.onMessageListener(e)))}callRemoteMethod(s,...t){return this.log("Calling Remote Method",{name:s,args:t}),new Promise(((r,n)=>{const o=this.registerCallback(r,n);this.postMessage({callId:o,type:e.MESSAGE,methodName:s,arguments:t})}))}log(...e){this.options.debugMode&&console.debug(\`[\${this.name}]\`,...e)}onMessageListener(s){this.log("Received message",s);const{data:t}=s,{allowedSenderOrigin:r}=this.options;switch(r&&s.origin!==r&&console.warn(\`Received message from invalid origin: \${s.origin}\`),t.type){case e.RESPONSE:return void this.popCallback(t.callId,t.success,t.result);case e.MESSAGE:this.callLocalMethod(t.methodName,t.arguments).then((e=>this.responseOtherSide(t.callId,e))).catch((e=>this.responseOtherSide(t.callId,e,!1)))}}async callLocalMethod(e,s){this.log("calling local method",e,s);const t=this.serviceMethods.get(e);if(!t)throw new Error(\`service method \${e} not found\`);return t(...s)}responseOtherSide(s,t,r=!0){this.log("responding to remote call",{id:s,result:t,success:r});const n=t=>{this.postMessage({callId:s,type:e.RESPONSE,success:r,result:t})};try{n(t)}catch(e){e instanceof DOMException&&n(JSON.parse(JSON.stringify(t)))}}registerCallback(e,s){const t=(++this.incrementalID).toString();return this.log("registering callback for id",t),this.callbacks.set(t,{success:e,failure:s}),t}popCallback(e,s,t){this.log("calling callback for id",e,{success:s,result:t});const r=this.callbacks.get(e);s?r?.success(t):r?.failure(t),this.callbacks.delete(e)}postMessage(e,s="*"){this.log("sending message",{data:e,targetOrigin:s}),this.postMessageInternal(e,s)}}new class{constructor(){const e=!!window?.debugMode;this.connection=new t("FRAME",window.parent.postMessage.bind(window.parent),{startTask:this.runCode.bind(this)},(e=>{window.addEventListener("message",e)}),{debugMode:e}),this.connection.callRemoteMethod("iframeInitialised");const s=Math.max(Math.ceil(navigator.hardwareConcurrency/2),1);this.connection.log(\`Creating \${s} workers\`),this.workerManager=new class{constructor(e=1){this.messageListeners=new Map,this.requestedWorkers=e,this.workers=Array.from({length:e},(()=>this.createWorker())),this.nextWorkerGenerator=this.nextWorker()}async execute(e){const s=this.nextWorkerGenerator.next().value,t={...e,contextVariable:e.contextVariable??"ctx"},r=this.runTask(s,t),n=new Promise(((s,t)=>{const r=AbortSignal.timeout(e.timeout);r.addEventListener("abort",(()=>{t(r.reason)}))}));return Promise.race([r,n]).catch((e=>{if("TimeoutError"===e.name)throw this.terminate(s),new DOMException("soft timeout reached","TimeoutError");throw e})).finally((()=>{this.removeMessageListener(e.id)}))}terminate(e){for(const s of this.messageListeners.values())e.removeEventListener("message",s);e.terminate(),this.rebuildWorkers()}runTask(e,s){return new Promise(((t,r)=>{const n=e=>{const{data:n}=e;n.id===s.id&&(n.success?t(n.result):r(n.result))};this.messageListeners.set(s.id,n),e.addEventListener("message",n),e.postMessage(s)}))}createWorker(){const e=URL.createObjectURL(new Blob(["${__WORKER_SOURCE__.replace(/(['`"$])/g, '\\$1')}"],{type:"application/javascript"}));return new Worker(e)}rebuildWorkers(){const e=this.requestedWorkers-this.workers.length;if(e<0)throw new Error("Cannot have less than 0 workers");if(e<=0)return;const s=Array.from({length:e},(()=>this.createWorker()));this.workers.push(...s)}*nextWorker(){let e=0;for(;;)e=(e+1)%this.workers.length,yield this.workers[e]}removeMessageListener(e){const s=this.messageListeners.get(e);s&&(this.workers.forEach((e=>e.removeEventListener("message",s))),this.messageListeners.delete(e))}}(s)}async runCode(e){return this.workerManager.execute(e)}}})();`;
|
5
5
|
export default source;
|
@@ -1,11 +1,15 @@
|
|
1
1
|
import { Task } from '../../types';
|
2
2
|
export default class Manager {
|
3
|
-
private
|
4
|
-
private
|
5
|
-
|
3
|
+
private readonly requestedWorkers;
|
4
|
+
private readonly workers;
|
5
|
+
private nextWorkerIndex;
|
6
|
+
private readonly messageListeners;
|
7
|
+
constructor(workers?: number);
|
6
8
|
execute(task: Task): Promise<unknown>;
|
7
|
-
terminate
|
9
|
+
private terminate;
|
8
10
|
private runTask;
|
9
11
|
private createWorker;
|
12
|
+
private rebuildWorkers;
|
13
|
+
private getWorker;
|
10
14
|
private removeMessageListener;
|
11
15
|
}
|
@@ -1,16 +1,19 @@
|
|
1
1
|
// this token (__WORKER_SOURCE__) is replaced by webpack with the source of the worker
|
2
2
|
const WORKER_SOURCE = '__WORKER_SOURCE__';
|
3
3
|
export default class Manager {
|
4
|
-
constructor() {
|
4
|
+
constructor(workers = 1) {
|
5
|
+
this.nextWorkerIndex = 0;
|
5
6
|
this.messageListeners = new Map();
|
6
|
-
this.
|
7
|
+
this.requestedWorkers = workers;
|
8
|
+
this.workers = Array.from({ length: workers }, () => this.createWorker());
|
7
9
|
}
|
8
10
|
async execute(task) {
|
11
|
+
const worker = this.getWorker();
|
9
12
|
const workerTask = {
|
10
13
|
...task,
|
11
14
|
contextVariable: task.contextVariable ?? 'ctx',
|
12
15
|
};
|
13
|
-
const result = this.runTask(workerTask);
|
16
|
+
const result = this.runTask(worker, workerTask);
|
14
17
|
const timeout = new Promise((_, reject) => {
|
15
18
|
const signal = AbortSignal.timeout(task.timeout);
|
16
19
|
signal.addEventListener('abort', () => {
|
@@ -20,7 +23,8 @@ export default class Manager {
|
|
20
23
|
return Promise.race([result, timeout])
|
21
24
|
.catch((e) => {
|
22
25
|
if (e.name === 'TimeoutError') {
|
23
|
-
this.terminate();
|
26
|
+
this.terminate(worker);
|
27
|
+
throw new DOMException('soft timeout reached', 'TimeoutError');
|
24
28
|
}
|
25
29
|
throw e;
|
26
30
|
})
|
@@ -28,14 +32,14 @@ export default class Manager {
|
|
28
32
|
this.removeMessageListener(task.id);
|
29
33
|
});
|
30
34
|
}
|
31
|
-
terminate() {
|
35
|
+
terminate(worker) {
|
32
36
|
for (const listener of this.messageListeners.values()) {
|
33
|
-
|
37
|
+
worker.removeEventListener('message', listener);
|
34
38
|
}
|
35
|
-
|
36
|
-
this.
|
39
|
+
worker.terminate();
|
40
|
+
this.rebuildWorkers();
|
37
41
|
}
|
38
|
-
runTask(task) {
|
42
|
+
runTask(worker, task) {
|
39
43
|
return new Promise((resolve, reject) => {
|
40
44
|
const listener = (event) => {
|
41
45
|
const { data } = event;
|
@@ -49,19 +53,33 @@ export default class Manager {
|
|
49
53
|
}
|
50
54
|
};
|
51
55
|
this.messageListeners.set(task.id, listener);
|
52
|
-
|
53
|
-
|
56
|
+
worker.addEventListener('message', listener);
|
57
|
+
worker.postMessage(task);
|
54
58
|
});
|
55
59
|
}
|
56
60
|
createWorker() {
|
57
61
|
const blob = URL.createObjectURL(new Blob([WORKER_SOURCE], { type: 'application/javascript' }));
|
58
62
|
return new Worker(blob);
|
59
63
|
}
|
64
|
+
rebuildWorkers() {
|
65
|
+
const needed = this.requestedWorkers - this.workers.length;
|
66
|
+
if (needed < 0)
|
67
|
+
throw new Error('Cannot have less than 0 workers');
|
68
|
+
if (needed <= 0)
|
69
|
+
return;
|
70
|
+
const newWorkers = Array.from({ length: needed }, () => this.createWorker());
|
71
|
+
this.workers.push(...newWorkers);
|
72
|
+
}
|
73
|
+
getWorker() {
|
74
|
+
const worker = this.workers[this.nextWorkerIndex];
|
75
|
+
this.nextWorkerIndex = (this.nextWorkerIndex + 1) % this.workers.length;
|
76
|
+
return worker;
|
77
|
+
}
|
60
78
|
removeMessageListener(id) {
|
61
79
|
const listener = this.messageListeners.get(id);
|
62
|
-
if (!listener)
|
80
|
+
if (!listener)
|
63
81
|
return;
|
64
|
-
|
65
|
-
this.
|
82
|
+
this.workers.forEach((worker) => worker.removeEventListener('message', listener));
|
83
|
+
this.messageListeners.delete(id);
|
66
84
|
}
|
67
85
|
}
|
@@ -1,4 +1,4 @@
|
|
1
1
|
// Auto-generated file
|
2
2
|
/* eslint-disable */
|
3
|
-
const source = `(()=>{"use strict";
|
3
|
+
const source = `(()=>{"use strict";const e=["TEMPORARY","PERSISTENT","console","self","onmessage","postMessage","global","allowed","Array","Boolean","Date","Function","Number","Object","RegExp","String","Error","EvalError","RangeError","ReferenceError","SyntaxError","TypeError","URIError","decodeURI","decodeURIComponent","encodeURI","encodeURIComponent","isFinite","isNaN","parseFloat","parseInt","Infinity","JSON","Math","NaN","undefined"];[...Object.getOwnPropertyNames(self),...Object.getOwnPropertyNames(self.__proto__)].forEach((r=>{e.includes(r)||Object.defineProperty(self,r,{get:()=>{throw new Error(\`Security Exception: cannot access \${r}\`)},set:()=>{throw new Error(\`Security Exception: cannot set \${r}\`)},configurable:!1})})),onmessage=e=>{let r,t=!0;try{r=Function(e.data.contextVariable,\`"use strict";return (\${e.data.code});\`)(e.data.context)}catch(e){r=e,t=!1}const o={id:e.data.id,result:r,success:t};postMessage(o)}})();`;
|
4
4
|
export default source;
|
@@ -44,7 +44,7 @@ export default class WebSandbox {
|
|
44
44
|
*
|
45
45
|
* This will remove the iframe from the DOM and remove the message listener.
|
46
46
|
*/
|
47
|
-
destroy(): void;
|
47
|
+
destroy(reason?: unknown): void;
|
48
48
|
private initialise;
|
49
49
|
private validateOptions;
|
50
50
|
private destroyAndRebuild;
|
@@ -29,8 +29,8 @@ export default class WebSandbox {
|
|
29
29
|
this.initialised = this.initialise();
|
30
30
|
this.frameAbortController = new AbortController();
|
31
31
|
if (options.abortSignal) {
|
32
|
-
this.promisifyAbortSignal(options.abortSignal).catch(() => {
|
33
|
-
void this.destroyAndRebuild(this.frame.id);
|
32
|
+
this.promisifyAbortSignal(options.abortSignal).catch((reason) => {
|
33
|
+
void this.destroyAndRebuild(this.frame.id, reason);
|
34
34
|
});
|
35
35
|
}
|
36
36
|
}
|
@@ -45,8 +45,8 @@ export default class WebSandbox {
|
|
45
45
|
*
|
46
46
|
* This will remove the iframe from the DOM and remove the message listener.
|
47
47
|
*/
|
48
|
-
destroy() {
|
49
|
-
this.frameAbortController.abort();
|
48
|
+
destroy(reason) {
|
49
|
+
this.frameAbortController.abort(reason);
|
50
50
|
this.frame.remove();
|
51
51
|
this.removeMessageListener();
|
52
52
|
}
|
@@ -79,11 +79,11 @@ export default class WebSandbox {
|
|
79
79
|
throw new Error('maximum timeout must be less than or equal to 5000ms');
|
80
80
|
}
|
81
81
|
}
|
82
|
-
async destroyAndRebuild(frameId) {
|
82
|
+
async destroyAndRebuild(frameId, reason) {
|
83
83
|
if (this.frame.id !== frameId) {
|
84
84
|
return;
|
85
85
|
}
|
86
|
-
this.destroy();
|
86
|
+
this.destroy(reason);
|
87
87
|
this.frame = this.createFrame();
|
88
88
|
this.frameAbortController = new AbortController();
|
89
89
|
await this.initialise();
|
@@ -117,7 +117,7 @@ export default class WebSandbox {
|
|
117
117
|
const signals = [task, timeout, frameAbortedSignal, userAbortedSignal].filter((i) => i !== null);
|
118
118
|
return Promise.race(signals).catch(async (e) => {
|
119
119
|
if (e.name === 'TimeoutError') {
|
120
|
-
await this.destroyAndRebuild(frameId);
|
120
|
+
await this.destroyAndRebuild(frameId, 'task timed out');
|
121
121
|
}
|
122
122
|
throw e;
|
123
123
|
});
|
package/esm/models/RocosError.js
CHANGED
@@ -25,6 +25,7 @@ export const errorCodes = {
|
|
25
25
|
EVALUATOR_SERVICE_ERROR: 'EVALUATOR_SERVICE_ERROR',
|
26
26
|
WEBRTC_SERVICE_ERROR: 'WEBRTC_SERVICE_ERROR',
|
27
27
|
DEVICE_CREDENTIALS_SERVICE_ERROR: 'DEVICE_CREDENTIALS_SERVICE_ERROR',
|
28
|
+
TARGET_SERVICE_ERROR: 'TARGET_SERVICE_ERROR',
|
28
29
|
};
|
29
30
|
export class RocosError extends Error {
|
30
31
|
constructor(err, code, statusCode) {
|
@@ -1,29 +1,30 @@
|
|
1
1
|
export declare enum ServiceEnum {
|
2
|
+
ASSET_STORAGE = "asset_storage",
|
2
3
|
AUTH = "auth",
|
3
|
-
TELEMETRY = "telemetry",
|
4
|
-
ROBOT = "robot",
|
5
|
-
EVENT = "event",
|
6
|
-
PROJECT = "project",
|
7
4
|
CALLER = "caller",
|
8
5
|
COMMAND = "command",
|
9
|
-
CONTROL = "control",
|
10
|
-
SEARCH = "search",
|
11
6
|
CONFIG_GROUP = "config_group",
|
7
|
+
CONTROL = "control",
|
12
8
|
DASHBOARD = "dashboard",
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
TIME_SYNCER = "time_syncer",
|
17
|
-
WORKFLOW = "workflow",
|
18
|
-
ASSET_STORAGE = "asset_storage",
|
19
|
-
PROFILE = "profile",
|
20
|
-
WEBRTC_SIGNALLING = "webrtc_signalling",
|
9
|
+
DEVICE_CREDENTIALS = "device_credentials",
|
10
|
+
EVENT = "event",
|
11
|
+
EVALUATOR = "evaluator",
|
21
12
|
FILE_ACCESSOR = "file_accessor",
|
22
|
-
|
23
|
-
SPOT_PROVISIONER = "spot_provisioner",
|
13
|
+
FUNCTION = "function",
|
24
14
|
INTEGRATION = "integration",
|
25
15
|
MAP = "map",
|
26
|
-
|
16
|
+
PROJECT = "project",
|
17
|
+
PROFILE = "profile",
|
18
|
+
ROBOT = "robot",
|
27
19
|
RTP_WEBRTC = "rtp_webrtc",
|
28
|
-
|
20
|
+
SCHEDULE = "schedule",
|
21
|
+
SEARCH = "search",
|
22
|
+
SPOT_PROVISIONER = "spot_provisioner",
|
23
|
+
STREAM = "stream",
|
24
|
+
TARGET = "target",
|
25
|
+
TELEMETRY = "telemetry",
|
26
|
+
TIME_SYNCER = "time_syncer",
|
27
|
+
USER = "user",
|
28
|
+
WEBRTC_SIGNALLING = "webrtc_signalling",
|
29
|
+
WORKFLOW = "workflow"
|
29
30
|
}
|
@@ -1,30 +1,31 @@
|
|
1
1
|
export var ServiceEnum;
|
2
2
|
(function (ServiceEnum) {
|
3
|
+
ServiceEnum["ASSET_STORAGE"] = "asset_storage";
|
3
4
|
ServiceEnum["AUTH"] = "auth";
|
4
|
-
ServiceEnum["TELEMETRY"] = "telemetry";
|
5
|
-
ServiceEnum["ROBOT"] = "robot";
|
6
|
-
ServiceEnum["EVENT"] = "event";
|
7
|
-
ServiceEnum["PROJECT"] = "project";
|
8
5
|
ServiceEnum["CALLER"] = "caller";
|
9
6
|
ServiceEnum["COMMAND"] = "command";
|
10
|
-
ServiceEnum["CONTROL"] = "control";
|
11
|
-
ServiceEnum["SEARCH"] = "search";
|
12
7
|
ServiceEnum["CONFIG_GROUP"] = "config_group";
|
8
|
+
ServiceEnum["CONTROL"] = "control";
|
13
9
|
ServiceEnum["DASHBOARD"] = "dashboard";
|
14
|
-
ServiceEnum["
|
15
|
-
ServiceEnum["
|
16
|
-
ServiceEnum["
|
17
|
-
ServiceEnum["TIME_SYNCER"] = "time_syncer";
|
18
|
-
ServiceEnum["WORKFLOW"] = "workflow";
|
19
|
-
ServiceEnum["ASSET_STORAGE"] = "asset_storage";
|
20
|
-
ServiceEnum["PROFILE"] = "profile";
|
21
|
-
ServiceEnum["WEBRTC_SIGNALLING"] = "webrtc_signalling";
|
10
|
+
ServiceEnum["DEVICE_CREDENTIALS"] = "device_credentials";
|
11
|
+
ServiceEnum["EVENT"] = "event";
|
12
|
+
ServiceEnum["EVALUATOR"] = "evaluator";
|
22
13
|
ServiceEnum["FILE_ACCESSOR"] = "file_accessor";
|
23
|
-
ServiceEnum["
|
24
|
-
ServiceEnum["SPOT_PROVISIONER"] = "spot_provisioner";
|
14
|
+
ServiceEnum["FUNCTION"] = "function";
|
25
15
|
ServiceEnum["INTEGRATION"] = "integration";
|
26
16
|
ServiceEnum["MAP"] = "map";
|
27
|
-
ServiceEnum["
|
17
|
+
ServiceEnum["PROJECT"] = "project";
|
18
|
+
ServiceEnum["PROFILE"] = "profile";
|
19
|
+
ServiceEnum["ROBOT"] = "robot";
|
28
20
|
ServiceEnum["RTP_WEBRTC"] = "rtp_webrtc";
|
29
|
-
ServiceEnum["
|
21
|
+
ServiceEnum["SCHEDULE"] = "schedule";
|
22
|
+
ServiceEnum["SEARCH"] = "search";
|
23
|
+
ServiceEnum["SPOT_PROVISIONER"] = "spot_provisioner";
|
24
|
+
ServiceEnum["STREAM"] = "stream";
|
25
|
+
ServiceEnum["TARGET"] = "target";
|
26
|
+
ServiceEnum["TELEMETRY"] = "telemetry";
|
27
|
+
ServiceEnum["TIME_SYNCER"] = "time_syncer";
|
28
|
+
ServiceEnum["USER"] = "user";
|
29
|
+
ServiceEnum["WEBRTC_SIGNALLING"] = "webrtc_signalling";
|
30
|
+
ServiceEnum["WORKFLOW"] = "workflow";
|
30
31
|
})(ServiceEnum || (ServiceEnum = {}));
|