@adonisjs/transmit
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -39,3 +39,3 @@ /* | ||
const channel = ctx.request.input('channel'); | ||
const success = transmit.subscribeToChannel(uid, channel, ctx); | ||
const success = transmit.$subscribeToChannel(uid, channel, ctx); | ||
if (!success) { | ||
@@ -49,3 +49,3 @@ return ctx.response.badRequest(); | ||
const channel = request.input('channel'); | ||
const success = transmit.unsubscribeFromChannel(uid, channel); | ||
const success = transmit.$unsubscribeFromChannel(uid, channel); | ||
if (!success) { | ||
@@ -52,0 +52,0 @@ return response.badRequest(); |
@@ -37,7 +37,7 @@ import Emittery from 'emittery'; | ||
getSubscriptionsForClient(uid: string): string[]; | ||
subscribeToChannel(uid: string, channel: string, ctx: HttpContext): Promise<boolean>; | ||
unsubscribeFromChannel(uid: string, channel: string): boolean; | ||
$subscribeToChannel(uid: string, channel: string, ctx: HttpContext): Promise<boolean>; | ||
$unsubscribeFromChannel(uid: string, channel: string): boolean; | ||
broadcastExcept(channel: string, payload: Record<string, unknown>, senderUid: string | string[]): void; | ||
broadcast(channel: string, payload: Record<string, unknown>): void; | ||
broadcast(channel: string, payload?: Record<string, unknown>): void; | ||
} | ||
export {}; |
@@ -75,3 +75,3 @@ /* | ||
} | ||
async subscribeToChannel(uid, channel, ctx) { | ||
async $subscribeToChannel(uid, channel, ctx) { | ||
const definitions = this.#secureChannelStore.match(channel); | ||
@@ -98,3 +98,3 @@ if (definitions) { | ||
} | ||
unsubscribeFromChannel(uid, channel) { | ||
$unsubscribeFromChannel(uid, channel) { | ||
void this.emit('unsubscribe', { uid, channel }); | ||
@@ -118,2 +118,5 @@ return this.#storage.removeChannelFromStream(uid, channel); | ||
broadcast(channel, payload) { | ||
if (!payload) { | ||
payload = {}; | ||
} | ||
this.#broadcastLocally(channel, payload); | ||
@@ -120,0 +123,0 @@ // @ts-ignore |
{ | ||
"name": "@adonisjs/transmit", | ||
"description": "A Server-Sent-Event module for AdonisJS.", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"engines": { | ||
@@ -6,0 +6,0 @@ "node": ">=18.16.0" |
@@ -50,3 +50,3 @@ /* | ||
const success = transmit.subscribeToChannel(uid, channel, ctx) | ||
const success = transmit.$subscribeToChannel(uid, channel, ctx) | ||
@@ -64,3 +64,3 @@ if (!success) { | ||
const success = transmit.unsubscribeFromChannel(uid, channel) | ||
const success = transmit.$unsubscribeFromChannel(uid, channel) | ||
@@ -67,0 +67,0 @@ if (!success) { |
@@ -40,12 +40,13 @@ <div align="center"> | ||
## Table of Contents | ||
<!-- START doctoc generated TOC please keep comment here to allow auto update --> | ||
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> | ||
## Table of Contents | ||
- [Installation](#installation) | ||
- [Usage](#usage) | ||
- [Channels](#channels) | ||
- [Channel Names](#channel-names) | ||
- [Channel Authorization](#channel-authorization) | ||
- [Installation](#installation) | ||
- [Usage](#usage) | ||
- [Channels](#channels) | ||
- [Channel Names](#channel-names) | ||
- [Channel Authorization](#channel-authorization) | ||
- [Syncing](#syncing) | ||
- [Events](#events) | ||
@@ -102,2 +103,17 @@ | ||
# Syncing | ||
Transmit 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). | ||
```ts | ||
// config/transmit.ts | ||
import { defineConfig, RedisTransport } from '@adonisjs/transmit' | ||
export default defineConfig({ | ||
transport: { | ||
driver: RedisTransport | ||
} | ||
}) | ||
``` | ||
# Events | ||
@@ -104,0 +120,0 @@ |
@@ -108,3 +108,3 @@ /* | ||
async subscribeToChannel(uid: string, channel: string, ctx: HttpContext): Promise<boolean> { | ||
async $subscribeToChannel(uid: string, channel: string, ctx: HttpContext): Promise<boolean> { | ||
const definitions = this.#secureChannelStore.match(channel) | ||
@@ -137,3 +137,3 @@ | ||
unsubscribeFromChannel(uid: string, channel: string): boolean { | ||
$unsubscribeFromChannel(uid: string, channel: string): boolean { | ||
void this.emit('unsubscribe', { uid, channel }) | ||
@@ -168,3 +168,7 @@ | ||
broadcast(channel: string, payload: Record<string, unknown>) { | ||
broadcast(channel: string, payload?: Record<string, unknown>) { | ||
if (!payload) { | ||
payload = {} | ||
} | ||
this.#broadcastLocally(channel, payload) | ||
@@ -171,0 +175,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
42374
1018
153