blink-realtime
Requires auth: initialize with auth: { mode: 'managed' } for realtime to work.
Getting Started
# Publish a message to a channel
blink realtime publish chat-room --type message --data '{"text":"Hello everyone!"}'
# Publish with user context
blink realtime publish notifications --type alert --data '{"level":"info","text":"Deploy complete"}'
MCP Tools
| Tool | Description |
|---|---|
blink_realtime_publish |
Publish event to a channel |
SDK Methods
// Simple subscribe/publish
const unsubscribe = await blink.realtime.subscribe('chat-room', (message) => {
console.log(message.data)
})
await blink.realtime.publish('chat-room', 'message', { text: 'Hello!' })
unsubscribe()
Channel API (Advanced)
const channel = blink.realtime.channel('game-lobby')
await channel.subscribe({
userId: user.id,
metadata: { displayName: user.name, status: 'online' }
})
channel.onMessage((msg) => {
if (msg.type === 'chat') addMessage(msg.data)
})
channel.onPresence((users) => {
setOnlineUsers(users)
})
await channel.publish('chat', { text: 'Hello!' }, { userId: user.id })
const history = await channel.getMessages({ limit: 50 })
const users = await channel.getPresence()
await channel.unsubscribe()
Message Format
{
id: '1640995200000-0',
type: 'chat',
data: { text: 'Hello!' },
timestamp: 1640995200000,
userId: 'user123',
metadata: { displayName: 'John' }
}
Presence Format
{
userId: 'user123',
metadata: { displayName: 'John', status: 'online' },
joinedAt: 1640995200000,
lastSeen: 1640995230000
}
React Cleanup (Critical)
useEffect(() => {
if (!user?.id) return
let channel: any = null
const init = async () => {
channel = blink.realtime.channel('room')
await channel.subscribe({ userId: user.id })
channel.onMessage((msg: any) => setMessages(prev => [...prev, msg]))
}
init().catch(console.error)
return () => { channel?.unsubscribe() }
}, [user?.id])
Never return cleanup from inside an async function — it gets lost. Store channel reference outside and clean up synchronously.
Use Cases
- Chat apps — messages + presence + history
- Live collaboration — cursor positions, document edits
- Notifications — real-time alerts pushed to connected clients
- Gaming — game state sync, lobby management
- Dashboards — live data updates
More from blink-new/blink-plugin
blink-full-stack
End-to-end guide for building and shipping a Blink app. Project setup, SDK init, auth, database, backend, deploy, and custom domains. Index to all other skills.
3blink-ai
AI Gateway for text generation, image generation/editing, video generation, text-to-speech, audio transcription, and AI phone calls. Unified access to 50+ models.
2blink-domains
Custom domain management. Add domains, DNS setup, SSL verification, domain search, and domain purchase via CLI.
2blink-queue
Background task queue and cron schedules. Enqueue tasks, named FIFO queues with parallelism, auto-retry. Requires Blink Backend (Pro+).
2blink-storage
File upload with progress tracking and public URLs. Download, remove files. CLI for management. Extension auto-detection.
2blink-database
Database CRUD with automatic camelCase conversion. Create, list, update, delete, upsert, count, exists. Raw SQL via CLI. Boolean handling for SQLite.
2