{"id":21721733,"url":"https://github.com/codesyncr/transmit-client","last_synced_at":"2025-03-20T21:45:14.261Z","repository":{"id":197159423,"uuid":"688227648","full_name":"CodeSyncr/transmit-client","owner":"CodeSyncr","description":null,"archived":false,"fork":false,"pushed_at":"2024-07-12T06:40:20.000Z","size":871,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-25T18:43:29.258Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/CodeSyncr.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-09-06T23:29:51.000Z","updated_at":"2024-07-12T06:40:23.000Z","dependencies_parsed_at":"2025-01-25T18:43:05.284Z","dependency_job_id":"f8c45b24-76a8-4ac7-8d12-22f949d2b860","html_url":"https://github.com/CodeSyncr/transmit-client","commit_stats":null,"previous_names":["codesyncr/transmit-client"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeSyncr%2Ftransmit-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeSyncr%2Ftransmit-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeSyncr%2Ftransmit-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeSyncr%2Ftransmit-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CodeSyncr","download_url":"https://codeload.github.com/CodeSyncr/transmit-client/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244694293,"owners_count":20494618,"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-11-26T02:18:46.842Z","updated_at":"2025-03-20T21:45:14.240Z","avatar_url":"https://github.com/CodeSyncr.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003ch1\u003e Adonis Transmit Client\u003c/h1\u003e\n  \u003cp\u003eA client for the native Server-Sent-Event (SSE) module of Adonis Transmit.\u003c/p\u003e\n\u003c/div\u003e\n\n\u003cbr /\u003e\n\n\u003cdiv align=\"center\"\u003e\n\n[![gh-workflow-image]][gh-workflow-url] [![npm-image]][npm-url] ![][typescript-image] [![license-image]][license-url] [![synk-image]][synk-url]\n\n\u003c/div\u003e\n\n\u003cdiv align=\"center\"\u003e\n  \u003ch3\u003e\n    \u003ca href=\"#installation\"\u003e\n      Usage\n    \u003c/a\u003e\n    \u003cspan\u003e | \u003c/span\u003e\n    \u003ca href=\"https://kyash.in\"\u003e\n      Checkout CodeSyncr\n    \u003c/a\u003e\n  \u003c/h3\u003e\n\u003c/div\u003e\n\n\u003cbr /\u003e\n\n\u003chr /\u003e\n\nAdonis Transmit Client is a client for the native Server-Sent-Event (SSE) module of Adonis Transmit. It is built on top of the [EventSource](https://developer.mozilla.org/en-US/docs/Web/API/ntSource) API and provides a simple API to receive events from the server.\n\n\u003c!-- START doctoc generated TOC please keep comment here to allow auto update --\u003e\n\u003c!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --\u003e\n## Table of Contents\n\n  - [Installation](#installation)\n  - [Usage](#usage)\n  - [Subscribing to channels](#subscribing-to-channels)\n    - [Subscription Request](#subscription-request)\n    - [Reconnecting](#reconnecting)\n    - [Unsubscribing](#unsubscribing)\n- [Events](#events)\n\n\u003c!-- END doctoc generated TOC please keep comment here to allow auto update --\u003e\n\n## Installation\n\nInstall the package from the npm registry as follows:\n\n```sh\nnpm i @brighthustle/transmit-client\n\n# yarn\nyarn add @brighthustle/transmit-client\n\n# pnpm\npnpm add @brighthustle/transmit-client\n```\n\nUsing the package as script tag on HTML:\n\n```sh\n\u003cscript src=\"https://www.unpkg.com/@brighthustle/transmit-client@0.0.3/src/transmit.js\"\u003e\u003c/script\u003e\n```\n\n## Usage\n\nThe module exposes a `Transmit` class, which can be used to connect to the server and listen for events.\n\n```ts\nimport { Transmit } from '@brighthustle/transmit-client'\n\nconst transmit = new Transmit({\n  baseUrl: 'http://localhost:3333',\n})\n```\n\n## Subscribing to channels\n\nThe `listenOn` method accepts the channel name and a callback to be invoked when the event is received from the server.\n\n```ts\ntransmit.listenOn\u003c{ message: string }\u003e('chat/1', (payload) =\u003e {\n  console.log(payload.message)\n})\n```\n\nYou can also listen from a channel only once.\n\n```ts\ntransmit.listenOnce\u003c{ message: string }\u003e('chat/1', () =\u003e {\n  console.log('first message received!')\n})\n```\n\n### Subscription Request\n\nYou can alter the subscription request by using the `beforeSubscribe` or `beforeUnsubscribe` options.\n\n```ts\nconst transmit = new Transmit({\n  baseUrl: 'http://localhost:3333',\n  beforeSubscribe: (_request: RequestInit) =\u003e {\n    console.log('beforeSubscribe')\n  },\n  beforeUnsubscribe: (_request: RequestInit) =\u003e {\n    console.log('beforeUnsubscribe')\n  },\n})\n```\n\n### Reconnecting\n\nThe transmit client will automatically reconnect to the server when the connection is lost. You can change the number of retries and hook into the reconnect lifecycle as follows:\n\n```ts\nconst transmit = new Transmit({\n  baseUrl: 'http://localhost:3333',\n  maxReconnectionAttempts: 5,\n  onReconnectAttempt: (attempt) =\u003e {\n    console.log('Reconnect attempt ' + attempt)\n  },\n  onReconnectFailed: () =\u003e {\n    console.log('Reconnect failed')\n  },\n})\n```\n\n### Unsubscribing\n\nThe `listenOn` method returns a function to unsubscribe from the channel.\n\n```ts\nconst unsubscribe = transmit.listenOn('chat/1', () =\u003e {\n  console.log('message received!')\n})\n\n// later\nunsubscribe()\n```\n\nWhen unsubscribing from a channel, the client will remove the local listener for that channel. By default, it will not send a request to the server when there are no more listener to unsubscribe from the channel. You can change this behavior by setting the `removeSubscriptionOnZeroListener` option to `true`.\n\n```ts\nconst transmit = new Transmit({\n  baseUrl: 'http://localhost:3333',\n  removeSubscriptionOnZeroListener: true,\n})\n```\n\nYou can also change the default settings locally by passing a boolean to the unsubscribe method.\n\n```ts\nconst unsubscribe = transmit.listenOn('chat/1', () =\u003e {\n  console.log('message received!')\n})\n\n// later\nunsubscribe(true) // or false\n```\n\n# Events\n\nThe`Transmit` class extends the [`EventTarget`](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget) class and emits multiple events.\n\n```ts\ntransmit.on('connected', () =\u003e {\n  console.log('connected')\n})\n\ntransmit.on('disconnected', () =\u003e {\n  console.log('disconnected')\n})\n\ntransmit.on('reconnecting', () =\u003e {\n  console.log('reconnecting')\n})\n```\n\n[gh-workflow-image]: https://img.shields.io/github/actions/workflow/status/CodeSyncr/transmit-client/test?style=for-the-badge\n[gh-workflow-url]: https://github.com/CodeSyncr/transmit-client/actions/workflows/test.yml \"Github action\"\n\n[typescript-image]: https://img.shields.io/badge/Typescript-294E80.svg?style=for-the-badge\u0026logo=typescript\n[typescript-url]: \"typescript\"\n\n[npm-image]: https://img.shields.io/npm/v/@CodeSyncr/transmit-client.svg?style=for-the-badge\u0026logo=npm\n[npm-url]: https://npmjs.org/package/@CodeSyncr/transmit-client 'npm'\n\n[license-image]: https://img.shields.io/npm/l/@CodeSyncr/transmit-client?color=blueviolet\u0026style=for-the-badge\n[license-url]: LICENSE.md 'license'\n\n[synk-image]: https://img.shields.io/snyk/vulnerabilities/github/CodeSyncr/transmit-client?label=Synk%20Vulnerabilities\u0026style=for-the-badge\n[synk-url]: https://snyk.io/test/github/CodeSyncr/transmit-client?targetFile=package.json \"synk\"","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodesyncr%2Ftransmit-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodesyncr%2Ftransmit-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodesyncr%2Ftransmit-client/lists"}