Relay Cloud manages connections and auth for you. Point any SDK at your Cloud endpoint and go. Try Relay Cloud →

SDKs & Integrations

Official SDKs for popular frameworks and languages.

SDK Language Install
relay-php PHP / Laravel composer require relayhq/relay-php
relay-node Node.js npm install @relayhq/relay-node
relay-ruby Ruby / Rails gem install relay-ruby
relay-python Python / Django pip install relay-python

Laravel (relay-php)

Installation

composer require relayhq/relay-php

Configuration

Add a relay connection to config/broadcasting.php:

'relay' => [
    'driver' => 'pusher',
    'key' => env('RELAY_APP_KEY'),
    'secret' => env('RELAY_APP_SECRET'),
    'app_id' => env('RELAY_APP_ID', 'app'),
    'options' => [
        'host' => env('RELAY_HOST', 'localhost'),
        'port' => env('RELAY_PORT', 6001),
        'scheme' => 'http',
    ],
],

Publishing Events

// Using Laravel broadcasting
broadcast(new MessageSent($message));

// Direct usage
use Pusher\Pusher;
$pusher = new Pusher($key, $secret, $appId, $options);
$pusher->trigger('my-channel', 'my-event', ['message' => 'Hello']);

Auth for Private Channels

Define authorization callbacks in routes/channels.php:

Broadcast::channel('orders.{id}', function ($user, $id) {
    return $user->id === Order::findOrNew($id)->user_id;
});

Node.js (relay-node)

Installation

npm install @relayhq/relay-node

Setup & Publishing

const Pusher = require('pusher');
const pusher = new Pusher({
    appId: 'app',
    key: 'my-key',
    secret: 'my-secret',
    host: 'localhost',
    port: 6001,
    useTLS: false,
});

// Single event
await pusher.trigger('my-channel', 'my-event', { message: 'Hello' });

// Batch
await pusher.triggerBatch([
    { channel: 'ch-1', name: 'evt-1', data: { msg: 'Hello' } },
    { channel: 'ch-2', name: 'evt-2', data: { msg: 'World' } },
]);

Express Auth Middleware

app.post('/broadcasting/auth', (req, res) => {
    const { socket_id, channel_name } = req.body;
    const auth = pusher.authorizeChannel(socket_id, channel_name);
    res.send(auth);
});

Rails (relay-ruby)

Installation

Add to your Gemfile:

gem 'pusher'

Configuration

# config/initializers/pusher.rb
Pusher.app_id = 'app'
Pusher.key = 'my-key'
Pusher.secret = 'my-secret'
Pusher.host = 'localhost'
Pusher.port = 6001
Pusher.encrypted = false

Usage

Pusher.trigger('my-channel', 'my-event', { message: 'Hello' })

# Batch
Pusher.trigger_batch([
  { channel: 'ch-1', name: 'evt-1', data: { msg: 'Hello' } }
])

Auth Controller

class PusherController < ApplicationController
  def auth
    response = Pusher.authenticate(params[:channel_name], params[:socket_id])
    render json: response
  end
end

Django/Python (relay-python)

Installation

pip install relay-python

Setup & Sync Publishing

import pusher

client = pusher.Pusher(
    app_id='app',
    key='my-key',
    secret='my-secret',
    host='localhost',
    port=6001,
    ssl=False
)

client.trigger('my-channel', 'my-event', {'message': 'Hello'})

Async

import asyncio
from pusher import AsyncPusher

async def publish():
    client = AsyncPusher(app_id='app', key='my-key', secret='my-secret', host='localhost', port=6001, ssl=False)
    await client.trigger('my-channel', 'my-event', {'message': 'Hello'})

Batch

client.trigger_batch([
    {'channel': 'ch-1', 'name': 'evt-1', 'data': {'msg': 'Hello'}},
])

Django Auth View

from django.http import JsonResponse
from django.views.decorators.csrf import csrf_exempt

@csrf_exempt
def pusher_auth(request):
    response = client.authenticate(
        channel=request.POST['channel_name'],
        socket_id=request.POST['socket_id']
    )
    return JsonResponse(response)
Skip the server setup. Relay Cloud gives you managed WebSocket infrastructure. Point your SDK at your Cloud endpoint and ship faster. Start Free →