Sockets as Observable
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 { Server } from 'http'; | |
import { Observable } from 'rxjs'; | |
import { Observer } from 'rxjs'; | |
import * as socketIoServer from 'socket.io'; | |
import {SocketObs} from './socket-obs'; | |
export function sockets(httpServer: Server, port) { | |
httpServer.listen(port, () => { | |
console.log('Running server on port %s', port); | |
}); | |
return new Observable<SocketObs>( | |
(subscriber: Observer<SocketObs>) => { | |
socketIoServer(httpServer).on('connect', | |
socket => { | |
console.log('client connected'); | |
subscriber.next(new SocketObs(socket)); | |
} | |
); | |
} | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment