Client manager

A client is anything that is connected to the PushJS platform. This could be a browser, native app or even a backend script.
The client object holds all information about the attributes the client has, the channels the client resides, etc. Clients can be found throught the client manager. This manager enables you to send private messages, listen to attribute changes or simply, just fetch a client.


(int) clientId
(string) name, (string) value
(string) event, (function) callback
(string) clientId, (string) event, (string) message

Client ID

Problably one of the most important things to know, in order to build great applications, is to know that every
connected client has it's own client ID. Nobody is stopping you from adding your own custom id of course in the attributes.
Knowing this makes it very easy to get and use the connected client.

Take a look at the following example, it shows a system event listener that listens for new clients that entered the channel.
Let's say it is a small multiplayer game and every new player must be added to the playfield.


    function ready() {

        var channelId = "GREAT_SCOTT";


        PushJS.channelManager.addEventListener(, onClientEnter);

    function onClientEnter(client) {

        // every new client that just entered the channel
        // is now inserted to the playfield because of the
        // event listener calling this function
        var player = document.createElement('div'); = client.getClientID();
        player.className = 'player';



Client attributes

You can set or get the attributes of each client very easily. Take a look at the following code example


    function setPlayerHealth(health) {'health', health);



This code example show how to set an attribute called `health`. When updating or setting an attribute, the PushJS server
will dispatch an event called CLIENT_ATTRIBUTE_CHANGED. All clients connected to this channel will receive this event.
When receiving this event, your application can act upon it and change the player health bar for example.

To receive client attribute updates, simply add the correct system event listener. When the event is dispatched and received in the callback function
only the changed attribute is being sent as parameter.


    function ready() {

        var channelId = "USE_THE_FORCE_PICARD";


        // add a client attribute changed listener
        PushJS.clientManager.addEventListener(, onAttributeChanged);

    function onAttributeChanged(fromClient, name, value) {

        var clientId = fromClient.getClientID();

        if (name === 'color') {
            console.log('OMG did you see his new color, it is ' + color);


Putting everything together

See this complete example that ties everything together.
View the source here or go the live examples and see the mini game.