mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-27 09:12:41 +01:00
f8431bbfee
Summary: Provide a reasonable JS API for the Aphlict client. Provide an example behavior to invoke it. Test Plan: Ran "aphlict_server.js" with: $ sudo node aphlict_server.js Loaded /aphlict/. Opened console. Got "hello" from the server every second. Got reasonable errors with the server not present ("Security exception", but this is because it can't connect to port 843 to access the policy server). Reviewers: ddfisher, keebuhm, allenjohnashton, btrahan Reviewed By: btrahan CC: aran, epriestley Maniphest Tasks: T944 Differential Revision: https://secure.phabricator.com/D1800
74 lines
1.8 KiB
JavaScript
74 lines
1.8 KiB
JavaScript
/**
|
|
* @provides javelin-aphlict
|
|
* @requires javelin-install
|
|
* javelin-util
|
|
*/
|
|
|
|
/**
|
|
* Simple JS API for the Flash Aphlict client. Example usage:
|
|
*
|
|
* var aphlict = new JX.Aphlict('aphlict_swf', '127.0.0.1', 2600)
|
|
* .setHandler(function(type, message) {
|
|
* JX.log("Got " + type + " event!")
|
|
* })
|
|
* .start();
|
|
*
|
|
* Your handler will receive these events:
|
|
*
|
|
* - `connect` The client initiated a connection to the server.
|
|
* - `connected` The client completed a connection to the server.
|
|
* - `close` The client disconnected from the server.
|
|
* - `error` There was an error.
|
|
* - `receive` Received a message from the server.
|
|
*
|
|
* You do not have to handle any of them in any specific way.
|
|
*/
|
|
JX.install('Aphlict', {
|
|
|
|
construct : function(id, server, port) {
|
|
if (__DEV__) {
|
|
if (JX.Aphlict._instance) {
|
|
JX.$E('Aphlict object is sort of a singleton..!');
|
|
}
|
|
}
|
|
|
|
JX.Aphlict._instance = this;
|
|
|
|
this._server = server;
|
|
this._port = port;
|
|
|
|
// Flash puts its "objects" into global scope in an inconsistent way,
|
|
// because it was written in like 1816 when globals were awesome and IE4
|
|
// didn't support other scopes since global scope is the best anyway.
|
|
var container = document[id] || window[id];
|
|
|
|
this._flashContainer = container;
|
|
},
|
|
|
|
members : {
|
|
_server : null,
|
|
_port : null,
|
|
start : function() {
|
|
this._flashContainer.connect(this._server, this._port);
|
|
}
|
|
},
|
|
|
|
properties : {
|
|
handler : null
|
|
},
|
|
|
|
statics : {
|
|
_instance : null,
|
|
didReceiveEvent : function(type, message) {
|
|
if (!JX.Aphlict._instance) {
|
|
return;
|
|
}
|
|
|
|
var handler = JX.Aphlict._instance.getHandler();
|
|
if (handler) {
|
|
handler(type, message);
|
|
}
|
|
}
|
|
}
|
|
|
|
});
|