rpaschoal / ng-chat-nodejs

A simple Node.js application that uses ng-chat.
MIT License
10 stars 15 forks source link

throw is deprecated: In favor of throwError creation function: import { throwError } from 'rxjs'; (deprecation) #1

Closed SamyakUkey closed 5 years ago

SamyakUkey commented 5 years ago

import { ChatAdapter, User, Message, ParticipantResponse } from 'ng-chat'; import {Observable, of, from } from 'rxjs'; import { map, catchError, } from 'rxjs/operators'; import { Socket } from 'ng-socket-io'; import { HttpClient, } from '@angular/common/http'; import { Response } from '@angular/http'; import { throwError } from 'rxjs';

export class SocketIOAdapter extends ChatAdapter { private socket: Socket; private http: HttpClient; private userId: string;

constructor(userId: string, socket: Socket, http: HttpClient) {
    super();
    this.socket = socket;
    this.http = http;
    this.userId = userId;

    this.InitializeSocketListerners();
}

listFriends(): Observable<ParticipantResponse[]> {
    // List connected users to show in the friends list
    // Sending the userId from the request body as this is just a demo
    return this.http
        .post('http://localhost:3000/listFriends', { userId: this.userId })
        .pipe(
            map((res: Response) => res.json()),
            catchError((error: any) => Observable.throw(error.json().error || 'Server error'))
        );
}

getMessageHistory(userId: any): Observable<Message[]> {
    // This could be an API call to your NodeJS application that would go to the database
    // and retrieve a N amount of history messages between the users.
    return of([]);
}

sendMessage(message: Message): void {
    this.socket.emit('sendMessage', message);
}

public InitializeSocketListerners(): void {
  this.socket.on('messageReceived', (messageWrapper) => {
    // Handle the received message to ng-chat

    this.onMessageReceived(messageWrapper.user, messageWrapper.message);
  });

  this.socket.on('friendsListChanged', (usersCollection: Array<ParticipantResponse>) => {
    // Handle the received message to ng-chat
    this.onFriendsListChanged(usersCollection.filter(x => x.participant.id !== this.userId));
  });
}

}

rpaschoal commented 5 years ago

Hello @SamyakUkey , could you please add more details to your issue?