Skip to content

Commit f30b59b

Browse files
committed
refactor signalR client-side files; bump node dependencies and .NET nuget packages
1 parent 7335e86 commit f30b59b

File tree

18 files changed

+93
-91
lines changed

18 files changed

+93
-91
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -267,4 +267,4 @@ paket-files/
267267

268268
# Python Tools for Visual Studio (PTVS)
269269
__pycache__/
270-
*.pyc
270+
*.pyc

GhostUI/ClientApp/package-lock.json

+20-21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

GhostUI/ClientApp/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"@microsoft/signalr": "^5.0.3",
1919
"axios": "^0.21.1",
2020
"bulma": "^0.9.2",
21-
"core-js": "^3.9.0",
21+
"core-js": "^3.9.1",
2222
"register-service-worker": "^1.7.2",
2323
"vue": "^2.6.12",
2424
"vue-class-component": "^7.2.6",
@@ -43,7 +43,7 @@
4343
"@vue/eslint-config-prettier": "^6.0.0",
4444
"@vue/eslint-config-typescript": "^7.0.0",
4545
"@vue/test-utils": "1.1.3",
46-
"eslint": "^7.20.0",
46+
"eslint": "^7.21.0",
4747
"eslint-plugin-prettier": "^3.3.1",
4848
"eslint-plugin-vue": "^7.6.0",
4949
"node-sass": "^5.0.0",

GhostUI/ClientApp/src/api/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export { AuthApi } from './auth.service';
22
export { SampleApi } from './sample.service';
3-
export { SignalRApi } from './signalR.service';
3+
export { SignalRApi } from './signalr.service';

GhostUI/ClientApp/src/api/signalR.service.ts

+27-41
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,10 @@
11
import { EventBus } from '@/event-bus';
2+
import { SIGNALR_CONFIG } from '../config';
23
import { HubConnection, HubConnectionBuilder, HubConnectionState } from '@microsoft/signalr';
34

