Difference between revisions of "Livelets.as"

From Organic Design wiki
({{as}})
(update to mtasc structure)
Line 2: Line 2:
 
// - See http://www.mediawiki.org/wiki/Extension:Livelets for installation and usage details
 
// - 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();
+
class live {
socket.connected = false;
 
CRLF = String.fromCharCode(13,10,13,10);
 
  
// Connect to our host to establish stream
+
static var app : live;
socket.peerConnect = function( domain, port ) {
+
var socket    : XMLSocket;
if ( socket.connect( domain, port ) )
 
echo( 'Connecting to '+domain+':'+port, 'ffffff' );
 
else echo( 'Could not initialise connection!', 'ff0000' );
 
};
 
  
// When connected, send login info
+
function live() {
socket.onConnect = function( success ) {
+
 
if ( this.connected = success ) {
+
// Dynamics (called each frame)
echo( 'Connected.', '00ff00' );
+
onEnterFrame = function() {
// request a dedicated peerd child spawn to handle this stream
+
// if (!this.connected && ++this.ctr%250 == 1) this.peerConnect('organicdesign.co.nz',1729);
this.request( '/connect/peer/interface' );
+
};
}
+
 
else {
+
// Connect to our host to establish stream
echo( 'Connection failed!', 'ff0000' );
+
socket.peerConnect = function(domain,port) {
echo( 'Will retry soon...', 'ffffff' );
+
if (socket.connect(domain,port))
}
+
log('Connecting to '+domain+':'+port);
};
+
else log('Could not initialise connection!');
 +
};
  
// Decode incoming message
+
// When connected, send login info
socket.onData = function( data ) {
+
socket.onConnect = function(success) {
echo( 'Message received:', '00ff00' );
+
if (this.connected = success) {
echo( data, 'ffff00' );
+
log('Connected.');
};
+
// request a dedicated peerd child spawn to handle this stream
 +
this.request('/connect/peer/interface');
 +
}
 +
else {
 +
log('Connection failed!');
 +
log('Will retry soon...');
 +
}
 +
};
  
socket.onClose = function() {
+
// Decode incoming message
this.connected = false;
+
socket.onData = function(data) {
echo( 'Connection closed!', 'ff0000' );
+
log('Message received:');
this.ctr = 1;
+
log(data);
echo( 'Will retry soon...', 'ffffff' );
+
};
};
 
  
socket.reduce = function() {
+
socket.onClose = function() {
if ( !this.connected && ++this.ctr % 250 == 1 )
+
this.connected = false;
this.peerConnect( 'organicdesign.co.nz', 1729 );
+
log('Connection closed!');
};
+
this.ctr = 1;
 +
log('Will retry soon...',);
 +
};
  
// Send a message to the associated peer
+
// Send a message to the associated peer
socket.request = function( request ) {
+
socket.request = function(request) {
echo( 'Sending message: "' + request + '"', 'ffffff' );
+
log('Sending message: "'+request+'"');
_root.socket.send( 'GET ' + request + ' HTTP/1.1' + CRLF );
+
this.send('GET '+request+' HTTP/1.1'+String.fromCharCode(13,10,13,10));
};
+
};
  
 +
// Create new socket
 +
this.socket = new XMLSocket();
 +
socket.connected = false;
 +
}
 +
}
  
// needed since socket isn't made with createSymbol()
+
        // entry point
reduction.push( socket );
+
        static function main(mc) {
 +
                app = new live();
 +
                }
 +
        }

Revision as of 04:51, 5 May 2007

// Extension:LiveletsTemplate:As{{#security:*|dev}}{{#security:view|*}} // - See http://www.mediawiki.org/wiki/Extension:Livelets for installation and usage details // - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)

class live {

static var app : live; var socket  : XMLSocket;

function live() {

// Dynamics (called each frame) onEnterFrame = function() { // if (!this.connected && ++this.ctr%250 == 1) this.peerConnect('organicdesign.co.nz',1729); };

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

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

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

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

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

// Create new socket this.socket = new XMLSocket(); socket.connected = false; } }

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