{"id":19245273,"url":"https://github.com/soketi/impl","last_synced_at":"2025-09-06T06:38:58.889Z","repository":{"id":170610883,"uuid":"644435451","full_name":"soketi/impl","owner":"soketi","description":null,"archived":false,"fork":false,"pushed_at":"2023-10-03T10:41:55.000Z","size":406,"stargazers_count":33,"open_issues_count":5,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-01T12:49:27.338Z","etag":null,"topics":["ably","helia","ipfs","libp2p","p2p","pusher","real","real-time","realtime","sockets","soketi","time","web","websocket","websockets","ws"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/soketi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null},"funding":{"github":"rennokki"}},"created_at":"2023-05-23T14:06:01.000Z","updated_at":"2024-12-11T14:43:59.000Z","dependencies_parsed_at":"2024-01-23T17:13:50.406Z","dependency_job_id":"2ac1d9ec-5db1-4260-8011-0c658366d5ea","html_url":"https://github.com/soketi/impl","commit_stats":null,"previous_names":["soketi/impl"],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soketi%2Fimpl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soketi%2Fimpl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soketi%2Fimpl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soketi%2Fimpl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/soketi","download_url":"https://codeload.github.com/soketi/impl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250040420,"owners_count":21365100,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ably","helia","ipfs","libp2p","p2p","pusher","real","real-time","realtime","sockets","soketi","time","web","websocket","websockets","ws"],"created_at":"2024-11-09T17:27:16.828Z","updated_at":"2025-04-21T10:33:17.403Z","avatar_url":"https://github.com/soketi.png","language":"TypeScript","funding_links":["https://github.com/sponsors/rennokki"],"categories":[],"sub_categories":[],"readme":"\u003e The 🇷🇺 Russian invasion of 🇺🇦 Ukraine breaches any law, including the UN Charter. [#StandWithUkraine](https://github.com/vshymanskyy/StandWithUkraine)\n\n\u003e Open-source is not about political views, but rather humanitar views. It's code by the people for the people. Unprovoked, unjustifiable and despicable action that is killing civilians is not tolerated. The [Renoki Co.](https://github.com/renoki-co) subsidiaries (including Soketi) has taken action to move away from Russian software and dependencies and block any access from Russia within their projects.\n\n# Soketi Implementation\n\n[![CI](https://github.com/soketi/impl/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/soketi/impl/actions/workflows/ci.yml)\n[![codecov](https://codecov.io/gh/soketi/impl/branch/master/graph/badge.svg)](https://codecov.io/gh/soketi/impl/branch/master)\n[![Latest Stable Version](https://img.shields.io/github/v/release/soketi/impl)](https://www.npmjs.com/package/@soketi/impl)\n[![Total Downloads](https://img.shields.io/npm/dt/@soketi/impl)](https://www.npmjs.com/package/@soketi/impl)\n[![License](https://img.shields.io/npm/l/@soketi/impl)](https://www.npmjs.com/package/@soketi/impl)\n\n[![Artifact Hub](https://img.shields.io/endpoint?url=https://artifacthub.io/badge/repository/soketi)](https://artifacthub.io/packages/search?repo=soketi)\n[![StandWithUkraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/master/badges/StandWithUkraine.svg)](https://github.com/vshymanskyy/StandWithUkraine/blob/master/docs/README.md)\n[![Discord](https://img.shields.io/discord/957380329985958038?color=%235865F2\u0026label=Discord\u0026logo=discord\u0026logoColor=%23fff)](https://discord.gg/VgfKCQydjb)\n\nSoketi Implementation is a TypeScript boilerplate to use on your WebSocket implementations. This represents a customizable single point of entry for your server, no matter what framework you are using.\n\n## General Implementations\n\nThe package comes with default implementations for the usual WebSocket operations, but as well as specific ones, like Pusher.\n\nThis is not providing a WebSocket server, but rather a way to implement your own WebSocket server, no matter what framework you are using.\n\nIn the examples, we will assume a pseudo-WebSocket server (not tied to any real use case).\n\n### Connections\n\nThis implementation provides a tracking of connections for the server:\n\n```js\nimport { Connections, Connection } from '@soketi/impl';\n\nconst conns = new Connections();\n\nserver.on('new-connection', async originalConnection =\u003e {\n    // Generate a unique ID for the connection.\n    const uniqueId = Math.random() * 1e5;\n\n    // If possible, associate the unique ID with the original connection.\n    // This can be used later to get the connection.\n    originalConnection.id = uniqueId;\n\n    // Create a new connection instance, binding\n    // the send and close methods to the underlying WebSocket.\n    const connection = new Connection(uniqueId, {\n        id: uniqueId,\n        send: (message) =\u003e originalConnection.send(message),\n        close: (...args) =\u003e originalConnection.close(...args),\n    });\n\n    // Add the connection to the connections tracker.\n    await conns.newConnection(connection);\n});\n```\n\nThis way, you can track connections and send messages to them:\n\n```js\nfor (const conn of conns.connections) {\n    // .send will call the send method of the underlying WebSocket.\n    await conn.send('Hello!');\n}\n```\n\nTo undo and remove a connection from the tracker, you can use `removeConnection`:\n\n```js\nawait conns.removeConnection(connection);\n```\n\n### Handlers for Websocket events\n\nThe package provides a way to handle WebSocket events at the general level,\nso that you don't have to implement them yourself. You will be defining both\nthe handlers, as well as the calls to them, in a static way.\n\n```js\nimport { Router as WsRouter } from '@soketi/impl';\nimport { Connections, Connection } from '@soketi/impl';\n\nconst conns = new Connections();\n\nWsRouter.onNewConnection(async conn =\u003e {\n    // As explained earlier in the connections, you can use it to add it to a tracker.\n    await conns.newConnection(conn);\n    await conn.send('Hello!');\n});\n\nserver.on('new-connection', async originalConnection =\u003e {\n    const connection = new Connection(...);\n\n    // Handle the connection via the router.\n    // This will call the handler defined above.\n    await WsRouter.handleNewConnection(connection);\n});\n```\n\nThe router provides handlers for the following events:\n\n- `onNewConnection(async (conn, ...args?) =\u003e {})` with `handleNewConnection(connection, ...args?)`\n- `onConnectionClosed(async (conn, code, msg, ...args?) =\u003e {})` with `handleConnectionClosed(connection, code, msg, ...args?)`\n- `onMessage(async (conn, message, ...args?) =\u003e {})` with `handleMessage(connection, message, ...args?)`\n- `onError(async (conn, error, ...args?) =\u003e {})` with `handleError(connection, error, ...args?)`\n\nYou can also register your own handlers:\n\n```js\nimport { Router as WsRouter } from '@soketi/impl';\n\n// Register a ping handler.\nWsRouter.registerHandler('onPing', async conn =\u003e {\n    await conn.send('Pong!');\n});\n\nserver.on('ping', async originalConnection =\u003e {\n    // Get the existing connection on a ping or message.\n    if (conns.connections.get(originalConnection.id)) {\n        await WsRouter.handle('onPing', connection);\n    }\n});\n```\n\n### Pusher\n\n- Public Channels ✅\n- Presence Channels ✅\n- Private Channels ✅\n- Encrypted Private Channels ✅\n- Client Events ✅\n- Webhooks ❌\n- REST API ❌\n- Metrics ❌\n\nSee more: [Pusher Channels](https://pusher.com/channels)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoketi%2Fimpl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsoketi%2Fimpl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoketi%2Fimpl/lists"}