@dronedeploy/rocos-js-sdk 4.4.4 → 4.4.5

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 (54) hide show
  1. package/LICENSE +3 -0
  2. package/cjs/api/StreamRegister.d.ts +18 -3
  3. package/cjs/api/StreamRegister.js +71 -38
  4. package/cjs/api/atoms/StreamHeartbeat.js +2 -2
  5. package/cjs/api/streams/telemetry/TelemetryStreamAbstract.d.ts +8 -1
  6. package/cjs/api/streams/telemetry/TelemetryStreamAbstract.js +83 -40
  7. package/cjs/api/streams/webRTCSignalling/WebRTCSignallingStreamAbstract.js +1 -1
  8. package/cjs/constants/api.d.ts +3 -2
  9. package/cjs/constants/api.js +5 -4
  10. package/cjs/constants/identifier.d.ts +1 -0
  11. package/cjs/constants/identifier.js +2 -1
  12. package/cjs/helpers/getUniqueId.js +2 -1
  13. package/cjs/models/callsigns/CallsignsLookup.d.ts +4 -0
  14. package/cjs/models/callsigns/CallsignsLookup.js +19 -0
  15. package/cjs/services/AssetStorageService.js +6 -1
  16. package/cjs/services/BaseServiceAbstract.js +1 -1
  17. package/cjs/services/BaseStreamService.d.ts +12 -1
  18. package/cjs/services/BaseStreamService.js +19 -30
  19. package/cjs/services/EnvironmentService.d.ts +4 -0
  20. package/cjs/services/EnvironmentService.js +5 -1
  21. package/cjs/services/MapService.d.ts +15 -3
  22. package/cjs/services/MapService.js +25 -13
  23. package/cjs/services/SearchService.js +1 -1
  24. package/cjs/services/TargetService.js +2 -2
  25. package/cjs/services/TelemetryService.d.ts +1 -1
  26. package/cjs/services/TelemetryService.js +29 -22
  27. package/cjs/services/WebRTCSignallingService.js +7 -9
  28. package/esm/api/StreamRegister.d.ts +18 -3
  29. package/esm/api/StreamRegister.js +71 -38
  30. package/esm/api/atoms/StreamHeartbeat.js +2 -2
  31. package/esm/api/streams/telemetry/TelemetryStreamAbstract.d.ts +8 -1
  32. package/esm/api/streams/telemetry/TelemetryStreamAbstract.js +84 -41
  33. package/esm/api/streams/webRTCSignalling/WebRTCSignallingStreamAbstract.js +2 -2
  34. package/esm/constants/api.d.ts +3 -2
  35. package/esm/constants/api.js +3 -2
  36. package/esm/constants/identifier.d.ts +1 -0
  37. package/esm/constants/identifier.js +1 -0
  38. package/esm/helpers/getUniqueId.js +2 -1
  39. package/esm/models/callsigns/CallsignsLookup.d.ts +4 -0
  40. package/esm/models/callsigns/CallsignsLookup.js +19 -0
  41. package/esm/services/AssetStorageService.js +6 -1
  42. package/esm/services/BaseServiceAbstract.js +1 -1
  43. package/esm/services/BaseStreamService.d.ts +12 -1
  44. package/esm/services/BaseStreamService.js +19 -30
  45. package/esm/services/EnvironmentService.d.ts +4 -0
  46. package/esm/services/EnvironmentService.js +5 -1
  47. package/esm/services/MapService.d.ts +15 -3
  48. package/esm/services/MapService.js +26 -14
  49. package/esm/services/SearchService.js +2 -2
  50. package/esm/services/TargetService.js +3 -3
  51. package/esm/services/TelemetryService.d.ts +1 -1
  52. package/esm/services/TelemetryService.js +30 -23
  53. package/esm/services/WebRTCSignallingService.js +8 -10
  54. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- import { API_GRAPHS_ASSETS_UPLOAD_URL, API_GRAPHS_ASSETS_URL, API_GRAPHS_TARGETS_URL, API_GRAPHS_TARGET_UPLOAD_URL, } from '../constants/api';
1
+ import { API_GRAPHS_ASSETS_UPLOAD_URL, API_GRAPHS_ASSETS_URL, API_GRAPHS_TARGETS_URL, API_GRAPHS_TARGET_MEDIA_URL, API_GRAPHS_TARGET_UPLOAD_URL, } from '../constants/api';
2
2
  import { RocosError, errorCodes } from '../models';
