Skip to content

Repository files navigation

Impulse Realtime

Super simple, type‑safe realtime via Server‑Sent Events (SSE).


1) Installation (CLI or Docker)

CLI (Node):

npx @impulselab/realtime-service --port 8080 --secret "$REALTIME_SECRET"

Docker:

docker run \
-p 8080:8080 \
-e REALTIME_SECRET="your-server-secret" \
ghcr.io/impulse-studio/realtime-service

Endpoints: GET / (SSE stream), POST / (push).


2) Types creation

Define your channel → payload map once, share it on client and server:

interfaceRealtimeTypes{'this:is:a:channel': {key: string}}

3) Client config

import{createRealtimeClient}from'@impulselab/realtime'constrc=createRealtimeClient<RealtimeTypes>({serviceUrl: process.env.SERVICE_URL!})// Public subscriberc.subscribe('this:is:a:channel',(event)=>{console.log(event.payload.key)})// Private subscribe (token) or group (topic)rc.subscribe('this:is:a:channel',(event)=>{console.log(event.payload.key)},{token: 'secret',topic: 'room-42'})// Unsubscribe helpersconstoff=rc.subscribe('this:is:a:channel',()=>{})off()rc.unsubscribeAll('this:is:a:channel')rc.unsubscribeAllChannels()

4) Server config

import{createServerClient}from'@impulselab/realtime'constsc=createServerClient<RealtimeTypes>({serviceUrl: process.env.SERVICE_URL!,token: process.env.TOKEN!})// Public pushawaitsc.push('this:is:a:channel',{key: 'value'})// Authenticated push (token)awaitsc.push('this:is:a:channel',{key: 'value'},{tokens: 'secret'})// Target a topic (room/group)awaitsc.push('this:is:a:channel',{key: 'value'},{topic: 'room-42'})// Auth + topic togetherawaitsc.push('this:is:a:channel',{key: 'value'},{tokens: ['secret','other'],topic: 'room-42'})

About

Implement server-side events easily with @impulselab/realtime

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages