Difference between revisions of "Livelets.as"
({{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) | ||
| − | |||
| − | + | 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. | + | 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...'); | ||
| + | } | ||
| + | }; | ||
| − | socket. | + | // Decode incoming message |
| − | + | socket.onData = function(data) { | |
| − | + | log('Message received:'); | |
| − | + | log(data); | |
| − | + | }; | |
| − | |||
| − | socket. | + | socket.onClose = function() { |
| − | + | this.connected = false; | |
| − | + | 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) { |
| − | + | 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(); | ||
| + | } | ||
| + | } | ||
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();
}
}



