From 8f7b7024c9157af628801d1294e0f43769b9a74d Mon Sep 17 00:00:00 2001 From: "CHIEFSOFT\\ameye" Date: Tue, 12 Mar 2024 10:44:55 -0400 Subject: [PATCH] socket layers --- REMEMBER.txt | 8 +++ package.json | 2 + src/app/services/socket-tools.service.spec.ts | 16 +++++ src/app/services/socket-tools.service.ts | 70 +++++++++++++++++++ src/environments/environment.prod.ts | 1 + src/environments/environment.ts | 1 + 6 files changed, 98 insertions(+) create mode 100644 src/app/services/socket-tools.service.spec.ts create mode 100644 src/app/services/socket-tools.service.ts diff --git a/REMEMBER.txt b/REMEMBER.txt index d94ee24..d64fe04 100644 --- a/REMEMBER.txt +++ b/REMEMBER.txt @@ -1,6 +1,11 @@ npm install @capacitor/assets --save-dev npx capacitor-assets generate +npm install socket.io-client +npm install @types/socket.io-client -D + + + ionic capacitor build ionic generate page familylogin @@ -82,6 +87,9 @@ ionic generate page addbank ionic generate service user-wallet ionic generate service waiting-interest +ionic generate service socket-tools + + ionic generate component tracking ionic generate component myjob-offers diff --git a/package.json b/package.json index 55d2c69..25d9ca8 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,7 @@ "jwt-decode": "^3.1.2", "onesignal-cordova-plugin": "^5.0.0-beta-02", "rxjs": "~6.6.0", + "socket.io-client": "^4.7.4", "tslib": "^2.2.0", "zone.js": "~0.11.4" }, @@ -62,6 +63,7 @@ "@types/jasmine": "~3.6.0", "@types/jasminewd2": "~2.0.3", "@types/node": "^12.11.1", + "@types/socket.io-client": "^3.0.0", "@typescript-eslint/eslint-plugin": "5.3.0", "@typescript-eslint/parser": "5.3.0", "eslint": "^7.6.0", diff --git a/src/app/services/socket-tools.service.spec.ts b/src/app/services/socket-tools.service.spec.ts new file mode 100644 index 0000000..fec4116 --- /dev/null +++ b/src/app/services/socket-tools.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { SocketToolsService } from './socket-tools.service'; + +describe('SocketToolsService', () => { + let service: SocketToolsService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(SocketToolsService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/src/app/services/socket-tools.service.ts b/src/app/services/socket-tools.service.ts new file mode 100644 index 0000000..9cc1264 --- /dev/null +++ b/src/app/services/socket-tools.service.ts @@ -0,0 +1,70 @@ +import { Injectable } from '@angular/core'; +import { io, Socket } from 'socket.io-client'; +import { BehaviorSubject, Observable, Subject } from 'rxjs'; +import { environment } from 'src/environments/environment'; + +@Injectable({ + providedIn: 'root' +}) +export class SocketToolsService { + + constructor() { + this.setup('NO-NEED-FOR-NOW'); + } + private socket: Socket; + private errorSubject: Subject; + errors$: Observable; + + private connectionSubject: Subject; + connected$: Observable; + setup(authToken: string): void { + // this.socket = io(environment.socketURL, { + // path: '/chat/', + // reconnection: true, + // autoConnect: false, + // extraHeaders: { + // Authorization: 'Bearer ' + authToken + // } + // }); + + this.socket = io(environment.socketURL); + this.connected$ = this.monitorConnection(); + this.socket.connect(); + } + + public joinSocketRoom(socketRoom){ + this.socket.emit("join_room", socketRoom); + } + public emmitSocketEvent(message, socketRoom){ + this.socket.emit("send_message", { message, socketRoom }); + } + private monitorConnection(): Observable { + this.connectionSubject = new BehaviorSubject(false); + + this.socket.on('connect', () => { + this.connectionSubject.next(true); + }); + + this.socket.on('connection', () => { + this.connectionSubject.next(true); + }); + + this.socket.on('disconnect', () => { + this.connectionSubject.next(false); + }); + + this.socket.on('disconnecting', () => { + this.connectionSubject.next(false); + }); + + return this.connectionSubject.asObservable(); + } + + stop(): void { + this.socket?.disconnect(); + // this.newMessagesSubject?.complete(); + this.connectionSubject?.complete(); + this.errorSubject?.complete(); + } + +} diff --git a/src/environments/environment.prod.ts b/src/environments/environment.prod.ts index 3da25ac..6145157 100644 --- a/src/environments/environment.prod.ts +++ b/src/environments/environment.prod.ts @@ -4,6 +4,7 @@ export const environment = { baseUrl: 'https://apigate.lotus.g1.wrenchboard.com/svs/user', images: 'https://apigate.lotus.g1.wrenchboard.com/svs/user', appleRedirectUri: 'https://users.wrenchboard.com/loginWithApple', + socketURL:'https://socket.wrenchboard.com', facebookAppId: '390204307987009', loginSocial: false, keys: { diff --git a/src/environments/environment.ts b/src/environments/environment.ts index 5873d73..a36c037 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -4,6 +4,7 @@ export const environment = { baseUrl: 'https://apigate.lotus.g1.wrenchboard.com/en/wrench/api/v1', images: 'https://apigate.lotus.g1.wrenchboard.com/en/wrench/api/v1/', appleRedirectUri: 'https://dev-users.wrenchboard.com/loginWithApple', + socketURL:'https://socket-dev.wrenchboard.com', facebookAppId: '677857427521030', loginSocial: true, keys: {