{"id":17215428,"url":"https://github.com/pixtron/ws","last_synced_at":"2025-06-27T02:33:32.941Z","repository":{"id":50784255,"uuid":"217859306","full_name":"pixtron/ws","owner":"pixtron","description":"Client for @pxtrn/ws pub/sub websocket server","archived":false,"fork":false,"pushed_at":"2021-05-29T18:19:40.000Z","size":5,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-25T11:48:06.340Z","etag":null,"topics":[],"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/pixtron.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-10-27T13:29:56.000Z","updated_at":"2019-10-27T14:36:38.000Z","dependencies_parsed_at":"2022-08-24T13:38:06.779Z","dependency_job_id":null,"html_url":"https://github.com/pixtron/ws","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/pixtron/ws","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pixtron%2Fws","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pixtron%2Fws/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pixtron%2Fws/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pixtron%2Fws/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pixtron","download_url":"https://codeload.github.com/pixtron/ws/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pixtron%2Fws/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262177958,"owners_count":23270966,"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":[],"created_at":"2024-10-15T03:24:23.389Z","updated_at":"2025-06-27T02:33:32.889Z","avatar_url":"https://github.com/pixtron.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @pxtrn/wss\n\nClient for `@pxtrn/wss` pub/sub websocket server\n\n## Installation\n\n`npm install --save @pxtrn/ws`\n\n## Usage\n\n### Basic example\n\n```js\nconst Ws = require('@pxtrn/ws');\n\nconst client = new Ws('wss://example.com');\n\nclient.on('update', (update) =\u003e {\n  console.log(`Got update for channel ${update.channel}`, update.data);\n});\n\nclient.subscribe('cats');\n```\n\n## API\n\n### Table of Contents\n\n- [Class: Ws](#class-ws)\n  - [new Ws(url[, options[, logger]])](#new-wsurl-options-logger)\n  - [Event: 'close'](#event-close)\n  - [Event: 'error'](#event-error)\n  - [Event: 'open'](#event-open)\n  - [Event: 'update'](#event-update)\n  - [async client.subscribe(channels)](#async-clientconnectchannels)\n  - [async client.unsubscribe(channels)](#async-clientconnectchannels)\n  - [async client.close()](#async-clientclose)\n\n### Class: Ws\n\nThis class represents a websocket server with simple pub/sub. It extends EventEmitter.\n\n#### new Ws(url[, options[, logger]])\n\n  `url` {String} Url of the @pxtrn/wss server\n- `options` {Object} Optional options\n  - `pingInterval` {Integer} Interval in ms for heartbeat ping. Default: `10000`,\n  - `pongTimeout` {Integer} Timeout in ms waiting for heartbeat pong response\n     from server. Default: `1000`,\n  - `reconnectTimeout` {Integer} Timeout in ms the client waits before trying\n     to reconnect after a lost connection. Default: `500`\n- `logger` {Object}\n\n  custom logger containing the following methods\n  ```js\n  const logger = {\n    silly: function(message, data) {},\n    debug: function(message, data) {},\n    notice: function(message, data) {},\n    info: function(message, data) {},\n    warning: function(message, data) {},\n    error: function(message, data) {},\n  }\n  ```\n\n#### Event: 'close'\n\nEmitted when the connection has been closed.\n\n#### Event: 'error'\n\n- `error` {Error}\n\nEmitted when an error occurs.\n\n#### Event: 'open'\n\nEmitted when the has been opened.\n\n#### Event: 'update'\n\n- `update` {Object}\n  - `channel` {String} The channel for which the update is.\n  - `data` {Mixed} Data the server sent\n\nEmitted when the server emits a channel update.\n\n#### async client.subscribe(channels)\n- `channels` {String|Array} Single channel or array of channels\n\nSubscribe to one or more channel(s?).\n\n#### async client.unsubscribe(channels)\n- `channels` {String|Array} Single channel or array of channels\n\nUnsubscribe from one or more channel(s?).\n\n#### async client.close()\n\nClose the connection to the server\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpixtron%2Fws","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpixtron%2Fws","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpixtron%2Fws/lists"}