Real-time Framework

Real-time’s Framework is a blindingly fast bi-directional persistently connected messaging system. It’s a unique means for a company to conduct a live online relationship with clients.

This has the massive advantage of allowing interaction to happen live in real-time, without delays or page refreshes, to create a durable and bidirectional relationship with each online user.

It works with two main components:

Enabling the live web is ORTC (Open Real-time Connectivity): A secure, fast and highly scalable cloud-hosted real-time many-to-many messaging system for web and mobile apps.


Here we can use ORTC client instead of xRTML code snippet provided by realtime.co for real-timeconnections.

The language of the Live Web s xRTML (Extensible Realtime Multiplatform Language): A set of api tools to build realtime web and mobile apps with an easy to use API based on a JavaScript library.
  

Steps:
Include this js plugin http://dfdbz2tdq3k01.cloudfront.net/js/2.1.0/ortc.js

For Sending Messages to Realtime:

window.onload = function () {

   loadOrtcFactory(IbtRealTimeSJType, function (factory, error) {

       if (error != null) {

           alert(“Factory error: ” + error.message);

       } else {

           if (factory != null) {

               // Create ORTC client

               var ortcClient = factory.createClient();

               // Set ORTC client properties

               ortcClient.setId(‘clientId’);

               ortcClient.setConnectionMetadata(‘clientConnMeta’);

               ortcClient.setClusterUrl(‘http://ortc-developers.realtime.co/server/2.1/‘);

               ortcClient.onConnected = function (ortc) {

                    // Connected           
// First Channel

                   ortcClient.subscribe(‘channel1’, true, function (ortc, channel, message) {

                        console.log(message)

                       ortcClient.unsubscribe(channel);

                   });

// Second Channel

                   ortcClient.subscribe(‘channel2’, true, function (ortc, channel, message) {

                        console.log(message)

                       ortcClient.unsubscribe(channel);

                   });

               };

               ortcClient.onDisconnected = function (ortc) {

                    // Disconnected

               };  
//Send your messages here

               ortcClient.onSubscribed = function (ortc, channel) {

                   // Subscribed to the channel ‘channel’);

                   ortcClient.send(channel, ‘Message to the channel’);

               };

               ortcClient.onUnsubscribed = function (ortc, channel) {

                   // Unsubscribed from the channel ‘channel’);

                   ortcClient.disconnect();

               };

                ortcClient.onException = function (ortc, exception) {

                    // Exception occurred: ‘exception’

               };

                ortcClient.onReconnecting = function (ortc) {

                    // Trying to reconnect

               };

                ortcClient.onReconnected = function (ortc) {

                    // Reconnected

               };

                           ortcClient.connect(‘myApplicationKey’, ‘myAuthenticationToken’);

            }

        }

    });

};

For Receiving Messages from Realtime to App Frontend:
//Here remove ortcClient.onSubscribed function

window.onload = function () {

   loadOrtcFactory(IbtRealTimeSJType, function (factory, error) {

       if (error != null) {

           alert(“Factory error: ” + error.message);

       } else {

           if (factory != null) {

               // Create ORTC client

               var ortcClient = factory.createClient();

               // Set ORTC client properties

               ortcClient.setId(‘clientId’);

               ortcClient.setConnectionMetadata(‘clientConnMeta’);

               ortcClient.setClusterUrl(‘http://ortc-developers.realtime.co/server/2.1/‘);

               ortcClient.onConnected = function (ortc) {

                    // Connected                   
// First Channel

                   ortcClient.subscribe(‘channel1’, true, function (ortc, channel, message) {

                        console.log(message)

                       ortcClient.unsubscribe(channel);

                   });

// Second Channel

                   ortcClient.subscribe(‘channel2’, true, function (ortc, channel, message) {

                        console.log(message)

                       ortcClient.unsubscribe(channel);

                   });

               };

               ortcClient.onDisconnected = function (ortc) {

                    // Disconnected

               }

               ortcClient.onUnsubscribed = function (ortc, channel) {

                   // Unsubscribed from the channel ‘channel’);

                    

                   ortcClient.disconnect();

               };

                ortcClient.onException = function (ortc, exception) {

                    // Exception occurred: ‘exception’

               };

                ortcClient.onReconnecting = function (ortc) {

                    // Trying to reconnect

               };

                ortcClient.onReconnected = function (ortc) {

                    // Reconnected

               };

                ortcClient.connect(‘myApplicationKey’, ‘myAuthenticationToken’);

            }

        }

    });

};

Conclusive Note:

The Real-time framework is henceforth an emerging and fast growing messaging system which helps the business to serve their clients at a very speedy rate and hence also avoid the time gap of providing the services.

This also gives a competitive advantage to the business, as it is the system, that is suitable for today’s recurrently growing world of business.

Read More : 

An Introduction to Rails API
Set up Rails environment
Image Manipulation
How to install Ruby on rails

Get in touch with us.

Lubaib C J

Senior Ruby on Rails Developer

Leave a Comment

Your email address will not be published. Required fields are marked *