/usr/share/games/flightgear/Phi/lib/props.js is in flightgear-phi 2016.4.2+dfsg1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | var PropertyChangeListenerObjects = {
_ws : null,
_listeners : {},
};
var PropertyChangeListener = function(callback) {
PropertyChangeListenerObjects._ws = new WebSocket('ws://' + location.host + '/PropertyListener');
PropertyChangeListenerObjects._ws.onopen = callback;
PropertyChangeListenerObjects._ws.onclose = function(ev) {
alert('Lost connection to FlightGear. Please reload this page and/or restart FlightGear.');
PropertyChangeListenerObjects._ws = null;
};
PropertyChangeListenerObjects._ws.onerror = function(ev) {
alert('Error communicating with FlightGear. Please reload this page and/or restart FlightGear.');
PropertyChangeListenerObjects._ws = null;
};
PropertyChangeListenerObjects._ws.onmessage = function(ev) {
try {
var node = JSON.parse(ev.data);
var cb = PropertyChangeListenerObjects._listeners[node.path];
for (var i = 0; i < cb.length; i++) {
var o = cb[i];
o.context ? o.context.call(o.cb(node)) : o.cb(node);
}
} catch (e) {
}
};
};
var NextListenerId = 0;
var SetListener = function(path, callback, context ) {
var o = PropertyChangeListenerObjects._listeners[path];
if (typeof (o) == 'undefined') {
o = new Array();
PropertyChangeListenerObjects._listeners[path] = o;
PropertyChangeListenerObjects._ws.send(JSON.stringify({
command : 'addListener',
node : path
}));
PropertyChangeListenerObjects._ws.send(JSON.stringify({
command : 'get',
node : path
}));
}
o.push({ cb: callback, ctx: context, id: NextListenerId });
return NextListenerId++;
};
var RemoveListener = function(id) {
// send unsubscribe over the socket.
var a = PropertyChangeListenerObjects._listeners;
for( var k in a ) {
var o = a[k];
for( var i = 0; i < o.length; i++ ) {
if( o[i].id == id ) {
//remote element from array
var rest = o.slice(i+1);
o.length = i;
o.push.apply(o,rest);
return;
}
}
if( o.length == 0 ) {
//TODO: send removeListener
}
};
}
|