Difference between revisions of "Livelets.as"
m |
({{legacy}}) |
||
| (7 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
| + | {{legacy}} | ||
| + | <as> | ||
// Extension:Livelets | // Extension:Livelets | ||
// - 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) |
| + | |||
| + | // 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 { | class live { | ||
| Line 8: | Line 14: | ||
static var app : live; | static var app : live; | ||
var socket : XMLSocket; | var socket : XMLSocket; | ||
| − | |||
| − | |||
// Entry point | // Entry point | ||
| Line 21: | Line 25: | ||
// Initialise objects | // Initialise objects | ||
this.socket = new XMLSocket(); | this.socket = new XMLSocket(); | ||
| − | + | _root.connected = false; | |
| − | + | _root.ctr = 1; | |
_root.onEnterFrame = this.reduce; | _root.onEnterFrame = this.reduce; | ||
| + | _root.log = this.log; | ||
// When connected, send login info | // When connected, send login info | ||
socket.onConnect = function(success) { | socket.onConnect = function(success) { | ||
| − | if ( | + | if (_root.connected = success) { |
| − | + | _root.log('Connected.'); | |
// request a dedicated peerd child spawn to handle this stream | // request a dedicated peerd child spawn to handle this stream | ||
| − | + | _root.request('/connect/peer/interface'); | |
} | } | ||
else { | else { | ||
| − | + | _root.log('Connection failed!'); | |
| − | + | _root.log('Will retry soon...'); | |
} | } | ||
}; | }; | ||
| Line 40: | Line 45: | ||
// Decode incoming message | // Decode incoming message | ||
socket.onData = function(data) { | socket.onData = function(data) { | ||
| − | + | _root.log('Message received:'); | |
| − | + | _root.log(data); | |
}; | }; | ||
socket.onClose = function() { | socket.onClose = function() { | ||
| − | + | _root.connected = false; | |
| − | + | _root.log('Connection closed!'); | |
| − | + | _root.ctr = 1; | |
| − | + | _root.log('Will retry soon...'); | |
}; | }; | ||
| Line 74: | Line 79: | ||
} | } | ||
} | } | ||
| + | </as> | ||
| + | [[Category:Livelets]] | ||
Latest revision as of 10:11, 14 March 2009
<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>



