Difference between revisions of "Livelets.as"
m |
m |
||
| Line 16: | Line 16: | ||
// Constructor | // Constructor | ||
function live() { | function live() { | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
// When connected, send login info | // When connected, send login info | ||
| Line 65: | Line 58: | ||
// Called periodically (per frame) | // Called periodically (per frame) | ||
function reduce() { | function reduce() { | ||
| − | // if (!this.connected && ++this.ctr%250 == 1) this.peerConnect('organicdesign.co.nz',1729); | + | // 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!'); | ||
| + | } | ||
} | } | ||
Revision as of 03:06, 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;
// Entry point static function main(mc) { app = new live(); }
// Constructor function live() {
// 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; _root.onEnterFrame = socket.reduce;
}
// 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!'); } }



