ng6-socket-io
Version:
Socket.IO Module for Angular 6 and RxJS6
25 lines (20 loc) • 440 B
text/typescript
import { Injectable } from '@angular/core';
import { Socket } from '../../../../../src/index';
import { map } from 'rxjs/operators';
({
providedIn: 'root'
})
export class ChatService {
constructor(private socket: Socket) {
}
getMessage() {
return this.socket
.fromEvent<any>('msg')
.pipe(
map(data => data.msg)
);
}
sendMessage(msg: string) {
this.socket.emit('msg', msg);
}
}