Docs/Quickstart
Docs/Getting Started

Quickstart

Connect your first WebSocket client and broadcast events in 60 seconds.

Quickstart

Get up and running with Socketo in less than a minute. In this guide, you will connect a client to Socketo, subscribe to a channel, and trigger your first real-time event from the backend.


1. Get Application Credentials

When using Socketo Cloud, create an app from your dashboard to get your credentials:

  • App ID & App Key: your_app_key
  • App Secret: your_app_secret
  • WebSocket Host (Client): wss.socketo.dev
  • REST API Host (Backend): api.socketo.dev

Note on App Key & App ID: In Socketo Cloud, your App Key and App ID use the same unified identifier (app.id). When configuring official Pusher server SDKs or framework environment variables, assign this value to both APP_ID and APP_KEY.

Local Development: When using @socketo/cli, you can use local for App ID, Key, and Secret with host localhost:8787.


2. Connect the Client

Install the Pusher client SDK:

bash
npm install pusher-js

Initialize the client and subscribe to a channel:

ts
import Pusher from 'pusher-js'

const pusher = new Pusher('YOUR_APP_KEY', {
  wsHost: 'wss.socketo.dev',
  wssPort: 443,
  forceTLS: true,
  cluster: 'socketo',
  enabledTransports: ['ws'],
})

const channel = pusher.subscribe('notifications')

channel.bind('new-message', (data: { text: string; sender: string }) => {
  console.log('Received message:', data.text, 'from', data.sender)
})

pusher.connection.bind('connected', () => {
  console.log('Connected to Socketo! Socket ID:', pusher.connection.socket_id)
})

3. Trigger an Event from Backend

Install the Pusher server SDK in your Node.js project:

bash
npm install pusher

Trigger an event to the notifications channel:

ts
import Pusher from 'pusher'

const pusher = new Pusher({
  appId: 'YOUR_APP_ID',
  key: 'YOUR_APP_KEY',
  secret: 'YOUR_APP_SECRET',
  host: 'api.socketo.dev',
  useTLS: true,
})

await pusher.trigger('notifications', 'new-message', {
  text: 'Hello from Socketo!',
  sender: 'Backend Worker',
})

console.log('Event triggered successfully!')

4. Or Trigger via Socketo CLI

You can also trigger events directly from your terminal:

bash
npx @socketo/cli trigger notifications new-message '{"text":"Hello from CLI!","sender":"Dev"}'

Next Steps