3
3
  import { BaseServiceAbstract } from './BaseServiceAbstract';
4
4
  import { RocosLogger } from '../logger/RocosLogger';
@@ -53,10 +53,10 @@ export class TargetService extends BaseServiceAbstract {
53
53
  });
54
54
  }
55
55
  async addMedia(projectId, targetId, media) {
56
- await this.callPost(formatServiceUrl(API_GRAPHS_TARGETS_URL, {
56
+ await this.callPut(formatServiceUrl(API_GRAPHS_TARGET_MEDIA_URL, {
57
57
  url: this.config.url,
58
58
  projectId,
59
- targetId,
59
+ targetId: encodeURIComponent(targetId),
60
60
  }, this.config.insecure), media, 'Failed to add media to a target');
61
61
  }
62
62
  }
@@ -46,6 +46,6 @@ export declare class TelemetryService extends BaseStreamService<ITelemetryStream
46
46
  monitorTelemetryWithTimeout(projectId: string, callsign: string, source: string, heartbeatTimeoutMs?: number, intervalMs?: number): Observable<TelemetryMonitorStatus>;
47
47
  protected initStream(stream: ITelemetryStream): Promise<void>;
48
48
  private buildScope;
49
- private createStream;
49
+ private buildStreamConfig;
50
50
  protected getStream(config: ITelemetryStreamConfig): ITelemetryStream;
51
51
  }
@@ -1,5 +1,5 @@
1
1
  import { BehaviorSubject, catchError, combineLatest, defer, distinctUntilChanged, from, interval, map, mergeAll, of, startWith, } from 'rxjs';
2
- import { CallsignStatus, CallsignsLookup, CallsignsLookupType, RocosError, SubscriberStatusEnum, TelemetryMonitorStatus, errorCodes, } from '../models';
2
+ import { CallsignStatus, CallsignsLookup, 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';
@@ -52,20 +52,33 @@ export class TelemetryService extends BaseStreamService {
52
52
  // scope is used as a key to generate unique streams
53
53
  // ideally there should be just one concurrent stream opened
54
54
  const scope = this.buildScope(params, callsignsLookup);
55
- const callsigns = callsignsLookup.lookupValue;
56
55
  const subscriptionParams = {
57
56
  uniqueId: getUniqueId(params.projectId, callsignsLookup, sources, scope),
58
- callsigns: callsignsLookup?.lookupType === CallsignsLookupType.List ? callsignsLookup.lookupValue : [],
57
+ callsigns: callsignsLookup.getCallsigns(),
59
58
  sources,
60
59
  };
61
60
  // `defer` acquires the stream only when subscribed; `finalize` releases it on unsubscribe, error
62
- // and complete — so acquire and release stay balanced on every path.
61
+ // and complete — so acquire and release stay balanced on every path. The registry refcount taken
62
+ // here keeps the stream alive until the finalize, so everything in between is race-free.
63
63
  return defer(() => {
64
- let acquired;
65
- const stream$ = this.createStream(params.projectId, callsignsLookup, sources, scope, (stream) => {
66
- acquired = stream;
64
+ const { stream, isNew, ready, release } = this.acquireStream(IDENTIFIER_NAME_TELEMETRY, this.buildStreamConfig(params.projectId, callsignsLookup, sources, scope));
65
+ try {
67
66
  stream.addSubscription(subscriptionParams);
68
- }).then((stream) => {
67
+ if (!isNew) {
68
+ stream.statusStream$.subscribe((msg) => {
69
+ this.streamStatusSubject$.next({
70
+ scope,
71
+ status: msg,
72
+ });
73
+ });
74
+ }
75
+ }
76
+ catch (e) {
77
+ // finalize below is not wired up yet, so a throw here must hand the refcount back itself.
78
+ release();
79
+ throw e;
80
+ }
81
+ const messages$ = ready.then(() => {
69
82
  if (!this.statusSubscription) {
70
83
  this.statusSubscription = stream.statusStream$.subscribe((msg) => {
71
84
  this.status = msg === SubscriberStatusEnum.STOPPED || msg === SubscriberStatusEnum.ALIVE;
@@ -74,9 +87,12 @@ export class TelemetryService extends BaseStreamService {
74
87
  }
75
88
  return from(stream.messageStream$);
76
89
  });
77
- return from(stream$).pipe(mergeAll(), filter((message) => {
78
- return callsigns.includes(message.callsign) && sources.includes(message.source);
79
- }), finalize(() => acquired?.removeSubscription(subscriptionParams, params.terminateReceiverGroupOnUnsubscribe)));
90
+ return from(messages$).pipe(mergeAll(), filter((message) => {
91
+ return callsignsLookup.includesCallsign(message.callsign) && sources.includes(message.source);
92
+ }), finalize(() => {
93
+ void stream.removeSubscription(subscriptionParams, params.terminateReceiverGroupOnUnsubscribe);
94
+ release();
95
+ }));
80
96
  });
81
97
  }
82
98
  /**
@@ -156,8 +172,8 @@ export class TelemetryService extends BaseStreamService {
156
172
  return `${params.projectId}-default-${flattenCallsignsLookup(callsignsLookup).join()}`;
157
173
  return `${params.projectId}-default`;
158
174
  }
159
- async createStream(projectId, callsignsLookup, sources, scope, onAcquire) {
160
- const newStream = await this.createStreamFromConfig(IDENTIFIER_NAME_TELEMETRY, {
175
+ buildStreamConfig(projectId, callsignsLookup, sources, scope) {
176
+ return {
161
177
  url: this.config.url,
162
178
  projectId,
163
179
  callsignsLookup,
@@ -169,16 +185,7 @@ export class TelemetryService extends BaseStreamService {
169
185
  insecure: this.config.insecure,
170
186
  transport: this.config.transport,
171
187
  fetch: this.config.fetch,
172
- }, onAcquire);
173
- if (!newStream.isNew) {
174
- newStream.stream.statusStream$.subscribe((msg) => {
175
- this.streamStatusSubject$.next({
176
- scope,
177
- status: msg,
178
- });
179
- });
180
- }
181
- return newStream.stream;
188
+ };
182
189
  }
183
190
  getStream(config) {
184
191
  if (config.transport === 'grpc-web') {
@@ -1,4 +1,4 @@
1
- import { IDENTIFIER_NAME_COMMAND } from '../constants/identifier';
1
+ import { IDENTIFIER_NAME_WEBRTC_SIGNALLING } from '../constants/identifier';
2
2
  import { RocosLogger } from '../logger/RocosLogger';
3
3
  import { RocosStore } from '../store/RocosStore';
4
4
  import { StreamRegister } from '../api/StreamRegister';
@@ -34,11 +34,9 @@ export class WebRTCSignallingService {
34
34
  }
35
35
  async createSignallingStream() {
36
36
  const scope = 'default';
37
- const identifier = StreamRegister.getIdentifier(IDENTIFIER_NAME_COMMAND, scope);
38
- const streamRegister = StreamRegister.getInstance();
39
- let stream = streamRegister.getStream(identifier);
40
- if (!stream) {
41
- stream = this.getStream({
37
+ const identifier = StreamRegister.getIdentifier(IDENTIFIER_NAME_WEBRTC_SIGNALLING, scope);
38
+ const { stream, ready } = StreamRegister.getInstance().acquireStream(identifier, () => {
39
+ const newStream = this.getStream({
42
40
  url: this.config.url,
43
41
  token: this.config.token,
44
42
  scope,
@@ -46,13 +44,13 @@ export class WebRTCSignallingService {
46
44
  port: this.config.port,
47
45
  insecure: this.config.insecure,
48
46
  });
49
- stream.statusStream$.subscribe((msg) => {
47
+ newStream.statusStream$.subscribe((msg) => {
50
48
  this.status = msg === SubscriberStatusEnum.STOPPED || msg === SubscriberStatusEnum.ALIVE;
51
49
  this.status$.next(msg);
52
50
  });
53
- streamRegister.addStream(stream);
54
- await this.initStream(stream);
55
- }
51
+ return newStream;
52
+ }, (newStream) => this.initStream(newStream));
53
+ await ready;
56
54
  return stream;
57
55
  }
58
56
  async initStream(stream) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dronedeploy/rocos-js-sdk",
3
- "version": "4.4.4",
3
+ "version": "4.4.5",
4
4
  "description": "Javascript SDK for rocos",
5
5
  "main": "cjs/index.js",
6
6
  "module": "esm/index.js",