{"id":26514601,"url":"https://github.com/mudssrali/wsgrok","last_synced_at":"2025-03-21T05:19:12.876Z","repository":{"id":274338293,"uuid":"922611979","full_name":"mudssrali/wsgrok","owner":"mudssrali","description":"WebSocket API wrapper for creating and managing WebSocket connections","archived":false,"fork":false,"pushed_at":"2025-03-04T07:49:04.000Z","size":8,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-04T07:55:16.162Z","etag":null,"topics":["real-time","websocket","websocket-api","wss"],"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/mudssrali.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":"2025-01-26T17:06:55.000Z","updated_at":"2025-03-04T07:49:08.000Z","dependencies_parsed_at":null,"dependency_job_id":"c33a0f11-7737-45eb-b992-50cf52931973","html_url":"https://github.com/mudssrali/wsgrok","commit_stats":null,"previous_names":["mudssrali/wssgrok","mudssrali/wsgrok"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mudssrali%2Fwsgrok","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mudssrali%2Fwsgrok/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mudssrali%2Fwsgrok/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mudssrali%2Fwsgrok/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mudssrali","download_url":"https://codeload.github.com/mudssrali/wsgrok/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244740319,"owners_count":20502060,"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":["real-time","websocket","websocket-api","wss"],"created_at":"2025-03-21T05:19:12.462Z","updated_at":"2025-03-21T05:19:12.860Z","avatar_url":"https://github.com/mudssrali.png","language":"TypeScript","readme":"# WSgrok\n\nWebSocket API wrapper for creating and managing WebSocket connections\n\n[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)\n\u003ca aria-label=\"Package size\" href=\"https://bundlephobia.com/result?p=wsgrok\"\u003e\n  \u003cimg alt=\"\" src=\"https://badgen.net/bundlephobia/minzip/wsgrok\"\u003e\n\u003c/a\u003e\n\n\n## Install\n\nInstall with npm or yarn via\n\n```\nyarn add wsgrok\n```\n\nor\n\n```\nnpm i wsgrok\n```\n\n## API\n\n```ts\ntype Event = \"connect\" | \"disconnect\" | \"message\" | \"verify\"\ninterface WSgrok {\n    url: string\n    ready: boolean\n    ws?: WebSocket\n    pingInterval?: number\n    pending: Map\u003cstring, {\n        resolve: (a: any) =\u003e any\n        reject: (a: any) =\u003e any\n    }\u003e\n    messageTimeout: number\n    connectionVerified: boolean\n    verify(): void\n    connect(): Promise\u003cvoid\u003e\n    on(event: Event, f: Function): void\n    onNext(event: Event, f: Function): void\n    cleanup(): void\n    ping(): void\n    send(message: any, timeout?: number): Promise\u003cany\u003e\n}\n```\n\n## Usage\n\n- Use `WSgrok` with events\n\n  ```ts\n  import WSgrok from 'wsgrok'\n\n  const wsgrok = new WSgrok(\"wss://example.com/ws\")\n\n  // on connected to host\n  wsgrok.on('connect', () =\u003e console.log(\"connected to a host\"))\n\n  // on disconnected from a host\n  wsgrok.on('disconnect', () =\u003e console.log(\"disconnected from a host\"))\n\n  // on receiving a new message from host\n  wsgrok.on('message', (message: any) =\u003e console.log(\"new message\", message))\n\n  // on verify a connection to host\n  wsgrok.on('verify', () =\u003e console.log(\"connection is verified\"))\n  ```\n\n- Make a request to host using `wsgrok.Send()` with `Promise`\n\n  ```ts\n  import WSgrok from 'wsgrok'\n  export const invokeService = () =\u003e {\n    const wsgrok = new WSgrok(\"wss://www.example.com/ws\")\n\n    wsgrok.send({\n      type: \"INVOKE_SERVICE\",\n      clientType: \"XNGINX\"\n      payload: {\n        initiatorId: \"xxxx-xxxx-xxxx\"\n        reqToken: \"xxxx-xxxx-xxxx\"\n      }\n    })\n      .then(response =\u003e {\n        // do your work here\n      })\n      .catch(error =\u003e {\n        // do your work here\n      })\n  }\n  ```\n\n  `Or with async arrow style`\n\n  ```ts\n  import WSgrok from 'wsgrok'\n\n  export const invokeService = aysnc () =\u003e {\n    const wsgrok = new WSgrok(\"wss://www.example.com/ws\")\n\n    try {\n      const response = await wsgrok.send({\n        type: \"INVOKE_SERVICE\",\n        clientType: \"XNGINX\",\n        payload: {\n          initiatorId: \"xxxx-xxxx-xxxx\"\n          reqToken: \"xxxx-xxxx-xxxx\"\n        }\n      })\n  \n      // handle server response here\n\n    } catch(error) {\n      // handle server error here\n    }\n  }\n  ```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmudssrali%2Fwsgrok","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmudssrali%2Fwsgrok","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmudssrali%2Fwsgrok/lists"}