{"library":"socket.io-middleware","title":"socket.io-middleware","type":"library","description":"Redux middleware for maintaining multiple socket.io connections. Version 2.0.1 (latest), released as a stable build. It enforces a pattern where only the middleware handles socket connections, and actions are dispatched to communicate with the server. Designed for multiple sockets, it organizes client and server events into separate directories with specific export formats. Differentiates from simpler single-connection solutions by requiring structured event arrays and opinionated directory layouts.","language":"javascript","status":"active","last_verified":"Fri May 01","install":{"commands":["npm install socket.io-middleware"],"cli":null},"imports":["import createSocketIoMiddleware from 'socket.io-middleware';","import { SocketIOAction } from 'socket.io-middleware';","import type { MiddlewareConfig } from 'socket.io-middleware';"],"auth":{"required":false,"env_vars":[]},"links":{"homepage":null,"github":"https://github.com/Vandise/redux-socket.io-middleware","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/socket.io-middleware","openapi_spec":null,"status_page":null,"smithery":null},"quickstart":{"code":"import { createStore, applyMiddleware } from 'redux';\nimport createSocketIoMiddleware from 'socket.io-middleware';\nimport io from 'socket.io-client';\n\nconst socket = io('http://localhost:3000');\nconst socketIoMiddleware = createSocketIoMiddleware(socket, 'server/');\n\nconst reducer = (state = {}, action) => {\n  switch (action.type) {\n    case 'SET_VALUE_FROM_SERVER':\n      return { ...state, value: action.payload };\n    default:\n      return state;\n  }\n};\n\nconst store = createStore(reducer, applyMiddleware(socketIoMiddleware));\n\nstore.dispatch({ type: 'CLIENT_ACTION', payload: 'hello' });","lang":"javascript","description":"Demonstrates creating the middleware with a socket instance and applying it to a Redux store, including dispatching a client action.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}