@dronedeploy/rocos-js-sdk 3.0.1-alpha.11 → 3.0.1-alpha.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (153) hide show
  1. package/cjs/IRocosSDK.d.ts +1 -2
  2. package/cjs/RocosSDK.d.ts +4 -6
  3. package/cjs/RocosSDK.js +1 -9
  4. package/cjs/api/streams/caller/CallerStream.js +5 -2
  5. package/cjs/api/streams/caller/CallerStreamNode.js +2 -1
  6. package/cjs/api/streams/command/CommandStream.js +5 -2
  7. package/cjs/api/streams/command/CommandStreamNode.js +2 -1
  8. package/cjs/api/streams/control/ControlStream.js +5 -2
  9. package/cjs/api/streams/control/ControlStreamAbstract.d.ts +1 -1
  10. package/cjs/api/streams/control/ControlStreamNode.js +2 -1
  11. package/cjs/api/streams/fileAccessor/FileAccessorStream.js +4 -1
  12. package/cjs/api/streams/fileAccessor/FileAccessorStreamNode.js +3 -1
  13. package/cjs/api/streams/search/SearchStream.js +5 -2
  14. package/cjs/api/streams/search/SearchStreamNode.js +2 -1
  15. package/cjs/api/streams/telemetry/TelemetryStream.js +4 -1
  16. package/cjs/api/streams/telemetry/TelemetryStreamAbstract.d.ts +1 -1
  17. package/cjs/api/streams/telemetry/TelemetryStreamNode.js +2 -1
  18. package/cjs/api/streams/webRTCSignalling/WebRTCSignallingStream.js +5 -2
  19. package/cjs/constants/api.d.ts +2 -4
  20. package/cjs/constants/api.js +4 -6
  21. package/cjs/helpers/getUniqueConfigKey.d.ts +6 -2
  22. package/cjs/helpers/getUniqueConfigKey.js +7 -2
  23. package/cjs/models/TelemetryStatus.d.ts +12 -0
  24. package/cjs/models/TelemetryStatus.js +17 -0
  25. package/cjs/models/Token.d.ts +2 -2
  26. package/cjs/models/Token.js +5 -5
  27. package/cjs/models/index.d.ts +1 -1
  28. package/cjs/models/index.js +1 -1
  29. package/cjs/node/RocosSDKNode.js +0 -3
  30. package/cjs/services/ProfileService.d.ts +23 -0
  31. package/cjs/services/ProfileService.js +28 -0
  32. package/cjs/services/RTPWebRTCService.d.ts +1 -1
  33. package/cjs/services/RTPWebRTCService.js +4 -2
  34. package/cjs/services/TelemetryService.d.ts +10 -1
  35. package/cjs/services/TelemetryService.js +27 -5
  36. package/cjs/services/index.d.ts +0 -1
  37. package/cjs/services/index.js +0 -1
  38. package/cjs/store/RocosStore.d.ts +1 -2
  39. package/esm/IRocosSDK.d.ts +1 -2
  40. package/esm/RocosSDK.d.ts +4 -6
  41. package/esm/RocosSDK.js +2 -10
  42. package/esm/api/streams/caller/CallerStream.js +5 -2
  43. package/esm/api/streams/caller/CallerStreamNode.js +2 -1
  44. package/esm/api/streams/command/CommandStream.js +5 -2
  45. package/esm/api/streams/command/CommandStreamNode.js +2 -1
  46. package/esm/api/streams/control/ControlStream.js +5 -2
  47. package/esm/api/streams/control/ControlStreamAbstract.d.ts +1 -1
  48. package/esm/api/streams/control/ControlStreamNode.js +2 -1
  49. package/esm/api/streams/fileAccessor/FileAccessorStream.js +4 -1
  50. package/esm/api/streams/fileAccessor/FileAccessorStreamNode.js +3 -1
  51. package/esm/api/streams/search/SearchStream.js +5 -2
  52. package/esm/api/streams/search/SearchStreamNode.js +2 -1
  53. package/esm/api/streams/telemetry/TelemetryStream.js +4 -1
  54. package/esm/api/streams/telemetry/TelemetryStreamAbstract.d.ts +1 -1
  55. package/esm/api/streams/telemetry/TelemetryStreamNode.js +2 -1
  56. package/esm/api/streams/webRTCSignalling/WebRTCSignallingStream.js +5 -2
  57. package/esm/constants/api.d.ts +2 -4
  58. package/esm/constants/api.js +2 -4
  59. package/esm/helpers/getUniqueConfigKey.d.ts +6 -2
  60. package/esm/helpers/getUniqueConfigKey.js +7 -2
  61. package/esm/models/TelemetryStatus.d.ts +12 -0
  62. package/esm/models/TelemetryStatus.js +14 -0
  63. package/esm/models/Token.d.ts +2 -2
  64. package/esm/models/Token.js +5 -5
  65. package/esm/models/index.d.ts +1 -1
  66. package/esm/models/index.js +1 -1
  67. package/esm/node/RocosSDKNode.js +1 -4
  68. package/esm/services/ProfileService.d.ts +23 -0
  69. package/esm/services/ProfileService.js +29 -1
  70. package/esm/services/RTPWebRTCService.d.ts +1 -1
  71. package/esm/services/RTPWebRTCService.js +4 -2
  72. package/esm/services/TelemetryService.d.ts +10 -1
  73. package/esm/services/TelemetryService.js +28 -6
  74. package/esm/services/index.d.ts +0 -1
  75. package/esm/services/index.js +0 -1
  76. package/esm/store/RocosStore.d.ts +1 -2
  77. package/package.json +1 -2
  78. package/cjs/helpers/cleanObject.spec.d.ts +0 -1
  79. package/cjs/helpers/cleanObject.spec.js +0 -55
  80. package/cjs/helpers/flattenObject.spec.d.ts +0 -1
  81. package/cjs/helpers/flattenObject.spec.js +0 -31
  82. package/cjs/helpers/flattenOneOf.spec.d.ts +0 -1
  83. package/cjs/helpers/flattenOneOf.spec.js +0 -159
  84. package/cjs/helpers/formatServiceUrl.spec.d.ts +0 -1
  85. package/cjs/helpers/formatServiceUrl.spec.js +0 -18
  86. package/cjs/helpers/getSha256Hex.spec.d.ts +0 -1
  87. package/cjs/helpers/getSha256Hex.spec.js +0 -19
  88. package/cjs/helpers/getSha256HexNode.spec.d.ts +0 -1
  89. package/cjs/helpers/getSha256HexNode.spec.js +0 -10
  90. package/cjs/helpers/getURLSearchParams.spec.d.ts +0 -1
  91. package/cjs/helpers/getURLSearchParams.spec.js +0 -21
  92. package/cjs/helpers/nanosecondToMillisecond.spec.d.ts +0 -1
  93. package/cjs/helpers/nanosecondToMillisecond.spec.js +0 -22
  94. package/cjs/helpers/splitRobotTopic.spec.d.ts +0 -1
  95. package/cjs/helpers/splitRobotTopic.spec.js +0 -53
  96. package/cjs/helpers/standardDeviation.spec.d.ts +0 -1
  97. package/cjs/helpers/standardDeviation.spec.js +0 -13
  98. package/cjs/helpers/websandbox/frame/worker/manager.spec.d.ts +0 -4
  99. package/cjs/helpers/websandbox/frame/worker/manager.spec.js +0 -132
  100. package/cjs/models/CallsignStatus.d.ts +0 -6
  101. package/cjs/models/CallsignStatus.js +0 -10
  102. package/cjs/models/Token.spec.d.ts +0 -1
  103. package/cjs/models/Token.spec.js +0 -110
  104. package/cjs/services/AuthService.spec.d.ts +0 -1
  105. package/cjs/services/AuthService.spec.js +0 -165
  106. package/cjs/services/CallerService.spec.d.ts +0 -1
  107. package/cjs/services/CallerService.spec.js +0 -229
  108. package/cjs/services/FunctionService.d.ts +0 -68
  109. package/cjs/services/FunctionService.js +0 -103
  110. package/cjs/services/PlatformTimeService.spec.d.ts +0 -1
  111. package/cjs/services/PlatformTimeService.spec.js +0 -182
  112. package/cjs/services/RTPWebRTCService.spec.d.ts +0 -4
  113. package/cjs/services/RTPWebRTCService.spec.js +0 -171
  114. package/cjs/services/TelemetryService.spec.d.ts +0 -1
  115. package/cjs/services/TelemetryService.spec.js +0 -39
  116. package/esm/helpers/cleanObject.spec.d.ts +0 -1
  117. package/esm/helpers/cleanObject.spec.js +0 -53
  118. package/esm/helpers/flattenObject.spec.d.ts +0 -1
  119. package/esm/helpers/flattenObject.spec.js +0 -29
  120. package/esm/helpers/flattenOneOf.spec.d.ts +0 -1
  121. package/esm/helpers/flattenOneOf.spec.js +0 -157
  122. package/esm/helpers/formatServiceUrl.spec.d.ts +0 -1
  123. package/esm/helpers/formatServiceUrl.spec.js +0 -16
  124. package/esm/helpers/getSha256Hex.spec.d.ts +0 -1
  125. package/esm/helpers/getSha256Hex.spec.js +0 -14
  126. package/esm/helpers/getSha256HexNode.spec.d.ts +0 -1
  127. package/esm/helpers/getSha256HexNode.spec.js +0 -8
  128. package/esm/helpers/getURLSearchParams.spec.d.ts +0 -1
  129. package/esm/helpers/getURLSearchParams.spec.js +0 -19
  130. package/esm/helpers/nanosecondToMillisecond.spec.d.ts +0 -1
  131. package/esm/helpers/nanosecondToMillisecond.spec.js +0 -20
  132. package/esm/helpers/splitRobotTopic.spec.d.ts +0 -1
  133. package/esm/helpers/splitRobotTopic.spec.js +0 -51
  134. package/esm/helpers/standardDeviation.spec.d.ts +0 -1
  135. package/esm/helpers/standardDeviation.spec.js +0 -11
  136. package/esm/helpers/websandbox/frame/worker/manager.spec.d.ts +0 -4
  137. package/esm/helpers/websandbox/frame/worker/manager.spec.js +0 -127
  138. package/esm/models/CallsignStatus.d.ts +0 -6
  139. package/esm/models/CallsignStatus.js +0 -7
  140. package/esm/models/Token.spec.d.ts +0 -1
  141. package/esm/models/Token.spec.js +0 -108
  142. package/esm/services/AuthService.spec.d.ts +0 -1
  143. package/esm/services/AuthService.spec.js +0 -163
  144. package/esm/services/CallerService.spec.d.ts +0 -1
  145. package/esm/services/CallerService.spec.js +0 -227
  146. package/esm/services/FunctionService.d.ts +0 -68
  147. package/esm/services/FunctionService.js +0 -99
  148. package/esm/services/PlatformTimeService.spec.d.ts +0 -1
  149. package/esm/services/PlatformTimeService.spec.js +0 -180
  150. package/esm/services/RTPWebRTCService.spec.d.ts +0 -4
  151. package/esm/services/RTPWebRTCService.spec.js +0 -169
  152. package/esm/services/TelemetryService.spec.d.ts +0 -1
  153. package/esm/services/TelemetryService.spec.js +0 -37
