Docs/Core concepts/Events

Events

An event is a named message with a JSON payload, published to a channel and delivered to every subscriber.

Concept· 4 min read

What an event is

An event is a named message carrying an arbitrary JSON payload. You publish it to a channel from a trusted server; EmitWave delivers it to every connected subscriber bound to that event name (or bound with bindAll).

Three things define a delivery: the channel it is published to, the event name, and the data payload.

Publishing an event

Every server SDK exposes the same shape — trigger(channel, event, data) — and signs the request with HMAC-SHA256 before sending it to the gateway.

publish.ts
// channel, event name, and arbitrary JSON data
await emitwave.trigger('orders', 'order.created', {
  id: 'ord_123',
  total: 4900,
})

See Publishing for the full signed path and the gateway endpoint.

Receiving an event

receive.ts
const channel = await emitwave.subscribe('orders')

channel.bind('order.created', (data) => {
  // data is the JSON you published
  console.log(data.id, data.total)
})

Event naming

Event names are free-form strings you choose; a dotted, domain-style convention such as order.created or message.updated keeps handlers readable. The name is matched exactly by bind().

Client-originated events are not enabled. Browsers subscribe and receive; all publishing originates from a trusted server with a server SDK.

Reserved SDK events

A few event names are produced by the SDK itself rather than the server, and are not passed to bindAll():

EventWhen it fires
cache_missA cache channel had no retained event on first subscribe
decryption_errorAn encrypted payload could not be decrypted