first commit

This commit is contained in:
wilfried 2021-05-27 10:53:34 +02:00
parent 6984c550fb
commit 595d0e3013
47 changed files with 13471 additions and 0 deletions

View 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();
});
});

View 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 ;
}
}

View 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();
});
});

View 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));
}
}