Realtime

Socketize can make your app realtime in no-time. You don't have to know anything about sockets, neither you've to run a server. We do these things for you.

With simple publish-subscribe (PubSub) mechanism, it's a breeze to use realtime technology in your app. Using Socketize.js you just subscribe for an event then you can publish data to the event using Socketize.js or REST API, all subscribers will receive this data in realtime.

Subscribe to a Channel

You can subscribe to channel. A channel is simply an event name you specify. For example, new_notification.

socketize.subscribe('new_notification', function(dataReceived) {
    // This will be fired when anything is published to a_channel
    alert(dataReceived);
});

Publish to a Channel

Now send something to all the subscribers. You can send string, array or object.

Using Socketize.js

socketize.publish('new_notification', 'Hi, channel subscriber.');

Using REST API

You can send message from your backend to your frontend clients using the REST API

curl "https://socketize.com/api/publish?channel=new_notification&value=Hi from API" -X GET -u public_key:private_key -H "Accept: application/vnd.socketize.v1+json"

Subscribe To a Key

Socketize database values are always associated with a key. You can simply subscribe to this key and you will be notified when the value changes, in realtime.

socketize.subscribeToKey('active_task', function(valueReceived) {
    // This will be fired when active_task is updated
    alert(valueReceived);
});


socketize.subscribeToKey('public/messages', function(valueReceived) {
    // This will be fired when public/messages is updated
    alert(valueReceived);
});

By default when a value is updated from a client and this client is also subscribed to the same key, then Socketize will ignore this(originating) client from receiving the value to prevent duplicate actions. To change this behavior pass this as the 3rd parameter of the subscribeToKey function: {ignore_me: false}