Building user-centric applications with Pusher's new users concept

Users-blog.png

A new user-centric model for Pusher Channels. Send realtime server messages to individuals and terminate connections for malicious users.

Introduction

At the core of the Pusher Channels model is a very simple proposition: we help get data to users who need it, fast.

While there are endless Pusher use cases which are modelled on large scale broadcast updates to huge numbers of users (think of dashboard updates, live sports scores or news events on an activity feed) many realtime applications also require the ability to address certain updates to individual users. Only a specified user needs to know where their food delivery is, or who has liked their social media post.

We have found recurring patterns in the applications of developers building with Pusher. Many of these use cases revolve around the user model of an application.

Today we’re releasing the first part of a new model that is more sympathetic to a user-based approach.

Enabling user-specific functionality

If you’re building an application with Pusher today, it’s likely that you have some user-specific functionality built into your app. Whether that’s user access management through functions like authenticated channels, messaging between your server and your user, presence indication or notifications.

You can do this already with Pusher’s pub/sub model of course, usually by creating a channel that only a single user is expected to join. This works well, and has been a popular solution. However, we want to provide more efficient mechanisms for building user-centric applications.

Today we’re releasing the first part of a new model that is more sympathetic to a user-based approach. The model identifies users as a distinct concept in the Pusher system and will help you automate more of your development when it comes to identifying connected users and expanding on the connection-user relationship.

What’s new?

There are 3 main parts to this initial launch:

  • Our client SDKs now provide a mechanism for authenticating a specific user and identifying who is on the end of the connection
  • You can send messages from your server addressed to this user; for example, to tell them the state of an order they are waiting for
  • To demonstrate the value of associating a user to a connection, we are also providing the ability to terminate the connection of a given user. This is a welcome addition in many contexts, especially when responding to malicious users and building apps which benefit from moderation features, such as chat

How can I get started with the new users concept?

To take advantage of our new user functionality you’ll need to:

  • Get the latest version 7.1.0-beta of Pusher-JS.
  • Use the signin() method after instantiating your Pusher instance in your client code to authenticate users.
  • Get the latest version 5.1.0-beta of the server SDK for node.js pusher-http-node.
  • Create a user authentication endpoint at yourserver.com/pusher/user-auth to provide user info for the client who is trying to sign in.
  • Use pusher.user.bind() to bind a callback to receive messages sent to the user.
  • Use sendToUser() method on the server SDK to send messages to a user.
  • User pusher.terminateUserConnections() on the server SDK to terminate all active connections of a user (note that it is up to you to make sure you prevent them from establishing new connections via your authentication endpoint).

What about data protection?

Your application has full control over the user data stored in Pusher User. The user data can be retrieved, updated, or deleted using the Server SDK.

Let us know what you think!

These new mechanisms are currently available as a limited release for pusher-js users. Support for other clients will be coming soon. Keep an eye out for more features which make use of the new concept by following us on Twitter. We plan to incorporate it into a new presence model soon.

Are there any user-oriented features you need for your Pusher apps? Reach out to our team to feedback on the users concept or check out our docs to get started.

Pusher is a hosted API toolkit with everything you need to build dynamic and engaging realtime apps. Sign up to try it out for free today.