
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
@brighthustle/transmit-client
Advanced tools
A client for the native Server-Sent-Event module of AdonisJS.
A client for the native Server-Sent-Event (SSE) module of Adonis Transmit.
Adonis Transmit Client is a client for the native Server-Sent-Event (SSE) module of Adonis Transmit. It is built on top of the EventSource API and provides a simple API to receive events from the server.
Install the package from the npm registry as follows:
npm i @brighthustle/transmit-client
# yarn
yarn add @brighthustle/transmit-client
# pnpm
pnpm add @brighthustle/transmit-client
Using the package as script tag on HTML:
<script src="https://www.unpkg.com/@brighthustle/transmit-client@0.0.3/src/transmit.js"></script>
The module exposes a Transmit
class, which can be used to connect to the server and listen for events.
import { Transmit } from '@brighthustle/transmit-client'
const transmit = new Transmit({
baseUrl: 'http://localhost:3333',
})
The listenOn
method accepts the channel name and a callback to be invoked when the event is received from the server.
transmit.listenOn<{ message: string }>('chat/1', (payload) => {
console.log(payload.message)
})
You can also listen from a channel only once.
transmit.listenOnce<{ message: string }>('chat/1', () => {
console.log('first message received!')
})
You can alter the subscription request by using the beforeSubscribe
or beforeUnsubscribe
options.
const transmit = new Transmit({
baseUrl: 'http://localhost:3333',
beforeSubscribe: (_request: RequestInit) => {
console.log('beforeSubscribe')
},
beforeUnsubscribe: (_request: RequestInit) => {
console.log('beforeUnsubscribe')
},
})
The 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:
const transmit = new Transmit({
baseUrl: 'http://localhost:3333',
maxReconnectionAttempts: 5,
onReconnectAttempt: (attempt) => {
console.log('Reconnect attempt ' + attempt)
},
onReconnectFailed: () => {
console.log('Reconnect failed')
},
})
The listenOn
method returns a function to unsubscribe from the channel.
const unsubscribe = transmit.listenOn('chat/1', () => {
console.log('message received!')
})
// later
unsubscribe()
When 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
.
const transmit = new Transmit({
baseUrl: 'http://localhost:3333',
removeSubscriptionOnZeroListener: true,
})
You can also change the default settings locally by passing a boolean to the unsubscribe method.
const unsubscribe = transmit.listenOn('chat/1', () => {
console.log('message received!')
})
// later
unsubscribe(true) // or false
TheTransmit
class extends the EventTarget
class and emits multiple events.
transmit.on('connected', () => {
console.log('connected')
})
transmit.on('disconnected', () => {
console.log('disconnected')
})
transmit.on('reconnecting', () => {
console.log('reconnecting')
})
FAQs
A client for the native Server-Sent-Event module of AdonisJS.
The npm package @brighthustle/transmit-client receives a total of 3 weekly downloads. As such, @brighthustle/transmit-client popularity was classified as not popular.
We found that @brighthustle/transmit-client demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.