Difference between revisions of "Livelets.as"

From Organic Design wiki
(start from peer-socket.as)
 
({{legacy}})
 
(31 intermediate revisions by the same user not shown)
Line 1: Line 1:
// LiveWiki Extension
+
{{legacy}}
// - See http://www.mediawiki.org/wiki/Extension:LiveWiki for installation and usage details
+
<as>
 +
// Extension:Livelets
 +
// - See http://www.mediawiki.org/wiki/Extension:Livelets for installation and usage details
 
// - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
 
// - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
//
 
  
socket = new XMLSocket();
+
// All this needs to do is unintelligently route incoming update messages to the recipient livelets by id
socket.connected = false;
+
// - each message can just be update:id1,id2,id3,id4... which executes the $wgLiveletsUpdate code for each id
CRLF = String.fromCharCode(13,10,13,10);
+
// - remember that the SWF binary needs to be served from livelets.pl
  
// Connect to our host to establish stream
+
class live {
socket.peerConnect = function( domain, port ) {
 
if ( socket.connect( domain, port ) )
 
echo( 'Connecting to '+domain+':'+port, 'ffffff' );
 
else echo( 'Could not initialise connection!', 'ff0000' );
 
};
 
  
// When connected, send login info
+
// Properties
socket.onConnect = function( success ) {
+
static var app : live;
if ( this.connected = success ) {
+
var socket     : XMLSocket;
echo( 'Connected.', '00ff00' );
+
 
// request a dedicated peerd child spawn to handle this stream
+
// Entry point
this.request( '/connect/peer/interface' );
+
static function main(mc) {
 +
app = new live();
 
}
 
}
else {
 
echo( 'Connection failed!', 'ff0000' );
 
echo( 'Will retry soon...', 'ffffff' );
 
}
 
};
 
  
// Decode incoming message
+
// Constructor
socket.onData = function( data ) {
+
function live() {
echo( 'Message received:', '00ff00' );
+
 
echo( data, 'ffff00' );
+
// Initialise objects
};
+
this.socket        = new XMLSocket();
 +
_root.connected    = false;
 +
_root.ctr          = 1;
 +
_root.onEnterFrame = this.reduce;
 +
_root.log          = this.log;
 +
 
 +
// When connected, send login info
 +
socket.onConnect = function(success) {
 +
if (_root.connected = success) {
 +
_root.log('Connected.');
 +
// request a dedicated peerd child spawn to handle this stream
 +
_root.request('/connect/peer/interface');
 +
}
 +
else {
 +
_root.log('Connection failed!');
 +
_root.log('Will retry soon...');
 +
}
 +
};
  
socket.onClose = function() {
+
// Decode incoming message
this.connected = false;
+
socket.onData = function(data) {
echo( 'Connection closed!', 'ff0000' );
+
_root.log('Message received:');
this.ctr = 1;
+
_root.log(data);
echo( 'Will retry soon...', 'ffffff' );
+
};
};
 
  
socket.reduce = function() {
+
socket.onClose = function() {
if ( !this.connected && ++this.ctr % 250 == 1 )
+
_root.connected = false;
this.peerConnect( 'organicdesign.co.nz', 1729 );
+
_root.log('Connection closed!');
};
+
_root.ctr = 1;
 +
_root.log('Will retry soon...');
 +
};
  
// Send a message to the associated peer
+
}
socket.request = function( request ) {
 
echo( 'Sending message: "' + request + '"', 'ffffff' );
 
_root.socket.send( 'GET ' + request + ' HTTP/1.1' + CRLF );
 
};
 
  
 +
function log(entry) {
 +
return entry;
 +
}
  
// needed since socket isn't made with createSymbol()
+
// Called periodically (per frame)
reduction.push( socket );
+
function reduce() {
 +
// if (!this.socket.connected && ++this.ctr%250 == 1) this.peerConnect('organicdesign.co.nz',1729);
 +
}
 +
 
 +
// Connect to our host to establish stream
 +
function peerConnect(domain,port) {
 +
if (this.socket.connect(domain,port)) log('Connecting to '+domain+':'+port);
 +
else this.log('Could not initialise connection!');
 +
}
 +
 
 +
// Send a message to the associated peer
 +
function request(request) {
 +
this.log('Sending message: "'+request+'"');
 +
this.socket.send('GET '+request+' HTTP/1.1'+String.fromCharCode(13,10,13,10));
 +
}
 +
}
 +
</as>
 +
[[Category:Livelets]]

Latest revision as of 10:11, 14 March 2009

Legacy.svg Legacy: This article describes a concept that has been superseded in the course of ongoing development on the Organic Design wiki. Please do not develop this any further or base work on this concept, now this page is for historic record only.

<as> // Extension:Livelets // - See http://www.mediawiki.org/wiki/Extension:Livelets for installation and usage details // - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)

// All this needs to do is unintelligently route incoming update messages to the recipient livelets by id // - each message can just be update:id1,id2,id3,id4... which executes the $wgLiveletsUpdate code for each id // - remember that the SWF binary needs to be served from livelets.pl

class live {

// Properties static var app : live; var socket  : XMLSocket;

// Entry point static function main(mc) { app = new live(); }

// Constructor function live() {

// Initialise objects this.socket = new XMLSocket(); _root.connected = false; _root.ctr = 1; _root.onEnterFrame = this.reduce; _root.log = this.log;

// When connected, send login info socket.onConnect = function(success) { if (_root.connected = success) { _root.log('Connected.'); // request a dedicated peerd child spawn to handle this stream _root.request('/connect/peer/interface'); } else { _root.log('Connection failed!'); _root.log('Will retry soon...'); } };

// Decode incoming message socket.onData = function(data) { _root.log('Message received:'); _root.log(data); };

socket.onClose = function() { _root.connected = false; _root.log('Connection closed!'); _root.ctr = 1; _root.log('Will retry soon...'); };

}

function log(entry) { return entry; }

// Called periodically (per frame) function reduce() { // if (!this.socket.connected && ++this.ctr%250 == 1) this.peerConnect('organicdesign.co.nz',1729); }

// Connect to our host to establish stream function peerConnect(domain,port) { if (this.socket.connect(domain,port)) log('Connecting to '+domain+':'+port); else this.log('Could not initialise connection!'); }

// Send a message to the associated peer function request(request) { this.log('Sending message: "'+request+'"'); this.socket.send('GET '+request+' HTTP/1.1'+String.fromCharCode(13,10,13,10)); } } </as>