SDKs overview

Pusher provides Software Development Kits (SDKs) and libraries designed to simplify the integration of real-time features into applications. These tools abstract the underlying WebSocket protocol, enabling developers to interact with Pusher's Channels and Beams products through language-specific APIs. The SDKs are categorized into client-side libraries for web and mobile frontends, and server-side libraries that facilitate communication with Pusher's API from backend applications.

The SDKs are developed and maintained by Pusher to ensure compatibility and leverage language-specific conventions. They handle connection management, authentication, event publishing, and event subscription, reducing the boilerplate code required for implementing real-time functionality. For instance, a JavaScript client-side SDK allows a web application to subscribe to a channel and receive updates as they are published by a server-side application using a corresponding server SDK.

Official SDKs by language

Pusher offers official SDKs for a range of popular programming languages and frameworks. These SDKs are maintained by Pusher and are the recommended method for integrating with their services. They are designed to provide a consistent developer experience across different environments while adhering to the idioms of each language. The table below outlines some of the key official SDKs, their typical package names, and installation methods.

For detailed API references and usage guides for each specific SDK, refer to the Pusher Channels library reference.

Language/Platform Package/Library Name Installation Command (Example) Maturity
JavaScript (Web) pusher-js npm install pusher-js or yarn add pusher-js Stable
Node.js (Server) pusher npm install pusher Stable
Ruby pusher gem install pusher Stable
Python pusher pip install pusher Stable
PHP pusher/pusher-php-server composer require pusher/pusher-php-server Stable
Laravel (Integrated via PHP SDK) composer require pusher/pusher-php-server Stable
iOS/Swift PusherSwift pod 'PusherSwift' (CocoaPods) or Swift Package Manager Stable
Android/Java com.pusher:pusher-java-client implementation 'com.pusher:pusher-java-client:x.y.z' (Gradle) Stable
.NET PusherClient (client), PusherServer (server) Install-Package PusherClient (NuGet), Install-Package PusherServer Stable
Go github.com/pusher/pusher-http-go go get github.com/pusher/pusher-http-go Stable

Installation

The installation process for Pusher SDKs typically involves using the package manager specific to the programming language or environment. After installation, developers usually configure the SDK with their Pusher application keys and cluster information, which are obtained from the Pusher dashboard.

Client-Side JavaScript Example (for Web Browsers)

npm install pusher-js
<!-- Or via CDN -->
<script src="https://js.pusher.com/8.0/pusher.min.js"></script>

Server-Side Node.js Example

npm install pusher

PHP Server-Side Example

composer require pusher/pusher-php-server

Python Server-Side Example

pip install pusher

Ruby Server-Side Example

gem install pusher

Quickstart example

This quickstart demonstrates a basic real-time messaging setup using Pusher. It involves a server-side component to publish events and a client-side component to subscribe and receive them. This example uses Node.js for the server and JavaScript for the web client, a common pattern for web applications requiring real-time updates.

Node.js Server (Publishing an Event)

First, set up your Node.js application to initialize the Pusher SDK with your credentials and then trigger an event on a specific channel. This example assumes you have your APP_ID, APP_KEY, APP_SECRET, and APP_CLUSTER configured.

// server.js
const Pusher = require('pusher');
const express = require('express');
const app = express();

// Initialize Pusher
const pusher = new Pusher({
  appId: 'YOUR_APP_ID',
  key: 'YOUR_APP_KEY',
  secret: 'YOUR_APP_SECRET',
  cluster: 'YOUR_APP_CLUSTER',
  useTLS: true,
});

app.use(express.json());

app.post('/send-message', (req, res) => {
  const message = req.body.message || 'Hello from server!';
  pusher.trigger('my-channel', 'my-event', {
    message: message
  });
  res.send('Event triggered!');
});

const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
  console.log(`Server listening on port ${PORT}`);
});

Client-Side JavaScript (Subscribing to an Event)

On the client-side, typically in your web application's HTML and JavaScript, you initialize the pusher-js client library with your application key and cluster. Then, you subscribe to the same channel and bind a callback function to the event. This function will execute whenever my-event is triggered on my-channel.

<!-- index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Pusher Quickstart</title>
    <script src="https://js.pusher.com/8.0/pusher.min.js"></script>
</head>
<body>
    <h1>Realtime Messages</h1>
    <div id="messages"></div>

    <script type="text/javascript">
        // Enable pusher logging - don't include this in production
        Pusher.logToConsole = true;

        var pusher = new Pusher('YOUR_APP_KEY', {
            cluster: 'YOUR_APP_CLUSTER'
        });

        var channel = pusher.subscribe('my-channel');
        channel.bind('my-event', function(data) {
            const messagesDiv = document.getElementById('messages');
            const newMessage = document.createElement('p');
            newMessage.textContent = `New message: ${data.message}`;
            messagesDiv.appendChild(newMessage);
        });
    </script>
</body>
</html>

After running the Node.js server and opening the index.html in a browser, sending a POST request to /send-message (e.g., using curl -X POST -H 'Content-Type: application/json' -d '{"message":"Hello from client server!"}' http://localhost:3000/send-message) will cause the message to appear in the browser in real-time. For a comprehensive guide on setting up your first application, refer to the Pusher JavaScript Channels getting started guide.

It's important to note that securing real-time applications, especially for features like chat, often involves authentication mechanisms. Pusher provides features for authenticating private and presence channels to control access to sensitive data streams, a concept standardized for web applications by the W3C's WebSocket API specification.

Community libraries

In addition to official SDKs, the Pusher ecosystem includes various community-contributed libraries and integrations. These libraries often extend Pusher's functionality or provide integrations for languages and frameworks not officially supported directly by Pusher, or offer specialized functionalities like UI components built on Pusher. While official SDKs are recommended for core integrations due to direct support, community libraries can be valuable for specific use cases or niche environments.

Examples of community contributions often include:

  • Libraries for less common programming languages.
  • Framework-specific wrappers (e.g., for certain front-end frameworks).
  • Tools for testing or debugging Pusher integrations.
  • Client libraries for embedded systems or IoT devices.

Developers are encouraged to check the respective project repositories for documentation, support, and community activity when considering a community library. The Pusher community page sometimes highlights notable contributions.