{"id":24568235,"url":"https://github.com/karsanda/socketto","last_synced_at":"2026-05-17T18:07:14.462Z","repository":{"id":42658972,"uuid":"464912730","full_name":"karsanda/socketto","owner":"karsanda","description":"\u003c 1 kB wrapper for WebSocket Web API","archived":false,"fork":false,"pushed_at":"2023-10-17T19:51:07.000Z","size":708,"stargazers_count":1,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-25T14:09:56.416Z","etag":null,"topics":["client-side","javascript","real-time","tcp","web","websocket","websockets"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/karsanda.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,"zenodo":null}},"created_at":"2022-03-01T13:51:58.000Z","updated_at":"2023-04-03T19:59:02.000Z","dependencies_parsed_at":"2025-07-07T07:37:35.741Z","dependency_job_id":"bab25d73-a48f-493f-8064-3dfe2b5da613","html_url":"https://github.com/karsanda/socketto","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/karsanda/socketto","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/karsanda%2Fsocketto","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/karsanda%2Fsocketto/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/karsanda%2Fsocketto/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/karsanda%2Fsocketto/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/karsanda","download_url":"https://codeload.github.com/karsanda/socketto/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/karsanda%2Fsocketto/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33149519,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-17T09:28:26.183Z","status":"ssl_error","status_checked_at":"2026-05-17T09:27:52.702Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["client-side","javascript","real-time","tcp","web","websocket","websockets"],"created_at":"2025-01-23T14:38:58.977Z","updated_at":"2026-05-17T18:07:14.435Z","avatar_url":"https://github.com/karsanda.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003e\n   Socketto \u003ca href=\"https://www.npmjs.org/package/socketto\"\u003e \n   \u003cimg src=\"https://img.shields.io/npm/v/socketto.svg?style=flat\" alt=\"npm\"\u003e\u003c/a\u003e\n   \u003cimg alt=\"NPM\" src=\"https://img.shields.io/npm/l/socketto\"\u003e\n\u003c/h1\u003e  \n\u003cp align=\"center\"\u003eTiny wrapper for \u003ca href=\"https://developer.mozilla.org/en-US/docs/Web/API/WebSocket\"\u003eWebSocket Web API\u003c/a\u003e\u003c/p\u003e\n  \n## Installation\nInstall with npm:\n```\nnpm i socketto\n```\n\nInstall with yarn:\n```\nyarn add socketto\n```\n\n## Usage\nYou can create a WebSocket connection based on the example below:\n```\nimport Socketto from 'socketto'\n\nconst ws = new Socketto('ws://localhost:8080',\n  { // these events are optional\n    onOpen: () =\u003e console.log('OPEN'),\n    onReconnect: () =\u003e console.log('RECONNECT'),\n    onMessage: (data) =\u003e { console.log(`RECEIVED MESSAGE ${data}`) },\n    onRetry: () =\u003e { console.log('RETRY TO CONNECT') },\n    onFailed: () =\u003e { console.log('FAILED TO CREATE CONNECTION') }\n  },\n  { // these options are optional\n    waitToReconnect: 1000,\n    maxReconnectAttempts: 4\n  }\n)\n\n// open connection\nws.createConnection()\n```\n\n## Events  \nYou can add callbacks up to four event handler that WebSocket listens to:\n\n### onOpen()  \nThis event will be triggered when WebSocket connection is opened\n\n### onReconnect()\nThis event will be triggered when WebSocket connection is estabilished successfully after retry\n\n### onMessage(data)\nThis event will be triggered when WebSocket receives message from server. Usually is used to render the message in UI. The parameter can be anything (e.g. string, object, etc.)  \n\n### onRetry()\nThis event will be triggered everytime WebSocket try to reconnect\n\n### onFailed()\nThis event will be triggered when WebSocket failed to create a connection after retry a certain times\n\n## Options\n### waitToReconnect\nHow long WebSocket will wait before trying to reconnect. Default value is 3 seconds\n\n### maxReconnectAttempts\nMaximum retry number allowed. Default value is 3\n\n## Reconnect  \nSocketto can reconnect by default using [exponential backoff](https://en.wikipedia.org/wiki/Exponential_backoff). It means that Socketto will increase the waiting time between retries after each retry failure. On default configuration, Socketto will try to reconnect 3 times, and wait for 3 seconds at the first retry. You can change the configuration when opening the connection. For example:\n```\nimport Socketto from 'socketto'\n\nconst ws = new Socketto('ws://localhost:8080', {\n  // event callbacks\n}, {\n  maxReconnectAttempts: 5,\n  waitToReconnect: 5000\n})\n```\nWith this configuration, Socketto will try to reconnect 5 times maximum, and will wait for 5 seconds for the first retry.\n\n## API\n### .createConnection()\n```\nws.createConnection()\n```\nThis API will try to open a WebSocket connection based on constructor parameters\n\n### .closeConnection()\n```\nws.closeConnection()\n```\nClose the WebSocket connection. By calling this API, WebSocket will immediately close its connection without retry\n\n### .send()\n```\nws.send('send-dummy-message')\n```\nSend any data through WebSocket connection\n\n### .readyState\n```\nws.readyState\n```\nReturns the current state of WebSocket connection based on [MDN](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/readyState)  \n|Value | State      | Description                                              |\n|------|------------|----------------------------------------------------------|\n| 0    | CONNECTING | Socket has been created. The connection is not yet open. |\n| 1    | OPEN       | The connection is open and ready to communicate.         |\n| 2    | CLOSING    | The connection is in the process of closing.             |\n| 3    | CLOSED     | The connection is closed or couldn't be opened.          |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkarsanda%2Fsocketto","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkarsanda%2Fsocketto","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkarsanda%2Fsocketto/lists"}