Last active
July 22, 2019 11:14
-
-
Save praveen001/64af3d21ce232bc31aafecaeed6e2abb to your computer and use it in GitHub Desktop.
WebSocket Redux 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
let webSocketSubject: WebSocketSubject<{}>; | |
let onOpenSubject = new Subject(); | |
let onCloseSubject = new Subject(); | |
// Create the websocket subject | |
const createSocket = websocketUrl => { | |
onOpenSubject = new Subject(); | |
onCloseSubject = new Subject(); | |
webSocketSubject = webSocket({ | |
url: websocketUrl, | |
openObserver: onOpenSubject, | |
closeObserver: onCloseSubject | |
}); | |
return webSocketSubject; | |
}; | |
// Connect to web socket | |
const connectEpic = (action$, state$: StateObservable<IState>) => | |
action$ | |
.ofType(WebsocketActionTypes.CONNECT) | |
.switchMap((action: IConnectWebsocketAction) => | |
createSocket(action.payload.websocketUrl) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment