@redux-observable-backend/websocket
v4.4.0
Published
Utilities for creating applications using WebSockets.
Downloads
15
Readme
Redux Observable Backend - WebSockets
For an example use case, look at ./app.js
.
Installation
This package requires you also install these peer dependencies:
@redux-observable-backend/node
@redux-observable-backend/redux-utils
rxjs
npm
npm i rxjs@redux-observable-backend/websocket @redux-observable-backend/node @redux-observable-backend/redux-utils
yarn
yarn add rxjs @redux-observable-backend/websocket @redux-observable-backend/node @redux-observable-backend/redux-utils
API
Redux
createHttpServers
createWebSocketServers
ofReponseType
ofRequestType
webSocketsEpic
webSocketsReducers
Custom Configuration
WebSocket Server
To configure the Webpack listener, you have 3 options available to modify in your ./localConfig.js
:
module.exports = { // ... other config options ... hostname, port, protocol, }
Testing
Join a Channel
To test joining a channel, load up a browser, and go to about:blank
.
Then paste this into the devtools console:
webSocket = new WebSocket('ws://localhost:3000', 'v1')
webSocket.onmessage = console.log
webSocket.onerror = console.error
webSocket.onclose = console.info
webSocket.onopen = () => {
console.log('READY')
webSocket
.send(
JSON
.stringify({
channelName: 'TestChannel',
type: 'REQUEST::JOIN_CHANNEL',
})
)
}