{"_id":"@socket.io/mongo-emitter","_rev":"2-c94680b7ac10d6c671c4ca44192a9eef","name":"@socket.io/mongo-emitter","dist-tags":{"latest":"0.2.0"},"versions":{"0.1.0":{"name":"@socket.io/mongo-emitter","version":"0.1.0","description":"The Socket.IO MongoDB emitter, allowing to communicate with a group of Socket.IO servers from another Node.js process","license":"MIT","repository":{"type":"git","url":"git+https://github.com/socketio/socket.io-mongo-emitter.git"},"main":"./dist/index.js","types":"./dist/index.d.ts","scripts":{"test":"npm run format:check && tsc && nyc mocha --require ts-node/register --timeout 5000 test/index.ts","format:check":"prettier --parser typescript --check 'lib/**/*.ts' 'test/**/*.ts'","format:fix":"prettier --parser typescript --write 'lib/**/*.ts' 'test/**/*.ts'","prepack":"tsc"},"dependencies":{"debug":"~4.3.1"},"devDependencies":{"@socket.io/mongo-adapter":"0.1.0","@types/debug":"^4.1.5","@types/expect.js":"^0.3.29","@types/mocha":"^8.2.1","@types/mongodb":"^3.6.17","@types/node":"^14.14.35","expect.js":"~0.3.1","mocha":"^8.3.2","mongodb":"^3.6.9","nyc":"^15.1.0","prettier":"^2.2.1","socket.io":"^4.1.1","socket.io-client":"^4.1.1","ts-node":"^9.1.1","typescript":"^4.2.3"},"keywords":["socket.io","mongodb","mongo","emitter"],"gitHead":"f88ec18d697ae242bd9d2d841a81a40f494b524c","bugs":{"url":"https://github.com/socketio/socket.io-mongo-emitter/issues"},"homepage":"https://github.com/socketio/socket.io-mongo-emitter#readme","_id":"@socket.io/mongo-emitter@0.1.0","_nodeVersion":"12.19.0","_npmVersion":"6.14.8","dist":{"integrity":"sha512-7tmy7uHn9drn4EQcL5Av4w87gGCX7KSPq0hKM25Pe/ZN0NP2b84DRVE6PLcAlT2pXAMp9KEOnN/7Pdl4lVUt+w==","shasum":"f54543f60c68ce29258f680bd901c0b09586ccd0","tarball":"https://registry.npmjs.org/@socket.io/mongo-emitter/-/mongo-emitter-0.1.0.tgz","fileCount":8,"unpackedSize":22058,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgtfKTCRA9TVsSAnZWagAACPEP/RR8tqDkllX186IVutUx\nOLyp4kcokvzV1fK7AAhT6UoY7txoBrPCJaNvO4OSZRUUTATl70gB/akDYTgI\neTv9CmSntCOnsf+iwAQwpdHu0fheR4jL2fYYSHhLA/kn6Hd5RaFK4kfsOYmV\nMwRyzfTMr3v04xiCBU1XLJXiHxXU6g3bJFPRbGXe2etLKXcbW6zA9yUorXsS\nYityizQxn1KGc+4jahpiUloZG/TJxvFSOorHohWmryXobpWS6MkYpTJCZ221\nDAcZRANvG/tkg7wYCgJ7QNoky44nTXzyxgHeMyNcr0L0NyS7U9BU7VYgt8by\nH23OIOt4sPnQIfIhNT2ZL/2AYNJbuF9lZfKuuX0I42oGPpc/SOmUpSm3sNsI\nGV25UUCg0ELfMYndZ+9h2jYhbF2EXruseTwRmQe5AVRcLmOqtntOn7qnjqAx\nskSFPW9dqeUiQDFLoSJ0pG3Z96e2aoHOqExxLR8NgC4GNcvF4KIAN5wAXSG/\nsR6QbPH2LBDHMY9X2GnDP0UEDeW8Jq6glbroMTKGNmVdCAheKF4OQiseTiP8\nBZHCgaAHiSNOprVYbTYQtyXhbTclTrZzhxivudO1x5BJPfh7MgCpQvmYK4Tn\n3cLXtKJ7KI0Thz3WDxZc4a5zG2hj15u4jZDEwOTSQ2be8oTZcY6nC5asbZ2J\n3UOv\r\n=HJlH\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQD6VQCFspy8Gd7BMc0/I09bkkWsO0sYRfgBeoKg9m7nzAIhAJmXez/7NgmQHjg1ljT/z8eiipZFD7jfDub6HuYtAauM"}]},"_npmUser":{"name":"darrachequesne","email":"damien.arrachequesne@gmail.com"},"directories":{},"maintainers":[{"name":"darrachequesne","email":"damien.arrachequesne@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/mongo-emitter_0.1.0_1622536850984_0.9106058200500458"},"_hasShrinkwrap":false},"0.2.0":{"name":"@socket.io/mongo-emitter","version":"0.2.0","description":"The Socket.IO MongoDB emitter, allowing to communicate with a group of Socket.IO servers from another Node.js process","license":"MIT","repository":{"type":"git","url":"git+https://github.com/socketio/socket.io-mongo-emitter.git"},"main":"./dist/index.js","types":"./dist/index.d.ts","scripts":{"test":"npm run format:check && tsc && nyc mocha --require ts-node/register --timeout 5000 test/index.ts","format:check":"prettier --parser typescript --check 'lib/**/*.ts' 'test/**/*.ts'","format:fix":"prettier --parser typescript --write 'lib/**/*.ts' 'test/**/*.ts'","prepack":"tsc"},"dependencies":{"debug":"~4.3.1"},"devDependencies":{"@socket.io/mongo-adapter":"0.1.0","@types/debug":"^4.1.5","@types/expect.js":"^0.3.29","@types/mocha":"^8.2.1","@types/mongodb":"^3.6.17","@types/node":"^14.14.35","expect.js":"~0.3.1","mocha":"^8.3.2","mongodb":"^3.6.9","nyc":"^15.1.0","prettier":"^2.2.1","socket.io":"^4.7.0","socket.io-client":"^4.7.0","ts-node":"^9.1.1","typescript":"^4.2.3"},"keywords":["socket.io","mongodb","mongo","emitter"],"gitHead":"b91b442e8878eae3b4767b70c1c0f8eebf7e4d5f","bugs":{"url":"https://github.com/socketio/socket.io-mongo-emitter/issues"},"homepage":"https://github.com/socketio/socket.io-mongo-emitter#readme","_id":"@socket.io/mongo-emitter@0.2.0","_nodeVersion":"20.3.0","_npmVersion":"9.6.7","dist":{"integrity":"sha512-5ABxW7RbCza74Qok78aR2yeR7AF3e/XaA3bXDKF9C1DuodNi9mYT7H1kh8OQlZ3yD0KP9o2Chf1ScVbV4F4syQ==","shasum":"3cb1a18671f6eb2fde31446aa612c926db0c107d","tarball":"https://registry.npmjs.org/@socket.io/mongo-emitter/-/mongo-emitter-0.2.0.tgz","fileCount":7,"unpackedSize":22783,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIFFp2u8plU3dakQf9rZuVJKzZiMrjQKEo7TJh0zghYnTAiEAtuCzuZMTmVg3+vzg0e1IL5YizTfmWMYSnAHAnXVcey0="}]},"_npmUser":{"name":"darrachequesne","email":"damien.arrachequesne@gmail.com"},"directories":{},"maintainers":[{"name":"darrachequesne","email":"damien.arrachequesne@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/mongo-emitter_0.2.0_1687878174962_0.5110240243689657"},"_hasShrinkwrap":false}},"time":{"created":"2021-06-01T08:40:50.983Z","0.1.0":"2021-06-01T08:40:51.107Z","modified":"2023-06-27T15:02:55.243Z","0.2.0":"2023-06-27T15:02:55.128Z"},"maintainers":[{"name":"darrachequesne","email":"damien.arrachequesne@gmail.com"}],"description":"The Socket.IO MongoDB emitter, allowing to communicate with a group of Socket.IO servers from another Node.js process","homepage":"https://github.com/socketio/socket.io-mongo-emitter#readme","keywords":["socket.io","mongodb","mongo","emitter"],"repository":{"type":"git","url":"git+https://github.com/socketio/socket.io-mongo-emitter.git"},"bugs":{"url":"https://github.com/socketio/socket.io-mongo-emitter/issues"},"license":"MIT","readme":"# Socket.IO MongoDB emitter\n\nThe `@socket.io/mongo-emitter` package allows you to easily communicate with a group of Socket.IO servers from another Node.js process (server-side).\n\n![Emitter diagram](./assets/emitter.png)\n\nIt must be used in conjunction with [`@socket.io/mongo-adapter`](https://github.com/socketio/socket.io-mongo-adapter/).\n\nSupported features:\n\n- [broadcasting](https://socket.io/docs/v4/broadcasting-events/)\n- [utility methods](https://socket.io/docs/v4/server-instance/#Utility-methods)\n  - [`socketsJoin`](https://socket.io/docs/v4/server-instance/#socketsJoin)\n  - [`socketsLeave`](https://socket.io/docs/v4/server-instance/#socketsLeave)\n  - [`disconnectSockets`](https://socket.io/docs/v4/server-instance/#disconnectSockets)\n  - [`serverSideEmit`](https://socket.io/docs/v4/server-instance/#serverSideEmit)\n\nRelated packages:\n\n- MongoDB adapter: https://github.com/socketio/socket.io-mongo-adapter/\n- Redis adapter: https://github.com/socketio/socket.io-redis-adapter/\n- Redis emitter: https://github.com/socketio/socket.io-redis-emitter/\n- Postgres adapter: https://github.com/socketio/socket.io-postgres-adapter/\n- Postgres emitter: https://github.com/socketio/socket.io-postgres-emitter/\n\n**Table of contents**\n\n- [Installation](#installation)\n- [Usage](#usage)\n- [API](#api)\n- [Known errors](#known-errors)\n- [License](#license)\n\n## Installation\n\n```\nnpm install @socket.io/mongo-emitter mongodb\n```\n\nFor TypeScript users, you might also need `@types/mongodb`.\n\n## Usage\n\n```js\nconst { Emitter } = require(\"@socket.io/mongo-emitter\");\nconst { MongoClient } = require(\"mongodb\");\n\nconst DB = \"mydb\";\nconst COLLECTION = \"socket.io-adapter-events\";\n\nconst mongoClient = new MongoClient(\"mongodb://localhost:27017/?replicaSet=rs0\", {\n  useUnifiedTopology: true,\n});\n\nconst main = async () => {\n  await mongoClient.connect();\n\n  const mongoCollection = mongoClient.db(DB).collection(COLLECTION);\n  const io = new Emitter(mongoCollection);\n\n  setInterval(() => {\n    io.emit(\"ping\", new Date());\n  }, 1000);\n}\n\nmain();\n```\n\n## API\n\n### `Emitter(mongoCollection[, nsp])`\n\n```js\nconst io = new Emitter(mongoCollection);\n```\n\nThe `mongoCollection` argument is a MongoDB [collection object](http://mongodb.github.io/node-mongodb-native/3.6/api/Collection.html) from the `mongodb` package.\n\n### `Emitter#to(room:string):BroadcastOperator`\n### `Emitter#in(room:string):BroadcastOperator`\n\nSpecifies a specific `room` that you want to emit to.\n\n```js\nio.to(\"room1\").emit(\"hello\");\n```\n\n### `Emitter#except(room:string):BroadcastOperator`\n\nSpecifies a specific `room` that you want to exclude from broadcasting.\n\n```js\nio.except(\"room2\").emit(\"hello\");\n```\n\n### `Emitter#of(namespace:string):Emitter`\n\nSpecifies a specific namespace that you want to emit to.\n\n```js\nconst customNamespace = io.of(\"/custom\");\n\ncustomNamespace.emit(\"hello\");\n```\n\n### `Emitter#socketsJoin(rooms:string|string[])`\n\nMakes the matching socket instances join the specified rooms:\n\n```js\n// make all Socket instances join the \"room1\" room\nio.socketsJoin(\"room1\");\n\n// make all Socket instances of the \"admin\" namespace in the \"room1\" room join the \"room2\" room\nio.of(\"/admin\").in(\"room1\").socketsJoin(\"room2\");\n```\n\n### `Emitter#socketsLeave(rooms:string|string[])`\n\nMakes the matching socket instances leave the specified rooms:\n\n```js\n// make all Socket instances leave the \"room1\" room\nio.socketsLeave(\"room1\");\n\n// make all Socket instances of the \"admin\" namespace in the \"room1\" room leave the \"room2\" room\nio.of(\"/admin\").in(\"room1\").socketsLeave(\"room2\");\n```\n\n### `Emitter#disconnectSockets(close:boolean)`\n\nMakes the matching socket instances disconnect:\n\n```js\n// make all Socket instances disconnect\nio.disconnectSockets();\n\n// make all Socket instances of the \"admin\" namespace in the \"room1\" room disconnect\nio.of(\"/admin\").in(\"room1\").disconnectSockets();\n\n// this also works with a single socket ID\nio.of(\"/admin\").in(theSocketId).disconnectSockets();\n```\n\n### `Emitter#serverSideEmit(ev:string[,...args:any[]])`\n\nEmits an event that will be received by each Socket.IO server of the cluster.\n\n```js\nio.serverSideEmit(\"ping\");\n```\n\n## Known errors\n\n- `TypeError: this.mongoCollection.insertOne is not a function`\n\nYou probably passed a MongoDB client instead of a MongoDB collection to the `Emitter` constructor.\n\n## License\n\n[MIT](LICENSE)\n","readmeFilename":"README.md"}