{"id":19528878,"url":"https://github.com/adonisjs/transmit","last_synced_at":"2026-02-16T14:13:08.844Z","repository":{"id":196260323,"uuid":"371582301","full_name":"adonisjs/transmit","owner":"adonisjs","description":"A Server-Sent-Event module for AdonisJS","archived":false,"fork":false,"pushed_at":"2024-12-10T19:28:45.000Z","size":100,"stargazers_count":77,"open_issues_count":2,"forks_count":7,"subscribers_count":5,"default_branch":"2.x","last_synced_at":"2025-03-31T10:06:42.556Z","etag":null,"topics":[],"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/adonisjs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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},"funding":{"github":"thetutlage"}},"created_at":"2021-05-28T04:45:53.000Z","updated_at":"2025-03-30T15:30:21.000Z","dependencies_parsed_at":"2024-01-22T12:41:20.953Z","dependency_job_id":"eee90a23-726f-45b2-a12a-21439102edec","html_url":"https://github.com/adonisjs/transmit","commit_stats":{"total_commits":112,"total_committers":7,"mean_commits":16.0,"dds":0.0535714285714286,"last_synced_commit":"f6054ff79a53b96e315655e163739ef67feb89e2"},"previous_names":["adonisjs/transmit"],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adonisjs%2Ftransmit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adonisjs%2Ftransmit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adonisjs%2Ftransmit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adonisjs%2Ftransmit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/adonisjs","download_url":"https://codeload.github.com/adonisjs/transmit/tar.gz/refs/heads/2.x","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247640465,"owners_count":20971557,"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-11T01:20:30.029Z","updated_at":"2026-01-24T20:38:00.697Z","avatar_url":"https://github.com/adonisjs.png","language":"TypeScript","funding_links":["https://github.com/sponsors/thetutlage"],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003ch1\u003e AdonisJS Transmit\u003c/h1\u003e\n  \u003cp\u003eA native Server-Sent-Event (SSE) module for AdonisJS.\u003c/p\u003e\n\u003c/div\u003e\n\n\u003cbr /\u003e\n\n\u003cdiv align=\"center\"\u003e\n\n[![typescript-image]][typescript-url]\n[![gh-workflow-image]][gh-workflow-url]\n[![npm-image]][npm-url]\n[![npm-download-image]][npm-download-url]\n[![license-image]][license-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://adonisjs.com\"\u003e\n      Checkout AdonisJS\n    \u003c/a\u003e\n  \u003c/h3\u003e\n\u003c/div\u003e\n\n\u003cbr /\u003e\n\n\u003chr /\u003e\n\nAdonisJS Transmit is a native Server-Sent-Event (SSE) module for AdonisJS. It provides a simple API to send events to the client. It also supports [Redis](https://redis.io/) as a Transport Layer for broadcasting events to multiple servers or instances.\n\nHere are a few things you should know before using this module.\n\n\u003cp\u003e\n👉 \u003cstrong\u003eUnidirectional Communication:\u003c/strong\u003e The data transmission occurs only from server to client, not the other way around.\t\u003cbr /\u003e\n👉 \u003cstrong\u003eTextual Data Only:\u003c/strong\u003e SSE only supports the transmission of textual data, binary data cannot be sent. \u003cbr /\u003e\n👉 \u003cstrong\u003eHTTP Protocol:\u003c/strong\u003e The underlying protocol used is the regular HTTP, not any special or proprietary protocol.\t\u003cbr /\u003e\n\u003c/p\u003e\n\n## Table of Contents\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\n  - [Installation](#installation)\n  - [Usage](#usage)\n  - [Channels](#channels)\n    - [Channel Names](#channel-names)\n    - [Channel Authorization](#channel-authorization)\n- [Syncing](#syncing)\n- [Ping](#ping)\n- [Events](#events)\n- [Avoiding GZip Interference](#avoiding-gzip-interference)\n\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\nnode ace add @adonisjs/transmit\n```\n\n## Usage\n\nThe module exposes a `transmit` instance, which can be used to send events to the client.\n\n```ts\nimport transmit from '@adonisjs/transmit/services/main'\n\n// Anywhere in your code\ntransmit.broadcast('channelName', { username: 'lanz' })\n```\n\n## Channels\n\nChannels are a way to group events. For example, you can have a channel for `users` and another for `posts`. The client can subscribe to one or more channels to receive events.\n\n### Channel Names\n\nChannels names must be a string and must not contain any special characters except `/`. The following are valid channel names.\n\n```ts\ntransmit.broadcast('users', { username: 'lanz' })\ntransmit.broadcast('users/1', { username: 'lanz' })\ntransmit.broadcast('users/1/posts', { username: 'lanz' })\n```\n\n### Channel Authorization\n\nYou can mark a channel as private and then authorize the client to subscribe to it. The authorization is done using a callback function.\n\n```ts\n// start/transmit.ts\n\nimport type { HttpContext } from '@adonisjs/core/http'\n\ntransmit.authorize\u003c{ id: string }\u003e('users/:id', (ctx: HttpContext, { id }) =\u003e {\n  return ctx.auth.user?.id === +id\n})\n```\n\n\u003e [!NOTE]\n\u003e Do not forget to add your `start/transmit.ts` file inside the `preloads` array of the `adonisrc.ts` file.\n\nWhen a client tries to subscribe to a private channel, the callback function is invoked with the channel params and the HTTP context. The callback function must return a boolean value to allow or disallow the subscription.\n\n# Syncing\n\nTransmit supports syncing events across multiple servers or instances using a transport layer. You can enable syncing by changing the configuration and referencing your driver (only Redis is available as of now).\n\n```ts\n// config/transmit.ts\nimport env from '#start/env'\nimport { defineConfig } from '@adonisjs/transmit'\nimport { redis } from '@adonisjs/transmit/transports'\n\nexport default defineConfig({\n  transport: {\n    driver: redis({\n      host: env.get('REDIS_HOST'),\n      port: env.get('REDIS_PORT'),\n      password: env.get('REDIS_PASSWORD'),\n    })\n  }\n})\n```\n\n\u003e [!NOTE]\n\u003e Ensure to have `ioredis` installed when using the `redis` driver.\n\n# Ping\n\nTransmit supports pinging the client to keep the connection alive. You can enable pinging by changing the configuration.\n\n```ts\n// config/transmit.ts\nimport { defineConfig } from '@adonisjs/transmit'\nimport { redis } from '@adonisjs/transmit/transports'\n\nexport default defineConfig({\n  pingInterval: '1m',\n})\n```\n\n# Events\n\nTransmit uses [Emittery](https://github.com/sindresorhus/emittery) to emit any lifecycle events. You can listen for events using the `on` method.\n\n```ts\ntransmit.on('broadcast', ({ channel, payload }) =\u003e {\n  logger.debug('TRANSMIT broadcasted')\n  logger.debug(`─ channel: ${channel}`)\n  logger.debug(`─ payload: ${JSON.stringify(payload)}`)\n})\n\ntransmit.on('connect', ({ uid }) =\u003e {\n  logger.debug('TRANSMIT connected')\n  logger.debug(`─ uid: ${uid}`)\n})\n\ntransmit.on('disconnect', ({ uid }) =\u003e {\n  logger.debug('TRANSMIT disconnected')\n  logger.debug(`─ uid: ${uid}`)\n})\n\ntransmit.on('subscribe', ({ channel, uid }) =\u003e {\n  logger.debug('TRANSMIT subscribed')\n  logger.debug(`─ channel: ${channel}`)\n  logger.debug(`─ uid: ${uid}`)\n})\n\ntransmit.on('unsubscribe', ({ channel, uid }) =\u003e {\n  logger.debug('TRANSMIT unsubscribed')\n  logger.debug(`─ channel: ${channel}`)\n  logger.debug(`─ uid: ${uid}`)\n})\n```\n\n# Avoiding GZip Interference\n\nWhen deploying applications that use `@adonisjs/transmit`, it’s important to ensure that GZip compression does not interfere with the `text/event-stream` content type used by Server-Sent Events (SSE). Compression applied to `text/event-stream` can cause connection issues, leading to frequent disconnects or SSE failures.\n\nIf your deployment uses a reverse proxy (such as Traefik or Nginx) or other middleware that applies GZip, ensure that compression is disabled for the `text/event-stream` content type.\n\n## Example Configuration for Traefik\n\n```plaintext\ntraefik.http.middlewares.gzip.compress=true\ntraefik.http.middlewares.gzip.compress.excludedcontenttypes=text/event-stream\ntraefik.http.routers.my-router.middlewares=gzip\n```\n\n\n[gh-workflow-image]: https://img.shields.io/github/actions/workflow/status/adonisjs/transmit/checks.yml?branch=2.x\u0026style=for-the-badge\n[gh-workflow-url]: https://github.com/adonisjs/transmit/actions/workflows/checks.yml 'GitHub action'\n[npm-image]: https://img.shields.io/npm/v/@adonisjs/transmit.svg?style=for-the-badge\u0026logo=npm\n[npm-url]: https://www.npmjs.com/package/@adonisjs/transmit\n[npm-download-image]: https://img.shields.io/npm/dm/@adonisjs/transmit?style=for-the-badge\n[npm-download-url]: https://www.npmjs.com/package/@adonisjs/transmit\n[typescript-image]: https://img.shields.io/badge/Typescript-294E80.svg?style=for-the-badge\u0026logo=typescript\n[typescript-url]: https://www.typescriptlang.org\n[license-image]: https://img.shields.io/npm/l/@rlanz/bus?color=blueviolet\u0026style=for-the-badge\n[license-url]: LICENSE.md\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadonisjs%2Ftransmit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadonisjs%2Ftransmit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadonisjs%2Ftransmit/lists"}