first commit
This commit is contained in:
parent
6984c550fb
commit
595d0e3013
47 changed files with 13471 additions and 0 deletions
16
frontend/src/app/services/auth/auth.service.spec.ts
Normal file
16
frontend/src/app/services/auth/auth.service.spec.ts
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { AuthService } from './auth.service';
|
||||
|
||||
describe('AuthService', () => {
|
||||
let service: AuthService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(AuthService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
79
frontend/src/app/services/auth/auth.service.ts
Normal file
79
frontend/src/app/services/auth/auth.service.ts
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import {Observable} from "rxjs";
|
||||
|
||||
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
|
||||
export class AuthService {
|
||||
// @ts-ignore
|
||||
// @ts-ignore
|
||||
public roomId: string;
|
||||
// @ts-ignore
|
||||
public messageText: string;
|
||||
public messageArray: {user: string, message: string}[] = [];
|
||||
private storageArray = [];
|
||||
|
||||
// @ts-ignore
|
||||
public showScreen: boolean;
|
||||
|
||||
// @ts-ignore
|
||||
public phone: string;
|
||||
// @ts-ignore
|
||||
public currentUser;
|
||||
// @ts-ignore
|
||||
public selectedUser;
|
||||
|
||||
public userList = [
|
||||
{
|
||||
id: 1,
|
||||
name: 'Yuki Vachot',
|
||||
phone: '0608020103',
|
||||
roomId: {
|
||||
2: 'room-1',
|
||||
3: 'room-2',
|
||||
4: 'room-3'
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: 'Wilfried Vallee',
|
||||
phone: '0604080701',
|
||||
roomId: {
|
||||
1: 'room-1',
|
||||
3: 'room-4',
|
||||
4: 'room-5'
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
name: 'Khai Phan',
|
||||
phone: '0603050960',
|
||||
roomId: {
|
||||
1: 'room-2',
|
||||
2: 'room-4',
|
||||
4: 'room-6'
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
constructor() {}
|
||||
sendAuthentication(phone: string): boolean {
|
||||
this.phone = phone;
|
||||
this.currentUser = this.userList.find(user => user.phone === this.phone.toString());
|
||||
this.userList = this.userList.filter((user) => user.phone !== this.phone.toString());
|
||||
//console.log("2 -", this.currentUser.phone);
|
||||
console.log("3 -", this.phone);
|
||||
if(this.currentUser) {
|
||||
this.showScreen = true;
|
||||
console.log("user : TRUE", this.phone.toString());
|
||||
} else {
|
||||
console.log("error user", this.phone.toString());
|
||||
}
|
||||
return this.showScreen ;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
16
frontend/src/app/services/chat/chat.service.spec.ts
Normal file
16
frontend/src/app/services/chat/chat.service.spec.ts
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { ChatService } from './chat.service';
|
||||
|
||||
describe('ChatService', () => {
|
||||
let service: ChatService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(ChatService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
47
frontend/src/app/services/chat/chat.service.ts
Normal file
47
frontend/src/app/services/chat/chat.service.ts
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import { io, Socket } from "socket.io-client";
|
||||
import {Observable} from "rxjs";
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class ChatService {
|
||||
|
||||
private socket: Socket;
|
||||
private url = 'http://localhost:3000';
|
||||
|
||||
constructor() {
|
||||
this.socket = io(this.url);
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
joinRoom(data): void {
|
||||
this.socket.emit('join', data);
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
sendMessage(data): void{
|
||||
this.socket.emit('message', data);
|
||||
}
|
||||
|
||||
getMessage(): Observable<any> {
|
||||
return new Observable<{user: string, message: string}>(observer => {
|
||||
this.socket.on('new message', (data) => {
|
||||
observer.next(data);
|
||||
});
|
||||
return () => {
|
||||
this.socket.disconnect();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
getStorage() {
|
||||
const storage = localStorage.getItem('chats');
|
||||
return storage ? JSON.parse(storage) : [];
|
||||
}
|
||||
|
||||
setStorage(data: any) {
|
||||
localStorage.setItem('chats', JSON.stringify(data));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in a new issue