{"id":13447909,"url":"https://github.com/bminer/ws-server-wrapper","last_synced_at":"2025-07-04T00:06:44.904Z","repository":{"id":56654025,"uuid":"81245482","full_name":"bminer/ws-server-wrapper","owner":"bminer","description":"Lightweight WebSocketServer wrapper lib using ws-wrapper to wrap connected WebSockets","archived":false,"fork":false,"pushed_at":"2025-01-19T03:58:03.000Z","size":52,"stargazers_count":19,"open_issues_count":2,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-06-28T05:40:54.262Z","etag":null,"topics":["event-handlers","nodejs","server","websocket","ws-wrapper"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bminer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-02-07T19:26:27.000Z","updated_at":"2025-05-20T09:17:56.000Z","dependencies_parsed_at":"2025-01-19T04:28:00.691Z","dependency_job_id":"0067fcaf-c074-440e-95af-fe595e569923","html_url":"https://github.com/bminer/ws-server-wrapper","commit_stats":{"total_commits":19,"total_committers":1,"mean_commits":19.0,"dds":0.0,"last_synced_commit":"5d1c73baab936819d8f5b64b0dbc8a260a23ec57"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/bminer/ws-server-wrapper","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bminer%2Fws-server-wrapper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bminer%2Fws-server-wrapper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bminer%2Fws-server-wrapper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bminer%2Fws-server-wrapper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bminer","download_url":"https://codeload.github.com/bminer/ws-server-wrapper/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bminer%2Fws-server-wrapper/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262744901,"owners_count":23357489,"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":["event-handlers","nodejs","server","websocket","ws-wrapper"],"created_at":"2024-07-31T05:01:30.035Z","updated_at":"2025-07-04T00:06:39.822Z","avatar_url":"https://github.com/bminer.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","Tools per Language"],"sub_categories":["Node.js"],"readme":"# ws-server-wrapper\n\nLightweight WebSocketServer wrapper lib using [ws-wrapper](https://github.com/bminer/ws-wrapper)\nand [ws](https://github.com/websockets/ws) to wrap connected WebSockets.  The\nonly dependency is ws-wrapper itself.\n\n## Install\n\n```\nnpm install ws-server-wrapper\n```\n\n## Usage\n\nSee [ws-wrapper](https://github.com/bminer/ws-wrapper) README or the API\ndocumentation below for more details.\n\nQuick Server-side Example:\n\nUse [ws-server-wrapper](https://github.com/bminer/ws-server-wrapper) to wrap\nthe [WebSocket.Server](https://github.com/websockets/ws/blob/master/doc/ws.md#class-websocketserver):\n\n```javascript\nconst WebSocketServer = require(\"ws\").Server\n\t, WebSocketServerWrapper = require(\"ws-server-wrapper\");\nvar wss = new WebSocketServer({port: 3000});\nvar serverWrapper = new WebSocketServerWrapper(wss);\n// Send \"msg\" event to all connected clients\nserverWrapper.emit(\"msg\", \"Hello!\");\n// For all connected clients, listen for the \"ping\" request on the channel \"pointless\"\nserverWrapper.of(\"pointless\").on(\"ping\", function() {\n  // `this` refers to the \"pointless\" channel for the socket who sent the \"ping\" request\n  // Let's just respond to the request with the value \"pong\"\n  return \"pong\";\n});\n```\n\n## API\n\nClass: WebSocketServerWrapper\n\nA WebSocketServerWrapper simply wraps around a\n[WebSocket.Server](https://github.com/websockets/ws/blob/master/doc/ws.md#class-websocketserver)\nto give you well-deserved functionality. :)\n\n`server = new WebSocketServerWrapper(webSocketServerInstance[, options]);`\n\nConstructs a new WebSocketServerWrapper, and binds it to the native\nWebSocketServer instance from [ws](https://github.com/websockets/ws).\n\n- `webSocketServerInstance` - the native WebSocketServer instance\n- `options` - options passed to each WebSocketWrapper constructor when a\n\tWebSocket connects.  See [the ws-wrapper API](https://github.com/bminer/ws-wrapper/#api)\n\tfor details.\n\t- `requestTimeout` - See [the ws-wrapper API](https://github.com/bminer/ws-wrapper/#api)\n\tAPI for more info. Defaults to 2 minutes if not specified.\n\t- `heartbeatInterval` - If set, a \"ping\" will be sent to all connected\n\tsockets every `heartbeatInterval` milliseconds.  If a \"pong\" response\n\tis not received by the start of the next ping, the connection will be\n\tterminated. Defaults to 1 minute if not specified.  Set to a falsy value\n\tto disable heartbeats.\n\nEvents\n\n- Event: \"connection\" - Emitted when a WebSocket connects to the WebSocketServer\n\t- `socket` - A WebSocketWrapper instance, wrapping a native WebSocket\n\t- `request` - A [http.IncomingMessage](https://nodejs.org/api/http.html#http_class_http_incomingmessage)\n\t\tinstance.\n- Event: \"disconnect\" - Emitted when a WebSocket disconnects from the WebSocketServer\n\t- `socket` - A WebSocketWrapper instance, wrapping a native WebSocket\n- Event: \"error\" - Emitted when an error occurs on the WebSocketServer\n\t- `err`\n\nThe EventEmitter-like API looks like this:\n\nSee the [ws-wrapper API documentation](https://github.com/bminer/ws-wrapper/#api)\nfor more details.\n\n- `server.on(eventName, listener)`\n\tAdds the `listener` function to the end of the listeners array for the\n\tevent named `eventName` for all connected sockets, now and in the future.\n\tWhen an event or request matching the `eventName` is received by any\n\tconnected WebSocket, the `listener` is called.\n\n\tValues returned by the `listener` callback are used to respond to\n\trequests.  If the return value of the `listener` is a `Promise`, the\n\tresponse to the request will be sent once the Promise is resolved or\n\trejected; otherwise, the return value of the `listener` is sent back to\n\tthe remote end immediately.\n\n\tIf the inbound message is a simple event (not a request), the return\n\tvalue of the `listener` is ignored.\n- `server.removeListener(eventName, listener)`\n\tRemoves the specified `listener` from the listener array for the event\n\tnamed `eventName`.\n- `server.removeAllListeners([eventName])`\n\tRemoves all listeners, or those of the specified `eventName`.\n- `server.eventNames()`\n\tReturns an array listing the events for which the emitter has registered\n\tlisteners.\n- `server.listeners(eventName)`\n\tReturns a copy of the array of listeners for the event named `eventName`.\n- `server.emit(eventName[, ...args])`\n\tSends an event to all connected WebSockets with the specified `eventName`\n  calling all listeners for `eventName` on the remote end, in the order they were\n\tregistered, passing the supplied arguments to each.\n\n**Note:** `server.once()`  and `server.request()` are not supported at this time.\n\nChannel API:\n- `server.of(channelName)`\n \tReturns the channel with the specified `channelName`.  Every channel has the\n \tsame EventEmitter-like API as described above for sending and handling\n \tchannel-specific events for all connected sockets.\n\nOther methods and properties:\n\n- `server.sockets` - A [Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)\n  of connected WebSocketWrappers.\n- `server.close()`\n\tCloses the native WebSocketServer\n\n## Detecting Broken Connections\n\nThe WebSocketServerWrapper will automatically (by default) ping all open sockets\non a regular basis. If there is no \"pong\" response by the start of the next ping,\nthe connection will be assumed to be \"broken\" and will be terminated automatically.   \nSee `options.heartbeatInterval` for more information.  Also see the approached\noutlined [here](https://github.com/websockets/ws#how-to-detect-and-close-broken-connections).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbminer%2Fws-server-wrapper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbminer%2Fws-server-wrapper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbminer%2Fws-server-wrapper/lists"}