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

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 (121) hide show
  1. package/cjs/RocosSDK.d.ts +3 -1
  2. package/cjs/RocosSDK.js +1 -0
  3. package/cjs/api/streams/caller/CallerStream.js +5 -2
  4. package/cjs/api/streams/caller/CallerStreamNode.js +2 -1
  5. package/cjs/api/streams/command/CommandStream.js +5 -2
  6. package/cjs/api/streams/command/CommandStreamNode.js +2 -1
  7. package/cjs/api/streams/control/ControlStream.js +5 -2
  8. package/cjs/api/streams/control/ControlStreamAbstract.d.ts +1 -1
  9. package/cjs/api/streams/control/ControlStreamNode.js +2 -1
  10. package/cjs/api/streams/fileAccessor/FileAccessorStream.js +4 -1
  11. package/cjs/api/streams/fileAccessor/FileAccessorStreamNode.js +3 -1
  12. package/cjs/api/streams/search/SearchStream.js +5 -2
  13. package/cjs/api/streams/search/SearchStreamNode.js +2 -1
  14. package/cjs/api/streams/telemetry/TelemetryStream.js +4 -1
  15. package/cjs/api/streams/telemetry/TelemetryStreamAbstract.d.ts +1 -1
  16. package/cjs/api/streams/telemetry/TelemetryStreamNode.js +2 -1
  17. package/cjs/api/streams/webRTCSignalling/WebRTCSignallingStream.js +5 -2
  18. package/cjs/constants/api.d.ts +2 -0
  19. package/cjs/constants/api.js +4 -2
  20. package/cjs/helpers/getUniqueConfigKey.d.ts +6 -2
  21. package/cjs/helpers/getUniqueConfigKey.js +7 -2
  22. package/cjs/services/ProfileService.d.ts +23 -0
  23. package/cjs/services/ProfileService.js +28 -0
  24. package/cjs/services/RTPWebRTCService.d.ts +1 -1
  25. package/cjs/services/RTPWebRTCService.js +4 -2
  26. package/cjs/store/RocosStore.d.ts +1 -2
  27. package/esm/RocosSDK.d.ts +3 -1
  28. package/esm/RocosSDK.js +1 -0
  29. package/esm/api/streams/caller/CallerStream.js +5 -2
  30. package/esm/api/streams/caller/CallerStreamNode.js +2 -1
  31. package/esm/api/streams/command/CommandStream.js +5 -2
  32. package/esm/api/streams/command/CommandStreamNode.js +2 -1
  33. package/esm/api/streams/control/ControlStream.js +5 -2
  34. package/esm/api/streams/control/ControlStreamAbstract.d.ts +1 -1
  35. package/esm/api/streams/control/ControlStreamNode.js +2 -1
  36. package/esm/api/streams/fileAccessor/FileAccessorStream.js +4 -1
  37. package/esm/api/streams/fileAccessor/FileAccessorStreamNode.js +3 -1
  38. package/esm/api/streams/search/SearchStream.js +5 -2
  39. package/esm/api/streams/search/SearchStreamNode.js +2 -1
  40. package/esm/api/streams/telemetry/TelemetryStream.js +4 -1
  41. package/esm/api/streams/telemetry/TelemetryStreamAbstract.d.ts +1 -1
  42. package/esm/api/streams/telemetry/TelemetryStreamNode.js +2 -1
  43. package/esm/api/streams/webRTCSignalling/WebRTCSignallingStream.js +5 -2
  44. package/esm/constants/api.d.ts +2 -0
  45. package/esm/constants/api.js +2 -0
  46. package/esm/helpers/getUniqueConfigKey.d.ts +6 -2
  47. package/esm/helpers/getUniqueConfigKey.js +7 -2
  48. package/esm/services/ProfileService.d.ts +23 -0
  49. package/esm/services/ProfileService.js +29 -1
  50. package/esm/services/RTPWebRTCService.d.ts +1 -1
  51. package/esm/services/RTPWebRTCService.js +4 -2
  52. package/esm/store/RocosStore.d.ts +1 -2
  53. package/package.json +1 -1
  54. package/cjs/helpers/cleanObject.spec.d.ts +0 -1
  55. package/cjs/helpers/cleanObject.spec.js +0 -55
  56. package/cjs/helpers/flattenObject.spec.d.ts +0 -1
  57. package/cjs/helpers/flattenObject.spec.js +0 -31
  58. package/cjs/helpers/flattenOneOf.spec.d.ts +0 -1
  59. package/cjs/helpers/flattenOneOf.spec.js +0 -159
  60. package/cjs/helpers/formatServiceUrl.spec.d.ts +0 -1
  61. package/cjs/helpers/formatServiceUrl.spec.js +0 -18
  62. package/cjs/helpers/getSha256Hex.spec.d.ts +0 -1
  63. package/cjs/helpers/getSha256Hex.spec.js +0 -19
  64. package/cjs/helpers/getSha256HexNode.spec.d.ts +0 -1
  65. package/cjs/helpers/getSha256HexNode.spec.js +0 -10
  66. package/cjs/helpers/getURLSearchParams.spec.d.ts +0 -1
  67. package/cjs/helpers/getURLSearchParams.spec.js +0 -21
  68. package/cjs/helpers/nanosecondToMillisecond.spec.d.ts +0 -1
  69. package/cjs/helpers/nanosecondToMillisecond.spec.js +0 -22
  70. package/cjs/helpers/splitRobotTopic.spec.d.ts +0 -1
  71. package/cjs/helpers/splitRobotTopic.spec.js +0 -53
  72. package/cjs/helpers/standardDeviation.spec.d.ts +0 -1
  73. package/cjs/helpers/standardDeviation.spec.js +0 -13
  74. package/cjs/helpers/websandbox/frame/worker/manager.spec.d.ts +0 -4
  75. package/cjs/helpers/websandbox/frame/worker/manager.spec.js +0 -132
  76. package/cjs/models/Token.spec.d.ts +0 -1
  77. package/cjs/models/Token.spec.js +0 -110
  78. package/cjs/services/AuthService.spec.d.ts +0 -1
  79. package/cjs/services/AuthService.spec.js +0 -165
  80. package/cjs/services/CallerService.spec.d.ts +0 -1
  81. package/cjs/services/CallerService.spec.js +0 -229
  82. package/cjs/services/PlatformTimeService.spec.d.ts +0 -1
  83. package/cjs/services/PlatformTimeService.spec.js +0 -182
  84. package/cjs/services/RTPWebRTCService.spec.d.ts +0 -4
  85. package/cjs/services/RTPWebRTCService.spec.js +0 -171
  86. package/cjs/services/TelemetryService.spec.d.ts +0 -1
  87. package/cjs/services/TelemetryService.spec.js +0 -39
  88. package/esm/helpers/cleanObject.spec.d.ts +0 -1
  89. package/esm/helpers/cleanObject.spec.js +0 -53
  90. package/esm/helpers/flattenObject.spec.d.ts +0 -1
  91. package/esm/helpers/flattenObject.spec.js +0 -29
  92. package/esm/helpers/flattenOneOf.spec.d.ts +0 -1
  93. package/esm/helpers/flattenOneOf.spec.js +0 -157
  94. package/esm/helpers/formatServiceUrl.spec.d.ts +0 -1
  95. package/esm/helpers/formatServiceUrl.spec.js +0 -16
  96. package/esm/helpers/getSha256Hex.spec.d.ts +0 -1
  97. package/esm/helpers/getSha256Hex.spec.js +0 -14
  98. package/esm/helpers/getSha256HexNode.spec.d.ts +0 -1
  99. package/esm/helpers/getSha256HexNode.spec.js +0 -8
  100. package/esm/helpers/getURLSearchParams.spec.d.ts +0 -1
  101. package/esm/helpers/getURLSearchParams.spec.js +0 -19
  102. package/esm/helpers/nanosecondToMillisecond.spec.d.ts +0 -1
  103. package/esm/helpers/nanosecondToMillisecond.spec.js +0 -20
  104. package/esm/helpers/splitRobotTopic.spec.d.ts +0 -1
  105. package/esm/helpers/splitRobotTopic.spec.js +0 -51
  106. package/esm/helpers/standardDeviation.spec.d.ts +0 -1
  107. package/esm/helpers/standardDeviation.spec.js +0 -11
  108. package/esm/helpers/websandbox/frame/worker/manager.spec.d.ts +0 -4
  109. package/esm/helpers/websandbox/frame/worker/manager.spec.js +0 -127
  110. package/esm/models/Token.spec.d.ts +0 -1
  111. package/esm/models/Token.spec.js +0 -108
  112. package/esm/services/AuthService.spec.d.ts +0 -1
  113. package/esm/services/AuthService.spec.js +0 -163
  114. package/esm/services/CallerService.spec.d.ts +0 -1
  115. package/esm/services/CallerService.spec.js +0 -227
  116. package/esm/services/PlatformTimeService.spec.d.ts +0 -1
  117. package/esm/services/PlatformTimeService.spec.js +0 -180
  118. package/esm/services/RTPWebRTCService.spec.d.ts +0 -4
  119. package/esm/services/RTPWebRTCService.spec.js +0 -169
  120. package/esm/services/TelemetryService.spec.d.ts +0 -1
  121. package/esm/services/TelemetryService.spec.js +0 -37
