{"id":20711475,"url":"https://github.com/codehz/ws-gateway","last_synced_at":"2025-06-29T18:04:25.318Z","repository":{"id":98091879,"uuid":"247612752","full_name":"codehz/ws-gateway","owner":"codehz","description":"WebSocket API gateway built using deno","archived":false,"fork":false,"pushed_at":"2020-04-24T14:42:51.000Z","size":65,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-23T07:16:27.827Z","etag":null,"topics":["api-gateway","deno","typescript","websocket"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/codehz.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":"2020-03-16T04:45:27.000Z","updated_at":"2023-05-22T18:03:24.000Z","dependencies_parsed_at":"2023-03-24T18:19:03.733Z","dependency_job_id":null,"html_url":"https://github.com/codehz/ws-gateway","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/codehz/ws-gateway","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codehz%2Fws-gateway","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codehz%2Fws-gateway/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codehz%2Fws-gateway/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codehz%2Fws-gateway/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codehz","download_url":"https://codeload.github.com/codehz/ws-gateway/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codehz%2Fws-gateway/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262642958,"owners_count":23341817,"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":["api-gateway","deno","typescript","websocket"],"created_at":"2024-11-17T02:15:38.646Z","updated_at":"2025-06-29T18:04:25.310Z","avatar_url":"https://github.com/codehz.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ws-gateway\nWebSocket API gateway built using deno\n\n[Protocol Draft](spec.md)\n\n## Usage\n\nFor service:\n\n``` typescript\nimport { delay } from \"https://deno.land/std/util.ts\";\nimport Service from \"https://deno.hertz.services/codehz/ws-gateway/sdk/service.ts\";\n\n// register service\nconst srv = new Service(\"sdk-demo\", \"0.0.1\", {\n  async echo(obj: Uint8Array) {\n    log.info(\"try to echo %#v\", obj);\n    return obj;\n  },\n  async delay(obj: Uint8Array) {\n    const dur = obj[0];\n    log.info(\"try to delay %d\", dur);\n    await async.delay(dur);\n  },\n  async exception(ex: Uint8Array) {\n    log.info(\"try to throw exception\");\n    throw new Error(dec.decode(ex));\n  },\n  async broadcast(obj: Uint8Array) {\n    const spl = obj[0];\n    const key = dec.decode(obj.subarray(1, spl + 1));\n    const data = obj.subarray(spl + 1);\n    await srv.broadcast(key, data);\n  },\n}, () =\u003e {\n  throw new Error(\"not implemented\");\n});\n\nawait srv.register(\"ws://127.0.0.1:8818\", \"demo\", e =\u003e log.error(\"%#v\", e));\n```\n\nFor client:\n\n``` typescript\nimport Client from \"https://deno.hertz.services/codehz/ws-gateway/sdk/client.ts\";\n\nconst enc = new TextEncoder();\nconst dec = new TextDecoder();\nconst client = new Client();\n// connect to ws-gateway\nawait client.connect(\"ws://127.0.0.1:8808\", e =\u003e log.error(\"%#v\", e));\n// get service proxy\nconst srv = await client.get(\"demo\");\n// wait service online (return immediately when online already)\nawait srv.waitOnline();\n// subscribe event listener\nawait srv.on(\"event\", async data =\u003e {\n  log.info(\"received event: %#v\", data);\n});\n// call method\nawait srv.call(\"delay\", new Uint8Array(255));\n// call method and wait result\nconst res = await srv.call(\"echo\", enc.encode(\"test\"));\n// parse result\nconsole.log(\"back: %s\", res.expectedString());\ntry {\n  await srv.call(\"exception\", enc.encode(\"expected exception\"));\n} catch(e) {\n  if (e instanceof MsgPackDecoder) {\n    console.log(\"expected exception from service: \", e);\n  }\n}\n// disconnect service\nawait srv.disconnect();\n// disconnect client\nawait client.disconnect();\n```\n\n## LICENSE\n\nGPL v3","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodehz%2Fws-gateway","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodehz%2Fws-gateway","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodehz%2Fws-gateway/lists"}