{"id":24455563,"url":"https://github.com/nixjs/grpc-stream-client","last_synced_at":"2026-04-26T08:34:16.626Z","repository":{"id":171670640,"uuid":"648247939","full_name":"nixjs/grpc-stream-client","owner":"nixjs","description":"A client-gRPC streaming written in TypeScript for browser applications. The focus is on simplicity, reliability, and extensibility. It provides convenient features to automatically reconnect and convert data to object.","archived":false,"fork":false,"pushed_at":"2023-06-02T00:10:00.000Z","size":98,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-12T14:29:54.726Z","etag":null,"topics":["grpc","grpc-react","grpc-retry","grpc-stream-client","grpc-streaming","grpc-typescript","grpc-web","grpc-web-retry","reconnecting","reconnecting-grpc","retry"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nixjs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2023-06-01T14:29:18.000Z","updated_at":"2023-06-07T14:14:54.000Z","dependencies_parsed_at":null,"dependency_job_id":"4e56561b-711a-4784-beb4-9ee637ce5f0a","html_url":"https://github.com/nixjs/grpc-stream-client","commit_stats":null,"previous_names":["nixjs/grpc-stream-client"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/nixjs/grpc-stream-client","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nixjs%2Fgrpc-stream-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nixjs%2Fgrpc-stream-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nixjs%2Fgrpc-stream-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nixjs%2Fgrpc-stream-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nixjs","download_url":"https://codeload.github.com/nixjs/grpc-stream-client/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nixjs%2Fgrpc-stream-client/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32290698,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-26T08:29:33.829Z","status":"ssl_error","status_checked_at":"2026-04-26T08:29:18.366Z","response_time":129,"last_error":"SSL_read: 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":["grpc","grpc-react","grpc-retry","grpc-stream-client","grpc-streaming","grpc-typescript","grpc-web","grpc-web-retry","reconnecting","reconnecting-grpc","retry"],"created_at":"2025-01-21T02:13:44.711Z","updated_at":"2026-04-26T08:34:16.621Z","avatar_url":"https://github.com/nixjs.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gRpc streaming client typescript\n\nA client-gRPC streaming written in TypeScript for browser applications. The focus is on simplicity, reliability, and extensibility. It provides convenient features to automatically reconnect and convert data to object.\n\n## Features\n\n- Dependency-free and small in size\n- When the connection is lost, it can optionally be configured to\n  - Automatically try to reconnect in a smart way\n- Easy to override metadata and request\n- Support uses the `backoff` factor to apply between attempts.\n- Builder-class for easy initialization and configuration\n- High test-coverage and in-code documentation\n  - Enables you to easily modify and extend the code\n\n## Installation\n\nIn your project-root:\n\n🚀 Install with npm\n\n```\nnpm install @nixjs23n6/grpc-stream-client\n```\n\n🚀 Install with yarn\n\n```\nyarn add @nixjs23n6/grpc-stream-client\n```\n\nIn your project-code:\n\n```typescript\nimport { StreamBuilder } from '@nixjs23n6/grpc-stream-client';\n```\n\n## Usage\n\n*Example proto:*\n\n```typescript\nexport class ChatClient {\n  constructor (hostname: string,\n               credentials?: null | { [index: string]: string; },\n               options?: null | { [index: string]: any; });\n\n  room(\n    request: JoinRoomRequest,\n    metadata?: grpcWeb.Metadata\n  ): grpcWeb.ClientReadableStream\u003cRoomEvent\u003e;\n}\n```\n\n#### Initialization\n\nCreate a new instance with the provided `StreamBuilder`:\n\n```typescript\nconst client = new ChatClient(\"host_name_url\")\nconst stream = new StreamBuilder(client, 'room').build();\n```\n\n#### Request\n\nAdd a request into builder:\n\n```typescript\nconst client = new ChatClient(\"host_name_url\")\nconst stream = new StreamBuilder(client, 'room').withRequest(new google_protobuf_empty_pb.Empty()).build();\n```\n\n#### Metadata\n\nAdd a metada into buider:\n\n```typescript\nconst client = new ChatClient(\"host_name_url\")\nlet deadline = new Date()\ndeadline.setSeconds(deadline.getSeconds() + BaseTimeoutStreamingRequest).toString()\nconst authorization = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c'\nconst stream = new StreamBuilder(client, 'room').withMetadata({ deadline, authorization }).build();\n```\n\n#### Events \u0026 Callbacks\n\nThere are five events which can be subscribed to through callbacks:\n\n```typescript\nexport enum StreamEvents {\n    data = 'data', // A data was received\n    metadata = 'metadata', // A metadata of the connection\n    error = 'error', // An error occurred\n    end = 'end', // Connection is ended\n    retry = 'retry', // A try to re-connect is made\n}\n```\n\nThe callbacks are called with the issuing streaming-instance and the causing event as arguments:\n\n```typescript\nconst client = new ChatClient(\"host_name_url\")\nconst stream = new StreamBuilder(client, 'room')\n    .onData((i, data) =\u003e console.log('[Stream] data', data)))\n    .onEnd((i) =\u003e console.log('[Stream] Ended'))\n    .onError((i, error) =\u003e console.log('[Stream] Error', error))\n    .onRetry((i, e) =\u003e console.log('[Stream] Retry', e))\n    .build();\n```\n\nYou can remove event-listener with `removeEventListener`:\n\n```typescript\nlet stream: Stream\n/* ... */\nstream.removeEventListener(StreamEvents.data, dataEventListener);\n```\n\n#### Retry advanced\n\nYou can update `metadata` or `request` when using `onRetry` method\n\n```typescript\nconst client = new ChatClient(\"host_name_url\")\nconst stream = new StreamBuilder(client, 'room')\n    .onRetry(async (instance) =\u003e {\n        const token = await requestNewAccessToken()\n            instance.metaData = {\n               authorization: token\n                deadline\n            }\n        })\n    .build();\n```\n\n#### Reconnect \u0026 Backoff\n\nIf you want the gRpc streaming to automatically try to re-connect when the connection is lost, you can provide it with a `Backoff`.\nThe streaming will use the `Backoff` to determine how long it should wait between re-tries. There are currently three\n`Backoff`-implementations. You can also implement your own by inheriting from the `Backoff`-interface.\n\n\u003e To use the Backoff feature, install package:\n\n```typescript\nyarn add @nixjs23n6/backoff-typescript\n// Or \nnpm install @nixjs23n6/backoff-typescript\n```\n\n##### ConstantBackOff\n\nThe `ConstantBackOff` will make the streaming wait a constant time between each connection retry. To use the `ConstantBackOff`\nwith a wait-time of `1 second`:\n\n```typescript\nconst client = new ChatClient(\"host_name_url\")\nconst stream = new StreamBuilder(client, 'room')\n    .withBackoff(new ConstantBackOff(1000)) // 1000ms = 1s\n    .build();\n```\n\n##### LinearBackOff\n\nThe `LinearBackOff` linearly increases the wait-time between connection-retries until an optional maximum is reached.\nTo use the `LinearBackOff` to initially wait `0 seconds` and increase the wait-time by `1 second` with every retry until\na maximum of `8 seconds` is reached:\n\n```typescript\nconst client = new ChatClient(\"host_name_url\")\nconst stream = new StreamBuilder(client, 'room')\n    .withBackoff(new LinearBackOff(0, 1000, 8000))\n    .build();\n```\n\n##### ExponentialBackOff\n\nThe `ExponentialBackOff` doubles the backoff with every retry until a maximum is reached. This is modelled after the binary\nexponential-backoff algorithm used in computer-networking. To use the `ExponentialBackOff` that will produce the series\n`[100, 200, 400, 800, 1600, 3200, 6400]`:\n\n```typescript\nconst client = new ChatClient(\"host_name_url\")\nconst stream = new StreamBuilder(client, 'room')\n    .withBackoff(new ExponentialBackOff(100, 7))\n    .build();\n```\n\n#### Build\n\nTo build the project run `yarn build`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnixjs%2Fgrpc-stream-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnixjs%2Fgrpc-stream-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnixjs%2Fgrpc-stream-client/lists"}