Docs/Getting started/Quickstart

Quickstart

Subscribe to a channel in the browser and publish your first signed event from a server — end to end in a few minutes.

Guide· 5 min read

Prerequisites

  • An EmitWave application — gives you a public key (ew_pk_…) and a server credential (key + secret).
  • An end-user token your application issues and EmitWave accepts as a Bearer token.
  • Node.js 18+ for the server example.
The server secret signs publish requests. Never ship it to the browser. The browser only ever needs the public key and an end-user token.

1. Install

# Browser / JS client (subscribe + presence)
npm install @emitwave/js
# Framework clients
npm install @emitwave/react @emitwave/js
npm install @emitwave/next @emitwave/react @emitwave/js
npm install @emitwave/vue @emitwave/js

2. Subscribe in the browser

connect() posts your public key with the end-user token to obtain a short-lived connection token, then opens the WebSocket. Public channels subscribe immediately.

client.ts
import { Emitwave } from '@emitwave/js'

const emitwave = new Emitwave('ew_pk_live_your_public_key', {
  authHeaders: async () => ({
    Authorization: `Bearer ${await getEndUserToken()}`,
  }),
})

emitwave.onState((state) => console.log('connection:', state))

await emitwave.connect()

const channel = await emitwave.subscribe('orders')
channel.bind('order.created', (order) => {
  console.log('new order', order.id, order.total)
})

Use onState() for the real connection state: connecting, connected, disconnected, or error.

3. Publish from your server

On a trusted server, call trigger(channel, event, data). The SDK hashes the exact JSON body and HMAC-signs the method, path, canonical query, and body hash before sending it to /apps/{appId}/events.

server.ts
import { Client } from '@emitwave/node'

const emitwave = new Client({
  appId: process.env.EMITWAVE_APP_ID,
  key: process.env.EMITWAVE_KEY,
  secret: process.env.EMITWAVE_SECRET,
  // gatewayUrl defaults to https://api.emitwave.com
})

await emitwave.trigger('orders', 'order.created', {
  id: 'ord_123',
  total: 4900,
})
The server SDKs publish to the EmitWave gateway at https://api.emitwave.com by default — you only set a gateway URL to target another environment. See the API reference for all base URLs.

4. Receive the event

EmitWave verifies the signature, rate-limits, scopes the channel to your application, and fans the event out. The browser handler bound to order.created fires with the event data. That's the full loop.

Client-originated events are not enabled. Browsers only subscribe; all publishing happens from a trusted server with a server SDK.

Next steps