aboutsummaryrefslogtreecommitdiff
path: root/frontend/src/app/_services
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/src/app/_services')
-rw-r--r--frontend/src/app/_services/signal-r.service.spec.ts (renamed from frontend/src/app/_services/web-socket.service.spec.ts)8
-rw-r--r--frontend/src/app/_services/signal-r.service.ts30
-rw-r--r--frontend/src/app/_services/web-socket.service.ts39
3 files changed, 34 insertions, 43 deletions
diff --git a/frontend/src/app/_services/web-socket.service.spec.ts b/frontend/src/app/_services/signal-r.service.spec.ts
index a86aeca7..f737fa50 100644
--- a/frontend/src/app/_services/web-socket.service.spec.ts
+++ b/frontend/src/app/_services/signal-r.service.spec.ts
@@ -1,13 +1,13 @@
import { TestBed } from '@angular/core/testing';
-import { WebSocketService } from './web-socket.service';
+import { SignalRService } from './signal-r.service';
-describe('WebSocketService', () => {
- let service: WebSocketService;
+describe('SignalRService', () => {
+ let service: SignalRService;
beforeEach(() => {
TestBed.configureTestingModule({});
- service = TestBed.inject(WebSocketService);
+ service = TestBed.inject(SignalRService);
});
it('should be created', () => {
diff --git a/frontend/src/app/_services/signal-r.service.ts b/frontend/src/app/_services/signal-r.service.ts
new file mode 100644
index 00000000..5eca48d3
--- /dev/null
+++ b/frontend/src/app/_services/signal-r.service.ts
@@ -0,0 +1,30 @@
+import { Injectable } from '@angular/core';
+import * as signalR from "@microsoft/signalr";
+import Shared from '../Shared';
+import { CookieService } from 'ngx-cookie-service';
+@Injectable({
+ providedIn: 'root'
+})
+export class SignalRService {
+private hubConnection?:signalR.HubConnection;
+public startConnection=()=>{
+
+ this.hubConnection= new signalR.HubConnectionBuilder()
+ .withUrl('http://localhost:5283/chatHub', {
+ accessTokenFactory: () => this.cookie.get("token"),
+ withCredentials: false
+ }).build();
+
+ this.hubConnection.on("Notify",(message:string) =>{
+ console.log(" "+message);
+ });
+
+
+
+ this.hubConnection
+ .start()
+ .then(()=>console.log("con Started"))
+ .catch(err=>console.log("Error"+err))
+}
+ constructor(private cookie:CookieService) { }
+}
diff --git a/frontend/src/app/_services/web-socket.service.ts b/frontend/src/app/_services/web-socket.service.ts
deleted file mode 100644
index 1a7efa87..00000000
--- a/frontend/src/app/_services/web-socket.service.ts
+++ /dev/null
@@ -1,39 +0,0 @@
-import { Injectable } from '@angular/core';
-import { ConstantBackoff, Websocket, WebsocketBuilder } from 'websocket-ts';
-import { API_SETTINGS } from 'src/config';
-
-@Injectable({
- providedIn: 'root'
-})
-export class WebSocketService {
-
- ws?: Websocket;
-
- private handlers: Function[] = [];
-
- constructor() {
- this.ws = new WebsocketBuilder(API_SETTINGS.apiWSUrl)
- .withBackoff(new ConstantBackoff(120000))
- .onOpen((i, e) => { /*console.log('WS: Connected to ' + API_SETTINGS.apiWSUrl)*/ })
- .onMessage((i, e) => {
- console.log('WS MESSAGE: ', e.data);
- this.handlers.forEach(handler => {
- handler(e.data);
- })
- })
- .onClose((i, e) => { /*console.log('WS: Connection closed!')*/ })
- .build();
- }
-
- send(msg: string) {
- this.ws?.send(msg);
- }
-
- addHandler(handler: Function) {
- this.handlers.push(handler);
- }
-
- removeHandler(handler: Function) {
- this.handlers.splice(this.handlers.indexOf(handler), 1);
- }
-}