Skip to content
Docs/Server Events
Docs/Events

Server Events

Server-to-client event publishing, multi-channel broadcast, and socket exclusion.

Overview

Server events originate from application backend services and are dispatched over WebSockets to subscribed clients. Events are published via Socketo's Pusher-compatible HTTP REST API.

Publishing Operations

1. Single Channel Trigger

ts
await pusher.trigger('orders', 'order-created', {
  orderId: 'ord_123',
  amount: 49.99,
})

2. Multi-Channel Broadcast

Publish a single payload to up to 100 channels simultaneously:

ts
await pusher.trigger(
  ['orders', 'analytics', 'warehouse'],
  'order-created',
  { orderId: 'ord_123' },
)

3. Socket Exclusion

Exclude the client that originated the action by passing its socket_id:

ts
await pusher.trigger('chat-room', 'message', { text: 'Hello!' }, {
  socket_id: originatingSocketId,
})

In Laravel, calling ->toOthers() on a broadcast event automatically populates this header.

4. Batch Triggering

Transmit up to 10 separate event payloads across different channels in a single HTTP request:

ts
await pusher.triggerBatch([
  { channel: 'orders', name: 'created', data: { id: 'ord_1' } },
  { channel: 'presence-lobby', name: 'announcement', data: { text: 'Maintenance in 5m' } },
  { channel: 'metrics', name: 'update', data: { cpu: 82 } },
])

5. Direct User Broadcast (sendToUser)

Send an event directly to all active socket connections belonging to a signed-in user:

ts
await pusher.sendToUser('user_42', 'payment-success', {
  invoiceId: 'inv_987',
})

Socketo delivers user events over the internal #server-to-user-<user_id> wire channel, triggering client callbacks registered via pusher.user.bind().

REST API Specification

To trigger events directly via HTTP without official SDKs, consult the REST API Endpoints reference.