socket layers
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
});
|
||||
@@ -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<string>;
|
||||
errors$: Observable<string>;
|
||||
|
||||
private connectionSubject: Subject<boolean>;
|
||||
connected$: Observable<boolean>;
|
||||
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<boolean> {
|
||||
this.connectionSubject = new BehaviorSubject<boolean>(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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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: {
|
||||
|
||||
@@ -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: {
|
||||
|
||||
Reference in New Issue
Block a user