Skip to content

Commit e1e3053

Browse files
author
Dennis Labordus
committed
Added switch between using Websockets or Rest to make difference.
Signed-off-by: Dennis Labordus <[email protected]>
1 parent 7b378b4 commit e1e3053

File tree

4 files changed

+26
-7
lines changed

4 files changed

+26
-7
lines changed

src/compas-services/CompasValidatorService.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ export function CompasSclValidatorService() {
2525
if (sclValidatorServiceUrl.startsWith("ws://") || sclValidatorServiceUrl.startsWith("wss://")) {
2626
return sclValidatorServiceUrl + (sclValidatorServiceUrl.endsWith("/") ? "" : "/");
2727
}
28+
if (sclValidatorServiceUrl.startsWith("http://") || sclValidatorServiceUrl.startsWith("https://")) {
29+
return sclValidatorServiceUrl.replace("http://", "ws://").replace("https://", "wss://")
30+
+ (sclValidatorServiceUrl.endsWith("/") ? "" : "/");
31+
}
2832

2933
return (document.location.protocol == "http:" ? "ws://" : "wss://")
3034
+ document.location.hostname + ":" + getWebsocketPort()
@@ -40,8 +44,7 @@ export function CompasSclValidatorService() {
4044

4145
return {
4246
useWebsocket(): boolean {
43-
const sclValidatorServiceUrl = getCompasSettings().sclValidatorServiceUrl;
44-
return !sclValidatorServiceUrl.startsWith("http");
47+
return getCompasSettings().useWebsockets === 'on';
4548
},
4649

4750
validateSCLUsingRest(type: string, doc: Document): Promise<Document> {

src/compas/CompasSettings.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ import '@material/mwc-button';
77
import {newWizardEvent} from '../foundation.js';
88
import {TextFieldBase} from "@material/mwc-textfield/mwc-textfield-base";
99
import {dispatchEventOnOpenScd} from "./foundation.js";
10+
import {Switch} from "@material/mwc-switch";
1011

1112
export type CompasSettingsRecord = {
1213
sclDataServiceUrl: string;
1314
sclValidatorServiceUrl: string;
1415
cimMappingServiceUrl: string;
1516
sclAutoAlignmentServiceUrl: string;
17+
useWebsockets: 'on' | 'off';
1618
};
1719

1820
export function CompasSettings() {
@@ -23,7 +25,8 @@ export function CompasSettings() {
2325
sclDataServiceUrl: this.getCompasSetting('sclDataServiceUrl'),
2426
sclValidatorServiceUrl: this.getCompasSetting('sclValidatorServiceUrl'),
2527
cimMappingServiceUrl: this.getCompasSetting('cimMappingServiceUrl'),
26-
sclAutoAlignmentServiceUrl: this.getCompasSetting('sclAutoAlignmentServiceUrl')
28+
sclAutoAlignmentServiceUrl: this.getCompasSetting('sclAutoAlignmentServiceUrl'),
29+
useWebsockets: this.getCompasSetting('useWebsockets')
2730
};
2831
},
2932

@@ -32,7 +35,8 @@ export function CompasSettings() {
3235
sclDataServiceUrl: '/compas-scl-data-service',
3336
sclValidatorServiceUrl: '/compas-scl-validator',
3437
cimMappingServiceUrl: '/compas-cim-mapping',
35-
sclAutoAlignmentServiceUrl: '/compas-scl-auto-alignment'
38+
sclAutoAlignmentServiceUrl: '/compas-scl-auto-alignment',
39+
useWebsockets: 'on'
3640
}
3741
},
3842

@@ -72,6 +76,10 @@ export class CompasSettingsElement extends LitElement {
7276
return <TextFieldBase>this.shadowRoot!.querySelector('mwc-textfield[id="sclAutoAlignmentServiceUrl"]');
7377
}
7478

79+
getUseWebsockets(): Switch {
80+
return <Switch>this.shadowRoot!.querySelector('mwc-switch[id="useWebsockets"]');
81+
}
82+
7583
valid(): boolean {
7684
return this.getSclDataServiceUrlField().checkValidity()
7785
&& this.getSclValidatorServiceUrlField().checkValidity()
@@ -89,6 +97,7 @@ export class CompasSettingsElement extends LitElement {
8997
CompasSettings().setCompasSetting('sclValidatorServiceUrl', this.getSclValidatorServiceUrlField().value);
9098
CompasSettings().setCompasSetting('cimMappingServiceUrl', this.getCimMappingServiceUrlField().value);
9199
CompasSettings().setCompasSetting('sclAutoAlignmentServiceUrl', this.getSclAutoAlignmentServiceUrlField().value);
100+
CompasSettings().setCompasSetting('useWebsockets', this.getUseWebsockets().checked ? 'on' : 'off');
92101
return true;
93102
}
94103

@@ -122,6 +131,11 @@ export class CompasSettingsElement extends LitElement {
122131
label="${translate('compas.settings.sclAutoAlignmentServiceUrl')}"
123132
value="${this.compasSettings.sclAutoAlignmentServiceUrl}" required>
124133
</mwc-textfield>
134+
<mwc-formfield label="${translate('compas.settings.useWebsockets')}">
135+
<mwc-switch id="useWebsockets"
136+
?checked=${this.compasSettings.useWebsockets === 'on'}>
137+
</mwc-switch>
138+
</mwc-formfield>
125139
126140
<mwc-button @click=${() => {
127141
if (this.reset()) {
@@ -137,7 +151,7 @@ export class CompasSettingsElement extends LitElement {
137151
width: 20vw;
138152
}
139153
140-
mwc-textfield {
154+
mwc-textfield, mwc-formfield {
141155
margin: 10px;
142156
width: 100%;
143157
}

src/translations/de.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,8 @@ export const de: Translations = {
650650
sclDataServiceUrl: 'CoMPAS SCL Data Service URL',
651651
sclValidatorServiceUrl: 'CoMPAS SCL Validator Service URL',
652652
cimMappingServiceUrl: 'CoMPAS CIM Mapping Service URL',
653-
sclAutoAlignmentServiceUrl: 'CoMPAS SCL Auto Alignment Service URL'
653+
sclAutoAlignmentServiceUrl: 'CoMPAS SCL Auto Alignment Service URL',
654+
useWebsockets: '???',
654655
},
655656
session: {
656657
headingExpiring: '???',

src/translations/en.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,8 @@ export const en = {
645645
sclDataServiceUrl: 'CoMPAS SCL Data Service URL',
646646
sclValidatorServiceUrl: 'CoMPAS SCL Validator Service URL',
647647
cimMappingServiceUrl: 'CoMPAS CIM Mapping Service URL',
648-
sclAutoAlignmentServiceUrl: 'CoMPAS SCL Auto Alignment Service URL'
648+
sclAutoAlignmentServiceUrl: 'CoMPAS SCL Auto Alignment Service URL',
649+
useWebsockets: 'Use Websockets',
649650
},
650651
session: {
651652
headingExpiring: 'Your session is about to expire!',

0 commit comments

Comments
 (0)