45
/**
5-
* SignalR hub defaults
6-
*/
7-
const _signalrConfig = {
8-
CONNECTION_DELAY: 0,
9-
HUB_MESSAGE_DELAY: 3000,
10-
BASE_URL: '/hubs/users',
11-
HUB_MESSAGE_TITLE: 'SignalR',
12-
LOGIN_USER_EVENT: 'UserLogin',
13-
LOGOUT_USER_EVENT: 'UserLogout',
14-
CLOSE_EVENT: 'CloseAllConnections'
15-
};
16-
17-
/**
18-
* SignalR API abstraction layer communication - configures/manages hub connections
6+
* SignalR API abstraction layer communication.
7+
* Configures/manages hub connections (typescript singleton pattern).
198
*/
209
class SignalRService {
2110
private _hubConnection: HubConnection;
@@ -32,46 +21,43 @@ class SignalRService {
3221

3322
public startConnection(): void {
3423
if (this._hubConnection.state === HubConnectionState.Disconnected) {
35-
setTimeout(() => {
36-
this._hubConnection.start().catch((e) => console.error(e));
37-
}, _signalrConfig.CONNECTION_DELAY);
24+
this._hubConnection
25+
.start()
26+
.catch((e) => console.error(e));
3827
}
3928
}
4029

4130
private createConnection(): void {
4231
this._hubConnection = new HubConnectionBuilder()
43-
.withUrl(_signalrConfig.BASE_URL)
32+
.withUrl(SIGNALR_CONFIG.baseUrl)
4433
.build();
4534
}
4635

36+
private hubToastMessage(
37+
message: string,
38+
title: string = SIGNALR_CONFIG.messageTitle,
39+
delay: number = SIGNALR_CONFIG.messageDelay
40+
): void {
41+
setTimeout(() => {
42+
EventBus.$snotify.info(message, title);
43+
}, delay);
44+
}
45+
4746
private registerOnServerEvents(): void {
48-
this._hubConnection.on(_signalrConfig.LOGIN_USER_EVENT, () => {
49-
setTimeout(() => {
50-
EventBus.$snotify.info(
51-
'A user has logged in',
52-
_signalrConfig.HUB_MESSAGE_TITLE
53-
);
54-
}, _signalrConfig.HUB_MESSAGE_DELAY);
47+
this._hubConnection.on(SIGNALR_CONFIG.events.login, () => {
48+
this.hubToastMessage('A user has logged in');
5549
});
5650

57-
this._hubConnection.on(_signalrConfig.LOGOUT_USER_EVENT, () => {
58-
setTimeout(() => {
59-
EventBus.$snotify.info(
60-
'A user has logged out',
61-
_signalrConfig.HUB_MESSAGE_TITLE
62-
);
63-
}, _signalrConfig.HUB_MESSAGE_DELAY);
51+
this._hubConnection.on(SIGNALR_CONFIG.events.logout, () => {
52+
this.hubToastMessage('A user has logged out');
6453
});
6554

66-
this._hubConnection.on(_signalrConfig.CLOSE_EVENT, (reason: string) => {
67-
this._hubConnection.stop().then(() => {
68-
setTimeout(() => {
69-
EventBus.$snotify.info(
70-
`Hub closed (${reason})`,
71-
_signalrConfig.HUB_MESSAGE_TITLE
72-
);
73-
}, _signalrConfig.HUB_MESSAGE_DELAY);
74-
});
55+
this._hubConnection.on(SIGNALR_CONFIG.events.closeConnections, (reason: string) => {
56+
this._hubConnection
57+
.stop()
58+
.then(() => {
59+
this.hubToastMessage(`Hub closed (${reason})`);
60+
});
7561
});
7662
}
7763
}

GhostUI/ClientApp/src/components/Settings.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
<script lang="ts">
5454
import { Component, Vue } from "vue-property-decorator";
5555
import { AuthModule } from "../store/modules/auth";
56-
import { NUGET_URL_CONFIG } from "../config/constants";
56+
import { NUGET_URL_CONFIG } from "../config";
5757
import { RouteConfig } from 'vue-router';
5858
5959
@Component

GhostUI/ClientApp/src/config/axios.config.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,13 @@ const handleAxiosError = (error: AxiosError): void => {
5555

5656

5757
// Log in console or use Snotify notification (via Global EventBus)
58-
EventBus.$snotify.error(`${message.status} (${message.body})`, 'XHR Error');
58+
EventBus.$snotify.error(
59+
`${message.status} (${message.body})`,
60+
'XHR Error'
61+
);
5962
};
6063

61-
export default class AxiosGlobalConfig {
64+
export class AxiosGlobalConfig {
6265
public static setup(): void {
6366
axios.interceptors.response.use(
6467
(response: AxiosResponse) => {

GhostUI/ClientApp/src/config/index.ts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export * from './constants';
2+
export * from './axios.config';
3+
export * from './signalr.config';
4+
export * from './vue-snotify.config';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* SignalR hub defaults
3+
* "baseUrl" needs full url or else prerendering fails (can't normalize /hubs/users)
4+
*/
5+
export type SignalRConfig = {
6+
baseUrl: string;
7+
messageTitle: string;
8+
messageDelay: number;
9+
events: Record<'login' | 'logout' | 'closeConnections', string>;
10+
};
11+
12+
export const SIGNALR_CONFIG: SignalRConfig = {
13+
messageDelay: 3000,
14+
baseUrl: '/hubs/users',
15+
messageTitle: 'SignalR',
16+
events: {
17+
login: 'UserLogin',
18+
logout: 'UserLogout',
19+
closeConnections: 'CloseAllConnections',
20+
},
21+
};

GhostUI/ClientApp/src/main.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ import App from '@/App.vue';
66
import store from '@/store';
77
import router from '@/router';
88
import { vClickOutside } from '@/plugins';
9-
import { SignalRApi } from '@/api/signalR.service';
10-
import AxiosGlobalConfig from '@/config/axios.config';
9+
import { SignalRApi } from '@/api/signalr.service';
10+
import { AxiosGlobalConfig, snotifyDefaults } from '@/config';
1111
import Snotify from 'vue-snotify';
12-
import { snotifyDefaults } from '@/config/vue-snotify.config';
1312

1413
// Install custom plugins/third-party packages
1514
Vue.use(vClickOutside);
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
import Dashboard from './Dashboard.vue';
22

3-
export {
4-
Dashboard
5-
};
3+
export { Dashboard };
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
import ForecastTable from './ForecastTable.vue';
22

3-
export {
4-
ForecastTable,
5-
};
3+
export { ForecastTable };
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
import FetchData from './FetchData.vue';
22

3-
export {
4-
FetchData
5-
};
3+
export { FetchData };

GhostUI/ClientApp/src/views/Form/Form.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@
5656

5757
<script lang="ts">
5858
import { Component, Vue } from "vue-property-decorator";
59+
import { DROPDOWN_TEST_DATA } from "../../config";
5960
import { VCheckbox, VDropdown } from "../../components";
60-
import { DROPDOWN_TEST_DATA } from "../../config/constants";
6161
import { FormModule, IDropdownOption } from "../../store/modules/form";
6262
6363
@Component({
+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
import Form from './Form.vue';
22

3-
export {
4-
Form
5-
};
3+
export { Form };
+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
import Login from './Login.vue';
22

3-
export {
4-
Login
5-
};
3+
export { Login };

GhostUI/GhostUI.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
<PackageReference Include="AspNetCore.HealthChecks.UI" Version="5.0.1" />
2222
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="5.0.1" />
2323
<PackageReference Include="AspNetCore.HealthChecks.UI.InMemory.Storage" Version="5.0.1" />
24-
<PackageReference Include="NSwag.AspNetCore" Version="13.10.6" />
25-
<PackageReference Include="NSwag.MSBuild" Version="13.10.6">
24+
<PackageReference Include="NSwag.AspNetCore" Version="13.10.7" />
25+
<PackageReference Include="NSwag.MSBuild" Version="13.10.7">
2626
<PrivateAssets>all</PrivateAssets>
2727
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
2828
</PackageReference>

GhostUI/wwwroot/docs/api-specification.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"x-generator": "NSwag v13.10.6.0 (NJsonSchema v10.3.8.0 (Newtonsoft.Json v12.0.0.0))",
2+
"x-generator": "NSwag v13.10.7.0 (NJsonSchema v10.3.9.0 (Newtonsoft.Json v12.0.0.0))",
33
"openapi": "3.0.0",
44
"info": {
55
"title": "GhostUI API",

0 commit comments

Comments
 (0)