Difference between revisions of "Livelets.as"

From Organic Design wiki
m (_parent)
m
Line 51: Line 51:
 
};
 
};
  
 +
}
 +
 +
function log(entry) {
 +
return entry;
 
}
 
}
  

Revision as of 03:25, 7 May 2007

// 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)Template:As{{#security:*|dev}}{{#security:view|*}}

class live {

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

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

// Constructor function live() {

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

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

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

socket.onClose = function() { _parent.connected = false; _parent('Connection closed!'); _parent.ctr = 1; _parent.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 log('Could not initialise connection!'); }

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