{"id":13515552,"url":"https://github.com/Nogard7491/wsc","last_synced_at":"2025-03-31T04:37:13.139Z","repository":{"id":57131743,"uuid":"159044796","full_name":"Nogard7491/wsc","owner":"Nogard7491","description":"Simple to use, blazing fast and thoroughly tested websocket client.","archived":false,"fork":false,"pushed_at":"2019-01-02T12:00:58.000Z","size":155,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-28T00:45:35.959Z","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/Nogard7491.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":"2018-11-25T15:14:44.000Z","updated_at":"2019-01-05T09:44:49.000Z","dependencies_parsed_at":"2022-09-03T06:43:27.395Z","dependency_job_id":null,"html_url":"https://github.com/Nogard7491/wsc","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nogard7491%2Fwsc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nogard7491%2Fwsc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nogard7491%2Fwsc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Nogard7491%2Fwsc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Nogard7491","download_url":"https://codeload.github.com/Nogard7491/wsc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246418693,"owners_count":20773935,"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-08-01T05:01:12.790Z","updated_at":"2025-03-31T04:37:11.516Z","avatar_url":"https://github.com/Nogard7491.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# Web Socket Client (wsc)\n\nWsc is simple to use, blazing fast and thoroughly tested websocket client.\n\n## Table of contents\n\n- [Installing](#installing)\n- [Requiring](#requiring)\n  - [Via tag \"script\"](#via-tag-script)\n  - [Via Node.js require](#via-nodejs-require)\n  - [Via ES6 import](#via-es6-import)\n- [Usage examples](#usage-examples)\n  - [Simple usage](#simple-usage)\n  - [Usage with options](#usage-with-options)\n- [Changelog](#changelog)\n- [License](#license)\n\n## Installing\n\n```\nnpm install @nogard7491/wsc --save\n```\n\n## Requiring\n\n### Via tag \"script\"\n\n```\n\u003cscript src=\"./node_modules/@nogard7491/wsc/dist/wsc-2.0.4.min.js\"\u003e\u003c/script\u003e\n\u003cscript\u003e\n    var wsc = new Wsc.default('ws://echo.websocket.org');\n\u003c/script\u003e\n```\n\n### Via Node.js require\n\n```\n\u003cscript\u003e\n    const Wsc = require('@nogard7491/wsc').default;\n\n    const wsc = new Wsc('ws://echo.websocket.org');\n\u003c/script\u003e\n```\n\n### Via ES6 import\n\n```\n\u003cscript\u003e\n    import Wsc from '@nogard7491/wsc';\n\n    const wsc = new Wsc('ws://echo.websocket.org');\n\u003c/script\u003e\n```\n\n## Usage examples\n\n### Simple usage\n\n```js\n/** @type {Wsc} wsc Websocket client. */\nvar wsc = new Wsc.default(\n    'ws://echo.websocket.org', // connecting url\n    undefined, // protocols\n);\n\n// triggered when trying to connect through a method call \"connect\"\nwsc.on('opening', function() {\n    console.log('opening', this.readyState);\n});\n\n// triggered when opening a connection\nwsc.on('open', function(event) {\n    console.log('open', this.readyState);\n});\n\n// triggered when a message is received\nwsc.on('message', function(event) {\n    console.log('message', this.readyState, '\"' + event.data + '\"');\n    this.close();\n});\n\n// triggered when trying to connect through a method call \"close\"\nwsc.on('closing', function() {\n    console.log('closing', this.readyState);\n});\n\n\n// triggered when closing a connection\nwsc.on('close', function(event) {\n    console.log('close', this.readyState);\n});\n\nwsc.connect();\nwsc.send('some data');\n```\n\n### Usage with options\n\n```js\n/** @type {Wsc} wsc Websocket client. */\nvar wsc = new Wsc.default('ws://echo.websocket.org', undefined, {\n    useMessageQueue: true, // use event queue with inactive connection\n    reconnection: true, // use reconnection\n    reconnectionOptions: { // reconnection options\n        attempts: 10, // max number of reconnection attempts or Infinity\n        delay: 1000, // reconnection delay time\n        maxDelay: 10000, // max reconnection delay time\n        increaseDelay: 1000, // delay time which will increase the main delay time when trying to reconnect\n    }\n});\n\n// triggered when trying to connect through a method call \"connect\"\nwsc.on('opening', function() {\n    console.log('opening');\n});\n\n// triggered when trying to connect through a method call \"close\"\nwsc.on('closing', function() {\n    console.log('closing');\n});\n\nwsc.connect();\nwsc.send('some data');\n\n// triggered when opening a connection\nwsc.on('open', function(event) {\n    console.log('open', event);\n});\n\n// triggered when a message is received\nwsc.on('message', function(event) {\n    console.log('message', event);\n    this.close();\n});\n\n// triggered when closing a connection\nlet eventId = wsc.on('close', function(event) {\n    console.log('close', event);\n});\n\n// removes event listener by identifier\nwsc.off(eventId);\n\n// removes event listeners by type\nwsc.off('open');\n\n// removes event listeners by handler\nwsc.off(function() {\n    console.log('closing');\n});\n```\n\n## Changelog\n\n### [v2.0.0 (2018-12-01)](https://github.com/Nogard7491/wsc/releases/tag/v2.0.0)\n\n#### Added\n\n- New methods \"on\" and \"off\" for adding and removing event listeners\n- Getting event listener identifier\n\n#### Removed\n\n- Old methods \"onOpening\", \"onOpen\", \"onReady\", \"onMessage\", \"onClosing\",\n\"onClose\" and \"onError\"\n\n### [v1.0.0 (2018-11-25)](https://github.com/Nogard7491/wsc/releases/tag/v1.0.0)\n\n## License\n\n[MIT](LICENSE.md)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNogard7491%2Fwsc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FNogard7491%2Fwsc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNogard7491%2Fwsc/lists"}