You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Wondering what's the right way to handle a websockets listener implemented through redux-logic with SSR. I've been using window.location to configure the listener. Should I use process.env variables to configure them when rendering on the server, or should I do something else with the listener (maybe bypass it entirely)?
Any advice welcome. Redux logic listener code is below.
websocket/logic.js:
import{createLogic}from'redux-logic'import{timer}from'rxjs'import{filter,tap,map,takeUntil,retryWhen,switchMap,}from'rxjs/operators'import{webSocket}from'rxjs/webSocket'importdebugfrom'debug'importstorefrom'../store'import{msgReceived,WS_CONNECT,WS_DISCONNECT,WS_MSG_ERROR,WS_MSG_SEND,WS_MSG_LISTEN,WS_MSG_STOP_LISTENING,}from'./actions'debug.enable('websocket/logic:*')constlog=debug('websocket/logic:log')// const info = debug('websocket/logic:info')consterror=debug('websocket/logic:error')constwsType=window.location.protocol==='http:' ? 'ws' : 'wss'constport=window.location.port ? `:${window.location.port}` : ''constWS_SERVER=`${wsType}://${window.location.hostname}${port}/ws`log(`ws server = ${WS_SERVER}`)constwsListenLogic=createLogic({type: WS_MSG_LISTEN,cancelType: WS_MSG_STOP_LISTENING,latest: true,// take latest onlywarnTimeout: 0,// long running logicprocessOptions: {failType: WS_MSG_ERROR,},process({ action$, cancelled$ }){constwsSubject$=webSocket({url: WS_SERVER,openObserver: {next: ()=>store.dispatch({type: WS_CONNECT}),},closeObserver: {next: ()=>store.dispatch({type: WS_DISCONNECT}),},})// send message on WS_MSG_SEND actionaction$.pipe(filter(action=>action.type===WS_MSG_SEND),tap(action=>wsSubject$.next(action.payload)),takeUntil(cancelled$)).subscribe()// dispatch msgReceived with payload from server// on any incoming messages// returning obs subscribes to itreturnwsSubject$.pipe(map(msg=>msgReceived(msg)),retryWhen(errors=>errors.pipe(tap(err=>error(err)),switchMap(err=>timer(1000)))))},})exportdefault[wsListenLogic]
The text was updated successfully, but these errors were encountered:
Wondering what's the right way to handle a websockets listener implemented through redux-logic with SSR. I've been using window.location to configure the listener. Should I use process.env variables to configure them when rendering on the server, or should I do something else with the listener (maybe bypass it entirely)?
Any advice welcome. Redux logic listener code is below.
websocket/logic.js:
The text was updated successfully, but these errors were encountered: