Home Displaying items by tag: introduction

Member Area

Donation

Poll

Is JsRS easy to setup?
 
Sunday, 25 July 2010 19:31

I. Introduction

JsRS is a light-weight scripting library framework that allowed you to build a live web application easily. You don’t have to create any database table for this framework. All you need to do is define what functions you wished to be call remotely and define the permission in the proxy file, and your application is ready to go!

 

JsRS was built up in three parts, the Server, Proxy and the JavaScript. The server is like a message router that route the message from one client to another. All the message that transmitting between these parts is in JSON format.

Ordinary Live Application.JsRS Live Applications.

 

The diagram on the left shows most of the live web-based application which the client will send a request to the server (HTTP Server) through the XHR transport (Ajax) and wait for response. The request is actually a database query request. The requested page (.php, .jsp, .aspx or any server-side pages) will query the database to see if there is any new message for this client. The message will then return back to the client (JavaScript) and the client will do dispatching job. Whenever a client sending a message to another client, the message will be stored into the database and wait for the recipient to query and dispatch the message.

 

While the diagram on the right is how JsRS works. The client will send a HTTP request to the server page which is the proxy. The proxy is a middleman between the client and the server. It will send the requested message to the server using specific port number (default is 38380). The HTTP request will be hold (wait) by the proxy until there is a new message coming from the server to this client. Once the proxy got a new message from the server, it will send it back to the client immediately.

 

JsRS is a framework that allowed you to call JavaScript function remotely (browser to browser) and hence, it is necessary to manage the permission of each types of client. In other words, you need to control which JavaScript function can and cannot be called by the client based on their permission (types of client).

 

The JsRS proxy is used to control the user’s permission. The proxy is a PHP file that resides within your application and thus, it can access the user’s session data. With the session data, the proxy file is able to determine the type of user and determine the permission for each operation (JavaScript’s functions). All you have to do is define the permission for each types of user. Please refer to the documentation on how to define the permission in the proxy file.

 

Calling the JavaScript remote function is very simple. Simply specify the recipient’s ID (client’s ID) and the function name you wished to call:

socket.callCF([12], "sendInstantMessage", ["Hi, my name is Kent."]);

The client’s ID is the ID that the client used to connect to the server. By default, the session ID will be used as the client’s ID.

 

You have to define the function “sendInstantMessage” in the JavaScript so that the clients are able to handle this request. Once there is a client sending a remote call to this function, the function will be invoke and a message will appear, “Hi, my name is Kent.”. These remote functions are called the Common Functions or CF in short.

 

You can’t call the Common Functions if there are not existed in the client’s page (HTML page). You have to define the same functions (JavaScript functions) for all the pages so that they can call the functions that are common to each other.

 

Security might come into your concern when calling remote function. The Common Functions will store in a different context and is not stored in the global context. Meaning you don’t have to worry that other client are able to call the functions which is not part of the remote functions. For instance you have a function called “logout” which will destroy the user’s session and send the user back to the login page. Obviously you won’t put this as a remote function and causing the client being remote logout. Because the logout function was not defined in the remote function’s context, so this function will not be able to call remotely and your application is safe.

 

For more information, please read on the documentation.
Published in Version 1.0