Created
May 5, 2017 18:10
-
-
Save Ibro/a535c10a348370650d184079a957f46c to your computer and use it in GitHub Desktop.
RxJS Socket.IO Angular Chat - Angular Service - Coding Blast - www.codingblast.com
This file contains 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 * as io from 'socket.io-client'; | |
import { Observable } from 'rxjs/Observable'; | |
export class ChatService { | |
private url = 'http://localhost:3000'; | |
private socket; | |
constructor() { | |
this.socket = io(this.url); | |
} | |
public sendMessage(message) { | |
this.socket.emit('new-message', message); | |
} | |
public getMessages = () => { | |
return Observable.create((observer) => { | |
this.socket.on('new-message', (message) => { | |
observer.next(message); | |
}); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment