Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Godind/issue298 #299

Merged
merged 3 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/app/app-initNetwork.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { IConnectionConfig } from "./app-settings.interfaces";
import { SignalKConnectionService } from "./signalk-connection.service";
import { AuthenticationService } from './authentication.service';
import { DefaultConnectionConfig } from './config.blank.const';
import { UUID } from './uuid';

const configFileVersion = 9; // used to change the Signal K configuration storage file name (ie. 9.0.0.json) that contains the configuration definitions. Applies only to remote storage.

Expand All @@ -40,7 +39,7 @@ export class AppNetworkInitService {

try {
if (this.config?.signalKUrl !== undefined && this.config.signalKUrl !== null) {
await this.connection.resetSignalK({url: this.config.signalKUrl, new: false});
await this.connection.resetSignalK({url: this.config.signalKUrl, new: false}, this.config.proxyEnabled);
}

if (!this.isLoggedIn && this.config?.signalKUrl && this.config?.useSharedConfig && this.config?.loginName && this.config?.loginPassword) {
Expand Down Expand Up @@ -85,7 +84,6 @@ export class AppNetworkInitService {

if (!this.config) {
this.config = DefaultConnectionConfig;
this.config.kipUUID = UUID.create();
this.config.signalKUrl = window.location.origin;
console.log(`[AppInit Network Service] Connection Configuration not found. Creating configuration using Auto-Discovery URL: ${this.config.signalKUrl}`);
localStorage.setItem('connectionConfig', JSON.stringify(this.config));
Expand Down
1 change: 1 addition & 0 deletions src/app/app-settings.interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface IConnectionConfig {
configVersion: number;
kipUUID: string;
signalKUrl: string;
proxyEnabled: boolean;
useDeviceToken: boolean;
loginName: string;
loginPassword: string;
Expand Down
27 changes: 12 additions & 15 deletions src/app/app-settings.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { IDataSet } from './data-set.service';
import { ISplitSet } from './layout-splits.service';
import { IWidget } from './widgets-interface';
import { IUnitDefaults } from './units.service';
import { UUID } from './uuid';

import { IConfig, IAppConfig, IConnectionConfig, IThemeConfig, IWidgetConfig, ILayoutConfig, IZonesConfig, INotificationConfig, IZone, ISignalKUrl } from "./app-settings.interfaces";
import { DefaultAppConfig, DefaultConnectionConfig as DefaultConnectionConfig, DefaultWidgetConfig, DefaultLayoutConfig, DefaultThemeConfig, DefaultZonesConfig } from './config.blank.const';
Expand All @@ -30,6 +31,7 @@ export class AppSettingsService {
private kipKNotificationConfig: BehaviorSubject<INotificationConfig> = new BehaviorSubject<INotificationConfig>(DefaultNotificationConfig);
private autoNightMode: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);

public proxyEnabled: boolean = false;
private useDeviceToken: boolean = false;
private loginName: string;
private loginPassword: string;
Expand All @@ -39,12 +41,11 @@ export class AppSettingsService {

private kipUUID: string;
public signalkUrl: ISignalKUrl;
widgets: Array<IWidget>;
splitSets: ISplitSet[] = [];
rootSplits: string[] = [];
dataSets: IDataSet[] = [];
zones: BehaviorSubject<Array<IZone>> = new BehaviorSubject<Array<IZone>>([]);
root
private widgets: Array<IWidget>;
private splitSets: ISplitSet[] = [];
private rootSplits: string[] = [];
private dataSets: IDataSet[] = [];
private zones: BehaviorSubject<Array<IZone>> = new BehaviorSubject<Array<IZone>>([]);

constructor(
private storage: StorageService
Expand Down Expand Up @@ -96,6 +97,7 @@ export class AppSettingsService {
this.resetConnection();
} else {
this.signalkUrl = {url: config.signalKUrl, new: false};
this.proxyEnabled = config.proxyEnabled;
this.useDeviceToken = config.useDeviceToken;
this.loginName = config.loginName;
this.loginPassword = config.loginPassword;
Expand Down Expand Up @@ -176,6 +178,7 @@ export class AppSettingsService {
this.replaceConfig('appConfig', upgradedConfig, true);
}
}

/**
* Get configuration from local browser storage rather then in
* memory running config.
Expand Down Expand Up @@ -277,6 +280,7 @@ public loadConfigFromLocalStorage(type: string) {
this.loginName = value.loginName;
this.loginPassword = value.loginPassword;
this.useSharedConfig = value.useSharedConfig;
this.proxyEnabled = value.proxyEnabled;
this.signalkUrl.url = value.signalKUrl;
if (!value.useSharedConfig) {
this.useDeviceToken = true;
Expand Down Expand Up @@ -536,6 +540,7 @@ public loadConfigFromLocalStorage(type: string) {
configVersion: configVersion,
kipUUID: this.kipUUID,
signalKUrl: this.signalkUrl.url,
proxyEnabled: this.proxyEnabled,
useDeviceToken: this.useDeviceToken,
loginName: this.loginName,
loginPassword: this.loginPassword,
Expand Down Expand Up @@ -617,7 +622,7 @@ public loadConfigFromLocalStorage(type: string) {

private getDefaultConnectionConfig(): IConnectionConfig {
let config: IConnectionConfig = DefaultConnectionConfig;
config.kipUUID = this.newUuid();
config.kipUUID = UUID.create();
config.signalKUrl = window.location.origin;
localStorage.setItem('connectionConfig', JSON.stringify(config));
return config;
Expand Down Expand Up @@ -646,12 +651,4 @@ public loadConfigFromLocalStorage(type: string) {
localStorage.setItem("zonesConfig", JSON.stringify(config));
return config;
}

private newUuid() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
return v.toString(16);
});
}

}
11 changes: 3 additions & 8 deletions src/app/config.blank.const.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { IConfig ,IAppConfig, IConnectionConfig, ILayoutConfig, IThemeConfig, IWidgetConfig, IZonesConfig } from "./app-settings.interfaces"
import { DefaultNotificationConfig } from './config.blank.notification.const';
import { DefaultUnitsConfig } from "./config.blank.units.const";
import { UUID } from "./uuid";

export const DefaultAppConfig: IAppConfig = {
"configVersion": 9,
Expand Down Expand Up @@ -57,18 +58,12 @@ export const defaultConfig: IConfig = {

export const DefaultConnectionConfig: IConnectionConfig = {
"configVersion": 9,
"kipUUID": newUuid(),
"kipUUID": UUID.create(),
"signalKUrl": null, // get's overwritten with host at getDefaultConnectionConfig()
"proxyEnabled": false,
"useDeviceToken": false,
"loginName": null,
"loginPassword": null,
"useSharedConfig": false,
"sharedConfigName": "default"
}

function newUuid() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
return v.toString(16);
});
}
11 changes: 3 additions & 8 deletions src/app/config.demo.const.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { IConfig, IAppConfig, IConnectionConfig, IThemeConfig, ILayoutConfig, IWidgetConfig, IZonesConfig } from "./app-settings.interfaces"
import { UUID } from "./uuid"

// Demo Mode config settings file
export const DemoAppConfig: IAppConfig = {
Expand Down Expand Up @@ -420,18 +421,12 @@ export const DemoConfig: IConfig = {

export const DemoConnectionConfig: IConnectionConfig = {
"configVersion": 9,
"kipUUID": newUuid(),
"kipUUID": UUID.create(),
"signalKUrl": "https://demo.signalk.org",
"proxyEnabled": false,
"useDeviceToken": false,
"loginName": null,
"loginPassword": null,
"useSharedConfig": false,
"sharedConfigName": "default"
}

function newUuid() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
return v.toString(16);
});
}
10 changes: 2 additions & 8 deletions src/app/data-set.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Injectable, NgZone } from '@angular/core';
import { Subscription, BehaviorSubject, sampleTime, pipe, UnaryFunction, filter, OperatorFunction, Observable, interval } from 'rxjs';
import { AppSettingsService } from './app-settings.service';
import { SignalKService } from './signalk.service';
import { UUID } from'./uuid'


export interface dataPoint {
Expand Down Expand Up @@ -70,13 +71,6 @@ export class DataSetService {
}
}

private newUuid() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
return v.toString(16);
});
}

public subscribeDataSet(uuid, dataSetUuid) {
//see if already subscribed, if yes return that...
let registerIndex = this.dataSetRegister.findIndex(registration => (registration.uuid == uuid) && (registration.dataSetUuid == dataSetUuid));
Expand Down Expand Up @@ -173,7 +167,7 @@ export class DataSetService {
}

public addDataSet(path: string, source: string, updateTimer: number, dataPoints: number ) {
let uuid = this.newUuid();
let uuid = UUID.create();

let newSub: IDataSet = {
uuid: uuid,
Expand Down
12 changes: 3 additions & 9 deletions src/app/layout-splits.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Router } from '@angular/router';

import { AppSettingsService } from './app-settings.service';
import { WidgetManagerService } from './widget-manager.service';
import { UUID } from './uuid'


interface ISplitArea {
Expand Down Expand Up @@ -45,13 +46,6 @@ export class LayoutSplitsService {
this.rootUUIDs = this.AppSettingsService.getRootSplits();
}

private newUuid() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
return v.toString(16);
});
}

getActiveRootSub() {
return this.activeRoot.asObservable();
}
Expand Down Expand Up @@ -101,7 +95,7 @@ export class LayoutSplitsService {
//should only ever be called when changing directions. widgetUUID of area we're splitting
// becomes first area of new split
newSplit(parentUUID: string, direction: string, widget1UUID: string, widget2UUID) {
let uuid = this.newUuid();
let uuid = UUID.create();
let newSplit: ISplitSet = {
uuid: uuid,
parentUUID: parentUUID,
Expand All @@ -126,7 +120,7 @@ export class LayoutSplitsService {

newRootSplit() {
//create new root split
let uuid = this.newUuid();
let uuid = UUID.create();
let newWidget = this.WidgetManagerService.newWidget();
let newRootSplit: ISplitSet = {
uuid: uuid,
Expand Down
5 changes: 5 additions & 0 deletions src/app/settings/signalk/signalk.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ <h1>Connection</h1>
</mat-error>
</mat-form-field>
<br/>
<mat-checkbox [(ngModel)]="connectionConfig.proxyEnabled" [ngModelOptions]="{standalone: false}" name="isProxyEnabled">Signal K server is behind a Proxy</mat-checkbox>
<br/>
<br/>
<br/>
<mat-slide-toggle name="useSharedConfigToggle" matTooltip="Activating authentication enables Signal K's user storage feature to save KIP configuration on the server. When authentication is not activated, KIP stores it's configuration locally in the Browser." #useSharedConfigToggle [(ngModel)]="connectionConfig.useSharedConfig" [ngModelOptions]="{standalone: true}" [disabled]="!connectionConfig.signalKUrl" (change)="useSharedConfigToggleClick($event)">
Signal K Authentication
</mat-slide-toggle>
Expand All @@ -18,6 +22,7 @@ <h1>Connection</h1>
<button mat-raised-button type="button" color="primary" matTooltip="Configure Signal K user authentication credentials. The user must be a valid pre existing Signal K server user. It is strongly recommended not to use the default Signal K Admin user." [disabled]="!connectionConfig.useSharedConfig" (click)="openUserCredentialModal(null)">
Set Credentials
</button>
<br/>
<div class="formActionFooter">
<mat-divider class="formActionDivider"></mat-divider>
<span *ngIf="(!connectionConfig.useSharedConfig && (authToken && !isLoggedIn))">
Expand Down
4 changes: 3 additions & 1 deletion src/app/settings/signalk/signalk.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { NotificationsService } from '../../notifications.service';
import { ModalUserCredentialComponent } from '../../modal-user-credential/modal-user-credential.component';
import { HttpErrorResponse } from '@angular/common/http';
import { compare } from 'compare-versions';
import { MatCheckboxChange } from '@angular/material/checkbox';


@Component({
Expand All @@ -32,6 +33,7 @@ export class SettingsSignalkComponent implements OnInit {
authToken: IAuthorizationToken;
isLoggedInSub: Subscription;
isLoggedIn: boolean;
public proxyEnabled: boolean = false;

endpointServiceStatus: IEndpointStatus;
skEndpointServiceStatusSub: Subscription;
Expand Down Expand Up @@ -136,7 +138,7 @@ export class SettingsSignalkComponent implements OnInit {
return;
}

if (this.connectionConfig.signalKUrl != this.appSettingsService.signalkUrl.url) {
if ((this.connectionConfig.signalKUrl !== this.appSettingsService.signalkUrl.url) || (this.connectionConfig.proxyEnabled !== this.appSettingsService.proxyEnabled )) {
this.appSettingsService.setConnectionConfig(this.connectionConfig);

if (this.connectionConfig.useSharedConfig) {
Expand Down
14 changes: 4 additions & 10 deletions src/app/settings/zones/zones.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { MatSort } from '@angular/material/sort';
import { AppSettingsService } from '../../app-settings.service';
import { IPathMetaData } from "../../app-interfaces";
import { IZone } from "../../app-settings.interfaces";
import { UUID } from './../../uuid';

@Component({
selector: 'settings-zones',
Expand Down Expand Up @@ -83,7 +84,7 @@ export class SettingsZonesComponent implements OnInit, AfterViewInit {
if (zone.uuid) {
this.editZone(zone);
} else {
zone.uuid = this.newUuid();
zone.uuid = UUID.create();
this.addZone(zone);
}
}
Expand Down Expand Up @@ -117,17 +118,10 @@ export class SettingsZonesComponent implements OnInit, AfterViewInit {
this.appSettingsService.saveZones(zones);
}
}

private newUuid() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
return v.toString(16);
});
}
}


// Add zone compoment
// Add zone component
@Component({
selector: 'dialog-new-zone',
templateUrl: 'new-zone.modal.html',
Expand Down Expand Up @@ -179,7 +173,7 @@ export class DialogNewZone {
}


// Edit zone compoment
// Edit zone component
@Component({
selector: 'dialog-edit-zone',
templateUrl: 'edit-zone.modal.html',
Expand Down
23 changes: 19 additions & 4 deletions src/app/signalk-connection.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class SignalKConnectionService {
* @return {*} {Promise<void>}
* @memberof SignalKConnectionService
*/
public async resetSignalK(skUrl: ISignalKUrl): Promise<void> {
public async resetSignalK(skUrl: ISignalKUrl, proxyEnabled?: boolean): Promise<void> {
if (skUrl.url === null) {
console.log("[Connection Service] Connection reset called with null or empty URL value");
return;
Expand All @@ -98,11 +98,26 @@ export class SignalKConnectionService {
console.log("[Connection Service] Connecting to: " + this.signalKURL.url);
const endpointResponse = await lastValueFrom(this.http.get<ISignalKEndpointResponse>(fullURL, {observe: 'response'}));

console.debug("[Connection Service] SignalK HTTP Endpoints retrieved");
console.debug("[Connection Service] Signal K HTTP Endpoints retrieved");
this.serverVersion$.next(endpointResponse.body.server.version);

this.serverServiceEndpoints.httpServiceUrl = endpointResponse.body.endpoints.v1["signalk-http"];
this.serverServiceEndpoints.WsServiceUrl = endpointResponse.body.endpoints.v1["signalk-ws"];
if (proxyEnabled) {
console.debug("[Connection Service] Proxy Mode Enabled");
const skHttpUrl = new URL(endpointResponse.body.endpoints.v1["signalk-http"]);
const skWsUrl = new URL(endpointResponse.body.endpoints.v1["signalk-ws"]);

this.serverServiceEndpoints.httpServiceUrl = window.location.origin + skHttpUrl.pathname;
console.debug("[Connection Service] Proxy HTTP URI: " +this.serverServiceEndpoints.httpServiceUrl);

this.serverServiceEndpoints.WsServiceUrl = window.location.protocol == 'https:' ? 'wss:' : 'ws:' + window.location.host + skWsUrl.pathname;
console.debug("[Connection Service] Proxy WebSocket URI: " + this.serverServiceEndpoints.WsServiceUrl);
} else {
this.serverServiceEndpoints.httpServiceUrl = endpointResponse.body.endpoints.v1["signalk-http"];
console.debug("[Connection Service] HTTP URI: " +this.serverServiceEndpoints.httpServiceUrl);
this.serverServiceEndpoints.WsServiceUrl = endpointResponse.body.endpoints.v1["signalk-ws"];
console.debug("[Connection Service] WebSocket URI: " + this.serverServiceEndpoints.WsServiceUrl);
}

this.serverServiceEndpoints.operation = 2;
this.serverServiceEndpoints.message = endpointResponse.status.toString();
this.serverServiceEndpoints.serverDescription = endpointResponse.body.server.id + " " + endpointResponse.body.server.version;
Expand Down
Loading