From 5d8f5578c363c3f994e1bb0a311bdbc6d4090723 Mon Sep 17 00:00:00 2001 From: ngawron Date: Mon, 7 Dec 2020 11:46:18 +0100 Subject: [PATCH] added base service --- .../ClientApp/package-lock.json | 59 +++++++++++++++---- .../SessionCompanion/ClientApp/package.json | 1 + .../signalR-service/base/signalR.service.ts | 41 +++++++++++++ .../signalR-service/gm-signalR.service.ts | 17 ++++++ .../signalR-service/player-signalR.service.ts | 17 ++++++ 5 files changed, 125 insertions(+), 10 deletions(-) create mode 100644 SessionCompanion/SessionCompanion/ClientApp/src/app/shared/signalR-service/base/signalR.service.ts create mode 100644 SessionCompanion/SessionCompanion/ClientApp/src/app/shared/signalR-service/gm-signalR.service.ts create mode 100644 SessionCompanion/SessionCompanion/ClientApp/src/app/shared/signalR-service/player-signalR.service.ts diff --git a/SessionCompanion/SessionCompanion/ClientApp/package-lock.json b/SessionCompanion/SessionCompanion/ClientApp/package-lock.json index c884853..9fe4ffb 100644 --- a/SessionCompanion/SessionCompanion/ClientApp/package-lock.json +++ b/SessionCompanion/SessionCompanion/ClientApp/package-lock.json @@ -2591,6 +2591,25 @@ "integrity": "sha512-tsAQNx32a8CoFhjhijUIhI4kccIAgmGhy8LZMZgGfmXcpMbPRUqn5LWmgRttILi6yeGmBJd2xsPkFMs0PzgPCw==", "dev": true }, + "@microsoft/signalr": { + "version": "5.0.0", + "resolved": "https://artifactory.platform.vwfs.io/artifactory/api/npm/vwfs-du-cp-npm-virtual/@microsoft/signalr/-/signalr-5.0.0.tgz", + "integrity": "sha1-DWT9HTIKxPv16SUCM0m4R63DSOo=", + "requires": { + "abort-controller": "^3.0.0", + "eventsource": "^1.0.7", + "fetch-cookie": "^0.7.3", + "node-fetch": "^2.6.0", + "ws": "^6.0.0" + }, + "dependencies": { + "node-fetch": { + "version": "2.6.1", + "resolved": "https://artifactory.platform.vwfs.io/artifactory/api/npm/vwfs-du-cp-npm-virtual/node-fetch/-/node-fetch-2.6.1.tgz", + "integrity": "sha1-BFvTI2Mfdu0uK1VXM5RBa2OaAFI=" + } + } + }, "@ngtools/webpack": { "version": "8.3.26", "resolved": "https://registry.npmjs.org/@ngtools/webpack/-/webpack-8.3.26.tgz", @@ -2960,6 +2979,14 @@ "integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==", "optional": true }, + "abort-controller": { + "version": "3.0.0", + "resolved": "https://artifactory.platform.vwfs.io/artifactory/api/npm/vwfs-du-cp-npm-virtual/abort-controller/-/abort-controller-3.0.0.tgz", + "integrity": "sha1-6vVNU7YrrkE46AnKIlyEOabvs5I=", + "requires": { + "event-target-shim": "^5.0.0" + } + }, "accepts": { "version": "1.3.7", "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.7.tgz", @@ -3291,8 +3318,7 @@ "async-limiter": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.1.tgz", - "integrity": "sha512-csOlWGAcRFJaI6m+F2WKdnMKr4HhdhFVBk0H/QbJFMCr+uO2kwohwXQPxw/9OCxp05r5ghVBFSyioixx3gfkNQ==", - "dev": true + "integrity": "sha512-csOlWGAcRFJaI6m+F2WKdnMKr4HhdhFVBk0H/QbJFMCr+uO2kwohwXQPxw/9OCxp05r5ghVBFSyioixx3gfkNQ==" }, "asynckit": { "version": "0.4.0", @@ -5267,6 +5293,11 @@ "is-symbol": "^1.0.2" } }, + "es6-denodeify": { + "version": "0.1.5", + "resolved": "https://artifactory.platform.vwfs.io/artifactory/api/npm/vwfs-du-cp-npm-virtual/es6-denodeify/-/es6-denodeify-0.1.5.tgz", + "integrity": "sha1-MdTV/pxVA+ElRgQ5MQ4WoqPznB8=" + }, "es6-promise": { "version": "4.2.8", "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.2.8.tgz", @@ -5332,6 +5363,11 @@ "integrity": "sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc=", "dev": true }, + "event-target-shim": { + "version": "5.0.1", + "resolved": "https://artifactory.platform.vwfs.io/artifactory/api/npm/vwfs-du-cp-npm-virtual/event-target-shim/-/event-target-shim-5.0.1.tgz", + "integrity": "sha1-XU0+vflYPWOlMzzi3rdICrKwV4k=" + }, "eventemitter3": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-4.0.0.tgz", @@ -5348,7 +5384,6 @@ "version": "1.0.7", "resolved": "https://registry.npmjs.org/eventsource/-/eventsource-1.0.7.tgz", "integrity": "sha512-4Ln17+vVT0k8aWq+t/bF5arcS3EpT9gYtW66EPacdj/mAFevznsnyoHLPy2BA8gbIQeIHoPsvwmfBftfcG//BQ==", - "dev": true, "requires": { "original": "^1.0.0" } @@ -5659,6 +5694,15 @@ "websocket-driver": ">=0.5.1" } }, + "fetch-cookie": { + "version": "0.7.3", + "resolved": "https://artifactory.platform.vwfs.io/artifactory/api/npm/vwfs-du-cp-npm-virtual/fetch-cookie/-/fetch-cookie-0.7.3.tgz", + "integrity": "sha1-uNAj9CHdKy9KDsqc1zGKln7U7tg=", + "requires": { + "es6-denodeify": "^0.1.1", + "tough-cookie": "^2.3.3" + } + }, "figgy-pudding": { "version": "3.5.1", "resolved": "https://registry.npmjs.org/figgy-pudding/-/figgy-pudding-3.5.1.tgz", @@ -8881,7 +8925,6 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/original/-/original-1.0.2.tgz", "integrity": "sha512-hyBVl6iqqUOJ8FqRe+l/gS8H+kKYjrEndd5Pm1MfBtsEKA038HkkdbAl/72EAXGyonD/PFsvmVG+EvcIpliMBg==", - "dev": true, "requires": { "url-parse": "^1.4.3" } @@ -9632,8 +9675,7 @@ "querystringify": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/querystringify/-/querystringify-2.1.1.tgz", - "integrity": "sha512-w7fLxIRCRT7U8Qu53jQnJyPkYZIaR4n5151KMfcJlO/A9397Wxb1amJvROTK6TOnp7PfoAmg/qXiNHI+08jRfA==", - "dev": true + "integrity": "sha512-w7fLxIRCRT7U8Qu53jQnJyPkYZIaR4n5151KMfcJlO/A9397Wxb1amJvROTK6TOnp7PfoAmg/qXiNHI+08jRfA==" }, "randombytes": { "version": "2.1.0", @@ -9974,8 +10016,7 @@ "requires-port": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz", - "integrity": "sha1-kl0mAdOaxIXgkc8NpcbmlNw9yv8=", - "dev": true + "integrity": "sha1-kl0mAdOaxIXgkc8NpcbmlNw9yv8=" }, "resolve": { "version": "1.15.1", @@ -11799,7 +11840,6 @@ "version": "1.4.7", "resolved": "https://registry.npmjs.org/url-parse/-/url-parse-1.4.7.tgz", "integrity": "sha512-d3uaVyzDB9tQoSXFvuSUNFibTd9zxd2bkVrDRvF5TmvWWQwqE4lgYJ5m+x1DbecWkw+LK4RNl2CU1hHuOKPVlg==", - "dev": true, "requires": { "querystringify": "^2.1.1", "requires-port": "^1.0.0" @@ -13781,7 +13821,6 @@ "version": "6.2.1", "resolved": "https://registry.npmjs.org/ws/-/ws-6.2.1.tgz", "integrity": "sha512-GIyAXC2cB7LjvpgMt9EKS2ldqr0MTrORaleiOno6TweZ6r3TKtoFQWay/2PceJ3RuBasOHzXNn5Lrw1X0bEjqA==", - "dev": true, "requires": { "async-limiter": "~1.0.0" } diff --git a/SessionCompanion/SessionCompanion/ClientApp/package.json b/SessionCompanion/SessionCompanion/ClientApp/package.json index 337a8e8..dd2400f 100644 --- a/SessionCompanion/SessionCompanion/ClientApp/package.json +++ b/SessionCompanion/SessionCompanion/ClientApp/package.json @@ -23,6 +23,7 @@ "@angular/platform-browser-dynamic": "8.2.12", "@angular/platform-server": "8.2.12", "@angular/router": "8.2.12", + "@microsoft/signalr": "^5.0.0", "@nguniversal/module-map-ngfactory-loader": "8.1.1", "aspnet-prerendering": "^3.0.1", "bootstrap": "^4.3.1", diff --git a/SessionCompanion/SessionCompanion/ClientApp/src/app/shared/signalR-service/base/signalR.service.ts b/SessionCompanion/SessionCompanion/ClientApp/src/app/shared/signalR-service/base/signalR.service.ts new file mode 100644 index 0000000..e597d57 --- /dev/null +++ b/SessionCompanion/SessionCompanion/ClientApp/src/app/shared/signalR-service/base/signalR.service.ts @@ -0,0 +1,41 @@ +import { Inject, Injectable } from '@angular/core'; +import { + HubConnection, + HubConnectionBuilder, + HubConnectionState, + LogLevel +} from '@microsoft/signalr'; +import { BehaviorSubject} from 'rxjs'; + +@Injectable({ providedIn: 'root' }) +export class SignalRService { + connectionEstablished$ = new BehaviorSubject(false); + + public hubConnection: HubConnection; + + constructor(@Inject('BASE_URL') baseUrl: string) { + this.createConnection(baseUrl); + } + + private createConnection(baseUrl: string) { + this.hubConnection = new HubConnectionBuilder() + .withUrl( baseUrl + 'sessionhub') + .withAutomaticReconnect() + .configureLogging(LogLevel.Information) + .build(); + } + + public startConnection() { + if (this.hubConnection.state === HubConnectionState.Connected) { + return; + } + + this.hubConnection.start().then( + () => { + console.log('Hub connection started!'); + this.connectionEstablished$.next(true); + }, + error => console.error(error) + ); + } +} \ No newline at end of file diff --git a/SessionCompanion/SessionCompanion/ClientApp/src/app/shared/signalR-service/gm-signalR.service.ts b/SessionCompanion/SessionCompanion/ClientApp/src/app/shared/signalR-service/gm-signalR.service.ts new file mode 100644 index 0000000..367d54f --- /dev/null +++ b/SessionCompanion/SessionCompanion/ClientApp/src/app/shared/signalR-service/gm-signalR.service.ts @@ -0,0 +1,17 @@ +import { Inject, Injectable } from '@angular/core'; +import { SignalRService } from './base/signalR.service'; + +@Injectable({ providedIn: 'root' }) +export class GMSignalRService { + signalR: SignalRService; + + constructor(@Inject('BASE_URL') baseUrl: string) { + this.signalR = new SignalRService(baseUrl); + this.registerOnServerEvents(); + this.signalR.startConnection(); + } + + private registerOnServerEvents(): void { + + } +} \ No newline at end of file diff --git a/SessionCompanion/SessionCompanion/ClientApp/src/app/shared/signalR-service/player-signalR.service.ts b/SessionCompanion/SessionCompanion/ClientApp/src/app/shared/signalR-service/player-signalR.service.ts new file mode 100644 index 0000000..b716f53 --- /dev/null +++ b/SessionCompanion/SessionCompanion/ClientApp/src/app/shared/signalR-service/player-signalR.service.ts @@ -0,0 +1,17 @@ +import { Inject, Injectable } from '@angular/core'; +import { SignalRService } from './base/signalR.service'; + +@Injectable({ providedIn: 'root' }) +export class PlayerSignalRService { + signalR: SignalRService; + + constructor(@Inject('BASE_URL') baseUrl: string) { + this.signalR = new SignalRService(baseUrl); + this.registerOnServerEvents(); + this.signalR.startConnection(); + } + + private registerOnServerEvents(): void { + + } +} \ No newline at end of file