@@ -1,68 +0,0 @@
1
- import { RocosError } from '../models/RocosError';
2
- import { BaseServiceAbstract } from './BaseServiceAbstract';
3
- import { IBaseService } from '../models/IBaseService';
4
- import { IExportDataQuery } from '../models/IExportDataQuery';
5
- import { IFunctionConfig } from '../models/IFunctionConfig';
6
- import { IRocosSDKConfig } from '../models/IRocosSDKConfig';
7
- export declare class FunctionService extends BaseServiceAbstract implements IBaseService {
8
- constructor(config: IRocosSDKConfig);
9
- protected getError(e: Error): RocosError;
10
- getStatus(): boolean;
11
- /**
12
- * Export data
13
- *
14
- * @param projectId - Project Id
15
- * @param query - Payload {@link IExportDataQuery}
16
- */
17
- exportJobs(projectId: string, query: IExportDataQuery): Promise<any>;
18
- /**
19
- * Create a function
20
- *
21
- * @param projectId - Project Id
22
- * @param model - Payload {@link IFunctionConfig}
23
- */
24
- create(projectId: string, model: IFunctionConfig): Promise<any>;
25
- /**
26
- * Get a functions
27
- *
28
- * @param projectId - Project Id
29
- */
30
- list(projectId: string): Promise<any>;
31
- /**
32
- * Update a function
33
- *
34
- * @param projectId - Project Id
35
- * @param functionId - Function Id
36
- * @param model - Payload {@link IFunctionConfig}
37
- */
38
- update(projectId: string, functionId: string, model: IFunctionConfig): Promise<any>;
39
- /**
40
- * Get function
41
- *
42
- * @param projectId - Project Id
43
- * @param functionId - Function Id
44
- */
45
- info(projectId: string, functionId: string): Promise<any>;
46
- /**
47
- * Delete function
48
- *
49
- * @param projectId - Project Id
50
- * @param functionId - Function Id
51
- */
52
- delete(projectId: string, functionId: string): Promise<any>;
53
- /**
54
- * Run a function
55
- *
56
- * @param projectId - Project Id
57
- * @param functionId - Function Id
58
- * @param body - Payload
59
- */
60
- run(projectId: string, functionId: string, body?: any): Promise<any>;
61
- /**
62
- * Get function pods
63
- *
64
- * @param projectId - Project Id
65
- * @param functionId - Function Id
66
- */
67
- pods(projectId: string, functionId: string): Promise<any>;
68
- }
@@ -1,103 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FunctionService = void 0;
4
- const api_1 = require("../constants/api");
5
- const RocosError_1 = require("../models/RocosError");
6
- const BaseServiceAbstract_1 = require("./BaseServiceAbstract");
7
- const ExportDataQuery_1 = require("../models/ExportDataQuery");
8
- const RocosLogger_1 = require("../logger/RocosLogger");
9
- const formatServiceUrl_1 = require("../helpers/formatServiceUrl");
10
- class FunctionService extends BaseServiceAbstract_1.BaseServiceAbstract {
11
- constructor(config) {
12
- super(config);
13
- this.logger = RocosLogger_1.RocosLogger.getInstance(`FunctionService(${this.config.url})`);
14
- }
15
- getError(e) {
16
- return new RocosError_1.RocosError(e, RocosError_1.errorCodes.FUNCTION_SERVICE_ERROR);
17
- }
18
- getStatus() {
19
- return true;
20
- }
21
- /**
22
- * Export data
23
- *
24
- * @param projectId - Project Id
25
- * @param query - Payload {@link IExportDataQuery}
26
- */
27
- // TODO: map the response object
28
- async exportJobs(projectId, query) {
29
- return this.callPost((0, formatServiceUrl_1.formatServiceUrl)(api_1.API_PROJECT_EXPORT_URL, { url: this.config.url, projectId }, this.config.insecure), new ExportDataQuery_1.ExportDataQuery(query).toJSON(), `Failed to export data for ${projectId}.`);
30
- }
31
- /**
32
- * Create a function
33
- *
34
- * @param projectId - Project Id
35
- * @param model - Payload {@link IFunctionConfig}
36
- */
37
- // TODO: map the response object
38
- async create(projectId, model) {
39
- return this.callPost((0, formatServiceUrl_1.formatServiceUrl)(api_1.API_PROJECT_FUNCTION_URL, { url: this.config.url, projectId }, this.config.insecure), model, `Failed to create function for ${projectId}.`);
40
- }
41
- /**
42
- * Get a functions
43
- *
44
- * @param projectId - Project Id
45
- */
46
- // TODO: map the response object
47
- async list(projectId) {
48
- return this.callGet((0, formatServiceUrl_1.formatServiceUrl)(api_1.API_PROJECT_FUNCTION_URL, { url: this.config.url, projectId }, this.config.insecure), `Failed to get functions for ${projectId}.`);
49
- }
50
- /**
51
- * Update a function
52
- *
53
- * @param projectId - Project Id
54
- * @param functionId - Function Id
55
- * @param model - Payload {@link IFunctionConfig}
56
- */
57
- // TODO: map the response object
58
- async update(projectId, functionId, model) {
59
- return this.callPut((0, formatServiceUrl_1.formatServiceUrl)(api_1.API_PROJECT_FUNCTION_ID_URL, { url: this.config.url, projectId, functionId }, this.config.insecure), model, `Failed to update function for ${projectId}, functionId ${functionId}.`);
60
- }
61
- /**
62
- * Get function
63
- *
64
- * @param projectId - Project Id
65
- * @param functionId - Function Id
66
- */
67
- // TODO: map the response object
68
- async info(projectId, functionId) {
69
- return this.callGet((0, formatServiceUrl_1.formatServiceUrl)(api_1.API_PROJECT_FUNCTION_ID_URL, { url: this.config.url, projectId, functionId }, this.config.insecure), `Failed to get function for ${projectId}, functionId ${functionId}.`);
70
- }
71
- /**
72
- * Delete function
73
- *
74
- * @param projectId - Project Id
75
- * @param functionId - Function Id
76
- */
77
- // TODO: map the response object
78
- async delete(projectId, functionId) {
79
- return this.callDelete((0, formatServiceUrl_1.formatServiceUrl)(api_1.API_PROJECT_FUNCTION_ID_URL, { url: this.config.url, projectId, functionId }, this.config.insecure), `Failed to delete function for ${projectId}, functionId ${functionId}.`);
80
- }
81
- /**
82
- * Run a function
83
- *
84
- * @param projectId - Project Id
85
- * @param functionId - Function Id
86
- * @param body - Payload
87
- */
88
- // TODO: map the response object
89
- async run(projectId, functionId, body = null) {
90
- return this.callPost((0, formatServiceUrl_1.formatServiceUrl)(api_1.API_PROJECT_FUNCTION_RUN_URL, { url: this.config.url, projectId, functionId }, this.config.insecure), body, `Failed to run function for ${projectId}, functionId ${functionId}.`);
91
- }
92
- /**
93
- * Get function pods
94
- *
95
- * @param projectId - Project Id
96
- * @param functionId - Function Id
97
- */
98
- // TODO: map the response object
99
- async pods(projectId, functionId) {
100
- return this.callGet((0, formatServiceUrl_1.formatServiceUrl)(api_1.API_PROJECT_FUNCTION_POD_URL, { url: this.config.url, projectId, functionId }, this.config.insecure), `Failed to ged function pods for ${projectId}, functionId ${functionId}.`);
101
- }
102
- }
103
- exports.FunctionService = FunctionService;
@@ -1 +0,0 @@
1
- export {};
@@ -1,182 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const PlatformTimeService_1 = require("./PlatformTimeService");
4
- const TimeSyncerService_1 = require("./TimeSyncerService");
5
- const helpers_1 = require("../helpers");
6
- // Subclass PlatformTimeService so that we can test the protected methods
7
- class PlatformtimeServicePublic extends PlatformTimeService_1.PlatFormTimeService {
8
- constructor(timeSyncerService) {
9
- super(timeSyncerService);
10
- }
11
- isReliableServerTime(platformTimeMeasurement) {
12
- return super.isReliableServerTime(platformTimeMeasurement);
13
- }
14
- calculateOffset(platformTimeMeasurement) {
15
- return super.calculateOffset(platformTimeMeasurement);
16
- }
17
- removeLongestAndShortest(platformTimeMeasurement) {
18
- return super.removeLongestAndShortest(platformTimeMeasurement);
19
- }
20
- static getInstance(timeSyncerService) {
21
- const instance = super.getInstance(timeSyncerService);
22
- return instance;
23
- }
24
- }
25
- describe('platformTimeService', () => {
26
- it('should calculate standard deviation correctly', () => {
27
- let numbers = [10, 12, 23, 23, 16, 23, 21, 16];
28
- let stdDev = (0, helpers_1.standardDeviation)(numbers);
29
- expect(Math.abs(stdDev - 4.8989794855664)).toBeLessThan(0.000001);
30
- numbers = [100, 12, 23, 23, 116, 23, 21, 162];
31
- stdDev = (0, helpers_1.standardDeviation)(numbers);
32
- expect(Math.abs(stdDev - 53.702886328394)).toBeLessThan(0.000001);
33
- });
34
- it('should be able to tell reliable server time response', () => {
35
- jest.useFakeTimers();
36
- const p = PlatformtimeServicePublic.getInstance(new TimeSyncerService_1.TimeSyncerService({}));
37
- const mock = {
38
- clientTimeStampEnd: 100,
39
- clientTimeStampStart: 20,
40
- serverTime: {
41
- now: 0,
42
- duration: 0,
43
- },
44
- };
45
- const mocks = [];
46
- mocks.push(mock);
47
- let isReliableServerTime = p.isReliableServerTime(mocks);
48
- expect(isReliableServerTime).toBeTruthy();
49
- for (let i = 0; i < 4; i++) {
50
- mocks.push({ ...mock });
51
- isReliableServerTime = p.isReliableServerTime(mocks);
52
- expect(isReliableServerTime).toBeTruthy();
53
- }
54
- });
55
- it('should be able to tell unreliable server time response', () => {
56
- jest.useFakeTimers();
57
- const p = PlatformtimeServicePublic.getInstance(new TimeSyncerService_1.TimeSyncerService({}));
58
- const mock = {
59
- clientTimeStampEnd: 100,
60
- clientTimeStampStart: 0,
61
- serverTime: {
62
- now: 0,
63
- duration: 0,
64
- },
65
- };
66
- const mocks = [];
67
- let isReliableServerTime = false;
68
- for (let i = 0; i < 5; i++) {
69
- const mockClone = { ...mock };
70
- mockClone.clientTimeStampEnd += i * 60;
71
- mocks.push(mockClone);
72
- }
73
- isReliableServerTime = p.isReliableServerTime(mocks);
74
- expect(isReliableServerTime).toBeTruthy();
75
- for (let i = 0; i < 5; i++) {
76
- const mockClone = { ...mock };
77
- mockClone.clientTimeStampEnd += i * 70;
78
- mocks.push(mockClone);
79
- }
80
- isReliableServerTime = p.isReliableServerTime(mocks);
81
- expect(isReliableServerTime).toBeTruthy();
82
- for (let i = 0; i < 5; i++) {
83
- const mockClone = { ...mock };
84
- mockClone.clientTimeStampEnd += i * 80;
85
- mocks.push(mockClone);
86
- }
87
- isReliableServerTime = p.isReliableServerTime(mocks);
88
- // std dev = 113.13708498985
89
- expect(isReliableServerTime).toBeFalsy();
90
- for (let i = 0; i < 5; i++) {
91
- const mockClone = { ...mock };
92
- mockClone.clientTimeStampEnd += i * 100;
93
- mocks.push(mockClone);
94
- }
95
- isReliableServerTime = p.isReliableServerTime(mocks);
96
- expect(isReliableServerTime).toBeFalsy();
97
- });
98
- it('should be able to remove shortest and longest correctly', () => {
99
- jest.useFakeTimers();
100
- const p = PlatformtimeServicePublic.getInstance(new TimeSyncerService_1.TimeSyncerService({}));
101
- const mock = {
102
- clientTimeStampEnd: 100,
103
- clientTimeStampStart: 0,
104
- serverTime: {
105
- now: 0,
106
- duration: 0,
107
- },
108
- };
109
- const mocks = [];
110
- let mockClone = { ...mock };
111
- mockClone.clientTimeStampEnd = 100;
112
- mocks.push(mockClone);
113
- mockClone = { ...mock };
114
- mockClone.clientTimeStampEnd = 200;
115
- mocks.push(mockClone);
116
- mockClone = { ...mock };
117
- mockClone.clientTimeStampEnd = 500;
118
- mocks.push(mockClone);
119
- mockClone = { ...mock };
120
- mockClone.clientTimeStampEnd = 400;
121
- mocks.push(mockClone);
122
- mockClone = { ...mock };
123
- mockClone.clientTimeStampEnd = 300;
124
- mocks.push(mockClone);
125
- const platformTimeMeasurement = p.removeLongestAndShortest(mocks);
126
- platformTimeMeasurement.forEach((p) => {
127
- expect(p.clientTimeStampEnd).not.toEqual(100);
128
- expect(p.clientTimeStampEnd).not.toEqual(500);
129
- });
130
- });
131
- it('should be able to calculate the offset correctly', () => {
132
- jest.useFakeTimers();
133
- const p = PlatformtimeServicePublic.getInstance(new TimeSyncerService_1.TimeSyncerService({}));
134
- const mock = {
135
- clientTimeStampEnd: 100,
136
- clientTimeStampStart: 0,
137
- serverTime: {
138
- now: 0,
139
- duration: 0,
140
- },
141
- };
142
- const mocks = [];
143
- let mockClone = { ...mock };
144
- mockClone.clientTimeStampEnd = 200;
145
- mocks.push(mockClone);
146
- mockClone = { ...mock };
147
- mockClone.clientTimeStampEnd = 500;
148
- mocks.push(mockClone);
149
- mockClone = { ...mock };
150
- mockClone.clientTimeStampEnd = 400;
151
- mocks.push(mockClone);
152
- const offset = p.calculateOffset(mocks);
153
- // (200-(200)/2 + 500 - (500)/2 + 400 - (400)/2)/3 = 183.333333333, round to 183
154
- expect(offset).toEqual(183);
155
- });
156
- it('should be able to filter where service time is not provided', () => {
157
- jest.useFakeTimers();
158
- const p = PlatformtimeServicePublic.getInstance(new TimeSyncerService_1.TimeSyncerService({}));
159
- const mock = {
160
- clientTimeStampEnd: 100,
161
- clientTimeStampStart: 0,
162
- serverTime: {
163
- now: 0,
164
- duration: 0,
165
- },
166
- };
167
- const mocks = [];
168
- let mockClone = { ...mock };
169
- mockClone.clientTimeStampEnd = 200;
170
- mockClone.serverTime = undefined;
171
- mocks.push(mockClone);
172
- mockClone = { ...mock };
173
- mockClone.clientTimeStampEnd = 500;
174
- mocks.push(mockClone);
175
- mockClone = { ...mock };
176
- mockClone.clientTimeStampEnd = 400;
177
- mocks.push(mockClone);
178
- const offset = p.calculateOffset(mocks);
179
- // (500 - (500)/2 + 400 - (400)/2)/2 = 225
180
- expect(offset).toEqual(225);
181
- });
182
- });
@@ -1,4 +0,0 @@
1
- /**
2
- * @jest-environment jsdom
3
- */
4
- export {};
@@ -1,171 +0,0 @@
1
- "use strict";
2
- /**
3
- * @jest-environment jsdom
4
- */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const rxjs_1 = require("rxjs");
7
- const RTPWebRTCService_1 = require("./RTPWebRTCService");
8
- class WebRTCMockHelper {
9
- constructor() {
10
- this.dataChannel = {
11
- label: 'submanager',
12
- onopen: () => void 0,
13
- onclose: () => void 0,
14
- onmessage: (e) => void 0,
15
- send: this.sendMessage.bind(this),
16
- close: this.close.bind(this),
17
- };
18
- this.connection = {
19
- ontrack: (event) => void 0,
20
- oniceconnectionstatechange: () => void 0,
21
- onicecandidate: async (event) => void 0,
22
- setRemoteDescription: jest.fn(),
23
- iceConnectionState: 'new',
24
- localDescription: null,
25
- createDataChannel: jest.fn().mockReturnValue(this.dataChannel),
26
- addTransceiver: jest.fn(),
27
- createOffer: this.createOffer.bind(this),
28
- setLocalDescription: jest.fn(),
29
- close: this.close.bind(this),
30
- };
31
- this.streams = [];
32
- }
33
- installMocks() {
34
- ;
35
- global.RTCPeerConnection = jest.fn().mockReturnValue(this.connection);
36
- global.RTCSessionDescription = jest.fn();
37
- this.mockFetch();
38
- }
39
- async createOffer() {
40
- await this.connection.onicecandidate({
41
- candidate: null,
42
- });
43
- this.connection.iceConnectionState = 'checking';
44
- this.connection.oniceconnectionstatechange();
45
- this.addTrack('my-stream-1');
46
- this.addTrack('my-stream-2');
47
- this.connection.iceConnectionState = 'connected';
48
- this.connection.oniceconnectionstatechange();
49
- this.dataChannel.onopen();
50
- return {
51
- sdp: 'my-sdp',
52
- type: 'offer',
53
- };
54
- }
55
- addTrack(name) {
56
- const stream = { name, active: true };
57
- this.streams.push(stream);
58
- this.connection.ontrack({
59
- streams: [stream],
60
- });
61
- }
62
- close() {
63
- this.streams.forEach((stream) => {
64
- stream.active = false;
65
- });
66
- this.dataChannel.onclose();
67
- this.connection.iceConnectionState = 'closed';
68
- this.connection.oniceconnectionstatechange();
69
- }
70
- sendMessage(message) {
71
- const { logLevel } = JSON.parse(message);
72
- if (logLevel === 'trace') {
73
- this.dataChannel.onmessage({
74
- data: message,
75
- });
76
- }
77
- }
78
- mockFetch() {
79
- global.fetch = jest.fn().mockImplementation((url) => {
80
- switch (url) {
81
- case 'https://localhost:0/sdp/configs':
82
- return Promise.resolve({
83
- json: () => ({
84
- iceServers: [
85
- {
86
- urls: ['stun:turn.localhost:443'],
87
- },
88
- ],
89
- }),
90
- });
91
- case 'https://localhost:0/sdp':
92
- return Promise.resolve({
93
- json: () => ({
94
- answer: btoa('null'),
95
- }),
96
- });
97
- default:
98
- throw new Error(`Unexpected URL: ${url}`);
99
- }
100
- });
101
- }
102
- }
103
- describe('RTPWebRTCService', () => {
104
- let service;
105
- beforeEach(() => {
106
- service = new RTPWebRTCService_1.RTPWebRTCService({
107
- url: 'localhost',
108
- port: 0,
109
- token: 'test',
110
- });
111
- });
112
- describe('streams$', () => {
113
- it('should emit a stream when a new stream is added', async () => {
114
- // Arrange
115
- new WebRTCMockHelper().installMocks();
116
- const connection = service.createPeerConnection({
117
- projectId: 'my-project',
118
- callsign: 'my-callsign',
119
- logLevel: 'trace',
120
- });
121
- // Act
122
- const streams = await (0, rxjs_1.lastValueFrom)(connection.streams$.pipe((0, rxjs_1.takeUntil)(connection.connect()), (0, rxjs_1.toArray)()));
123
- // Assert
124
- expect(streams).toEqual([
125
- [
126
- {
127
- name: 'my-stream-1',
128
- active: true,
129
- },
130
- ],
131
- [
132
- {
133
- name: 'my-stream-1',
134
- active: true,
135
- },
136
- {
137
- name: 'my-stream-2',
138
- active: true,
139
- },
140
- ],
141
- ]);
142
- });
143
- it('should reset the streams when the connection is disconnected and the streams become inactive', async () => {
144
- // Arrange
145
- new WebRTCMockHelper().installMocks();
146
- const connection = service.createPeerConnection({
147
- projectId: 'my-project',
148
- callsign: 'my-callsign',
149
- logLevel: 'trace',
150
- });
151
- // Act
152
- const streams = await (0, rxjs_1.lastValueFrom)(connection.streams$.pipe((0, rxjs_1.takeUntil)((async () => {
153
- await connection.connect();
154
- connection.disconnect();
155
- await connection.connect();
156
- })()), (0, rxjs_1.toArray)()));
157
- expect(streams).toEqual([
158
- [{ name: 'my-stream-1', active: false }],
159
- [
160
- { name: 'my-stream-1', active: false },
161
- { name: 'my-stream-2', active: false },
162
- ],
163
- [{ name: 'my-stream-1', active: true }],
164
- [
165
- { name: 'my-stream-1', active: true },
166
- { name: 'my-stream-2', active: true },
167
- ],
168
- ]);
169
- });
170
- });
171
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,39 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const models_1 = require("../models");
4
- const rxjs_1 = require("rxjs");
5
- const TelemetryService_1 = require("./TelemetryService");
6
- describe('TelemetryService', () => {
7
- describe('getRobotStatusChanges', () => {
8
- it('should emit unknown to begin with', async () => {
9
- const service = new TelemetryService_1.TelemetryService({ url: '', token: '' });
10
- // Mock 5 heartbeat messages
11
- jest.spyOn(service, 'subscribe').mockReturnValue(rxjs_1.NEVER);
12
- const lastValue = await (0, rxjs_1.lastValueFrom)(service.getRobotStatusChanges('project', 'callsign').pipe((0, rxjs_1.take)(1)));
13
- expect(lastValue).toEqual(models_1.CallsignStatus.UNKNOWN);
14
- });
15
- it('should emit online if the robot emits a heartbeat', async () => {
16
- const service = new TelemetryService_1.TelemetryService({ url: '', token: '' });
17
- // Mock 5 heartbeat messages
18
- jest
19
- .spyOn(service, 'subscribe')
20
- .mockReturnValue((0, rxjs_1.from)([0, 1, 2, 3, 4]).pipe((0, rxjs_1.delay)(100)));
21
- const lastValue = await (0, rxjs_1.lastValueFrom)(service.getRobotStatusChanges('project', 'callsign', 1000, 10).pipe((0, rxjs_1.take)(2)));
22
- expect(lastValue).toEqual(models_1.CallsignStatus.ONLINE);
23
- }, 10000);
24
- it('should emit offline if the robot never emits', async () => {
25
- const service = new TelemetryService_1.TelemetryService({ url: '', token: '' });
26
- // Mock 5 heartbeat messages
27
- jest.spyOn(service, 'subscribe').mockReturnValue(rxjs_1.NEVER);
28
- const lastValue = await (0, rxjs_1.lastValueFrom)(service.getRobotStatusChanges('project', 'callsign', 100, 10).pipe((0, rxjs_1.take)(2)));
29
- expect(lastValue).toEqual(models_1.CallsignStatus.OFFLINE);
30
- });
31
- it('should emit an error if the telemetry errors', async () => {
32
- const service = new TelemetryService_1.TelemetryService({ url: '', token: '' });
33
- // Mock 5 heartbeat messages
34
- jest.spyOn(service, 'subscribe').mockReturnValue((0, rxjs_1.throwError)(() => new Error('test')));
35
- const lastValue = await (0, rxjs_1.lastValueFrom)(service.getRobotStatusChanges('project', 'callsign', 100, 10).pipe((0, rxjs_1.take)(2)));
36
- expect(lastValue).toEqual(models_1.CallsignStatus.ERROR);
37
- });
38
- });
39
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,53 +0,0 @@
1
- import { cleanObject } from "./cleanObject";
2
- describe('cleanObject', () => {
3
- const testObject = {
4
- test1: 'test1',
5
- test2: 'test2',
6
- test3: () => 'test3',
7
- test4: {
8
- test1: 'test1.1',
9
- test5: 'test5',
10
- test6: {
11
- test7: 'test7',
12
- test1: 'test1.2',
13
- test2: 'test2.1',
14
- test8: () => 'test8',
15
- },
16
- test8: () => 'test8',
17
- },
18
- test9: ['test9.1', 'test9.2', () => 'test8'],
19
- test10: [
20
- {
21
- test7: 'test7',
22
- test1: 'test1.2',
23
- test2: 'test2.1',
24
- test8: () => 'test8',
25
- },
26
- {
27
- test8: () => 'test8',
28
- },
29
- ],
30
- };
31
- it('should clean object to values only', () => {
32
- const newObject = cleanObject(testObject);
33
- expect(newObject?.test3).toBeUndefined();
34
- expect(newObject?.test4?.test8).toBeUndefined();
35
- expect(newObject?.test4?.test6?.test8).toBeUndefined();
36
- expect(newObject?.test4?.test5).toEqual('test5');
37
- expect(newObject?.test5).toBeUndefined();
38
- expect(newObject?.test4?.test6?.test1).toEqual('test1.2');
39
- expect(newObject?.test4?.test6?.test2).toEqual('test2.1');
40
- expect(newObject?.test1).toEqual('test1');
41
- expect(newObject?.test2).toEqual('test2');
42
- expect(newObject?.test9).toEqual(expect.arrayContaining(['test9.1', 'test9.2']));
43
- expect(newObject?.test9).toEqual(expect.not.arrayContaining([() => 'test8']));
44
- expect(newObject?.test10).toEqual(expect.arrayContaining([
45
- {
46
- test7: 'test7',
47
- test1: 'test1.2',
48
- test2: 'test2.1',
49
- },
50
- {},
51
- ]));
52
- });
53
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,29 +0,0 @@
1
- import { flattenObject } from './flattenObject';
2
- describe('flattenObject', () => {
3
- const testObject = {
4
- test1: 'test1',
5
- test2: 'test2',
6
- test3: () => 'test3',
7
- test4: {
8
- test1: 'test1.1',
9
- test5: 'test5',
10
- test6: {
11
- test7: 'test7',
12
- test1: 'test1.2',
13
- test2: 'test2.1',
14
- test8: () => 'test8',
15
- },
16
- test8: () => 'test8',
17
- },
18
- };
19
- it('should flatten object to a single level', () => {
20
- const newObject = flattenObject(testObject);
21
- expect(newObject?.test3).toBeUndefined();
22
- expect(newObject?.test4?.test8).toBeUndefined();
23
- expect(newObject?.test4?.test6?.test8).toBeUndefined();
24
- expect(newObject?.test4?.test5).toBeUndefined();
25
- expect(newObject?.test5).toEqual('test5');
26
- expect(newObject?.test1).toEqual('test1.2');
27
- expect(newObject?.test2).toEqual('test2.1');
28
- });
29
- });
@@ -1 +0,0 @@
1
- export {};