@@ -1,227 +0,0 @@
1
- import { AckStatus, ResultStatus, Stage, UIDVersion, } from '../models';
2
- import { concatMap, delay, from, of } from 'rxjs';
3
- import { CallerService } from './CallerService';
4
- import { TestScheduler } from 'rxjs/testing';
5
- const makeCallerMessage = (responses) => ({
6
- responses: {
7
- responses: responses ?? [],
8
- },
9
- });
10
- const makeCallerChunkedMessage = (responses) => {
11
- return responses.map((response, index) => {
12
- if ('return' in response) {
13
- throw new Error('Cannot create chunked message with return');
14
- }
15
- const chunk = response;
16
- chunk.chunkIndex = index;
17
- chunk.chunkCount = responses.length;
18
- chunk.header = {
19
- created: '0',
20
- meta: {},
21
- };
22
- return {
23
- chunks: {
24
- chunks: [chunk],
25
- },
26
- };
27
- });
28
- };
29
- const uid = {
30
- hash: 'hash',
31
- version: UIDVersion.HEADER_HASH_RAND,
32
- };
33
- const ack = (id) => ({
34
- uid,
35
- ack: {
36
- status: AckStatus.PROGRESS,
37
- message: id,
38
- stage: Stage.AGENT,
39
- },
40
- });
41
- const ret = (id) => {
42
- const encoder = new TextEncoder();
43
- const payload = encoder.encode(JSON.stringify({ id }));
44
- return {
45
- uid,
46
- return: {
47
- payload,
48
- },
49
- };
50
- };
51
- const chunkRet = (payload) => {
52
- const array = new TextEncoder().encode(payload);
53
- return {
54
- uid,
55
- payload: array,
56
- chunkIndex: 0,
57
- chunkCount: 1,
58
- header: {
59
- created: '0',
60
- meta: {},
61
- },
62
- };
63
- };
64
- const res = (ok) => ({
65
- uid,
66
- result: {
67
- status: ok ? ResultStatus.COMPLETE_SUCCESS : ResultStatus.FATAL,
68
- message: ok ? 'everything is fine' : 'nothing is fine',
69
- },
70
- });
71
- let testScheduler;
72
- let service;
73
- describe('CallerService', () => {
74
- beforeEach(() => {
75
- service = new CallerService({
76
- url: 'http://localhost:8080',
77
- token: 'token',
78
- });
79
- testScheduler = new TestScheduler((actual, expected) => {
80
- expect(actual).toEqual(expected);
81
- });
82
- });
83
- describe('callRaw', () => {
84
- it('should handle a successful call', () => {
85
- // Arrange
86
- jest.spyOn(service, 'invokeRequest').mockImplementation(() => {
87
- return from([
88
- makeCallerMessage([ack('a')]),
89
- makeCallerMessage([ack('b')]),
90
- makeCallerMessage([ack('c'), ret(1)]),
91
- makeCallerMessage([ret(2)]),
92
- makeCallerMessage([ret(3), ret(4)]),
93
- makeCallerMessage([ack('d')]),
94
- makeCallerMessage([ack('e')]),
95
- makeCallerMessage([ack('f')]),
96
- makeCallerMessage([ack('g'), res(true)]),
97
- makeCallerMessage([ack('h')]),
98
- ]).pipe(concatMap((item) => of(item).pipe(delay(1))));
99
- });
100
- testScheduler.run(({ expectObservable }) => {
101
- // Act
102
- const call = service.call({
103
- callsign: 'callsign',
104
- projectId: 'project',
105
- source: '/test',
106
- });
107
- // Assert
108
- const expectedAckMarbles = '-abc--def|';
109
- const expectedRetMarbles = '---ab(cd)|';
110
- const expectedResMarbles = '---------(a|)';
111
- const expectedAckValues = {
112
- a: { stage: Stage.AGENT, status: AckStatus.PROGRESS, message: 'a' },
113
- b: { stage: Stage.AGENT, status: AckStatus.PROGRESS, message: 'b' },
114
- c: { stage: Stage.AGENT, status: AckStatus.PROGRESS, message: 'c' },
115
- d: { stage: Stage.AGENT, status: AckStatus.PROGRESS, message: 'd' },
116
- e: { stage: Stage.AGENT, status: AckStatus.PROGRESS, message: 'e' },
117
- f: { stage: Stage.AGENT, status: AckStatus.PROGRESS, message: 'f' },
118
- };
119
- const expectedReturnValues = {
120
- a: { id: 1 },
121
- b: { id: 2 },
122
- c: { id: 3 },
123
- d: { id: 4 },
124
- };
125
- const expectedResultValues = {
126
- a: { status: ResultStatus.COMPLETE_SUCCESS, message: 'everything is fine' },
127
- };
128
- expectObservable(call.ack$).toBe(expectedAckMarbles, expectedAckValues);
129
- expectObservable(call.return$).toBe(expectedRetMarbles, expectedReturnValues);
130
- expectObservable(call.result$).toBe(expectedResMarbles, expectedResultValues);
131
- });
132
- });
133
- it('should handle a failed call', () => {
134
- // Arrange
135
- jest.spyOn(service, 'invokeRequest').mockImplementation(() => {
136
- return from([
137
- makeCallerMessage([ack('a')]),
138
- makeCallerMessage([ack('b')]),
139
- makeCallerMessage([ack('c'), ret(1)]),
140
- makeCallerMessage([ret(2)]),
141
- makeCallerMessage([ret(3), ret(4)]),
142
- makeCallerMessage([ack('d')]),
143
- makeCallerMessage([ack('e')]),
144
- makeCallerMessage([ack('f')]),
145
- makeCallerMessage([ack('g'), res(false)]),
146
- makeCallerMessage([ack('h')]),
147
- ]).pipe(concatMap((item) => of(item).pipe(delay(1))));
148
- });
149
- testScheduler.run(({ expectObservable }) => {
150
- // Act
151
- const call = service.call({
152
- callsign: 'callsign',
153
- projectId: 'project',
154
- source: '/test',
155
- });
156
- // Assert
157
- const expectedAckMarbles = '-abc--def#';
158
- const expectedRetMarbles = '---ab(cd)#';
159
- const expectedResMarbles = '---------(a|)';
160
- const expectedAckValues = {
161
- a: { stage: Stage.AGENT, status: AckStatus.PROGRESS, message: 'a' },
162
- b: { stage: Stage.AGENT, status: AckStatus.PROGRESS, message: 'b' },
163
- c: { stage: Stage.AGENT, status: AckStatus.PROGRESS, message: 'c' },
164
- d: { stage: Stage.AGENT, status: AckStatus.PROGRESS, message: 'd' },
165
- e: { stage: Stage.AGENT, status: AckStatus.PROGRESS, message: 'e' },
166
- f: { stage: Stage.AGENT, status: AckStatus.PROGRESS, message: 'f' },
167
- };
168
- const expectedReturnValues = {
169
- a: { id: 1 },
170
- b: { id: 2 },
171
- c: { id: 3 },
172
- d: { id: 4 },
173
- };
174
- const expectedResultValues = {
175
- a: { status: ResultStatus.FATAL, message: 'nothing is fine' },
176
- };
177
- expectObservable(call.ack$).toBe(expectedAckMarbles, expectedAckValues, res(false).result);
178
- expectObservable(call.return$).toBe(expectedRetMarbles, expectedReturnValues, res(false).result);
179
- expectObservable(call.result$).toBe(expectedResMarbles, expectedResultValues);
180
- });
181
- });
182
- it('should handle a successful chunked call', () => {
183
- // Arrange
184
- jest.spyOn(service, 'invokeRequest').mockImplementation(() => {
185
- return from([
186
- ...makeCallerChunkedMessage([
187
- chunkRet('[{"'),
188
- chunkRet('id":1},'),
189
- ack('a'),
190
- chunkRet('{"id":2}'),
191
- ack('b'),
192
- chunkRet(']'),
193
- ]),
194
- makeCallerMessage([ack('c'), ret(3)]),
195
- makeCallerMessage([res(true)]),
196
- ]).pipe(concatMap((item) => of(item).pipe(delay(1))));
197
- });
198
- testScheduler.run(({ expectObservable }) => {
199
- // Act
200
- const call = service.call({
201
- callsign: 'callsign',
202
- projectId: 'project',
203
- source: '/test',
204
- });
205
- // Assert
206
- const expectedAckMarbles = '---a-b-c|';
207
- const expectedRetMarbles = '------ab|';
208
- const expectedResMarbles = '--------(a|)';
209
- const expectedAckValues = {
210
- a: { stage: Stage.AGENT, status: AckStatus.PROGRESS, message: 'a' },
211
- b: { stage: Stage.AGENT, status: AckStatus.PROGRESS, message: 'b' },
212
- c: { stage: Stage.AGENT, status: AckStatus.PROGRESS, message: 'c' },
213
- };
214
- const expectedReturnValues = {
215
- a: [{ id: 1 }, { id: 2 }],
216
- b: { id: 3 },
217
- };
218
- const expectedResultValues = {
219
- a: { status: ResultStatus.COMPLETE_SUCCESS, message: 'everything is fine' },
220
- };
221
- expectObservable(call.ack$).toBe(expectedAckMarbles, expectedAckValues);
222
- expectObservable(call.return$).toBe(expectedRetMarbles, expectedReturnValues);
223
- expectObservable(call.result$).toBe(expectedResMarbles, expectedResultValues);
224
- });
225
- });
226
- });
227
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,180 +0,0 @@
1
- import { PlatFormTimeService } from "./PlatformTimeService";
2
- import { TimeSyncerService } from "./TimeSyncerService";
3
- import { standardDeviation } from "../helpers";
4
- // Subclass PlatformTimeService so that we can test the protected methods
5
- class PlatformtimeServicePublic extends PlatFormTimeService {
6
- constructor(timeSyncerService) {
7
- super(timeSyncerService);
8
- }
9
- isReliableServerTime(platformTimeMeasurement) {
10
- return super.isReliableServerTime(platformTimeMeasurement);
11
- }
12
- calculateOffset(platformTimeMeasurement) {
13
- return super.calculateOffset(platformTimeMeasurement);
14
- }
15
- removeLongestAndShortest(platformTimeMeasurement) {
16
- return super.removeLongestAndShortest(platformTimeMeasurement);
17
- }
18
- static getInstance(timeSyncerService) {
19
- const instance = super.getInstance(timeSyncerService);
20
- return instance;
21
- }
22
- }
23
- describe('platformTimeService', () => {
24
- it('should calculate standard deviation correctly', () => {
25
- let numbers = [10, 12, 23, 23, 16, 23, 21, 16];
26
- let stdDev = standardDeviation(numbers);
27
- expect(Math.abs(stdDev - 4.8989794855664)).toBeLessThan(0.000001);
28
- numbers = [100, 12, 23, 23, 116, 23, 21, 162];
29
- stdDev = standardDeviation(numbers);
30
- expect(Math.abs(stdDev - 53.702886328394)).toBeLessThan(0.000001);
31
- });
32
- it('should be able to tell reliable server time response', () => {
33
- jest.useFakeTimers();
34
- const p = PlatformtimeServicePublic.getInstance(new TimeSyncerService({}));
35
- const mock = {
36
- clientTimeStampEnd: 100,
37
- clientTimeStampStart: 20,
38
- serverTime: {
39
- now: 0,
40
- duration: 0,
41
- },
42
- };
43
- const mocks = [];
44
- mocks.push(mock);
45
- let isReliableServerTime = p.isReliableServerTime(mocks);
46
- expect(isReliableServerTime).toBeTruthy();
47
- for (let i = 0; i < 4; i++) {
48
- mocks.push({ ...mock });
49
- isReliableServerTime = p.isReliableServerTime(mocks);
50
- expect(isReliableServerTime).toBeTruthy();
51
- }
52
- });
53
- it('should be able to tell unreliable server time response', () => {
54
- jest.useFakeTimers();
55
- const p = PlatformtimeServicePublic.getInstance(new TimeSyncerService({}));
56
- const mock = {
57
- clientTimeStampEnd: 100,
58
- clientTimeStampStart: 0,
59
- serverTime: {
60
- now: 0,
61
- duration: 0,
62
- },
63
- };
64
- const mocks = [];
65
- let isReliableServerTime = false;
66
- for (let i = 0; i < 5; i++) {
67
- const mockClone = { ...mock };
68
- mockClone.clientTimeStampEnd += i * 60;
69
- mocks.push(mockClone);
70
- }
71
- isReliableServerTime = p.isReliableServerTime(mocks);
72
- expect(isReliableServerTime).toBeTruthy();
73
- for (let i = 0; i < 5; i++) {
74
- const mockClone = { ...mock };
75
- mockClone.clientTimeStampEnd += i * 70;
76
- mocks.push(mockClone);
77
- }
78
- isReliableServerTime = p.isReliableServerTime(mocks);
79
- expect(isReliableServerTime).toBeTruthy();
80
- for (let i = 0; i < 5; i++) {
81
- const mockClone = { ...mock };
82
- mockClone.clientTimeStampEnd += i * 80;
83
- mocks.push(mockClone);
84
- }
85
- isReliableServerTime = p.isReliableServerTime(mocks);
86
- // std dev = 113.13708498985
87
- expect(isReliableServerTime).toBeFalsy();
88
- for (let i = 0; i < 5; i++) {
89
- const mockClone = { ...mock };
90
- mockClone.clientTimeStampEnd += i * 100;
91
- mocks.push(mockClone);
92
- }
93
- isReliableServerTime = p.isReliableServerTime(mocks);
94
- expect(isReliableServerTime).toBeFalsy();
95
- });
96
- it('should be able to remove shortest and longest correctly', () => {
97
- jest.useFakeTimers();
98
- const p = PlatformtimeServicePublic.getInstance(new TimeSyncerService({}));
99
- const mock = {
100
- clientTimeStampEnd: 100,
101
- clientTimeStampStart: 0,
102
- serverTime: {
103
- now: 0,
104
- duration: 0,
105
- },
106
- };
107
- const mocks = [];
108
- let mockClone = { ...mock };
109
- mockClone.clientTimeStampEnd = 100;
110
- mocks.push(mockClone);
111
- mockClone = { ...mock };
112
- mockClone.clientTimeStampEnd = 200;
113
- mocks.push(mockClone);
114
- mockClone = { ...mock };
115
- mockClone.clientTimeStampEnd = 500;
116
- mocks.push(mockClone);
117
- mockClone = { ...mock };
118
- mockClone.clientTimeStampEnd = 400;
119
- mocks.push(mockClone);
120
- mockClone = { ...mock };
121
- mockClone.clientTimeStampEnd = 300;
122
- mocks.push(mockClone);
123
- const platformTimeMeasurement = p.removeLongestAndShortest(mocks);
124
- platformTimeMeasurement.forEach((p) => {
125
- expect(p.clientTimeStampEnd).not.toEqual(100);
126
- expect(p.clientTimeStampEnd).not.toEqual(500);
127
- });
128
- });
129
- it('should be able to calculate the offset correctly', () => {
130
- jest.useFakeTimers();
131
- const p = PlatformtimeServicePublic.getInstance(new TimeSyncerService({}));
132
- const mock = {
133
- clientTimeStampEnd: 100,
134
- clientTimeStampStart: 0,
135
- serverTime: {
136
- now: 0,
137
- duration: 0,
138
- },
139
- };
140
- const mocks = [];
141
- let mockClone = { ...mock };
142
- mockClone.clientTimeStampEnd = 200;
143
- mocks.push(mockClone);
144
- mockClone = { ...mock };
145
- mockClone.clientTimeStampEnd = 500;
146
- mocks.push(mockClone);
147
- mockClone = { ...mock };
148
- mockClone.clientTimeStampEnd = 400;
149
- mocks.push(mockClone);
150
- const offset = p.calculateOffset(mocks);
151
- // (200-(200)/2 + 500 - (500)/2 + 400 - (400)/2)/3 = 183.333333333, round to 183
152
- expect(offset).toEqual(183);
153
- });
154
- it('should be able to filter where service time is not provided', () => {
155
- jest.useFakeTimers();
156
- const p = PlatformtimeServicePublic.getInstance(new TimeSyncerService({}));
157
- const mock = {
158
- clientTimeStampEnd: 100,
159
- clientTimeStampStart: 0,
160
- serverTime: {
161
- now: 0,
162
- duration: 0,
163
- },
164
- };
165
- const mocks = [];
166
- let mockClone = { ...mock };
167
- mockClone.clientTimeStampEnd = 200;
168
- mockClone.serverTime = undefined;
169
- mocks.push(mockClone);
170
- mockClone = { ...mock };
171
- mockClone.clientTimeStampEnd = 500;
172
- mocks.push(mockClone);
173
- mockClone = { ...mock };
174
- mockClone.clientTimeStampEnd = 400;
175
- mocks.push(mockClone);
176
- const offset = p.calculateOffset(mocks);
177
- // (500 - (500)/2 + 400 - (400)/2)/2 = 225
178
- expect(offset).toEqual(225);
179
- });
180
- });
@@ -1,4 +0,0 @@
1
- /**
2
- * @jest-environment jsdom
3
- */
4
- export {};
@@ -1,169 +0,0 @@
1
- /**
2
- * @jest-environment jsdom
3
- */
4
- import { lastValueFrom, takeUntil, toArray } from 'rxjs';
5
- import { RTPWebRTCService } from './RTPWebRTCService';
6
- class WebRTCMockHelper {
7
- constructor() {
8
- this.dataChannel = {
9
- label: 'submanager',
10
- onopen: () => void 0,
11
- onclose: () => void 0,
12
- onmessage: (e) => void 0,
13
- send: this.sendMessage.bind(this),
14
- close: this.close.bind(this),
15
- };
16
- this.connection = {
17
- ontrack: (event) => void 0,
18
- oniceconnectionstatechange: () => void 0,
19
- onicecandidate: async (event) => void 0,
20
- setRemoteDescription: jest.fn(),
21
- iceConnectionState: 'new',
22
- localDescription: null,
23
- createDataChannel: jest.fn().mockReturnValue(this.dataChannel),
24
- addTransceiver: jest.fn(),
25
- createOffer: this.createOffer.bind(this),
26
- setLocalDescription: jest.fn(),
27
- close: this.close.bind(this),
28
- };
29
- this.streams = [];
30
- }
31
- installMocks() {
32
- ;
33
- global.RTCPeerConnection = jest.fn().mockReturnValue(this.connection);
34
- global.RTCSessionDescription = jest.fn();
35
- this.mockFetch();
36
- }
37
- async createOffer() {
38
- await this.connection.onicecandidate({
39
- candidate: null,
40
- });
41
- this.connection.iceConnectionState = 'checking';
42
- this.connection.oniceconnectionstatechange();
43
- this.addTrack('my-stream-1');
44
- this.addTrack('my-stream-2');
45
- this.connection.iceConnectionState = 'connected';
46
- this.connection.oniceconnectionstatechange();
47
- this.dataChannel.onopen();
48
- return {
49
- sdp: 'my-sdp',
50
- type: 'offer',
51
- };
52
- }
53
- addTrack(name) {
54
- const stream = { name, active: true };
55
- this.streams.push(stream);
56
- this.connection.ontrack({
57
- streams: [stream],
58
- });
59
- }
60
- close() {
61
- this.streams.forEach((stream) => {
62
- stream.active = false;
63
- });
64
- this.dataChannel.onclose();
65
- this.connection.iceConnectionState = 'closed';
66
- this.connection.oniceconnectionstatechange();
67
- }
68
- sendMessage(message) {
69
- const { logLevel } = JSON.parse(message);
70
- if (logLevel === 'trace') {
71
- this.dataChannel.onmessage({
72
- data: message,
73
- });
74
- }
75
- }
76
- mockFetch() {
77
- global.fetch = jest.fn().mockImplementation((url) => {
78
- switch (url) {
79
- case 'https://localhost:0/sdp/configs':
80
- return Promise.resolve({
81
- json: () => ({
82
- iceServers: [
83
- {
84
- urls: ['stun:turn.localhost:443'],
85
- },
86
- ],
87
- }),
88
- });
89
- case 'https://localhost:0/sdp':
90
- return Promise.resolve({
91
- json: () => ({
92
- answer: btoa('null'),
93
- }),
94
- });
95
- default:
96
- throw new Error(`Unexpected URL: ${url}`);
97
- }
98
- });
99
- }
100
- }
101
- describe('RTPWebRTCService', () => {
102
- let service;
103
- beforeEach(() => {
104
- service = new RTPWebRTCService({
105
- url: 'localhost',
106
- port: 0,
107
- token: 'test',
108
- });
109
- });
110
- describe('streams$', () => {
111
- it('should emit a stream when a new stream is added', async () => {
112
- // Arrange
113
- new WebRTCMockHelper().installMocks();
114
- const connection = service.createPeerConnection({
115
- projectId: 'my-project',
116
- callsign: 'my-callsign',
117
- logLevel: 'trace',
118
- });
119
- // Act
120
- const streams = await lastValueFrom(connection.streams$.pipe(takeUntil(connection.connect()), toArray()));
121
- // Assert
122
- expect(streams).toEqual([
123
- [
124
- {
125
- name: 'my-stream-1',
126
- active: true,
127
- },
128
- ],
129
- [
130
- {
131
- name: 'my-stream-1',
132
- active: true,
133
- },
134
- {
135
- name: 'my-stream-2',
136
- active: true,
137
- },
138
- ],
139
- ]);
140
- });
141
- it('should reset the streams when the connection is disconnected and the streams become inactive', async () => {
142
- // Arrange
143
- new WebRTCMockHelper().installMocks();
144
- const connection = service.createPeerConnection({
145
- projectId: 'my-project',
146
- callsign: 'my-callsign',
147
- logLevel: 'trace',
148
- });
149
- // Act
150
- const streams = await lastValueFrom(connection.streams$.pipe(takeUntil((async () => {
151
- await connection.connect();
152
- connection.disconnect();
153
- await connection.connect();
154
- })()), toArray()));
155
- expect(streams).toEqual([
156
- [{ name: 'my-stream-1', active: false }],
157
- [
158
- { name: 'my-stream-1', active: false },
159
- { name: 'my-stream-2', active: false },
160
- ],
161
- [{ name: 'my-stream-1', active: true }],
162
- [
163
- { name: 'my-stream-1', active: true },
164
- { name: 'my-stream-2', active: true },
165
- ],
166
- ]);
167
- });
168
- });
169
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,37 +0,0 @@
1
- import { CallsignStatus } from '../models';
2
- import { NEVER, delay, from, lastValueFrom, take, throwError } from 'rxjs';
3
- import { TelemetryService } from './TelemetryService';
4
- describe('TelemetryService', () => {
5
- describe('getRobotStatusChanges', () => {
6
- it('should emit unknown to begin with', async () => {
7
- const service = new TelemetryService({ url: '', token: '' });
8
- // Mock 5 heartbeat messages
9
- jest.spyOn(service, 'subscribe').mockReturnValue(NEVER);
10
- const lastValue = await lastValueFrom(service.getRobotStatusChanges('project', 'callsign').pipe(take(1)));
11
- expect(lastValue).toEqual(CallsignStatus.UNKNOWN);
12
- });
13
- it('should emit online if the robot emits a heartbeat', async () => {
14
- const service = new TelemetryService({ url: '', token: '' });
15
- // Mock 5 heartbeat messages
16
- jest
17
- .spyOn(service, 'subscribe')
18
- .mockReturnValue(from([0, 1, 2, 3, 4]).pipe(delay(100)));
19
- const lastValue = await lastValueFrom(service.getRobotStatusChanges('project', 'callsign', 1000, 10).pipe(take(2)));
20
- expect(lastValue).toEqual(CallsignStatus.ONLINE);
21
- }, 10000);
22
- it('should emit offline if the robot never emits', async () => {
23
- const service = new TelemetryService({ url: '', token: '' });
24
- // Mock 5 heartbeat messages
25
- jest.spyOn(service, 'subscribe').mockReturnValue(NEVER);
26
- const lastValue = await lastValueFrom(service.getRobotStatusChanges('project', 'callsign', 100, 10).pipe(take(2)));
27
- expect(lastValue).toEqual(CallsignStatus.OFFLINE);
28
- });
29
- it('should emit an error if the telemetry errors', async () => {
30
- const service = new TelemetryService({ url: '', token: '' });
31
- // Mock 5 heartbeat messages
32
- jest.spyOn(service, 'subscribe').mockReturnValue(throwError(() => new Error('test')));
33
- const lastValue = await lastValueFrom(service.getRobotStatusChanges('project', 'callsign', 100, 10).pipe(take(2)));
34
- expect(lastValue).toEqual(CallsignStatus.ERROR);
35
- });
36
- });
37
- });