Livelets

From Organic Design wiki
Revision as of 09:23, 30 March 2007 by Sven (talk | contribs) (typos)


The idea of this extension is to allow live articles to be transcluded which update automatically on change in a non-polling, fully event-driven way. It will use the parser-functions syntax to make it very similar in usage to normal templates.

It's being partially paid for by client needs, but will of course be free and LGPL - I say partially paid for because it's being done in a far more powerful and generic way than the client requires - in fact they don't even need the live aspect, it's only the division of the page into separate requests to make local caching more efficient that they really need!

But since we already have all the code written to handle sockets between PERL and SWF, which won't ever be used for anything now since our peer interface is now in C and SDL, it seemed like a good opportunity to get it working in the field.

LiveTemplates.php

  • Ensure the PERL socket server is running
  • Add the parser function and internal hook
  • Add the "live" action
  • Add the AfterSaveComplete hook
  • Insert the SWF into the page somewhere invisible but active
  • Add the JS headscripts

Parser Function

Converts the syntax to tag-hook along with the parameters

Internal Tag Hook

There's no HTML content because the parser-function doesn't actually do any transclusion, the information that arrives here is the article name and parameters. This hook returns the JavaScript container which makes a separate request for the content when it runs in the browser. The request uses the live action and passes the parameters used in the original parser-function transclude statement.

Live Action

This does the actual Generating of the HTML for a live container. It would probably change the content AfterDatabaseFetch to a normal transclude with the parameters. It must also ensure that none of the HTML head, scripts, body or any skin components are sent, only the HTML of the rendered template itself.

AfterSaveComplete Hook

For now all clients with live templates could be notified on any article change. later we may want to maintain a tree of articles and their current subscribers (which must include articles changing inside transclusion structures of live templates).

JavaScript Functions

The JS can send HTTP requests itself with the XMLHTTPRequest object, but must rely on the SWF to call some kind of onData event handler function.

SWF Movie

Even the SWF XMLSocket is crippled in three main ways:

  • It can only recieve incoming data from servers in the same domain the SWF was served from
  • It can only use port number >1023
  • Most importantly - it is not a true listener, it can only listen on streams it has already established with the server. A server cannot spontaneously request a new connection from the SWF socket.

This third item is very important, because it means that a permenantly running server must be present, so we may need to include a simple server daemon using the code from server.pl, unless PHP can somehow be used to do it....?

PERL Server

Although PHP has socket capability it seems that many users would not have the functionality easily available as it often requires PHP to be recompiled with the --enable-sockets switch. Also, the PHP server script would need to be set up to run as a daemon, and many PHP installs do not support command-line PHP by default. So it seems to me that a PERL server would be simplest to implement, especially since we already have working socket code in PERL, it's available by default on virtually all Linux's, and is easy to install on Win32 as well.

Rather than installing the daemon into init.d or as a service, the PHP script could check whether an instance is running and execute it if not so that the installation would then be no different than for most extensions, of putting the files into the extensions directory and ensuring they have the right permissions.

Examples & Usage Ideas

  • Forms: Allowing forms to be submitted which can be posted to the server without reloading the page. Any items which may change are made into live templates.
  • Caching: Normal templates which are used across many articles like those which include category links would be far more efficient when wrapped inside a live template.
  • Collaboration: The edit form could be modified to post the form without reloading the page, and to have a live preview of the content which would make article editing much more chat-like.
  • Channels: having live content opens up the whole channel aspect...