@shapediver/viewer.session-engine.session-engine 2.7.9 → 2.8.0
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.
- package/dist/implementation/OutputLoader.d.ts.map +1 -1
- package/dist/implementation/OutputLoader.js +2 -3
- package/dist/implementation/OutputLoader.js.map +1 -1
- package/dist/implementation/SessionEngine.d.ts +2 -0
- package/dist/implementation/SessionEngine.d.ts.map +1 -1
- package/dist/implementation/SessionEngine.js +263 -321
- package/dist/implementation/SessionEngine.js.map +1 -1
- package/dist/implementation/dto/Export.d.ts.map +1 -1
- package/dist/implementation/dto/Export.js +7 -10
- package/dist/implementation/dto/Export.js.map +1 -1
- package/dist/implementation/dto/FileParameter.d.ts.map +1 -1
- package/dist/implementation/dto/FileParameter.js +5 -8
- package/dist/implementation/dto/FileParameter.js.map +1 -1
- package/dist/implementation/dto/Output.d.ts.map +1 -1
- package/dist/implementation/dto/Output.js +4 -5
- package/dist/implementation/dto/Output.js.map +1 -1
- package/dist/implementation/dto/Parameter.d.ts.map +1 -1
- package/dist/implementation/dto/Parameter.js +32 -53
- package/dist/implementation/dto/Parameter.js.map +1 -1
- package/package.json +9 -10
- package/src/implementation/OutputLoader.ts +2 -3
- package/src/implementation/SessionEngine.ts +101 -143
- package/src/implementation/dto/Export.ts +8 -10
- package/src/implementation/dto/FileParameter.ts +6 -9
- package/src/implementation/dto/Output.ts +5 -6
- package/src/implementation/dto/Parameter.ts +33 -54
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { HttpClient, HttpResponse, PerformanceEvaluator, UuidGenerator, SystemInfo, Logger, LOGGING_TOPIC, ShapeDiverViewerSessionError, ShapeDiverViewerError, Converter, SettingsEngine, EVENTTYPE, EventEngine, StateEngine, ShapeDiverViewerSettingsError } from '@shapediver/viewer.shared.services'
|
|
1
|
+
import { HttpClient, HttpResponse, PerformanceEvaluator, UuidGenerator, SystemInfo, Logger, ShapeDiverViewerSessionError, ShapeDiverViewerError, Converter, SettingsEngine, EVENTTYPE, EventEngine, StateEngine, ShapeDiverViewerSettingsError } from '@shapediver/viewer.shared.services'
|
|
3
2
|
|
|
4
3
|
import { OutputDelayException } from './OutputDelayException'
|
|
5
4
|
import { OutputLoader } from './OutputLoader'
|
|
@@ -25,25 +24,25 @@ import { convert, ISettingsV3_3, latestVersion, validate, versions } from '@shap
|
|
|
25
24
|
export class SessionEngine implements ISessionEngine {
|
|
26
25
|
// #region Properties (40)
|
|
27
26
|
|
|
28
|
-
private readonly _converter: Converter =
|
|
29
|
-
private readonly _eventEngine =
|
|
27
|
+
private readonly _converter: Converter = Converter.instance;
|
|
28
|
+
private readonly _eventEngine = EventEngine.instance;
|
|
30
29
|
private readonly _exports: { [key: string]: IExport; } = {};
|
|
31
|
-
private readonly _httpClient: HttpClient =
|
|
30
|
+
private readonly _httpClient: HttpClient = HttpClient.instance;
|
|
32
31
|
private readonly _id: string;
|
|
33
|
-
private readonly _logger: Logger =
|
|
32
|
+
private readonly _logger: Logger = Logger.instance;
|
|
34
33
|
private readonly _modelViewUrl: string;
|
|
35
34
|
private readonly _outputLoader: OutputLoader;
|
|
36
35
|
private readonly _outputs: { [key: string]: IOutput; } = {};
|
|
37
36
|
private readonly _outputsFreeze: { [key: string]: boolean; } = {};
|
|
38
37
|
private readonly _parameterValues: { [key: string]: string; } = {};
|
|
39
38
|
private readonly _parameters: { [key: string]: IParameter<any>; } = {};
|
|
40
|
-
private readonly _performanceEvaluator =
|
|
41
|
-
private readonly _sceneTree: ITree =
|
|
42
|
-
private readonly _sessionEngineId = (
|
|
39
|
+
private readonly _performanceEvaluator = PerformanceEvaluator.instance;
|
|
40
|
+
private readonly _sceneTree: ITree = Tree.instance;
|
|
41
|
+
private readonly _sessionEngineId = (UuidGenerator.instance).create();
|
|
43
42
|
private readonly _settingsEngine: SettingsEngine = new SettingsEngine();
|
|
44
|
-
private readonly _stateEngine: StateEngine =
|
|
43
|
+
private readonly _stateEngine: StateEngine = StateEngine.instance;
|
|
45
44
|
private readonly _ticket: string;
|
|
46
|
-
private readonly _uuidGenerator =
|
|
45
|
+
private readonly _uuidGenerator = UuidGenerator.instance;
|
|
47
46
|
|
|
48
47
|
private _automaticSceneUpdate: boolean = true;
|
|
49
48
|
private _bearerToken?: string;
|
|
@@ -56,7 +55,7 @@ export class SessionEngine implements ISessionEngine {
|
|
|
56
55
|
} = {};
|
|
57
56
|
private _excludeViewports: string[] = [];
|
|
58
57
|
private _headers = {
|
|
59
|
-
"X-ShapeDiver-Origin": (
|
|
58
|
+
"X-ShapeDiver-Origin": (SystemInfo.instance).origin,
|
|
60
59
|
"X-ShapeDiver-SessionEngineId": this._sessionEngineId,
|
|
61
60
|
"X-ShapeDiver-BuildVersion": '',
|
|
62
61
|
"X-ShapeDiver-BuildDate": ''
|
|
@@ -121,7 +120,7 @@ export class SessionEngine implements ISessionEngine {
|
|
|
121
120
|
|
|
122
121
|
public set automaticSceneUpdate(value: boolean) {
|
|
123
122
|
this._automaticSceneUpdate = value;
|
|
124
|
-
value ? this.
|
|
123
|
+
value ? this.addToSceneTree(this._node) : this.removeFromSceneTree(this._node);
|
|
125
124
|
}
|
|
126
125
|
|
|
127
126
|
public get bearerToken(): string | undefined {
|
|
@@ -228,7 +227,6 @@ export class SessionEngine implements ISessionEngine {
|
|
|
228
227
|
// #region Public Methods (22)
|
|
229
228
|
|
|
230
229
|
public applySettings(response: ShapeDiverResponseDto, sections?: ISettingsSections) {
|
|
231
|
-
try {
|
|
232
230
|
sections = sections || {};
|
|
233
231
|
if (sections.session === undefined) {
|
|
234
232
|
sections.session = {
|
|
@@ -247,15 +245,13 @@ export class SessionEngine implements ISessionEngine {
|
|
|
247
245
|
if ((<ShapeDiverResponseDto>response).viewer !== undefined) {
|
|
248
246
|
config = (<ShapeDiverResponseDto>response).viewer!.config;
|
|
249
247
|
} else {
|
|
250
|
-
|
|
251
|
-
throw this._logger.handleError(LOGGING_TOPIC.SETTINGS, 'Session.applySettings', error);
|
|
248
|
+
throw new ShapeDiverViewerSettingsError('Session.applySettings: No config object available.');
|
|
252
249
|
}
|
|
253
250
|
|
|
254
251
|
try {
|
|
255
252
|
validate(config)
|
|
256
253
|
} catch (e) {
|
|
257
|
-
|
|
258
|
-
throw this._logger.handleError(LOGGING_TOPIC.SETTINGS, 'Session.applySettings', error);
|
|
254
|
+
throw new ShapeDiverViewerSettingsError('Session.applySettings: Was not able to validate config object.');
|
|
259
255
|
}
|
|
260
256
|
|
|
261
257
|
const settings = <ISettingsV3_3>convert(config, latestVersion);
|
|
@@ -350,11 +346,6 @@ export class SessionEngine implements ISessionEngine {
|
|
|
350
346
|
currentSettings.environment.map = settings.environment.map;
|
|
351
347
|
currentSettings.environment.mapAsBackground = settings.environment.mapAsBackground;
|
|
352
348
|
}
|
|
353
|
-
|
|
354
|
-
} catch (e) {
|
|
355
|
-
if (e instanceof ShapeDiverViewerError || e instanceof ShapeDiverBackendError) throw e;
|
|
356
|
-
throw this._logger.handleError(LOGGING_TOPIC.GENERAL, 'Session.applySettings', e);
|
|
357
|
-
}
|
|
358
349
|
}
|
|
359
350
|
|
|
360
351
|
public canGoBack(): boolean {
|
|
@@ -373,11 +364,11 @@ export class SessionEngine implements ISessionEngine {
|
|
|
373
364
|
try {
|
|
374
365
|
this._httpClient.removeDataLoading(this._sessionId!)
|
|
375
366
|
await this._sdk.session.close(this._sessionId!);
|
|
376
|
-
if (this._automaticSceneUpdate) this.
|
|
367
|
+
if (this._automaticSceneUpdate) this.removeFromSceneTree(this._node);
|
|
377
368
|
|
|
378
369
|
this._closed = true;
|
|
379
370
|
} catch (e) {
|
|
380
|
-
await this.handleError(
|
|
371
|
+
await this.handleError(e, retry);
|
|
381
372
|
return await this.close(true);
|
|
382
373
|
}
|
|
383
374
|
}
|
|
@@ -408,7 +399,7 @@ export class SessionEngine implements ISessionEngine {
|
|
|
408
399
|
const oldNode = this.node.cloneInstance();
|
|
409
400
|
this.#customizationProcess = customizationId;
|
|
410
401
|
|
|
411
|
-
this._logger.debugLow(
|
|
402
|
+
this._logger.debugLow(`Session(${this.id}).customize: Customizing session.`);
|
|
412
403
|
|
|
413
404
|
for (let r in this._stateEngine.renderingEngines)
|
|
414
405
|
this._stateEngine.renderingEngines[r].busy.push(customizationId);
|
|
@@ -428,7 +419,7 @@ export class SessionEngine implements ISessionEngine {
|
|
|
428
419
|
if (this._stateEngine.renderingEngines[r].busy.includes(customizationId))
|
|
429
420
|
this._stateEngine.renderingEngines[r].busy.splice(this._stateEngine.renderingEngines[r].busy.indexOf(customizationId), 1);
|
|
430
421
|
|
|
431
|
-
this._logger.debug(
|
|
422
|
+
this._logger.debug(`Session(${this.id}).customize: Session customization was exceeded by other customization request.`);
|
|
432
423
|
|
|
433
424
|
const eventCancel1a: ITaskEvent = { type: TASK_TYPE.SESSION_CUSTOMIZATION, id: eventId, progress: 1, data: { sessionId: this.id }, status: 'Session customization was exceeded by other customization request' };
|
|
434
425
|
this._eventEngine.emitEvent(EVENTTYPE.TASK.TASK_CANCEL, eventCancel1a);
|
|
@@ -445,7 +436,7 @@ export class SessionEngine implements ISessionEngine {
|
|
|
445
436
|
|
|
446
437
|
const eventCancel1b: ITaskEvent = { type: TASK_TYPE.SESSION_CUSTOMIZATION, id: eventId, progress: 1, data: { sessionId: this.id }, status: 'Session customization was exceeded by other customization request' };
|
|
447
438
|
this._eventEngine.emitEvent(EVENTTYPE.TASK.TASK_CANCEL, eventCancel1b);
|
|
448
|
-
this._logger.debug(
|
|
439
|
+
this._logger.debug(`Session(${this.id}).customize: Session customization was exceeded by other customization request.`);
|
|
449
440
|
return new SessionTreeNode();
|
|
450
441
|
}
|
|
451
442
|
|
|
@@ -471,7 +462,7 @@ export class SessionEngine implements ISessionEngine {
|
|
|
471
462
|
// update the session engine parameter values if everything succeeded
|
|
472
463
|
for (const parameterId in this.parameters)
|
|
473
464
|
this.parameterValues[parameterId] = parameterSet[parameterId].valueString;
|
|
474
|
-
this._logger.info(
|
|
465
|
+
this._logger.info(`Session(${this.id}).customize: Customizing session with parameters ${JSON.stringify(this.parameterValues)}.`);
|
|
475
466
|
|
|
476
467
|
const eventRequest: ITaskEvent = { type: TASK_TYPE.SESSION_CUSTOMIZATION, id: eventId, progress: 0.25, data: { sessionId: this.id }, status: 'Sending customization request' };
|
|
477
468
|
this._eventEngine.emitEvent(EVENTTYPE.TASK.TASK_PROCESS, eventRequest);
|
|
@@ -489,7 +480,7 @@ export class SessionEngine implements ISessionEngine {
|
|
|
489
480
|
|
|
490
481
|
const eventCancel2: ITaskEvent = { type: TASK_TYPE.SESSION_CUSTOMIZATION, id: eventId, progress: 1, data: { sessionId: this.id }, status: 'Session customization was exceeded by other customization request' };
|
|
491
482
|
this._eventEngine.emitEvent(EVENTTYPE.TASK.TASK_CANCEL, eventCancel2);
|
|
492
|
-
this._logger.debug(
|
|
483
|
+
this._logger.debug(`Session(${this.id}).customize: Session customization was exceeded by other customization request.`);
|
|
493
484
|
return newNode;
|
|
494
485
|
}
|
|
495
486
|
|
|
@@ -499,11 +490,11 @@ export class SessionEngine implements ISessionEngine {
|
|
|
499
490
|
this.#parameterHistoryForward = [];
|
|
500
491
|
}
|
|
501
492
|
|
|
502
|
-
if (this.automaticSceneUpdate) this.
|
|
493
|
+
if (this.automaticSceneUpdate) this.removeFromSceneTree(this.node);
|
|
503
494
|
this._node = newNode;
|
|
504
|
-
if (this.automaticSceneUpdate) this.
|
|
495
|
+
if (this.automaticSceneUpdate) this.addToSceneTree(this.node);
|
|
505
496
|
|
|
506
|
-
this._logger.debug(
|
|
497
|
+
this._logger.debug(`Session(${this.id}).customize: Customization request finished, updating geometry.`);
|
|
507
498
|
|
|
508
499
|
// set the session values to the current ones in all parameters
|
|
509
500
|
for (const parameterId in this.parameters)
|
|
@@ -530,7 +521,7 @@ export class SessionEngine implements ISessionEngine {
|
|
|
530
521
|
if (this._stateEngine.renderingEngines[r].busy.includes(customizationId))
|
|
531
522
|
this._stateEngine.renderingEngines[r].busy.splice(this._stateEngine.renderingEngines[r].busy.indexOf(customizationId), 1);
|
|
532
523
|
|
|
533
|
-
this._logger.debug(
|
|
524
|
+
this._logger.debug(`Session(${this.id}).customize: Session customized.`);
|
|
534
525
|
|
|
535
526
|
this._eventEngine.emitEvent(EVENTTYPE.SESSION.SESSION_CUSTOMIZED, { sessionId: this.id });
|
|
536
527
|
|
|
@@ -546,13 +537,11 @@ export class SessionEngine implements ISessionEngine {
|
|
|
546
537
|
if (this._stateEngine.renderingEngines[r].busy.includes(customizationId))
|
|
547
538
|
this._stateEngine.renderingEngines[r].busy.splice(this._stateEngine.renderingEngines[r].busy.indexOf(customizationId), 1);
|
|
548
539
|
|
|
549
|
-
|
|
550
|
-
throw this._logger.handleError(LOGGING_TOPIC.SESSION, `Session(${this.id}).customize`, e);
|
|
540
|
+
throw e;
|
|
551
541
|
}
|
|
552
542
|
}
|
|
553
543
|
|
|
554
544
|
public async customizeParallel(parameterValues: { [key: string]: string }): Promise<ITreeNode> {
|
|
555
|
-
try {
|
|
556
545
|
const parameterSet: {
|
|
557
546
|
[key: string]: string
|
|
558
547
|
} = {};
|
|
@@ -564,15 +553,11 @@ export class SessionEngine implements ISessionEngine {
|
|
|
564
553
|
const newNode = await this.customizeSession(parameterSet, () => false, true);
|
|
565
554
|
newNode.excludeViewports = JSON.parse(JSON.stringify(this._excludeViewports));
|
|
566
555
|
return newNode;
|
|
567
|
-
} catch (e) {
|
|
568
|
-
if (e instanceof ShapeDiverViewerError || e instanceof ShapeDiverBackendError) throw e;
|
|
569
|
-
throw this._logger.handleError(LOGGING_TOPIC.SESSION, `Session(${this.id}).customize`, e);
|
|
570
|
-
}
|
|
571
556
|
}
|
|
572
557
|
|
|
573
558
|
public async goBack(): Promise<ITreeNode> {
|
|
574
559
|
if (!this.canGoBack()) {
|
|
575
|
-
this._logger.debug(
|
|
560
|
+
this._logger.debug(`Session(${this.id}).goBack: Cannot go further back.`);
|
|
576
561
|
return new TreeNode();
|
|
577
562
|
}
|
|
578
563
|
// get the current parameter set and store it in the forward history later on
|
|
@@ -595,7 +580,7 @@ export class SessionEngine implements ISessionEngine {
|
|
|
595
580
|
|
|
596
581
|
public async goForward(): Promise<ITreeNode> {
|
|
597
582
|
if (!this.canGoForward()) {
|
|
598
|
-
this._logger.debug(
|
|
583
|
+
this._logger.debug(`Session(${this.id}).goForward: Cannot go further forward.`);
|
|
599
584
|
return new TreeNode();
|
|
600
585
|
}
|
|
601
586
|
// get the last undone parameter set and apply the values to the parameters
|
|
@@ -621,10 +606,8 @@ export class SessionEngine implements ISessionEngine {
|
|
|
621
606
|
public async init(parameterValues?: {
|
|
622
607
|
[key: string]: string;
|
|
623
608
|
}, retry = false): Promise<void> {
|
|
624
|
-
if (this._initialized === true)
|
|
625
|
-
|
|
626
|
-
throw this._logger.handleError(LOGGING_TOPIC.SESSION, 'Session.init', error);
|
|
627
|
-
}
|
|
609
|
+
if (this._initialized === true)
|
|
610
|
+
throw new ShapeDiverViewerSessionError('Session.init: Session already initialized.');
|
|
628
611
|
|
|
629
612
|
try {
|
|
630
613
|
this._performanceEvaluator.startSection('sessionResponse');
|
|
@@ -655,7 +638,7 @@ export class SessionEngine implements ISessionEngine {
|
|
|
655
638
|
this.updateResponseDto(this._responseDto, parameterSet);
|
|
656
639
|
this._initialized = true;
|
|
657
640
|
} catch (e) {
|
|
658
|
-
await this.handleError(
|
|
641
|
+
await this.handleError(e, retry);
|
|
659
642
|
return await this.init(parameterValues, true);
|
|
660
643
|
}
|
|
661
644
|
}
|
|
@@ -694,7 +677,7 @@ export class SessionEngine implements ISessionEngine {
|
|
|
694
677
|
if (e instanceof OutputDelayException) {
|
|
695
678
|
await this.timeout(e.delay);
|
|
696
679
|
} else {
|
|
697
|
-
await this.handleError(
|
|
680
|
+
await this.handleError(e, retry);
|
|
698
681
|
if (cancelRequest()) return new SessionTreeNode();
|
|
699
682
|
return await this.loadOutputsParallel(responseDto, cancelRequest, true);
|
|
700
683
|
}
|
|
@@ -710,7 +693,7 @@ export class SessionEngine implements ISessionEngine {
|
|
|
710
693
|
this.updateResponseDto(responseDto);
|
|
711
694
|
return await this.loadOutputsParallel(responseDto, cancelRequest);
|
|
712
695
|
} catch (e) {
|
|
713
|
-
await this.handleError(
|
|
696
|
+
await this.handleError(e, retry);
|
|
714
697
|
if (cancelRequest()) return new SessionTreeNode();
|
|
715
698
|
return await this.loadOutputsParallel(responseDto, cancelRequest, true);
|
|
716
699
|
}
|
|
@@ -736,9 +719,9 @@ export class SessionEngine implements ISessionEngine {
|
|
|
736
719
|
|
|
737
720
|
if (cancelRequest()) return node;
|
|
738
721
|
|
|
739
|
-
if (this._automaticSceneUpdate) this.
|
|
722
|
+
if (this._automaticSceneUpdate) this.removeFromSceneTree(this._node);
|
|
740
723
|
this._node = node;
|
|
741
|
-
if (this._automaticSceneUpdate) this.
|
|
724
|
+
if (this._automaticSceneUpdate) this.addToSceneTree(this._node);
|
|
742
725
|
|
|
743
726
|
this.node.excludeViewports = JSON.parse(JSON.stringify(this._excludeViewports));
|
|
744
727
|
|
|
@@ -748,7 +731,7 @@ export class SessionEngine implements ISessionEngine {
|
|
|
748
731
|
if (e instanceof OutputDelayException) {
|
|
749
732
|
await this.timeout(e.delay);
|
|
750
733
|
} else {
|
|
751
|
-
await this.handleError(
|
|
734
|
+
await this.handleError(e, retry);
|
|
752
735
|
if (cancelRequest()) return new SessionTreeNode();
|
|
753
736
|
return await this.loadOutputs(cancelRequest, true);
|
|
754
737
|
}
|
|
@@ -764,7 +747,7 @@ export class SessionEngine implements ISessionEngine {
|
|
|
764
747
|
this.updateResponseDto(responseDto);
|
|
765
748
|
return await this.loadOutputs(cancelRequest);
|
|
766
749
|
} catch (e) {
|
|
767
|
-
await this.handleError(
|
|
750
|
+
await this.handleError(e, retry);
|
|
768
751
|
if (cancelRequest()) return new SessionTreeNode();
|
|
769
752
|
return await this.loadOutputs(cancelRequest, true);
|
|
770
753
|
}
|
|
@@ -781,17 +764,15 @@ export class SessionEngine implements ISessionEngine {
|
|
|
781
764
|
this.updateResponseDto(responseDto);
|
|
782
765
|
return this.exports[exportId];
|
|
783
766
|
} catch (e) {
|
|
784
|
-
await this.handleError(
|
|
767
|
+
await this.handleError(e, retry);
|
|
785
768
|
return await this.requestExport(exportId, parameters, maxWaitTime, true);
|
|
786
769
|
}
|
|
787
770
|
}
|
|
788
771
|
|
|
789
772
|
public resetSettings(sections?: ISettingsSections): void {
|
|
790
|
-
if (!this._responseDto)
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
}
|
|
794
|
-
try {
|
|
773
|
+
if (!this._responseDto)
|
|
774
|
+
throw new ShapeDiverViewerSessionError(`Session.resetSettings: responseDto not available.`);
|
|
775
|
+
|
|
795
776
|
sections = sections || {};
|
|
796
777
|
if (sections.session === undefined) {
|
|
797
778
|
sections.session = {
|
|
@@ -807,27 +788,17 @@ export class SessionEngine implements ISessionEngine {
|
|
|
807
788
|
sections.viewport = { ar: true, scene: true, camera: true, light: true, environment: true, general: true };
|
|
808
789
|
|
|
809
790
|
return this.applySettings(this._responseDto, sections);
|
|
810
|
-
} catch (e) {
|
|
811
|
-
if (e instanceof ShapeDiverViewerError || e instanceof ShapeDiverBackendError) throw e;
|
|
812
|
-
throw this._logger.handleError(LOGGING_TOPIC.GENERAL, 'Session.resetSettings', e);
|
|
813
|
-
}
|
|
814
791
|
}
|
|
815
792
|
|
|
816
793
|
public async saveDefaultParameterValues(): Promise<boolean> {
|
|
817
|
-
|
|
818
|
-
this._logger.debugLow(LOGGING_TOPIC.SESSION, `Session(${this.id}).saveDefaultParameters: Saving default parameters.`);
|
|
794
|
+
this._logger.debugLow(`Session(${this.id}).saveDefaultParameters: Saving default parameters.`);
|
|
819
795
|
const response = await this.saveDefaultParameters();
|
|
820
796
|
if (response) {
|
|
821
|
-
this._logger.debug(
|
|
797
|
+
this._logger.debug(`Session(${this.id}).saveDefaultParameters: Saved default parameters.`);
|
|
822
798
|
} else {
|
|
823
|
-
|
|
824
|
-
throw this._logger.handleError(LOGGING_TOPIC.SESSION, `Session(${this.id}).saveDefaultParameters`, error);
|
|
799
|
+
throw new ShapeDiverViewerSessionError(`Session(${this.id}).saveDefaultParameters: Could not save default parameters.`);
|
|
825
800
|
}
|
|
826
801
|
return response;
|
|
827
|
-
} catch (e) {
|
|
828
|
-
if (e instanceof ShapeDiverViewerError || e instanceof ShapeDiverBackendError) throw e;
|
|
829
|
-
throw this._logger.handleError(LOGGING_TOPIC.SESSION, `Session(${this.id}).saveDefaultParameters`, e);
|
|
830
|
-
}
|
|
831
802
|
}
|
|
832
803
|
|
|
833
804
|
public async saveDefaultParameters(retry = false): Promise<boolean> {
|
|
@@ -836,7 +807,7 @@ export class SessionEngine implements ISessionEngine {
|
|
|
836
807
|
await this._sdk.model.setDefaultParams(this._modelId!, this._parameterValues)
|
|
837
808
|
return true;
|
|
838
809
|
} catch (e) {
|
|
839
|
-
await this.handleError(
|
|
810
|
+
await this.handleError(e, retry);
|
|
840
811
|
return await this.saveDefaultParameters(true);
|
|
841
812
|
}
|
|
842
813
|
}
|
|
@@ -860,7 +831,7 @@ export class SessionEngine implements ISessionEngine {
|
|
|
860
831
|
await this._sdk.export.updateDefinitions(this._modelId!, exports);
|
|
861
832
|
return true;
|
|
862
833
|
} catch (e) {
|
|
863
|
-
await this.handleError(
|
|
834
|
+
await this.handleError(e, retry);
|
|
864
835
|
return await this.saveExportProperties(exports, true);
|
|
865
836
|
}
|
|
866
837
|
}
|
|
@@ -884,7 +855,7 @@ export class SessionEngine implements ISessionEngine {
|
|
|
884
855
|
await this._sdk.output.updateDefinitions(this._modelId!, outputs);
|
|
885
856
|
return true;
|
|
886
857
|
} catch (e) {
|
|
887
|
-
await this.handleError(
|
|
858
|
+
await this.handleError(e, retry);
|
|
888
859
|
return await this.saveOutputProperties(outputs, true);
|
|
889
860
|
}
|
|
890
861
|
}
|
|
@@ -908,7 +879,7 @@ export class SessionEngine implements ISessionEngine {
|
|
|
908
879
|
await this._sdk.model.updateParameterDefinitions(this._modelId!, parameters);
|
|
909
880
|
return true;
|
|
910
881
|
} catch (e) {
|
|
911
|
-
await this.handleError(
|
|
882
|
+
await this.handleError(e, retry);
|
|
912
883
|
return await this.saveParameterProperties(parameters, true);
|
|
913
884
|
}
|
|
914
885
|
}
|
|
@@ -919,22 +890,20 @@ export class SessionEngine implements ISessionEngine {
|
|
|
919
890
|
try {
|
|
920
891
|
validate(json, <versions>this._viewerSettingsVersion)
|
|
921
892
|
} catch (e) {
|
|
922
|
-
|
|
923
|
-
throw this._logger.handleError(LOGGING_TOPIC.SETTINGS, 'Session.applySettings', error);
|
|
893
|
+
throw new ShapeDiverViewerSettingsError('Session.saveSettings: Settings could not be validated. ' + (<Error>e).message, <Error>e);
|
|
924
894
|
}
|
|
925
895
|
|
|
926
896
|
try {
|
|
927
897
|
await this._sdk.model.updateConfig(this._modelId!, json);
|
|
928
898
|
return true;
|
|
929
899
|
} catch (e) {
|
|
930
|
-
await this.handleError(
|
|
900
|
+
await this.handleError(e, retry);
|
|
931
901
|
return await this.saveSettings(json, true);
|
|
932
902
|
}
|
|
933
903
|
}
|
|
934
904
|
|
|
935
905
|
public async saveUiProperties(saveInSettings: boolean = true): Promise<boolean> {
|
|
936
|
-
|
|
937
|
-
this._logger.debugLow(LOGGING_TOPIC.SESSION, `Session(${this.id}).saveSessionProperties: Saving session properties.`);
|
|
906
|
+
this._logger.debugLow(`Session(${this.id}).saveSessionProperties: Saving session properties.`);
|
|
938
907
|
|
|
939
908
|
// settings saving
|
|
940
909
|
this._saveSessionSettings();
|
|
@@ -983,15 +952,11 @@ export class SessionEngine implements ISessionEngine {
|
|
|
983
952
|
const response = saveInSettings ? await this.saveSettings(this._settingsEngine.convertToTargetVersion()) : true;
|
|
984
953
|
|
|
985
954
|
if (response && responseP && responseO && responseE) {
|
|
986
|
-
this._logger.debug(
|
|
955
|
+
this._logger.debug(`Session(${this.id}).saveSessionProperties: Saved session properties.`);
|
|
987
956
|
} else {
|
|
988
|
-
this._logger.warn(
|
|
957
|
+
this._logger.warn(`Session(${this.id}).saveSessionProperties: Could not save session properties.`);
|
|
989
958
|
}
|
|
990
959
|
return response && responseP && responseO && responseE;
|
|
991
|
-
} catch (e) {
|
|
992
|
-
if (e instanceof ShapeDiverViewerError || e instanceof ShapeDiverBackendError) throw e;
|
|
993
|
-
throw this._logger.handleError(LOGGING_TOPIC.SESSION, `Session(${this.id}).saveSessionProperties`, e);
|
|
994
|
-
}
|
|
995
960
|
}
|
|
996
961
|
|
|
997
962
|
public async updateOutputs(): Promise<ITreeNode> {
|
|
@@ -1003,7 +968,7 @@ export class SessionEngine implements ISessionEngine {
|
|
|
1003
968
|
const oldNode = this.node.cloneInstance();
|
|
1004
969
|
this.#customizationProcess = customizationId;
|
|
1005
970
|
|
|
1006
|
-
this._logger.debugLow(
|
|
971
|
+
this._logger.debugLow(`Session(${this.id}).updateOutputs: Updating Outputs.`);
|
|
1007
972
|
|
|
1008
973
|
for (let r in this._stateEngine.renderingEngines)
|
|
1009
974
|
this._stateEngine.renderingEngines[r].busy.push(customizationId);
|
|
@@ -1024,15 +989,15 @@ export class SessionEngine implements ISessionEngine {
|
|
|
1024
989
|
|
|
1025
990
|
const eventCancel1: ITaskEvent = { type: TASK_TYPE.SESSION_OUTPUTS_UPDATE, id: eventId, progress: 1, data: { sessionId: this.id }, status: 'Output updating was exceeded by other customization request' };
|
|
1026
991
|
this._eventEngine.emitEvent(EVENTTYPE.TASK.TASK_CANCEL, eventCancel1);
|
|
1027
|
-
this._logger.debug(
|
|
992
|
+
this._logger.debug(`Session(${this.id}).updateOutputs: Output updating was exceeded by other request.`);
|
|
1028
993
|
return newNode;
|
|
1029
994
|
}
|
|
1030
995
|
|
|
1031
|
-
if (this.automaticSceneUpdate) this.
|
|
996
|
+
if (this.automaticSceneUpdate) this.removeFromSceneTree(this.node);
|
|
1032
997
|
this._node = newNode;
|
|
1033
|
-
if (this.automaticSceneUpdate) this.
|
|
998
|
+
if (this.automaticSceneUpdate) this.addToSceneTree(this.node);
|
|
1034
999
|
|
|
1035
|
-
this._logger.debug(
|
|
1000
|
+
this._logger.debug(`Session(${this.id}).updateOutputs: Updating outputs finished, updating geometry.`);
|
|
1036
1001
|
|
|
1037
1002
|
if (this._updateCallback) this._updateCallback(newNode, oldNode);
|
|
1038
1003
|
|
|
@@ -1055,7 +1020,7 @@ export class SessionEngine implements ISessionEngine {
|
|
|
1055
1020
|
if (this._stateEngine.renderingEngines[r].busy.includes(customizationId))
|
|
1056
1021
|
this._stateEngine.renderingEngines[r].busy.splice(this._stateEngine.renderingEngines[r].busy.indexOf(customizationId), 1);
|
|
1057
1022
|
|
|
1058
|
-
this._logger.debug(
|
|
1023
|
+
this._logger.debug(`Session(${this.id}).updateOutputs: Updated outputs.`);
|
|
1059
1024
|
|
|
1060
1025
|
const eventEnd: ITaskEvent = { type: TASK_TYPE.SESSION_OUTPUTS_UPDATE, id: eventId, progress: 1, data: { sessionId: this.id }, status: 'Outputs updated' };
|
|
1061
1026
|
this._eventEngine.emitEvent(EVENTTYPE.TASK.TASK_END, eventEnd);
|
|
@@ -1075,11 +1040,10 @@ export class SessionEngine implements ISessionEngine {
|
|
|
1075
1040
|
await this._sdk.utils.upload(fileAsset.href, await data.arrayBuffer(), type);
|
|
1076
1041
|
return fileAsset.id;
|
|
1077
1042
|
} else {
|
|
1078
|
-
|
|
1079
|
-
throw this._logger.handleError(LOGGING_TOPIC.SESSION, 'Session.uploadFile', error);
|
|
1043
|
+
throw new ShapeDiverViewerSessionError(`Session.uploadFile: Upload reply has not the required format.`);
|
|
1080
1044
|
}
|
|
1081
1045
|
} catch (e) {
|
|
1082
|
-
await this.handleError(
|
|
1046
|
+
await this.handleError(e, retry);
|
|
1083
1047
|
return await this.uploadFile(parameterId, data, type, true);
|
|
1084
1048
|
}
|
|
1085
1049
|
}
|
|
@@ -1088,13 +1052,11 @@ export class SessionEngine implements ISessionEngine {
|
|
|
1088
1052
|
this.checkAvailability('gltf-upload');
|
|
1089
1053
|
try {
|
|
1090
1054
|
const responseDto = await this._sdk.gltf.upload(this._sessionId!, await blob.arrayBuffer(), 'model/gltf-binary', conversion);
|
|
1091
|
-
if (!responseDto || !responseDto.gltf || !responseDto.gltf.href)
|
|
1092
|
-
|
|
1093
|
-
throw this._logger.handleError(LOGGING_TOPIC.SESSION, 'Session.uploadGLTF', error);
|
|
1094
|
-
}
|
|
1055
|
+
if (!responseDto || !responseDto.gltf || !responseDto.gltf.href)
|
|
1056
|
+
throw new ShapeDiverViewerSessionError(`Session.uploadGLTF: Upload reply has not the required format.`);
|
|
1095
1057
|
return responseDto;
|
|
1096
1058
|
} catch (e) {
|
|
1097
|
-
await this.handleError(
|
|
1059
|
+
await this.handleError(e, retry);
|
|
1098
1060
|
return await this.uploadGLTF(blob, conversion, true);
|
|
1099
1061
|
}
|
|
1100
1062
|
}
|
|
@@ -1156,7 +1118,7 @@ export class SessionEngine implements ISessionEngine {
|
|
|
1156
1118
|
if (this.outputs[outputId].status_computation && this.outputs[outputId].status_computation !== ShapeDiverResponseModelComputationStatus.SUCCESS)
|
|
1157
1119
|
warning += `\n\t- status_computation is ${this.outputs[outputId].status_computation}`;
|
|
1158
1120
|
if (warning)
|
|
1159
|
-
this._logger.warn(
|
|
1121
|
+
this._logger.warn(`\nOutput(${outputId}):${warning}`);
|
|
1160
1122
|
}
|
|
1161
1123
|
|
|
1162
1124
|
// set the export definitions
|
|
@@ -1169,36 +1131,26 @@ export class SessionEngine implements ISessionEngine {
|
|
|
1169
1131
|
if (this.exports[exportId].status_computation && this.exports[exportId].status_computation !== ShapeDiverResponseModelComputationStatus.SUCCESS)
|
|
1170
1132
|
warning += `\n\t- status_computation is ${this.exports[exportId].status_computation}`;
|
|
1171
1133
|
if (warning)
|
|
1172
|
-
this._logger.warn(
|
|
1134
|
+
this._logger.warn(`\nExport(${exportId}):${warning}`);
|
|
1173
1135
|
}
|
|
1174
1136
|
}
|
|
1175
1137
|
|
|
1176
1138
|
private checkAvailability(action?: string, checkForModelId = false) {
|
|
1177
|
-
if (!this._responseDto)
|
|
1178
|
-
|
|
1179
|
-
throw this._logger.handleError(LOGGING_TOPIC.SESSION, 'Session.checkAvailability', error);
|
|
1180
|
-
}
|
|
1139
|
+
if (!this._responseDto)
|
|
1140
|
+
throw new ShapeDiverViewerSessionError(`Session.checkAvailability: responseDto not available.`);
|
|
1181
1141
|
|
|
1182
|
-
if (!this._sessionId)
|
|
1183
|
-
|
|
1184
|
-
throw this._logger.handleError(LOGGING_TOPIC.SESSION, 'Session.checkAvailability', error);
|
|
1185
|
-
}
|
|
1142
|
+
if (!this._sessionId)
|
|
1143
|
+
throw new ShapeDiverViewerSessionError(`Session.checkAvailability: sessionId not available.`);
|
|
1186
1144
|
|
|
1187
|
-
if (checkForModelId && !this._modelId)
|
|
1188
|
-
|
|
1189
|
-
throw this._logger.handleError(LOGGING_TOPIC.SESSION, 'Session.checkAvailability', error);
|
|
1190
|
-
}
|
|
1145
|
+
if (checkForModelId && !this._modelId)
|
|
1146
|
+
throw new ShapeDiverViewerSessionError(`Session.checkAvailability: modelId not available.`);
|
|
1191
1147
|
|
|
1192
|
-
if (action && !this._responseDto.actions)
|
|
1193
|
-
|
|
1194
|
-
throw this._logger.handleError(LOGGING_TOPIC.SESSION, 'Session.checkAvailability', error);
|
|
1195
|
-
}
|
|
1148
|
+
if (action && !this._responseDto.actions)
|
|
1149
|
+
throw new ShapeDiverViewerSessionError(`Session.checkAvailability: actions not available.`);
|
|
1196
1150
|
|
|
1197
1151
|
const responseDtoAction = this._responseDto.actions?.find(a => a.name === action);
|
|
1198
|
-
if (action && !responseDtoAction)
|
|
1199
|
-
|
|
1200
|
-
throw this._logger.handleError(LOGGING_TOPIC.SESSION, 'Session.checkAvailability', error);
|
|
1201
|
-
}
|
|
1152
|
+
if (action && !responseDtoAction)
|
|
1153
|
+
throw new ShapeDiverViewerSessionError(`Session.checkAvailability: action ${action} not available.`);
|
|
1202
1154
|
}
|
|
1203
1155
|
|
|
1204
1156
|
private async customizeInternal(cancelRequest: () => boolean): Promise<ISessionTreeNode> {
|
|
@@ -1215,35 +1167,30 @@ export class SessionEngine implements ISessionEngine {
|
|
|
1215
1167
|
if (parallel === false) this.updateResponseDto(responseDto);
|
|
1216
1168
|
return parallel === false ? this.loadOutputs(cancelRequest) : this.loadOutputsParallel(responseDto, cancelRequest);
|
|
1217
1169
|
} catch (e) {
|
|
1218
|
-
await this.handleError(
|
|
1170
|
+
await this.handleError(e, retry);
|
|
1219
1171
|
if (cancelRequest()) return new SessionTreeNode();
|
|
1220
1172
|
return await this.customizeSession(parameters, cancelRequest, parallel, true);
|
|
1221
1173
|
}
|
|
1222
1174
|
}
|
|
1223
1175
|
|
|
1224
|
-
private async handleError(
|
|
1176
|
+
private async handleError(e: ShapeDiverBackendError | ShapeDiverViewerError | Error | unknown, retry = false) {
|
|
1225
1177
|
if (e instanceof ShapeDiverResponseError) {
|
|
1226
1178
|
if (e.error === ShapeDiverResponseErrorType.SESSION_GONE_ERROR) {
|
|
1227
1179
|
// case 1: the session is no longer available
|
|
1228
1180
|
// we try to re-initialize the session 3 times, if that does not work, we close it
|
|
1229
1181
|
|
|
1230
|
-
this._logger.warn(
|
|
1182
|
+
this._logger.warn(`The session has been closed, trying to re-initialize.`);
|
|
1231
1183
|
|
|
1232
1184
|
if (this._retryCounter < 3) {
|
|
1233
1185
|
// we retry this 3 times, the `retry` option in the init function is set to true and passed on
|
|
1234
1186
|
this._retryCounter = retry ? this._retryCounter + 1 : 1;
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
await this.init(this.parameterValues, true);
|
|
1238
|
-
} catch (e) {
|
|
1239
|
-
if (e instanceof ShapeDiverViewerError || e instanceof ShapeDiverBackendError) throw e;
|
|
1240
|
-
throw this._logger.handleError(topic, scope, e);
|
|
1241
|
-
}
|
|
1187
|
+
this._initialized = false;
|
|
1188
|
+
await this.init(this.parameterValues, true);
|
|
1242
1189
|
} else {
|
|
1243
1190
|
// the retries were exceeded, we close the session
|
|
1244
|
-
this._logger.warn(
|
|
1191
|
+
this._logger.warn('Tried to retry the connect multiple times, bearer token still not valid. Closing Session.');
|
|
1245
1192
|
try { await this._closeOnFailure(); } catch (e) { }
|
|
1246
|
-
throw
|
|
1193
|
+
throw e;
|
|
1247
1194
|
}
|
|
1248
1195
|
} else if (e.error === ShapeDiverResponseErrorType.JWT_VALIDATION_ERROR) {
|
|
1249
1196
|
// if any of the above errors occur, we try to get a new bearer token
|
|
@@ -1252,24 +1199,24 @@ export class SessionEngine implements ISessionEngine {
|
|
|
1252
1199
|
if (this._refreshBearerToken) {
|
|
1253
1200
|
this.bearerToken = await this._refreshBearerToken();
|
|
1254
1201
|
this._retryCounter = retry ? this._retryCounter + 1 : 1;
|
|
1255
|
-
this._logger.warn(
|
|
1202
|
+
this._logger.warn('Re-trying with new bearer token.');
|
|
1256
1203
|
} else {
|
|
1257
1204
|
// no bearer tokens are supplied, we close the session
|
|
1258
|
-
this._logger.warn(
|
|
1205
|
+
this._logger.warn('No retry possible, no new bearer token was supplied. Closing Session.');
|
|
1259
1206
|
try { await this._closeOnFailure(); } catch (e) { }
|
|
1260
|
-
throw
|
|
1207
|
+
throw e;
|
|
1261
1208
|
}
|
|
1262
1209
|
} else {
|
|
1263
1210
|
// the retries were exceeded, we close the session
|
|
1264
|
-
this._logger.warn(
|
|
1211
|
+
this._logger.warn('Tried to retry the connect multiple times, bearer token still not valid. Closing Session.');
|
|
1265
1212
|
try { await this._closeOnFailure(); } catch (e) { }
|
|
1266
|
-
throw
|
|
1213
|
+
throw e;
|
|
1267
1214
|
}
|
|
1268
1215
|
} else {
|
|
1269
|
-
throw
|
|
1216
|
+
throw e;
|
|
1270
1217
|
}
|
|
1271
1218
|
} else {
|
|
1272
|
-
throw
|
|
1219
|
+
throw e;
|
|
1273
1220
|
}
|
|
1274
1221
|
}
|
|
1275
1222
|
|
|
@@ -1384,5 +1331,16 @@ export class SessionEngine implements ISessionEngine {
|
|
|
1384
1331
|
}
|
|
1385
1332
|
}
|
|
1386
1333
|
|
|
1334
|
+
private addToSceneTree(node: ITreeNode) {
|
|
1335
|
+
this._sceneTree.addNode(node);
|
|
1336
|
+
this._sceneTree.root.updateVersion();
|
|
1337
|
+
}
|
|
1338
|
+
|
|
1339
|
+
private removeFromSceneTree(node: ITreeNode) {
|
|
1340
|
+
this._sceneTree.removeNode(node);
|
|
1341
|
+
this._sceneTree.root.updateVersion();
|
|
1342
|
+
}
|
|
1343
|
+
|
|
1344
|
+
|
|
1387
1345
|
// #endregion Private Methods (8)
|
|
1388
1346
|
}
|