{"_id":"@braceta/redux-websocket","_rev":"7-ca80b5e49b39c585dd221922c1fa644b","time":{"1.1.6":"2019-10-14T03:31:02.797Z","created":"2019-10-14T03:32:43.245Z","1.1.7":"2019-10-14T03:32:43.617Z","modified":"2022-04-04T20:19:41.544Z"},"name":"@braceta/redux-websocket","dist-tags":{"latest":"1.1.7"},"versions":{"1.1.7":{"name":"@braceta/redux-websocket","version":"1.1.7","description":"A redux middleware to handle websocket connections","main":"dist","scripts":{"build":"npm run clean && npm run build:types && webpack && rimraf dist/__tests__","build:types":"tsc --emitDeclarationOnly --outdir dist","build:watch":"npm run clean && npm run build:types && webpack --watch","clean":"rimraf dist","check-types":"tsc --noEmit","format":"prettier --write \"src/**/*.ts\"","lint":"eslint --cache --ext .js,.jsx,.ts,.tsx --format=pretty --ignore-path .gitignore ./src ./demo","prepare":"npm run build","test":"jest --coverage"},"repository":{"type":"git","url":"git+https://github.com/dothingsio/redux-websocket.git"},"keywords":["redux"],"author":{"name":"Giant Machines","email":"contact@giantmachines.com","url":"https://giantmachines.com"},"license":"MIT","dependencies":{"redux":"~4"},"devDependencies":{"@babel/cli":"7.2.0","@babel/core":"7.2.0","@babel/plugin-proposal-class-properties":"7.2.1","@babel/plugin-proposal-object-rest-spread":"7.2.0","@babel/preset-env":"7.2.0","@babel/preset-typescript":"7.1.0","@types/jest":"24.0.1","@types/ws":"6.0.1","@typescript-eslint/eslint-plugin":"1.3.0","babel-loader":"8.0.4","eslint-config-airbnb-typescript":"1.1.0","eslint-formatter-pretty":"2.1.1","eslint-plugin-eslint-comments":"3.0.1","eslint-plugin-import":"2.16.0","eslint-plugin-jest":"22.2.1","eslint-plugin-jsx-a11y":"6.2.0","eslint-plugin-promise":"4.0.1","eslint-plugin-react":"7.12.4","eslint":"5.12.1","flux-standard-action":"2.1.0","jest":"24.1.0","redux-mock-store":"1.5.3","rimraf":"2.6.3","ts-jest":"24.0.1","typescript":"3.3.3","webpack-cli":"3.2.3","webpack":"4.29.3"},"gitHead":"d7d176c2ca3b0ef7b1ae0d1f3ff0d5f0bc43c03f","bugs":{"url":"https://github.com/dothingsio/redux-websocket/issues"},"homepage":"https://github.com/dothingsio/redux-websocket#readme","_id":"@braceta/redux-websocket@1.1.7","_nodeVersion":"12.11.1","_npmVersion":"6.11.3","dist":{"integrity":"sha512-pdKp30YVeTCHDGsLuFxXug78yR0iZ5tfELv3swOJVSgYFAZkzEgoJqMEM+qXzZQHMrhmTG8IWWhqggR0mYKCfA==","shasum":"2c488766cc836ccb9a3f4c04175eb4862d417a88","tarball":"https://registry.npmjs.org/@braceta/redux-websocket/-/redux-websocket-1.1.7.tgz","fileCount":10,"unpackedSize":47772,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdo+xcCRA9TVsSAnZWagAAFIoP/jRNH2mseQF/SX5cEvsC\nazCpsIVIBtlxTewzkbKxVG06v0rQAki6Fs3WO2RwylCqi7FxRBMkaxTjwVhY\nyByh675t1Me5J5hvMs+9NmsHWnzmd0S2UnHarRtfa6oLA3AtLrGG5ARQhNuw\nIx99Jis/xFd/CVIzf+FzYNwAenPOHBaMELfXYQ4lUZ3f1BqFnSaCPHdAwtVt\n2tChXWVKTEILDlFPscSEVWa0X5tj3JN1tXCutCwTYCDTztrPAfhqA3c9/q2i\nzuHOjNkWNSRcWojy9syFZoY6HF53Pe86OX1ETkquQyvCNmAnXmReomUaBFAC\nNtU9Vx+nA2Wuks+QUaMdqSj2rqQCkjuGsc4NbCSwOn32xoZI4RtaytQSjDrg\ngh1BdvmLH6Hqf7SX8Dx6TxW6G6/HA/ctCx++aoOSProbUXgsyCS0dUbq2gZm\nkBhtB+dOvB4xCmt1HU/3u/SZJChayOTtkPPxQK6xaroKha9sQhdhF1sNZk4m\ndYwT8jzMedud5tGXVv/LOdTVzSBrgu70dZJZWqHGb3t47cW91BTx6ToxYw4g\nffnJW+YSIos1MFCfbspThe4j1j4GgE5/YxNY012bGKDjjYrgbX+WHHOO/wEW\nibT59eIjyZ1G6yJetBRx7igd5+fPOtCX7wM3GwtcW/pYtYA3rkut4PwexLm0\nwiWf\r\n=jKlo\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDlp4VFkVq5Znkn08yOohnifY6D8wN42TZGVT3vPsnOaAIhAMnFAgEo5BZjSguaLON9rG/ymH8SFEvgiB7LKKML0TQB"}]},"maintainers":[{"name":"braceta","email":"labraceta@gmail.com"}],"_npmUser":{"name":"braceta","email":"labraceta@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/redux-websocket_1.1.7_1571023963466_0.8363753153488009"},"_hasShrinkwrap":false}},"maintainers":[{"name":"braceta","email":"labraceta@gmail.com"}],"description":"A redux middleware to handle websocket connections","homepage":"https://github.com/dothingsio/redux-websocket#readme","keywords":["redux"],"repository":{"type":"git","url":"git+https://github.com/dothingsio/redux-websocket.git"},"author":{"name":"Giant Machines","email":"contact@giantmachines.com","url":"https://giantmachines.com"},"bugs":{"url":"https://github.com/dothingsio/redux-websocket/issues"},"license":"MIT","readme":"# redux-websocket [![codecov](https://codecov.io/gh/giantmachines/redux-websocket/branch/master/graph/badge.svg)](https://codecov.io/gh/giantmachines/redux-websocket) [![npm version](https://badge.fury.io/js/%40giantmachines%2Fredux-websocket.svg)](https://badge.fury.io/js/%40giantmachines%2Fredux-websocket) ![npm](https://img.shields.io/npm/dm/@giantmachines/redux-websocket)\n\n`redux-websocket` is a Redux middleware for managing data over a WebSocket connection.\n\nThis middleware uses actions to interact with a WebSocket connection including connecting, disconnecting, sending messages, and receiving messages. All actions follow the [Flux Standard Action](https://github.com/acdlite/flux-standard-action) model.\n\n### Features\n\n- Written in TypeScript.\n- Interact with a WebSocket connection by dispatching actions.\n- Connect to multiple WebSocket streams by creating multiple middleware instances.\n- Handle WebSocket events with Redux middleware, integrate with Saga, and use reducers to persist state.\n- Automatically handle reconnection.\n\n## Installation\n\n```sh\n$ npm i @giantmachines/redux-websocket\n```\n\n## Configuration\n\nConfigure your Redux store to use the middleware with `applyMiddleware`. This package exports a function to create an instance of a middleware, which allows for configuration options, detailed below. Furthermore, you can create multiple instances of this middleware in order to connect to multiple WebSocket streams.\n\n```js\nimport { applyMiddleware, compose, createStore } from 'redux';\nimport reduxWebsocket from '@giantmachines/redux-websocket';\n\nimport reducer from './store/reducer';\n\n// Create the middleware instance.\nconst reduxWebsocketMiddleware = reduxWebsocket();\n\n// Create the Redux store.\nconst store = createStore(\n  reducer,\n  applyMiddleware(websocketMiddleware)\n);\n```\n\nYou may also pass options to the `reduxWebsocket` function.\n\n#### Available options\n\n```js\ninterface Options {\n  // Defaults to 'REDUX_WEBSOCKET'. Use this option to set a custom action type\n  // prefix. This is useful when you're creating multiple instances of the\n  // middleware, and need to handle actions dispatched by each middleware instance separately.\n  prefix?: string,\n  // Defaults to 2000. Amount of time to wait between reconnection attempts.\n  reconnectInterval?: number,\n  // Defaults to false. If set to true, will attempt to reconnect when conn is closed without error event\n  // e.g. when server closes connection\n  reconnectOnClose?: boolean,\n  // Callback when the WebSocket connection is open. Useful for when you\n  // need a reference to the WebSocket instance.\n  onOpen?: (socket: WebSocket) => void,\n\n}\n```\n\n## Usage\n\n`redux-websocket` will dispatch some actions automatically, based on what the internal WebSocket connection. Some actions will need to be dispatched by you.\n\n### User dispatched actions\n\nThese actions must be dispatched by you, however we do export action creator functions that can be used.\n\n> ⚠️ If you have created your middleware with a `prefix` option, make sure you pass that prefix as the second argument to all of these action creators.\n\n---\n\n##### ➡️ `REDUX_WEBSOCKET::WEBSOCKET_CONNECT`\n\n###### Example:\n\n```js\nimport { connect } from '@giantmachines/redux-websocket';\n\nstore.dispatch(connect('wss://my-server.com'));\n\n// You can also provide protocols if needed.\n// See: https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/WebSocket\n//\n// Note that this function only allows passing an array of protocols, even though\n// the spec allows passing a string or an array of strings. This is to support\n// the prefix argument, in the case that you've prefixed your action names.\nstore.dispatch(connect('wss://my-server.com', ['v1.stream.example.com']));\n\n// ...other ways to call this function:\nstore.dispatch(connect('wss://my-server.com', ['v1.stream.example.com'], 'MY_PREFIX'));\nstore.dispatch(connect('wss://my-server.com', 'MY_PREFIX'));\n```\n\n###### Arguments:\n\n1. `url` *(`string`)*: WebSocket URL to connect to.\n2. \\[`protocols`\\] *(`string[]`)*: Optional sub-protocols.\n2. \\[`prefix`\\] *(`string`)*: Optional action type prefix.\n\n---\n\n##### ➡️ `REDUX_WEBSOCKET::WEBSOCKET_DISCONNECT`\n\n###### Example:\n\n```js\nimport { disconnect } from '@giantmachines/redux-websocket';\n\nstore.dispatch(disconnect());\n```\n\n###### Arguments:\n\n1. \\[`prefix`\\] *(`string`)*: Optional action type prefix.\n\n---\n\n##### ➡️ `REDUX_WEBSOCKET::WEBSOCKET_SEND`\n\n###### Example:\n\n```js\nimport { send } from '@giantmachines/redux-websocket';\n\nstore.dispatch(send({ my: 'message' }));\n```\n\n###### Arguments:\n\n1. `message` *(`any`)*: Any JSON serializable value. This will be stringified and sent over the connection. If the value passed is not serializable, `JSON.stringify` will throw an error.\n2. \\[`prefix`\\] *(`string`)*: Optional action type prefix.\n\n---\n\n### Library dispatched actions\n\nThese actions are dispatched automatically by the middlware.\n\n##### ⬅️ `REDUX_WEBSOCKET::OPEN`\n\nDispatched when the WebSocket connection successfully opens, including after automatic reconnect.\n\n###### Structure\n\n```js\n{\n    type: 'REDUX_WEBSOCKET::OPEN',\n    meta: {\n        timestamp: string,\n    },\n}\n```\n\n---\n\n##### ⬅️ `REDUX_WEBSOCKET::CLOSED`\n\nDispatched when the WebSocket connection successfully closes, both when you ask the middleware to close the connection, and when the connection drops.\n\n###### Structure\n\n```js\n{\n    type: 'REDUX_WEBSOCKET::CLOSED',\n    meta: {\n        timestamp: string,\n    },\n}\n```\n\n---\n\n##### ⬅️ `REDUX_WEBSOCKET::MESSAGE`\n\nDispatched when the WebSocket connection receives a message. The payload includes a `message` key, which is JSON, and an `origin` key, which is the address of the connection from which the message was recieved.\n\n###### Structure\n\n```js\n{\n    type: 'REDUX_WEBSOCKET::MESSAGE',\n    meta: {\n        timestamp: string,\n    },\n    payload: {\n        message: string,\n        origin: string,\n    },\n}\n```\n\n---\n\n##### ⬅️ `REDUX_WEBSOCKET::BROKEN`\n\nDispatched when the WebSocket connection is dropped. This action will always be dispatched _after_ the `CLOSED` action.\n\n###### Structure\n\n```js\n{\n    type: 'REDUX_WEBSOCKET::BROKEN',\n    meta: {\n        timestamp: string,\n    },\n}\n```\n\n---\n\n##### ⬅️ `REDUX_WEBSOCKET::BEGIN_RECONNECT`\n\nDispatched when the middleware is starting the reconnection process.\n\n###### Structure\n\n```js\n{\n    type: 'REDUX_WEBSOCKET::BEGIN_RECONNECT',\n    meta: {\n        timestamp: string,\n    },\n}\n```\n\n---\n\n##### ⬅️ `REDUX_WEBSOCKET::RECONNECT_ATTEMPT`\n\nDispatched every time the middleware attempts a reconnection. Includes a `count` as part of the payload.\n\n###### Structure\n\n```js\n{\n    type: 'REDUX_WEBSOCKET::RECONNECT_ATTEMPT',\n    meta: {\n        timestamp: string,\n    },\n    payload: {\n        count: number,\n    },\n}\n```\n\n---\n\n##### ⬅️ `REDUX_WEBSOCKET::RECONNECTED`\n\nDispatched when the middleware reconnects. This action is dispached right before an `OPEN` action.\n\n###### Structure\n\n```js\n{\n    type: 'REDUX_WEBSOCKET::RECONNECTED',\n    meta: {\n        timestamp: string,\n    },\n}\n```\n\n---\n\n##### ⬅️ `REDUX_WEBSOCKET::ERROR`\n\nGeneral purpose error action.\n\n###### Structure\n\n```js\n{\n    type: 'REDUX_WEBSOCKET::ERROR',\n    error: true,\n    meta: {\n        timestamp: string,\n        message: string,\n        name: string,\n        originalAction: Action | null,\n    },\n    payload: Error,\n}\n```\n","readmeFilename":"README.md"}