@dronedeploy/rocos-js-sdk 3.0.7 → 3.0.8
Sign up to get free protection for your applications and to get access to all the features.
- package/cjs/IRocosSDK.d.ts +1 -1
- package/cjs/RocosSDK.js +1 -0
- package/cjs/helpers/nanosecondToMillisecond.js +2 -5
- package/cjs/models/IRobotSettings.d.ts +1 -1
- package/cjs/models/IRocosSDKConfig.d.ts +5 -0
- package/cjs/services/BaseServiceAbstract.js +2 -1
- package/cjs/services/CallerService.js +1 -1
- package/cjs/services/PlatformTimeService.js +0 -2
- package/cjs/services/TelemetryService.js +1 -1
- package/cjs/services/WebRTCSignallingService.js +11 -11
- package/esm/IRocosSDK.d.ts +1 -1
- package/esm/RocosSDK.js +1 -0
- package/esm/helpers/nanosecondToMillisecond.js +2 -5
- package/esm/models/IRobotSettings.d.ts +1 -1
- package/esm/models/IRocosSDKConfig.d.ts +5 -0
- package/esm/services/BaseServiceAbstract.js +2 -1
- package/esm/services/CallerService.js +1 -1
- package/esm/services/PlatformTimeService.js +0 -2
- package/esm/services/TelemetryService.js +2 -2
- package/esm/services/WebRTCSignallingService.js +11 -11
- package/package.json +1 -1
package/cjs/IRocosSDK.d.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import { AssetStorageService, AuthService, CallerService, CommandService, ConfigGroupService, ControlService, DashboardService, DeviceCredentialsService, EnvironmentService, 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
3
|
export declare abstract class IRocosSDK {
|
4
|
-
abstract getService<T extends IBaseService>(
|
4
|
+
abstract getService<T extends IBaseService>(_name: ServiceEnum): T;
|
5
5
|
abstract getAuthService(): AuthService;
|
6
6
|
abstract getRobotService(): RobotService;
|
7
7
|
abstract getEventService(): EventService;
|
package/cjs/RocosSDK.js
CHANGED
@@ -1,16 +1,13 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.nanosecondToMillisecond = void 0;
|
4
|
-
function isNumber(n) {
|
5
|
-
return typeof n === 'number';
|
6
|
-
}
|
7
4
|
const nanosecondToMillisecond = (nano) => {
|
8
|
-
if (
|
5
|
+
if (typeof nano === 'number') {
|
9
6
|
return nano / 1e6;
|
10
7
|
}
|
11
8
|
if (nano.length < 16) {
|
12
9
|
return Number(nano) / 1e6;
|
13
10
|
}
|
14
|
-
return Number(nano.slice(0, -6)
|
11
|
+
return Number(`${nano.slice(0, -6)}.${nano.slice(-6)}`);
|
15
12
|
};
|
16
13
|
exports.nanosecondToMillisecond = nanosecondToMillisecond;
|
@@ -10,6 +10,11 @@ interface ConfigBase {
|
|
10
10
|
options?: IStreamOptions;
|
11
11
|
port?: number;
|
12
12
|
insecure?: boolean;
|
13
|
+
hooks?: {
|
14
|
+
http?: {
|
15
|
+
onResponse?: (res: Response) => void;
|
16
|
+
};
|
17
|
+
};
|
13
18
|
}
|
14
19
|
export interface IRocosSDKConfigApp extends ConfigBase {
|
15
20
|
appId: string;
|
@@ -61,6 +61,7 @@ class BaseServiceAbstract {
|
|
61
61
|
async fetchOrThrow(url, config, responseType) {
|
62
62
|
this.logger.debug('Fetching', { url, config });
|
63
63
|
const res = await fetch(url, config);
|
64
|
+
this.config.hooks?.http?.onResponse?.(res.clone());
|
64
65
|
if (!res.ok) {
|
65
66
|
const payload = await res.text();
|
66
67
|
this.logger.warn('Failed HTTP Response', { status: res.statusText, payload, response: res });
|
@@ -83,7 +84,7 @@ class BaseServiceAbstract {
|
|
83
84
|
try {
|
84
85
|
return JSON.parse(textRes);
|
85
86
|
}
|
86
|
-
catch
|
87
|
+
catch {
|
87
88
|
this.logger.error('Failed to parse JSON from response', { textRes });
|
88
89
|
return textRes;
|
89
90
|
}
|
@@ -1,7 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.CallerService = void 0;
|
4
|
-
const splitRobotTopic_1 = require("../helpers/splitRobotTopic");
|
5
4
|
const models_1 = require("../models");
|
6
5
|
const rxjs_1 = require("rxjs");
|
7
6
|
const operators_1 = require("rxjs/operators");
|
@@ -9,6 +8,7 @@ const callerMessageHelpers_1 = require("../helpers/callerMessageHelpers");
|
|
9
8
|
const BaseStreamService_1 = require("./BaseStreamService");
|
10
9
|
const CallerStream_1 = require("../api/streams/caller/CallerStream");
|
11
10
|
const identifier_1 = require("../constants/identifier");
|
11
|
+
const splitRobotTopic_1 = require("../helpers/splitRobotTopic");
|
12
12
|
const uuid_1 = require("uuid");
|
13
13
|
class CallerService extends BaseStreamService_1.BaseStreamService {
|
14
14
|
constructor(config) {
|
@@ -119,9 +119,7 @@ class PlatFormTimeService {
|
|
119
119
|
let totalServerTimeOffset = 0;
|
120
120
|
const measurementsWithValues = platformTimeMeasurements.filter((x) => !!x?.serverTime);
|
121
121
|
measurementsWithValues.forEach((x) => {
|
122
|
-
// eslint-disable-next-line operator-linebreak
|
123
122
|
totalServerTimeOffset +=
|
124
|
-
// eslint-disable-next-line no-mixed-operators
|
125
123
|
x.clientTimeStampEnd - (x.clientTimeStampEnd - x.clientTimeStampStart) / 2 - x.serverTime.now / 10 ** 6;
|
126
124
|
});
|
127
125
|
// final platformTimeOffset is in miliseconds
|
@@ -126,7 +126,7 @@ class TelemetryService extends BaseStreamService_1.BaseStreamService {
|
|
126
126
|
sources: [source],
|
127
127
|
callsigns: [callsign],
|
128
128
|
}).pipe((0, rxjs_1.map)(() => Date.now()));
|
129
|
-
return (0, rxjs_1.combineLatest)([heartbeatTime$.pipe((0, rxjs_1.startWith)(startedAt)), (0, rxjs_1.interval)(intervalMs)]).pipe((0, rxjs_1.map)(([lastHeartbeat
|
129
|
+
return (0, rxjs_1.combineLatest)([heartbeatTime$.pipe((0, rxjs_1.startWith)(startedAt)), (0, rxjs_1.interval)(intervalMs)]).pipe((0, rxjs_1.map)(([lastHeartbeat]) => {
|
130
130
|
const now = Date.now();
|
131
131
|
// If we haven't received a heartbeat, but we've only just started
|
132
132
|
if (lastHeartbeat === startedAt && now - startedAt <= heartbeatTimeoutMs) {
|
@@ -60,20 +60,20 @@ class WebRTCSignallingService {
|
|
60
60
|
return stream;
|
61
61
|
}
|
62
62
|
async initStream(stream) {
|
63
|
+
if (this.config.token)
|
64
|
+
return;
|
63
65
|
// an async callback to set the stream token in case one was not set at startup
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
stream.setToken(this.config.token);
|
71
|
-
}
|
72
|
-
}
|
73
|
-
catch (e) {
|
74
|
-
this.logger.info('Can not retrieve auth token for web rtc signalling stream', e);
|
66
|
+
try {
|
67
|
+
const authService = RocosStore_1.RocosStore.getSDKInstance(this.config).getAuthService();
|
68
|
+
const token = await authService.getToken();
|
69
|
+
if (token?.value) {
|
70
|
+
this.config.token = token?.value;
|
71
|
+
stream.setToken(this.config.token);
|
75
72
|
}
|
76
73
|
}
|
74
|
+
catch (e) {
|
75
|
+
this.logger.info('Can not retrieve auth token for web rtc signalling stream', e);
|
76
|
+
}
|
77
77
|
}
|
78
78
|
getStream(config) {
|
79
79
|
return new WebRTCSignallingStream_1.WebRTCSignallingStream(config);
|
package/esm/IRocosSDK.d.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import { AssetStorageService, AuthService, CallerService, CommandService, ConfigGroupService, ControlService, DashboardService, DeviceCredentialsService, EnvironmentService, 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
3
|
export declare abstract class IRocosSDK {
|
4
|
-
abstract getService<T extends IBaseService>(
|
4
|
+
abstract getService<T extends IBaseService>(_name: ServiceEnum): T;
|
5
5
|
abstract getAuthService(): AuthService;
|
6
6
|
abstract getRobotService(): RobotService;
|
7
7
|
abstract getEventService(): EventService;
|
package/esm/RocosSDK.js
CHANGED
@@ -335,6 +335,7 @@ export class RocosSDK {
|
|
335
335
|
if (!override)
|
336
336
|
return this.config;
|
337
337
|
// strip out the overrides from the config
|
338
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
338
339
|
const { overrides: _, ...config } = this.config;
|
339
340
|
return {
|
340
341
|
...config,
|
@@ -1,12 +1,9 @@
|
|
1
|
-
function isNumber(n) {
|
2
|
-
return typeof n === 'number';
|
3
|
-
}
|
4
1
|
export const nanosecondToMillisecond = (nano) => {
|
5
|
-
if (
|
2
|
+
if (typeof nano === 'number') {
|
6
3
|
return nano / 1e6;
|
7
4
|
}
|
8
5
|
if (nano.length < 16) {
|
9
6
|
return Number(nano) / 1e6;
|
10
7
|
}
|
11
|
-
return Number(nano.slice(0, -6)
|
8
|
+
return Number(`${nano.slice(0, -6)}.${nano.slice(-6)}`);
|
12
9
|
};
|
@@ -10,6 +10,11 @@ interface ConfigBase {
|
|
10
10
|
options?: IStreamOptions;
|
11
11
|
port?: number;
|
12
12
|
insecure?: boolean;
|
13
|
+
hooks?: {
|
14
|
+
http?: {
|
15
|
+
onResponse?: (res: Response) => void;
|
16
|
+
};
|
17
|
+
};
|
13
18
|
}
|
14
19
|
export interface IRocosSDKConfigApp extends ConfigBase {
|
15
20
|
appId: string;
|
@@ -58,6 +58,7 @@ export class BaseServiceAbstract {
|
|
58
58
|
async fetchOrThrow(url, config, responseType) {
|
59
59
|
this.logger.debug('Fetching', { url, config });
|
60
60
|
const res = await fetch(url, config);
|
61
|
+
this.config.hooks?.http?.onResponse?.(res.clone());
|
61
62
|
if (!res.ok) {
|
62
63
|
const payload = await res.text();
|
63
64
|
this.logger.warn('Failed HTTP Response', { status: res.statusText, payload, response: res });
|
@@ -80,7 +81,7 @@ export class BaseServiceAbstract {
|
|
80
81
|
try {
|
81
82
|
return JSON.parse(textRes);
|
82
83
|
}
|
83
|
-
catch
|
84
|
+
catch {
|
84
85
|
this.logger.error('Failed to parse JSON from response', { textRes });
|
85
86
|
return textRes;
|
86
87
|
}
|
@@ -1,4 +1,3 @@
|
|
1
|
-
import { splitRobotTopic } from '../helpers/splitRobotTopic';
|
2
1
|
import { ResultStatus, RocosResponseLevel, } from '../models';
|
3
2
|
import { Subject, map, mergeMap, take, takeUntil } from 'rxjs';
|
4
3
|
import { filter, finalize } from 'rxjs/operators';
|
@@ -6,6 +5,7 @@ import { getResponses, handleChunkedMessages } from '../helpers/callerMessageHel
|
|
6
5
|
import { BaseStreamService } from './BaseStreamService';
|
7
6
|
import { CallerStream } from '../api/streams/caller/CallerStream';
|
8
7
|
import { IDENTIFIER_NAME_CALLER } from '../constants/identifier';
|
8
|
+
import { splitRobotTopic } from '../helpers/splitRobotTopic';
|
9
9
|
import { v4 } from 'uuid';
|
10
10
|
export class CallerService extends BaseStreamService {
|
11
11
|
constructor(config) {
|
@@ -116,9 +116,7 @@ export class PlatFormTimeService {
|
|
116
116
|
let totalServerTimeOffset = 0;
|
117
117
|
const measurementsWithValues = platformTimeMeasurements.filter((x) => !!x?.serverTime);
|
118
118
|
measurementsWithValues.forEach((x) => {
|
119
|
-
// eslint-disable-next-line operator-linebreak
|
120
119
|
totalServerTimeOffset +=
|
121
|
-
// eslint-disable-next-line no-mixed-operators
|
122
120
|
x.clientTimeStampEnd - (x.clientTimeStampEnd - x.clientTimeStampStart) / 2 - x.serverTime.now / 10 ** 6;
|
123
121
|
});
|
124
122
|
// final platformTimeOffset is in miliseconds
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { BehaviorSubject, catchError, combineLatest, distinctUntilChanged, from, interval, map, mergeAll, of, startWith, } from 'rxjs';
|
2
|
-
import { CallsignStatus, CallsignsLookup, CallsignsLookupType, RocosError,
|
2
|
+
import { CallsignStatus, CallsignsLookup, CallsignsLookupType, RocosError, SubscriberStatusEnum, TelemetryMonitorStatus, errorCodes, } from '../models';
|
3
3
|
import { filter, finalize } from 'rxjs/operators';
|
4
4
|
import { BaseStreamService } from './BaseStreamService';
|
5
5
|
import { IDENTIFIER_NAME_TELEMETRY } from '../constants/identifier';
|
@@ -123,7 +123,7 @@ export class TelemetryService extends BaseStreamService {
|
|
123
123
|
sources: [source],
|
124
124
|
callsigns: [callsign],
|
125
125
|
}).pipe(map(() => Date.now()));
|
126
|
-
return combineLatest([heartbeatTime$.pipe(startWith(startedAt)), interval(intervalMs)]).pipe(map(([lastHeartbeat
|
126
|
+
return combineLatest([heartbeatTime$.pipe(startWith(startedAt)), interval(intervalMs)]).pipe(map(([lastHeartbeat]) => {
|
127
127
|
const now = Date.now();
|
128
128
|
// If we haven't received a heartbeat, but we've only just started
|
129
129
|
if (lastHeartbeat === startedAt && now - startedAt <= heartbeatTimeoutMs) {
|
@@ -57,20 +57,20 @@ export class WebRTCSignallingService {
|
|
57
57
|
return stream;
|
58
58
|
}
|
59
59
|
async initStream(stream) {
|
60
|
+
if (this.config.token)
|
61
|
+
return;
|
60
62
|
// an async callback to set the stream token in case one was not set at startup
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
stream.setToken(this.config.token);
|
68
|
-
}
|
69
|
-
}
|
70
|
-
catch (e) {
|
71
|
-
this.logger.info('Can not retrieve auth token for web rtc signalling stream', e);
|
63
|
+
try {
|
64
|
+
const authService = RocosStore.getSDKInstance(this.config).getAuthService();
|
65
|
+
const token = await authService.getToken();
|
66
|
+
if (token?.value) {
|
67
|
+
this.config.token = token?.value;
|
68
|
+
stream.setToken(this.config.token);
|
72
69
|
}
|
73
70
|
}
|
71
|
+
catch (e) {
|
72
|
+
this.logger.info('Can not retrieve auth token for web rtc signalling stream', e);
|
73
|
+
}
|
74
74
|
}
|
75
75
|
getStream(config) {
|
76
76
|
return new WebRTCSignallingStream(config);
|