
I recently announced Realplexor -
habrahabr.ru/blogs/hi/79189 - a single-threaded event-oriented Comet server written in Perl and having a ready-made API for JavaScript and PHP. With it, you can create sites where users interact with each other in
real time , without reloading the page and without a significant expenditure of traffic.
Today I want to introduce and, as usual, a bit of “digging around in the engine” of the first version of the product
Live broadcast , running on the RuTvit platform using Realplexor. This is a widget that a webmaster can install on your website in 1 minute in order to arrange microblogging communication with the audience in real time.
With the help of "Live" the audience of the site communicates with each other in real time - "right now", being in a separate "chat room", tied to your site. The widget can be used for “direct dialogue” with many users at once: for example, to receive bugs or feature requests. If the user with whom you spoke is still on the site, you will see his presence: there will be a green circle near his name.
')
To start the communication, the site visitor does not need to go through the registration procedure. Authorization is done by OpenID. Those. it is enough for him to have an account on Yandex, Google, LiveJournal, etc., to start writing messages; not even an e-mail is required.
To insert a widget on the site, simply download a piece of HTML code from the page
rutvit.ru/tools/widgets/chat - by the way, customization of colors and even all CSS is possible there, and paste it on any (or even all) pages of your site:
<iframe src="http://rutvit.ru/tools/widgets/chat/embed?tag=&q=" width="280" height="400" style="border:1px solid #cccccc;overflow:hidden" frameborder="0"></iframe>
How is it arranged inside?
Technically, the widget is a kind of JavaScript application that is loaded into the IFRAME tag. It is safe: because the content of the IFRAME is on a different domain, your website cookies and the DOM tree of the page are not accessible to it.
A special JavaScript code organizes a permanent (long-polling) connection with the whole “battery” of Realplexor servers and uses the Realplexor JavaScript API. Unlike the usual “polling”, in which the script has to re-request data from the server every few seconds, the “long-polling” implemented in Realplexor works much more optimally. It creates an XMLHttpRequest object that loads a special URL on the Realplexor server. At the same time, the server “hangs” and returns nothing to the client until a new message arrives in the chat (the connection can “hang” for at least an hour, which is why the technology is called “long polling”). As soon as the message appears, Realplexor sends it to all connected clients and closes the connection; the client creates a new XMLHttpRequest object and connects to the server again. Also, the client reconnects to the server in case of an unexpected disconnection.
Realplexor supports centralized start / restart / shutdown of its daemon as a whole “battery” of processes, each of which is serviced by an independent set of users. This allows for optimal utilization of CPU resources, compensating for the fundamental single-threading of the event model. In the case of the Live broadcast widget, site owners are evenly distributed across servers; thus, power can be increased by installing additional machines. However, even one machine is sufficient in many cases: for example, having an 8-core processor, you can run a Realplexor battery from 8 processes and get an 8-fold increase in performance.
OpenID authorization occurs inside the iframe; thus, having logged in once on any site with the established “Live broadcast” (or just being logged in to RuTvit), you will be logged in to all other widgets on other sites.
Technically, all messages written by users in the widget are stored in RouTwith with the tag #WashSite (you can change this tag during installation). Thus, the widget displays nothing more than tweets from the VashSayt channel; Widget is an interface for working with a microblogging service through the prism of your site.
Instead of conclusion
We have a lot of ideas for the development of the widget. However, I will be happy to receive feedback and new ideas that will make the “Live broadcast” better. In particular, the opinion of webmasters is interesting: what would you like to have in such a widget, so that it becomes a useful tool for you?
It would be fair to give references to similar (to varying degrees) products: 1 2 3 4 5 . The key difference of “Live” from the analogues is that it is built on the basis of the microblogging system, and does not exist by itself “in a vacuum”.