Created
February 28, 2017 22:00
-
-
Save REPTILEHAUS/ba8036c6667c1134b5688911698c46cc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Injectable } from '@angular/core'; | |
| import { Subject } from 'rxjs/Subject'; | |
| import { Observable } from 'rxjs/Observable'; | |
| import * as io from 'socket.io-client'; | |
| @Injectable() | |
| export class ChatService { | |
| private url = 'http://localhost:5000'; | |
| private socket; | |
| sendMessage(message){ | |
| this.socket.emit('add-message', message); | |
| } | |
| getMessages() { | |
| let observable = new Observable(observer => { | |
| this.socket = io(this.url); | |
| this.socket.on('message', (data) => { | |
| observer.next(data); | |
| }); | |
| return () => { | |
| this.socket.disconnect(); | |
| }; | |
| }) | |
| return observable; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment