1. Martin Thorsen Ranang
  2. orbited

Commits

desmaj  committed 9dd54c9

moved the local jsio around and made a couple of fixes (proper import syntax for 'Class' and changed getLogger to get in mspp

  • Participants
  • Parent commits 59a7b7b
  • Branches 0.8

Comments (0)

Files changed (87)

File daemon/orbited/chat/index.html

View file
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
   <title>Orbited In-browser IRC</title>
   <link rel="stylesheet" href="chat.css" />
-  <script src="../static/jsio/jsio.js"></script>
-  <script src="../static/Orbited.js"></script>
+  <script src="/static/Orbited.js"></script>
   <script>
     TCPSocket = Orbited.TCPSocket;
 //    socket.settings.hostname = 'test.live.nowsayso.com';

File daemon/orbited/js_src/Orbited.js

View file
-jsio('import Class');
-jsio('import jsio.logging');
+jsio('from base import Class');
+jsio('import logging');
 jsio('from net.protocols.mspp import MSPPStream, MSPPProtocol');
 
-exports.logging = jsio.logging;
+exports.logging = logging;
 
 // autodetect host + port!!!
 exports.settings = { 'host': 'localhost', 'port': 8000, 'path': '/csp'};

File daemon/orbited/js_src/compile.sh

View file
 #!/bin/bash
-DEFAULT_JSIO_PATH=./jsio
-jsio_compile orbited.pkg -j ${JSIO_PATH:-$DEFAULT_JSIO_PATH} -o ../static/Orbited.js
+DEFAULT_JSIO_PATH=../jsio
+jsio_compile orbited.pkg -j ${JSIO_PATH:-$DEFAULT_JSIO_PATH} -o ../static/Orbited.js $@

File daemon/orbited/js_src/jsio/base.js

-exports.log = jsio.__env.log;
-exports.GLOBAL = jsio.__env.global;
-
-exports.bind = function(context, method /*, VARGS*/) {
-	if(arguments.length > 2) {
-		var args = Array.prototype.slice.call(arguments, 2);
-		return typeof method == 'string'
-			? function() {
-				if (context[method]) {
-					return context[method].apply(context, args.concat(Array.prototype.slice.call(arguments, 0)));
-				} else {
-					throw logger.error('No method:', method, 'for context', context);
-				}
-			}
-			: function() { return method.apply(context, args.concat(Array.prototype.slice.call(arguments, 0))); }
-	} else {
-		return typeof method == 'string'
-			? function() {
-				if (context[method]) {
-					return context[method].apply(context, arguments);
-				} else {
-					throw logger.error('No method:', method, 'for context', context);
-				}
-			}
-			: function() { return method.apply(context, arguments); }
-	}
-}
-
-exports.Class = function(parent, proto) {
-	if(!parent) { throw new Error('parent or prototype not provided'); }
-	if(!proto) { proto = parent; parent = null; }
-	else if(parent instanceof Array) { // multiple inheritance, use at your own risk =)
-		proto.prototype = {};
-		for(var i = 0, p; p = parent[i]; ++i) {
-			for(var item in p.prototype) {
-				if(!(item in proto.prototype)) {
-					proto.prototype[item] = p.prototype[item];
-				}
-			}
-		}
-		parent = parent[0]; 
-	} else {
-		proto.prototype = parent.prototype;
-	}
-
-	var cls = function() { if(this.init) { return this.init.apply(this, arguments); }}
-	cls.prototype = new proto(parent ? function(context, method, args) {
-		var args = args || [];
-		var target = proto;
-		while(target = target.prototype) {
-			if(target[method]) {
-				return target[method].apply(context, args);
-			}
-		}
-		throw new Error('method ' + method + ' does not exist');
-	} : null);
-	cls.prototype.constructor = cls;
-	return cls;
-}
-
-exports.$setTimeout = function(f, t/*, VARGS */) {
-	var args = Array.prototype.slice.call(arguments, 2);
-	return setTimeout(function() {
-		try {
-			f.apply(this, args);
-		} catch(e) {
-			// log?
-		}
-	}, t)
-}
-
-exports.$setInterval = function(f, t/*, VARGS */) {
-	var args = Array.prototype.slice.call(arguments, 2);
-	return setInterval(function() {
-		try {
-			f.apply(this, args);
-		} catch(e) {
-			// log?
-		}
-	}, t)
-}
-
-// node doesn't let you call clearTimeout(null)
-exports.$clearTimeout = function (timer) { return timer ? clearTimeout(timer) : null; };
-exports.$clearInterval = function (timer) { return timer ? clearInterval(timer) : null; };
-
-// keep logging local variables out of other closures in this file!
-exports.logging = (function() {
-	
-	// logging namespace, this is what is exported
-	var logging = {
-			DEBUG: 1,
-			LOG: 2,
-			INFO: 3,
-			WARN: 4,
-			ERROR: 5
-		},
-		loggers = {}, // effectively globals - all loggers and a global production state
-		production = false;
-
-	logging.setProduction = function(prod) { production = !!prod; }
-	logging.get = function(name) {
-		return loggers.hasOwnProperty(name) ? loggers[name]
-			: (loggers[name] = new Logger(name));
-	}
-	logging.set = function(name, _logger) {
-		loggers[name] = _logger;
-	}
-	
-	logging.getAll = function() { return loggers; }
-
-	logging.__create = function(pkg, ctx) { ctx.logger = logging.get(pkg); }
-	
-	var Logger = exports.Class(function() {
-		this.init = function(name, level) {
-			this._name = name;
-			this._level = level || logging.LOG;
-			this._listener = exports.log;
-		}
-		
-		this.setLevel = function(level) { this._level = level; }
-	
-		var SLICE = Array.prototype.slice;
-		
-		function makeLogFunction(level, type) {
-			return function() {
-				if (!production && level >= this._level) {
-					return this._listener.apply(this._listener, [type, this._name].concat(SLICE.call(arguments)));
-				}
-				return arguments[0];
-			}
-		}
-	
-		this.setListener = function(listener) { log = listener; }
-		this.debug = makeLogFunction(logging.DEBUG, "DEBUG");
-		this.log = makeLogFunction(logging.LOG, "LOG");
-		this.info = makeLogFunction(logging.INFO, "INFO");
-		this.warn = makeLogFunction(logging.WARN, "WARN");
-		this.error = makeLogFunction(logging.ERROR, "ERROR");
-	});
-
-	return logging;
-})();
-
-var logger = exports.logging.get('jsiocore');

File daemon/orbited/js_src/jsio/index.js

-// This is strictly for nodejs, not browsers.
-require('./jsio');
-

File daemon/orbited/js_src/jsio/jsio.js

-// jsio/browser.js
-
-;(function() {
-	var ENV, sourceCache = {
-		// Insert pre-loaded modules here...
-		
-	};
-	
-	function bind(context, method/*, args... */) {
-		var args = Array.prototype.slice.call(arguments, 2);
-		return function(){
-			method = (typeof method == 'string' ? context[method] : method);
-			return method.apply(context, args.concat(Array.prototype.slice.call(arguments, 0)));
-		}
-	}
-	
-	jsio = bind(this, importer, null, '');
-	jsio.__filename = 'jsio.js';
-	jsio.modules = [];
-	jsio.setCachedSrc = function(pkg, filePath, src) {
-		sourceCache[pkg] = { filePath: filePath, src: src };
-	}
-	jsio.getCachedSrc = function(pkg) { return sourceCache[pkg]; }
-	jsio.path = {};
-	jsio.setPath = function(path) { jsio.path.__default__ = typeof path == 'string' ? [path] : path; }
-	jsio.setEnv = function(env) {
-		if(ENV && (env == ENV || env == ENV.name)) { return; }
-		
-		if(typeof env == 'string') {
-			switch(env) {
-				case 'node':
-					ENV = new ENV_node();
-					break;
-				case 'browser':
-				default:
-					ENV = new ENV_browser();
-					break;
-			}
-			ENV.name = env;
-		} else {
-			ENV = env;
-		}
-		
-		jsio.__env = ENV;
-		jsio.__dir = ENV.getCwd();
-		if(!jsio.path.__default__) { jsio.setPath(ENV.getPath()); }
-	}
-	
-	if (typeof process !== 'undefined' && process.version) {
-		jsio.setEnv('node');
-	} else if (typeof XMLHttpRequest != 'undefined' || typeof ActiveXObject != 'undefined') {
-		jsio.setEnv('browser');
-	}
-	
-	// DONE
-	
-	/*
-	function ENV_abstract() {
-		this.global = null;
-		this.getCwd = function() {};
-		this.getPath = function() {};
-		this.eval = function(code, path) {};
-		this.findModule = function(pathString) {};
-		this.log = function(args...) {};
-	}
-	*/
-	
-	function ENV_node() {
-		var fs = require('fs'),
-			sys = require('sys');
-		
-		this.global = GLOBAL;
-		this.getCwd = process.cwd;
-		this.log = function() {
-			var msg;
-			try {
-				sys.error(msg = Array.prototype.map.call(arguments, function(a) {
-					if ((a instanceof Error) && a.message) {
-						return 'Error:' + a.message + '\nStack:' + a.stack + '\nArguments:' + a.arguments;
-					}
-					return typeof a == 'string' ? a : JSON.stringify(a);
-				}).join(' '));
-			} catch(e) {
-				sys.error(msg = Array.prototype.join.call(arguments, ' ') + '\n');
-			}
-			return msg;
-		}
-		
-		this.getPath = function() {
-			var segments = __filename.split('/');
-			segments.pop();
-			return segments.join('/') || '.';
-		}
-		this.eval = process.compile;
-		this.findModule = function(possibilities) {
-			for (var i = 0, possible; possible = possibilities[i]; ++i) {
-				try {
-					possible.src = fs.readFileSync(possible.filePath);
-					return possible;
-				} catch(e) {
-				}
-			}
-			return false;
-		}
-
-		this.require = require;
-		this.include = include;
-	}
-	
-	function ENV_browser() {
-		var XHR = window.XMLHttpRequest || function() { return new ActiveXObject("Msxml2.XMLHTTP"); },
-			SLICE = Array.prototype.slice,
-			cwd = null,
-			path = null;
-		
-		this.global = window;
-		this.global.jsio = jsio;
-		
-		this.log = function() {
-			var args = SLICE.call(arguments, 0);
-			if (typeof console != 'undefined' && console.log) {
-				if (console.log.apply) {
-					console.log.apply(console, arguments);
-				} else { // IE doesn't support log.apply, and the argument cannot be arguments - it must be an array
-					console.log(args);
-				}
-			}
-			return args.join(' ');
-		}
-		
-		this.getCwd = function() {
-			if(!cwd) {
-				var location = window.location.toString().split('#')[0];
-				cwd = location.substring(0, location.lastIndexOf('/') + 1);
-			}
-			return cwd;
-		}
-		
-		this.getPath = function() {
-			if(!path) {
-				try {
-					var filename = new RegExp('(.*?)' + jsio.__filename + '(\\?.*)?$'),
-						scripts = document.getElementsByTagName('script');
-					
-					for (var i = 0, script; script = scripts[i]; ++i) {
-						var result = script.src.match(filename);
-						if (result) {
-							path = result[1];
-							if (/^[A-Za-z]*:\/\//.test(path)) { path = makeRelativePath(path, this.getCwd()); }
-							break;
-						}
-					}
-				} catch(e) {}
-				
-				if(!path) { path = '.'; }
-			}
-			return path;
-		}
-
-		// IE6 won't return an anonymous function from eval, so use the function constructor instead
-		var rawEval = typeof eval('(function(){})') == 'undefined'
-			? function(src, path) { return (new Function('return ' + src))(); }
-			: function(src, path) { var src = src + '\n//@ sourceURL=' + path; return window.eval(src); }
-
-		// provide an eval with reasonable debugging
-		this.eval = function(code, path) {
-			try { return rawEval(code, path); } catch(e) {
-				if(e instanceof SyntaxError) {
-					e.message = "a syntax error is preventing execution of " + path;
-					e.type = "syntax_error";
-					try {
-						var cb = function() {
-							var el = document.createElement('iframe');
-							el.style.cssText = "position:absolute;top:-999px;left:-999px;width:1px;height:1px;visibility:hidden";
-							el.src = 'javascript:document.open();document.write("<scr"+"ipt src=\'' + path + '\'></scr"+"ipt>")';
-							setTimeout(function() {try{document.body.appendChild(el)}catch(e){}}, 0);
-						};
-						if (document.body) { cb(); }
-						else { window.addEventListener('load', cb, false); }
-					} catch(f) {}
-				}
-				throw e;
-			}
-		}
-		
-		this.findModule = function(possibilities) {
-			for (var i = 0, possible; possible = possibilities[i]; ++i) {
-				var xhr = new XHR();
-				try {
-					xhr.open('GET', possible.filePath, false);
-					xhr.send(null);
-				} catch(e) {
-					ENV.log('e:', e);
-					continue; // firefox file://
-				}
-				
-				if (xhr.status == 404 || // all browsers, http://
-					xhr.status == -1100 || // safari file://
-					// XXX: We have no way to tell in opera if a file exists and is empty, or is 404
-					// XXX: Use flash?
-					//(!failed && xhr.status == 0 && !xhr.responseText && EXISTS)) // opera
-					false)
-				{
-					continue;
-				}
-				
-				possible.src = xhr.responseText;
-				return possible;
-			}
-			
-			return false;
-		}
-	};
-	
-	function ensureHasTrailingSlash(str) { return str.length && str.replace(/([^\/])$/, '$1/') || str; }
-	function removeTrailingSlash(str) { return str.replace(/\/$/,''); }
-	
-	function guessModulePath(pathString) {
-		// resolve relative paths
-		if(pathString.charAt(0) == '.') {
-			// count the number of dots
-			var i = 0;
-			while(pathString.charAt(i + 1) == '.') { ++i; }
-
-			// remove one path segment for each dot from the cwd 
-			var prefix = removeTrailingSlash(ENV.getCwd());
-			if (i) { prefix = prefix.split('/').slice(0, -i).join('/'); }
-			
-			return [{filePath: prefix + '/' + pathString.substring(i + 1).split('.').join('/') + '.js'}];
-		}
-		
-		// resolve absolute paths with respect to jsio packages/
-		var pathSegments = pathString.split('.'),
-			baseMod = pathSegments[0],
-			modPath = pathSegments.join('/');
-		
-		if (baseMod in jsio.path) {
-			return [{filePath: ensureHasTrailingSlash(jsio.path[baseMod]) + modPath + '.js'}];
-		}
-		
-		var out = [];
-		var paths = typeof jsio.path.__default__ == 'string' ? [jsio.path.__default__] : jsio.path.__default__;
-		for (var i = 0, len = paths.length; i < len; ++i) {
-			var path = ensureHasTrailingSlash(paths[i]);
-			out.push({filePath: path + modPath + '.js', baseMod: baseMod, basePath: path});
-		}
-		return out;
-	}
-	
-	// load a module from a file
-	function loadModule(pathString) {
-		var possibilities = guessModulePath(pathString),
-			module = ENV.findModule(possibilities);
-		if(!module) {
-			var paths = [];
-			for (var i = 0, p; p = possibilities[i]; ++i) { paths.push(p.filePath); }
-			throw new Error("Module not found: " + pathString + " (looked in " + paths.join(', ') + ")");
-		}
-		
-		if (!(module.baseMod in jsio.path)) {
-			jsio.path[module.baseMod] = module.basePath;
-		}
-		
-		return module;
-	}
-	
-	function execModule(context, module) {
-		var code = "(function(_){with(_){delete _;(function(){" + module.src + "\n}).call(this)}})";
-		var fn = ENV.eval(code, module.filePath);
-		try {
-			fn.call(context.exports, context);
-		} catch(e) {
-			if(e.type == "syntax_error") {
-				throw new Error("error importing module: " + e.message);
-			} else if (!e.jsioLogged) {
-				e.jsioLogged = true;
-				if (e.type == "stack_overflow") {
-					ENV.log("Stack overflow in", module.filePath, ':', e);
-				} else {
-					ENV.log("ERROR LOADING", module.filePath, ':', e);
-				}
-			}
-			throw e;
-		}
-	};
-	
-	function resolveRelativePath(pkg, path, pathSep) {
-		// does the pkg need to be resolved, i.e. is it a relative path?
-		if(!path || (pathSep = pathSep || '.') != pkg.charAt(0)) { return pkg; }
-		
-		var i = 1;
-		while(pkg.charAt(i) == pathSep) { ++i; }
-		path = path.split(pathSep).slice(0, -i);
-		if(path.length) {
-			path = path.join(pathSep);
-			if(path.charAt(path.length - 1) != pathSep) { path += pathSep; }
-		}
-		return path + pkg.substring(i);
-	}
-	
-	function resolveImportRequest(path, request) {
-		var match, imports = [];
-		if((match = request.match(/^(from|external)\s+([\w.$]+)\s+import\s+(.*)$/))) {
-
-			imports[0] = {
-				from: resolveRelativePath(match[2], path),
-				external: match[1] == 'external',
-				'import': {}
-			};
-			
-			match[3].replace(/\s*([\w.$*]+)(?:\s+as\s+([\w.$]+))?/g, function(_, item, as) {
-				imports[0]['import'][item] = as || item;
-			});
-		} else if((match = request.match(/^import\s+(.*)$/))) {
-			match[1].replace(/\s*([\w.$]+)(?:\s+as\s+([\w.$]+))?,?/g, function(_, pkg, as) {
-				fullPkg = resolveRelativePath(pkg, path);
-				imports[imports.length] = as ? {from: fullPkg, as: as} : {from: fullPkg, as: pkg};
-			});
-		} else if((match = request.match(/[\w.0-9$\/]/))) { // CommonJS syntax
-			var req = match[0],
-				isAbsolute = req.charAt(0) == '/';
-			
-			req = req.replace(/^\//, '') // leading slash not needed
-				.replace(/\.\.?\//g, '.') // replace relative path indicators with dots
-				.replace(/\//g, '.'); // any remaining slashes are path separators
-			
-			// isAbsolute handles the edge case where the path looks like /../foo
-			imports[0] = {
-				from: isAbsolute ? req : resolveRelativePath(req, path),
-				as: req
-			};
-		} else {
-			var msg = 'Invalid jsio request: jsio(\'' + request + '\')';
-			throw SyntaxError ? new SyntaxError(msg) : new Error(msg);
-		}
-		return imports;
-	};
-	
-	function makeContext(pkgPath, filePath) {
-		var ctx = {
-				exports: {},
-				global: ENV.global
-			},
-			cwd = ENV.getCwd(),
-			i = filePath.lastIndexOf('/'),
-			isRelative = i > 0;
-		
-		ctx.require = ctx.jsio = bind(this, importer, ctx, pkgPath);
-		ctx.module = {id: pkgPath};
-		
-		if (pkgPath != 'base') {
-			ctx.jsio('from base import *');
-			ctx.logging.__create(pkgPath, ctx);
-		}
-		
-		// TODO: FIX for "trailing ." case
-		ctx.jsio.__jsio = jsio;
-		ctx.jsio.__env = jsio.__env;
-		ctx.jsio.__dir = isRelative ? makeRelativePath(filePath.substring(0, i), cwd) : '';
-		ctx.jsio.__filename = isRelative ? filePath.substring(i) : filePath;
-		ctx.jsio.__path = pkgPath;
-		return ctx;
-	};
-	
-	function makeRelativePath(path, relativeTo) {
-		var i = path.match('^' + relativeTo);
-		if (i && i[0] == relativeTo) {
-			var offset = path[relativeTo.length] == '/' ? 1 : 0
-			return path.slice(relativeTo.length + offset);
-		}
-		return path;
-	};
-	
-	function importer(context, path, request, altContext) {
-		// importer is bound to a module's (or global) context -- we can override this
-		// by using altContext as in jsio('import foo', obj) --> obj.foo
-		context = altContext || context || ENV.global;
-		
-		// parse the import request(s)
-		var imports = resolveImportRequest(path, request),
-			numImports = imports.length,
-			retVal = numImports > 1 ? {} : null;
-		
-		// import each requested item
-		for(var i = 0; i < numImports; ++i) {
-			var item = imports[i],
-				pkg = item.from,
-				modules = jsio.modules;
-			
-			// eval any packages that we don't know about already
-			if(!(pkg in modules)) {
-				try {
-					var module = sourceCache[pkg] || loadModule(pkg);
-				} catch(e) {
-					ENV.log('\nError executing \'', request, '\': could not load module', pkg, '\n\tpath:', path, '\n\trequest:', request, '\n');
-					throw e;
-				}
-				
-				if(!item.external) {
-					var newContext = makeContext(pkg, module.filePath);
-					modules[pkg] = newContext.exports;
-					execModule(newContext, module);
-					modules[pkg] = newContext.exports;
-				} else {
-					var newContext = modules[pkg] = {};
-					
-					// capture the requested objects so they don't escape into the global scope
-					for(var j in item['import']) { newContext[j] = undefined; }
-					
-					execModule(newContext, module);
-					for(var j in item['import']) {
-						if(newContext[j] === undefined) {
-							newContext[j] = ENV.global[j];
-						}
-					}
-				}
-			}
-			
-			var module = modules[pkg];
-			
-			// return the module if we're only importing one module
-			if (numImports == 1) { retVal = module; }
-			
-			// add the module to the current context
-			if (item.as) {
-				// remove trailing/leading dots
-				var as = item.as.match(/^\.*(.*?)\.*$/)[1],
-					segments = as.split('.'),
-					kMax = segments.length - 1,
-					c = context;
-				
-				// build the object in the context
-				for(var k = 0; k < kMax; ++k) {
-					var segment = segments[k];
-					if (!segment) continue;
-					if (!c[segment]) { c[segment] = {}; }
-					c = c[segment];
-				}
-				
-				c[segments[kMax]] = module;
-				
-				// there can be multiple module imports with this syntax (import foo, bar)
-				if (numImports > 1) {
-					retVal[as] = module;
-				}
-			} else if(item['import']) {
-				// there can only be one module import with this syntax 
-				// (from foo import bar), so retVal will already be set here
-				if(item['import']['*']) {
-					for(var k in modules[pkg]) { context[k] = module[k]; }
-				} else {
-					try {
-						for(var k in item['import']) { context[item['import'][k]] = module[k]; }
-					} catch(e) {
-						ENV.log('module: ', modules);
-						throw e;
-					}
-				}
-			}
-		}
-		
-		return retVal;
-	}
-})();

File daemon/orbited/js_src/jsio/lib/Enum.js

-exports = function() {
-	if (arguments.length == 1) {
-		if (typeof arguments[0] == 'object') {
-			var obj = arguments[0];
-			for (var i in obj) {
-				if (!(obj[i] in obj)) {
-					obj[obj[i]] = i;
-				}
-			}
-			return obj;
-		} else if (typeof arguments[0] != 'string') {
-			keys = arguments[0];
-		}
-	}
-	
-	if (!keys) { var keys = arguments; }
-	var obj = {};
-	for(var i = 0, len = keys.length; i < len; ++i) {
-		if (keys[i]) {
-			obj[keys[i]] = i + 1;
-		}
-		obj[i + 1] = keys[i];
-	}
-	return obj;
-}

File daemon/orbited/js_src/jsio/lib/Hash.js

-/**
- * basic Hash/Set class
- *  var h = new Hash('a', 'b', 'c');
- *  h.contains('a') ==> true
- *
- *  var h = new Hash({a: '1', b: '2', c: '3'});
- *  h.contains('1') ==> true
- *  h.hasKey('a') ==> true
- */
-exports = Class(function() {
-	this.init = function() {
-		this.m_keys = {};
-		this.m_dict = {};
-		this.m_values = {};
-		if (arguments.length == 1 && typeof arguments == 'object') {
-			var dict = arguments[0];
-			for (var i in dict) {
-				if (dict.hasOwnProperty(i)) {
-					this.m_keys[i] = true;
-					this.m_values[i] = dict[i];
-				}
-			}
-		} else {
-			for (var i = 0, len = arguments.length; i < len; i++) {
-				this.m_keys[arguments[i]] = true;
-				this.m_values[arguments[i]] = true;
-			};
-		}
-	}
-	
-	this.contains = function(val) { return this.m_values.hasOwnProperty(val); }
-	this.hasKey = this.containsKey = function(key) { return this.m_keys.hasOwnProperty(key); }
-	this.each = function(f, ctx) {
-		for (var i in keys) {
-			if (this.m_keys.hasOwnProperty(i)) {
-				f.call(ctx || GLOBAL, i, this.m_values[i], this);
-			}
-		}
-	}
-});

File daemon/orbited/js_src/jsio/lib/PubSub.js

-var ctx = jsio.__env.global;
-
-exports = Class(function() {
-	this.publish = function(signal) {
-		if(this._subscribers) {
-			var args = Array.prototype.slice.call(arguments, 1);
-			if(this._subscribers.__any) {
-				var anyArgs = [signal].concat(args);
-				for(var i = 0, sub; sub = this._subscribers.__any[i]; ++i) {
-					sub.apply(ctx, args);
-				}
-			}
-		
-			if(!this._subscribers[signal]) { return; }		
-			for(var i = 0, sub; sub = this._subscribers[signal][i]; ++i) {
-				sub.apply(ctx, args);
-			}
-		}
-		return this;
-	}
-	
-	this.subscribe = function(signal, ctx, method) {
-		if(!this._subscribers) { this._subscribers = {}; }
-		if(!this._subscribers[signal]) { this._subscribers[signal] = []; }
-		var cb = bind.apply(ctx, Array.prototype.slice.call(arguments, 1));
-		cb._ctx = ctx; // references for unsubscription
-		cb._method = method;
-		this._subscribers[signal].push(cb);
-		return this;
-	}
-	
-	// if no method is specified, all subscriptions with a callback context of ctx will be removed
-	this.unsubscribe = function(signal, ctx, method) {
-		var subs = this._subscribers[signal];
-		for (var i = 0, c; c = subs[i]; ++i) {
-			if (c._ctx == ctx && (!method || c._method == method)) {
-				subs.splice(i--, 1);
-			}
-		}
-		return this;
-	}
-});
-

File daemon/orbited/js_src/jsio/logging.js

-exports.UIWatcher = Class(function() {
-	
-});

File daemon/orbited/js_src/jsio/net.js

-jsio('import net.env');
-jsio('import std.JSON as JSON');
-
-JSON.createGlobal(); // create the global JSON object if it doesn't already exist
-
-exports.listen = function(server, transportName, opts) {
-	if (!transportName) {
-		throw logger.error('No transport provided for net.listen');
-	}
-	var listenerClass = net.env.getListener(transportName);
-	var listener = new listenerClass(server, opts);
-	listener.listen();
-	return listener;
-}
-
-exports.connect = function(protocolInstance, transportName, opts) {
-	var ctor = net.env.getConnector(transportName),
-		connector = new ctor(protocolInstance, opts);
-	
-	connector.connect();
-	return connector;
-}
-
-exports.quickServer = function(protocolClass) {
-	jsio('import net.interfaces');
-	return new net.interfaces.Server(protocolClass);
-}

File daemon/orbited/js_src/jsio/net/buffer.js

-jsio('from net.interfaces import Protocol');
-
-var EmptyBufferError = exports.EmptyBufferError = Class(function () {
-	this.init = function(message) { this.message = message; }
-})
-
-exports.Buffer = Class(function(supr) {
-
-	this.init = function(rawBuffer) {
-		
-		this._rawBuffer = !!rawBuffer ? rawBuffer : "";
-	}
-
-	this.getLength = function() {
-		return this._rawBuffer.length;
-	}
-
-	this.append = function(data) {
-		logger.debug('append', JSON.stringify(data));
-		this._rawBuffer += data;
-	}
-
-	this.peekBytes = function(num) {
-		if (!!num)
-			return this._rawBuffer.slice(0, num);
-		else 
-			return this._rawBuffer;
-	}
-
-	this.peekToDelimiter = function(delimiter) {
-		delimiter = delimiter ? delimiter : '\n';
-		var i = this._rawBuffer.indexOf(delimiter);
-		if (i == -1)
-			throw new EmptyBufferError("delimiter " + delimiter + "not present in buffer");
-		else
-			return this._rawBuffer.slice(0, i);
-	}
-
-	this.consumeBytes = function(num) {
-		var output = this.peekBytes(num);
-		this._rawBuffer = this._rawBuffer.slice(output.length);
-		return output;
-	}
-	this.consumeMaxBytes = function(num) {
-		var output = this._rawBuffer.slice(0, num);
-		this._rawBuffer = this._rawBuffer(num);
-		return output;
-	}
-	this.consumeAllBytes = function() {
-		var temp = this._rawBuffer;
-		this._rawBuffer = "";
-		return temp;
-	}
-	
-	this.consumeThroughDelimiter = function(delimiter) {
-		return this.consumeToDelimiter(delimiter) + this.consumeBytes(delimiter.length);
-	}
-
-	this.consumeToDelimiter = function(delimiter) {
-		delimiter = !!delimiter ? delimiter : "\n"
-		var output = this.peekToDelimiter(delimiter);
-		this._rawBuffer = this._rawBuffer.slice(output.length);
-		return output;
-	}
-
-	this.hasBytes = function(num) {
-		num = num ? num : 0;
-		return this._rawBuffer.length >= num;
-	}
-
-	this.hasDelimiter = function(delimiter) {
-		delimiter = !!delimiter ? delimiter : '\n';
-		return (this._rawBuffer.indexOf(delimiter) != -1);
-	}
-
-})

File daemon/orbited/js_src/jsio/net/csp/client.js

-jsio('import std.base64 as base64');
-jsio('import std.utf8 as utf8');
-jsio('import std.uri as uri'); 
-jsio('import net.errors as errors');
-jsio('import .transports');
-jsio('import lib.Enum as Enum');
-
-var READYSTATE = exports.READYSTATE = Enum({
-	INITIAL: 0,
-	CONNECTING: 1,
-	CONNECTED: 2,
-	DISCONNECTING: 3,
-	DISCONNECTED:  4
-});
-
-
-exports.CometSession = Class(function(supr) {
-	var id = 0;
-	var kDefaultBackoff = 50;
-	var kDefaultTimeoutInterval = 45000;
-	var kDefaultHandshakeTimeout = 10000;
-	this.init = function() {
-		this._id = ++id;
-		this._url = null;
-		this.readyState = READYSTATE.INITIAL;
-		this._sessionKey = null;
-		this._transport = null;
-		this._options = null;
-		
-		this._utf8ReadBuffer = "";
-		this._writeBuffer = "";
-		
-		this._packetsInFlight = null;
-		this._lastEventId = null;
-		this._lastSentId = null;
-		
-		this._handshakeLater = null;
-		this._handshakeBackoff = kDefaultBackoff;
-		this._handshakeRetryTimer = null;
-		this._handshakeTimeoutTimer = null;
-
-		this._timeoutTimer = null;
-
-		
-		this._writeBackoff = kDefaultBackoff;
-		this._cometBackoff = kDefaultBackoff;
-		
-		this._nullInBuffer = false;
-		this._nullInFlight= false;
-		this._nullSent = false;
-		this._nullReceived = false;
-	}
-	
-	
-	this.setEncoding = function(encoding) {
-		if (encoding == this._options.encoding) { 
-			return; 
-		}
-		if (encoding != 'utf8' && encoding != 'plain') {
-			throw new errors.InvalidEncodingError();
-		}
-		if (encoding == 'plain' && this._buffer) {
-			var buffer = this._utf8ReadBuffer;
-			this._utf8ReadBuffer = "";
-			this._doOnRead(buffer);
-		}
-		this._options.encoding = encoding;
-	}
-
-
-	this.connect = function(url, options) {
-		this._url = url.replace(/\/$/,'');
-		this._options = options || {};
-		
-		this._options.encoding = this._options.encoding || 'utf8';
-		this.setEncoding(this._options.encoding); // enforce encoding constraints
-		
-		this._options.connectTimeout = this._options.connectTimeout || kDefaultHandshakeTimeout;
-		
-		var transportClass = transports.chooseTransport(url, this._options);
-		this._transport = new transportClass();
-		
-		this._transport.handshakeFailure = bind(this, this._handshakeFailure);
-		this._transport.handshakeSuccess = bind(this, this._handshakeSuccess);
-		
-		this._transport.cometFailure = bind(this, this._cometFailure);
-		this._transport.cometSuccess = bind(this, this._cometSuccess);
-		
-		this._transport.sendFailure = bind(this, this._writeFailure);
-		this._transport.sendSuccess = bind(this, this._writeSuccess);
-		this.readyState = READYSTATE.CONNECTING;
-		this._transport.handshake(this._url, this._options);
-		
-		this._handshakeTimeoutTimer = $setTimeout(bind(this, this._handshakeTimeout), 
-			this._options.connectTimeout);
-	}
-
-	this.write = function(data, encoding) {
-		if (this.readyState != READYSTATE.CONNECTED) {
-			throw new errors.ReadyStateError();
-		}
-		encoding = encoding || this._options.encoding || 'utf8';
-		if (encoding == 'utf8') {
-			data = utf8.encode(data);
-		}
-		this._writeBuffer += data;
-		this._doWrite();
-	}
-	
-	// Close due to protocol error
-	this._protocolError = function(msg) {
-		logger.debug('_protocolError', msg);
-		// Immediately fire the onclose
-		// send a null packet to the server
-		// don't wait for a null packet back.
-		this.readyState = READYSTATE.DISCONNECTED;
-		this._doWrite(true);
-		this._doOnDisconnect(new errors.ServerProtocolError(msg));
-	}
-	
-	this._receivedNullPacket = function() {
-		logger.debug('_receivedNullPacket');
-		// send a null packet back to the server
-		this._receivedNull = true;
-		
-		// send our own null packet back. (maybe)
-		if (!(this._nullInFlight || this._nullInBuffer || this._nullSent)) {
-			this.readyState = READYSTATE.DISCONNECTING;
-			this._doWrite(true);
-		}
-		else {
-			this.readyState = READYSTATE.DISCONNECTED;
-		}
-		
-		// fire an onclose
-		this._doOnDisconnect(new errors.ConnectionClosedCleanly());
-
-	}
-	
-	this._sentNullPacket = function() {
-		logger.debug('_sentNullPacket');
-		this._nullSent = true;
-		if (this._nullSent && this._nullReceived) {
-			this.readyState = READYSTATE.DISCONNECTED;
-		}
-	}
-	
-	
-	// User Calls close
-	this.close = function(err) {
-		logger.debug('close called', err, 'readyState', this.readyState);
-
-		// 
-		switch(this.readyState) {
-			case READYSTATE.CONNECTING:
-				clearTimeout(this._handshakeRetryTimer);
-				clearTimeout(this._handshakeTimeoutTimer);
-				this.readyState = READYSTATE.DISCONNECTED;
-				this._doOnDisconnect(err);
-				break;
-			case READYSTATE.CONNECTED:
-				this.readyState = READYSTATE.DISCONNECTING;
-				this._doWrite(true);
-				clearTimeout(this._timeoutTimer);
-				break;
-			case READYSTATE.DISCONNECTED:
-				throw new errors.ReadyStateError("Session is already disconnected");
-				break;
-		}
-		
-		this._sessionKey = null;
-		this._opened = false; // what is this used for???
-		this.readyState = READYSTATE.DISCONNECTED;
-		
-		this._doOnDisconnect(err);
-	}
-
-	
-	this._handshakeTimeout = function() {
-		logger.debug('handshake timeout');
-		this._handshakeTimeoutTimer = null;
-		this._doOnDisconnect(new errors.ServerUnreachable());
-	}
-	
-	this._handshakeSuccess = function(data) {
-		logger.debug('handshake success', data);
-		if (this.readyState != READYSTATE.CONNECTING) { 
-			logger.debug('received handshake success in invalid readyState:', this.readyState);
-			return; 
-		}
-		clearTimeout(this._handshakeTimeoutTimer);
-		this._handshakeTimeoutTimer = null;
-		this._sessionKey = data.response.session;
-		this._opened = true;
-		this.readyState = READYSTATE.CONNECTED;
-		this._doOnConnect();
-		this._doConnectComet();
-	}
-	
-	this._handshakeFailure = function(data) {
-		logger.debug('handshake failure', data);
-		if (this.readyState != READYSTATE.CONNECTING) { return; }
-		if (data.status == 404) {
-			clearTimeout(this._handshakeTimeoutTimer);
-			return this._doOnDisconnect(new errors.ServerUnreachable());
-		}
-		
-		logger.debug('trying again in ', this._handshakeBackoff);
-		this._handshakeRetryTimer = $setTimeout(bind(this, function() {
-			this._handshakeRetryTimer = null;
-			this._transport.handshake(this._url, this._options);
-		}), this._handshakeBackoff);
-		
-		this._handshakeBackoff *= 2;
-	}
-	
-	this._writeSuccess = function() {
-		if (this.readyState != READYSTATE.CONNECTED && this.readyState != READYSTATE.DISCONNECTING) {
-			return;
-		}
-		if (this._nullInFlight) {
-			return this._sentNullPacket();
-		}
-		this._resetTimeoutTimer();
-		this.writeBackoff = kDefaultBackoff;
-		this._packetsInFlight = null;
-		if (this._writeBuffer || this._nullInBuffer) {
-			this._doWrite(this._nullInBuffer);
-		}
-	}
-	
-	this._writeFailure = function() {
-		if (this.readyState != READYSTATE.CONNECTED && this.READYSTATE != READYSTATE.DISCONNECTING) { return; }
-		this._writeTimer = $setTimeout(bind(this, function() {
-			this._writeTimer = null;
-			this.__doWrite(this._nullInBuffer);
-		}), this._writeBackoff);
-		this._writeBackoff *= 2;
-	}	
-
-	this._doWrite = function(sendNull) {
-		if (this._packetsInFlight) {
-			if (sendNull) {
-				this._nullInBuffer = true;
-				return; 
-			}
-			return;
-		}
-		this.__doWrite(sendNull);
-	}
-	
-	this.__doWrite = function(sendNull) {
-		logger.debug('_writeBuffer:', this._writeBuffer);
-		if (!this._packetsInFlight && this._writeBuffer) {
-			this._packetsInFlight = [this._transport.encodePacket(++this._lastSentId, this._writeBuffer, this._options)];
-			this._writeBuffer = "";
-		}
-		if (sendNull && !this._writeBuffer) {
-			if (!this._packetsInFlight) {
-				this._packetsInFlight = [];
-			}
-			this._packetsInFlight.push([++this._lastSentId, 0, null]);
-			this._nullInFlight = true;
-		}
-		if (!this._packetsInFlight) {
-			logger.debug("no packets to send");
-			return;
-		}
-		logger.debug('sending packets:', JSON.stringify(this._packetsInFlight));
-		this._transport.send(this._url, this._sessionKey, this._lastEventId || 0, JSON.stringify(this._packetsInFlight), this._options);
-	}
-	
-	this._doConnectComet = function() {
-		logger.debug('_doConnectComet');
-//		return;
-		this._transport.comet(this._url, this._sessionKey, this._lastEventId || 0, this._options);
-	}
-
-	this._cometFailure = function(data) {
-		if (this.readyState != READYSTATE.CONNECTED) { return; }
-		if (data.status == 404 && data.response == 'Session not found') {
-			return this.close(new errors.ExpiredSession(data));
-		}
-		
-		this._cometTimer = $setTimeout(bind(this, function() {
-			this._doConnectComet();
-		}), this._cometBackoff);
-		this._cometBackoff *= 2;
-	}
-	
-	this._cometSuccess = function(data) {
-		if (this.readyState != READYSTATE.CONNECTED && this.readyState != READYSTATE.DISCONNECTING) { return; }
-		logger.debug('comet Success:', data);
-		this._cometBackoff = kDefaultBackoff;
-		this._resetTimeoutTimer();
-		
-		var response = data.response;
-		for (var i = 0, packet; (packet = response[i]) || i < response.length; i++) {
-			logger.debug('process packet:', packet);
-			if (packet === null) {
-				return this.close(new errors.ServerProtocolError(data));
-			}
-			logger.debug('process packet', packet);
-			var ackId = packet[0];
-			var encoding = packet[1];
-			var data = packet[2];
-			if (typeof(this._lastEventId) == 'number' && ackId <= this._lastEventId) {
-				continue;
-			}
-			if (typeof(this._lastEventId) == 'number' && ackId != this._lastEventId+1) {
-				return this._protocolError("Ack id too high");
-			}
-			this._lastEventId = ackId;
-			if (data == null) {
-				return this._receivedNullPacket();
-			}
-			if (encoding == 1) { // base64 encoding
-				try {
-					logger.debug('before base64 decode:', data);
-					data = base64.decode(data);
-					logger.debug('after base64 decode:', data);
-				} catch(e) {
-					return this._protocolError("Unable to decode base64 payload");
-				}
-			}
-			if (this._options.encoding == 'utf8') {
-				// TODO: need an incremental utf8 decoder for this stuff.
-				this._utf8ReadBuffer += data;
-				logger.debug('before utf8 decode, _utf8ReadBuffer:', this._utf8ReadBuffer);
-				var result = utf8.decode(this._utf8ReadBuffer);
-				data = result[0];
-				this._utf8ReadBuffer = this._utf8ReadBuffer.slice(result[1]);
-				logger.debug('after utf8 decode, _utf8ReadBuffer:', this._utf8ReadBuffer, 'data:', data );
-			}
-			logger.debug('dispatching data:', data);
-			try {
-				this._doOnRead(data);
-			} catch(e) {
-				logger.error('application code threw an error. (re-throwing in timeout):', e);
-				// throw the error later
-				setTimeout(function() {
-					logger.debug('timeout fired, throwing error', e);
-					throw e;
-				}, 0);
-			}
-		}
-		// reconnect comet last, after we process all of the packet ids
-		this._doConnectComet();
-		
-	}
-
-	this._doOnRead = function(data) {
-		if (typeof(this.onread) == 'function') {
-			logger.debug('call onread function', data);
-			this.onread(data);
-		}
-		else {
-			logger.debug('skipping onread callback (function missing)');
-		}
-	}
-	
-	this._doOnDisconnect = function(err) {
-		if (typeof(this.ondisconnect) == 'function') {
-			logger.debug('call ondisconnect function', err);
-			this.ondisconnect(err);
-		}
-		else {
-			logger.debug('skipping ondisconnect callback (function missing)');
-		}
-	}
-	
-	this._doOnConnect = function() {
-		if (typeof(this.onconnect) == 'function') {
-			logger.debug('call onconnect function');
-			try {
-				this.onconnect();
-			} catch(e) {
-				logger.debug('onconnect caused errror', e);
-				// throw error later
-				setTimeout(function() { throw e }, 0);
-			}
-		}
-		else {
-			logger.debug('skipping onconnect callback (function missing)');
-		}
-	}
-
-	this._resetTimeoutTimer = function() {
-		clearTimeout(this._timeoutTimer);
-		this._timeoutTimer = $setTimeout(bind(this, function() {
-			logger.debug('connection timeout expired');
-			this.close(new errors.ConnectionTimeout())
-		}), this._getTimeoutInterval())
-	}
-	
-	this._getTimeoutInterval = function() {
-		return kDefaultTimeoutInterval;
-	}
-
-});

File daemon/orbited/js_src/jsio/net/csp/transports.js

-jsio('import std.uri as uri'); 
-jsio('import std.base64 as base64');
-jsio('from util.browserdetect import BrowserDetect');
-
-;(function() {
-	var doc;
-	exports.getDoc = function() {
-		if (doc) { return doc; }
-		try {
-			doc = window.ActiveXObject && new ActiveXObject('htmlfile');
-			if (doc) {
-				doc.open().write('<html></html>');
-				doc.close();
-				window.attachEvent('onunload', function() {
-					try { doc.body.innerHTML = ''; } catch(e) {}
-					doc = null;
-				});
-			}
-		} catch(e) {}
-		
-		if (!doc) { doc = document; }
-		return doc;
-	};
-
-	exports.XHR = function() {
-		var win = window,
-			doc = exports.getDoc();
-		//if (doc.parentWindow) { win = doc.parentWindow; }
-		
-		return new (exports.XHR = win.XMLHttpRequest ? win.XMLHttpRequest
-			: function() { return win.ActiveXObject && new win.ActiveXObject('Msxml2.XMLHTTP') || null; });
-	}
-	
-	exports.createXHR = function() { return new exports.XHR(); }
-
-})();
-
-function isLocalFile(url) { return /^file:\/\//.test(url); }
-function isWindowDomain(url) { return uri.isSameDomain(url, window.location.href); }
-
-function canUseXHR(url) {
-	// always use jsonp for local files
-	if (isLocalFile(url)) { return false; }
-	
-	// try to create an XHR using the same function the XHR transport uses
-	var xhr = new exports.XHR();
-	if (!xhr) { return false; }
-	
-	// if the URL requested is the same domain as the window,
-	// then we can use same-domain XHRs
-	if (isWindowDomain(url)) { return true; }
-	
-	// if the URL requested is a different domain than the window,
-	// then we need to check for cross-domain support
-	if (window.XMLHttpRequest
-			&& (xhr.__proto__ == XMLHttpRequest.prototype // WebKit Bug 25205
-				|| xhr instanceof window.XMLHttpRequest)
-			&& xhr.withCredentials !== undefined
-		|| window.XDomainRequest 
-			&& xhr instanceof window.XDomainRequest) {
-		return true;
-	}
-};
-
-var transports = exports.transports = {};
-
-exports.chooseTransport = function(url, options) {
-	switch(options.preferredTransport) {
-		case 'jsonp':
-			return transports.jsonp;
-		case 'xhr':
-		default:
-			if (canUseXHR(url)) { return transports.xhr; };
-			return transports.jsonp;
-	}
-};
-
-// TODO: would be nice to use these somewhere...
-
-var PARAMS = {
-	'xhrstream':   {"is": "1", "bs": "\n"},
-	'xhrpoll':     {"du": "0"},
-	'xhrlongpoll': {},
-	'sselongpoll': {"bp": "data: ", "bs": "\r\n", "se": "1"},
-	'ssestream':   {"bp": "data: ", "bs": "\r\n", "se": "1", "is": "1"}
-};
-
-exports.Transport = Class(function(supr) {
-	this.handshake = function(url, options) {
-		throw new Error("handshake Not Implemented"); 
-	};
-	this.comet = function(url, sessionKey, lastEventId, options) { 
-		throw new Error("comet Not Implemented"); 
-	};
-	this.send = function(url, sessionKey, data, options) { 
-		throw new Error("send Not Implemented");
-	};
-	this.encodePacket = function(packetId, data, options) { 
-		throw new Error("encodePacket Not Implemented"); 
-	};
-	this.abort = function() { 
-		throw new Error("abort Not Implemented"); 
-	};
-});
-
-var baseTransport = Class(exports.Transport, function(supr) {
-	this.init = function() {
-		this._aborted = false;
-		this._handshakeArgs = {
-			d:'{}',
-			ct:'application/javascript'
-		};
-	};
-	
-	this.handshake = function(url, options) {
-		logger.debug('handshake:', url, options);
-		this._makeRequest('send', url + '/handshake', 
-						  this._handshakeArgs, 
-						  this.handshakeSuccess, 
-						  this.handshakeFailure);
-	};
-	
-	this.comet = function(url, sessionKey, lastEventId, options) {
-		logger.debug('comet:', url, sessionKey, lastEventId, options);
-		args = {
-			s: sessionKey,
-			a: lastEventId
-		};
-		this._makeRequest('comet', url + '/comet', 
-						  args, 
-						  this.cometSuccess, 
-						  this.cometFailure);
-	};
-	
-	this.send = function(url, sessionKey, lastEventId, data, options) {
-		logger.debug('send:', url, sessionKey, data, options);
-		args = {
-			d: data,
-			s: sessionKey,
-			a: lastEventId
-		};
-		this._makeRequest('send', url + '/send', 
-						  args, 
-						  this.sendSuccess, 
-						  this.sendFailure);
-	};
-});
-
-transports.xhr = Class(baseTransport, function(supr) {
-	
-	this.init = function() {
-		supr(this, 'init');
-	
-		this._xhr = {
-			'send': new exports.XHR(),
-			'comet': new exports.XHR()
-		};
-	};
-
-	this.abort = function() {
-		this._aborted = true;
-		for(var i in this._xhr) {
-			if(this._xhr.hasOwnProperty(i)) {
-				this._abortXHR(i);
-			}
-		}
-	};
-	
-	this._abortXHR = function(type) {
-		logger.debug('aborting XHR');
-
-		var xhr = this._xhr[type];
-		try {
-			if('onload' in xhr) {
-				xhr.onload = xhr.onerror = xhr.ontimeout = null;
-			} else if('onreadystatechange' in xhr) {
-				xhr.onreadystatechange = null;
-			}
-			if(xhr.abort) { xhr.abort(); }
-		} catch(e) {
-			logger.debug('error aborting xhr', e);
-		}
-		
-		// do not reuse aborted XHRs
-		this._xhr[type] = new exports.XHR();
-	};
-	
-	var mustEncode = !(exports.createXHR().sendAsBinary);
-	this.encodePacket = function(packetId, data, options) {
-		// we don't need to base64 encode things unless there's a null character in there
-		return mustEncode ? [ packetId, 1, base64.encode(data) ] : [ packetId, 0, data ];
-	};
-
-	this._onReadyStateChange = function(rType, cb, eb) {
-		
-		var response = '',
-			xhr = this._xhr[rType];
-		
-		try {
-			var data = {status: xhr.status};
-		} catch(e) { eb({response: 'Could not access status'}); }
-		
-		try {
-			if(xhr.readyState != 4) { return; }
-			
-			data.response = eval(xhr.responseText);
-			if(data.status != 200) { 
-				logger.debug('XHR failed with status ', xhr.status);
-				eb(data);
-				return;
-			}
-			
-			logger.debug('XHR data received');
-		} catch(e) {
-			logger.debug('Error in XHR::onReadyStateChange', e);
-			eb(data);
-			this._abortXHR(rType);
-			logger.debug('done handling XHR error');
-			return;
-		}
-		
-		cb(data);
-	};
-
-	/**
-	 * even though we encode the POST body as in application/x-www-form-urlencoded
-	 */
-	this._makeRequest = function(rType, url, args, cb, eb) {
-		if (this._aborted) {
-			return;
-		}
-		var xhr = this._xhr[rType], data = args.d || null;
-		if('d' in args) { delete args.d; }
-		xhr.open('POST', url + '?' + uri.buildQuery(args)); // must open XHR first
-		xhr.setRequestHeader('Content-Type', 'text/plain'); // avoid preflighting
-		if('onload' in xhr) {
-			xhr.onload = bind(this, '_onReadyStateChange', rType, cb, eb);
-			xhr.onerror = xhr.ontimeout = eb;
-		} else if('onreadystatechange' in xhr) {
-			xhr.onreadystatechange = bind(this, '_onReadyStateChange', rType, cb, eb);
-		}
-		// NOTE WELL: Firefox (and probably everyone else) likes to encode our nice
-		//						binary strings as utf8. Don't let them! Say no to double utf8
-		//						encoding. Once is good, twice isn't better.
-		var supportsBinary = !!xhr.sendAsBinary;
-		if (supportsBinary) {
-			// xhr.setRequestHeader('x-CSP-SendAsBinary', 'true');
-		}
-		setTimeout(bind(xhr, supportsBinary ? 'sendAsBinary' : 'send', data), 0);
-	};
-});
-
-var EMPTY_FUNCTION = function() {},
-	SLICE = Array.prototype.slice;
-
-transports.jsonp = Class(baseTransport, function(supr) {
-	var doc;
-	
-	var createIframe = function() {
-		var doc = exports.getDoc();
-		if (!doc.body) { return false; }
-		
-		var i = doc.createElement("iframe");
-		with(i.style) { display = 'block'; width = height = border = margin = padding = '0'; overflow = visibility = 'hidden'; position = 'absolute'; top = left = '-999px'; }
-		i.cbId = 0;
-		doc.body.appendChild(i);
-		i.src = 'javascript:var d=document;d.open();d.write("<html><body></body></html>");d.close();';
-		return i;
-	};
-
-	var cleanupIframe = function(ifr) {
-		var win = ifr.contentWindow, doc = win.document;
-		logger.debug('removing script tags');
-		
-		var scripts = doc.getElementsByTagName('script');
-		for (var i = scripts.length - 1; i >= 0; --i) {
-			doc.body.removeChild(scripts[i]);
-		}
-		
-		logger.debug('deleting iframe callbacks');
-		win['cb' + ifr.cbId] = win['eb' + ifr.cbId] = EMPTY_FUNCTION;
-	};
-
-	var removeIframe = function(ifr) {
-		$setTimeout(function() {
-			if(ifr && ifr.parentNode) { ifr.parentNode.removeChild(ifr); }
-		}, 60000);
-	};
-
-	this.init = function() {
-		supr(this, 'init');
-
-		this._onReady = [];
-		this._isReady = false;
-
-		this._createIframes();
-	};
-
-	this._createIframes = function() {
-		this._ifr = {
-			send: createIframe(),
-			comet: createIframe()
-		};
-		
-		if(this._ifr.send === false) { return $setTimeout(bind(this, '_createIframes'), 100); }
-		
-		this._isReady = true;
-
-		var readyArgs = this._onReady;
-		this._onReady = [];
-		for(var i = 0, args; args = readyArgs[i]; ++i) {
-			this._makeRequest.apply(this, args);
-		}
-	};
-
-	this.encodePacket = function(packetId, data, options) {
-		return [ packetId, 1, base64.encode(data) ];
-	};
-
-	this.abort = function() {
-		this._aborted = true;
-		for(var i in this._ifr) {
-			if(this._ifr.hasOwnProperty(i)) {
-				var ifr = this._ifr[i];
-				cleanupIframe(ifr);
-				removeIframe(ifr);
-			}
-		}
-	};
-	
-	this._makeRequest = function(rType, url, args, cb, eb) {
-		if(!this._isReady) { return this._onReady.push(arguments); }
-		
-		var ifr = this._ifr[rType],
-			id = ++ifr.cbId,
-			req = {
-				type: rType,
-				id: id,
-				cb: cb,
-				eb: eb,
-				cbName: 'cb' + id,
-				ebName: 'eb' + id,
-				completed: false
-			};
-		
-		args.n = Math.random();	
-		switch(rType) {
-			case 'send': args.rs = ';'; args.rp = req.cbName; break;
-			case 'comet': args.bs = ';'; args.bp = req.cbName; break;
-		}
-		
-		req.url = url + '?' + uri.buildQuery(args)
-		
-		$setTimeout(bind(this, '_request', req), 0);
-	}
-	
-	this._request = function(req) {
-		var ifr = this._ifr[req.type],
-			win = ifr.contentWindow,
-			doc = win.document,
-			body = doc.body;
-
-		win[req.ebName] = bind(this, checkForError, req);
-		win[req.cbName] = bind(this, onSuccess, req);
-		
-		if(BrowserDetect.isWebKit) {
-			// this will probably cause loading bars in Safari -- might want to rethink?
-			doc.open();
-			doc.write('<scr'+'ipt src="'+req.url+'"></scr'+'ipt><scr'+'ipt>'+ebName+'(false)</scr'+'ipt>');
-			doc.close();
-		} else {
-			var s = doc.createElement('script');
-			s.src = req.url;
-			
-			// IE
-			if(s.onreadystatechange === null) { s.onreadystatechange = bind(this, onReadyStateChange, req, s); }
-			body.appendChild(s);
-			
-			if(!BrowserDetect.isIE) {
-				var s = doc.createElement('script');
-				s.innerHTML = req.ebName+'(false)';
-				body.appendChild(s);
-			}
-		}
-		
-		killLoadingBar();
-	};
-	
-	function onSuccess(req, response) {
-		logger.debug('successful: ', req.url, response);
-		req.completed = true;
-		
-		logger.debug('calling the cb');
-		req.cb.call(GLOBAL, {status: 200, response: response});
-		logger.debug('cb called');
-	}
-	
-	// IE6/7 onReadyStateChange
-	function onReadyStateChange(req, scriptTag) {
-		if (scriptTag && scriptTag.readyState != 'loaded') { return; }
-		scriptTag.onreadystatechange = function() {};
-		checkForError.call(this, req);
-	}
-
-	function checkForError(req, response) {
-		cleanupIframe(this._ifr[req.type]);
-		
-		if (!req.completed) {
-			var data = {
-				status: response ? 200 : 404,
-				response: response || 'Unable to load resouce'
-			};
-			
-			logger.debug('error making request:', req.url, data);
-			logger.debug('calling eb');
-			req.eb.call(GLOBAL, data);
-		}
-	}
-	
-	var killLoadingBar = BrowserDetect.isFirefox ? function() {
-		var b = document.body;
-		if (!b) { return; }
-		
-		if (!killLoadingBar.iframe) { killLoadingBar.iframe = document.createElement('iframe'); }
-		b.insertBefore(killLoadingBar.iframe, b.firstChild);
-		b.removeChild(killLoadingBar.iframe);
-	} : function() {};
-});
-	

File daemon/orbited/js_src/jsio/net/env.js

-function getObj(objectName, transportName, envName) {
-	try {
-		jsio('from .env.' + (envName || jsio.__env.name) + '.' + transportName + ' import ' + objectName + ' as result');
-	} catch(e) {
-		throw logger.error('Invalid transport (', transportName, ') or environment (', envName, ')');
-	}
-	return result;
-}
-
-exports.getListener = bind(this, getObj, 'Listener');
-exports.getConnector = bind(this, getObj, 'Connector');

File daemon/orbited/js_src/jsio/net/env/browser/csp.js

-jsio('import net.interfaces');
-jsio('from net.csp.client import CometSession');
-jsio('import std.utf8 as utf8');
-
-exports.Connector = Class(net.interfaces.Connector, function() {
-	this.connect = function() {
-		this._state = net.interfaces.STATE.CONNECTING;
-		
-		var conn = new CometSession();
-		conn.onconnect = bind(this, 'cometSessionOnConnect', conn);
-		conn.ondisconnect = bind(this, 'onDisconnect');
-		
-		logger.debug('opening the connection');
-		this._opts.encoding = 'plain';
-		var url = this._opts.url;
-		delete this._opts.url;
-		conn.connect(url, this._opts);//{encoding: 'plain'});
-	}
-	
-	this.cometSessionOnConnect = function(conn) {
-		logger.debug('conn has opened');
-		this.onConnect(new Transport(conn));
-	}
-});
-
-var Transport = Class(net.interfaces.Transport, function() {
-	this.init = function(conn) {
-		this._conn = conn;
-	}
-	
-	this.makeConnection = function(protocol) {
-		this._conn.onread = bind(protocol, 'dataReceived');
-	}
-	
-	this.write = function(data) {
-		this._conn.write(this._encoding == 'utf8' ? utf8.encode(data) : data);
-	}
-	
-	this.loseConnection = function(protocol) {
-		this._conn.close();
-	}
-});

File daemon/orbited/js_src/jsio/net/env/browser/networkConsole.html

-<!DOCTYPE html>
-<html>
-<head>
-	<script src="../../../jsio.js"></script>
-	<script>
-	jsio('from base import *');
-	jsio('import net.interfaces');
-
-	ConsoleClient = Class(net.interfaces.Protocol, function() {
-		var parity = true;
-		this.connectionMade = function() {
-			document.getElementById('con').style.display = 'block';
-			document.getElementById('inputArea').style.display = 'block';
-		}
-		this.connectionLost = function(reason) {
-			console.log('connection lost', reason);
-		}
-		this.dataReceived = function(data) {
-			console.log('data received:', data);
-		
-			var line = document.getElementById('con').insertBefore(document.createElement('div'), document.getElementById('con').firstChild);
-			line.innerHTML = data;
-			line.style.backgroundColor = parity ? '#EEE' : '#F5F5F4';
-			parity = !parity;
-		}
-	});
-	</script>
-	<style>
-	.connectBtn { float: left; }
-	
-	#con {
-		clear: both;
-		border: 1px solid #CCC;
-	}
-	</style>
-</head>
-<body>
-	<div id="wrapper">
-		<div id="inputArea" style="display:none; float:left"></div>
-		<div id="con" style="display:none"><br></div>
-	</div>
-	<script>
-		var wrapper = document.getElementById('wrapper');
-		var inputArea = document.getElementById('inputArea');
-		var con = document.getElementById('con');
-		var connectBtn = wrapper.insertBefore(document.createElement('button'), inputArea);
-		connectBtn.innerHTML = 'connect';
-		connectBtn.onclick = connect;
-		connectBtn.className = 'connectBtn';
-		
-		var client;
-		function connect() {
-			client = new ConsoleClient();
-			var match = window.location.search.substring(1).match('^(.*&)?protocol=([^&]*)');
-			var protocolName = match ? match[2] : 'postmessage';
-			net.connect(client, protocolName, {host: "localhost", port: 5555});
-			connectBtn.innerHTML = 'disconnect';
-			connectBtn.onclick = disconnect;
-		};
-		
-		function disconnect() {
-			connect.innerHTML = 'connect';
-			connect.onclick = connect;
-			client.transport.loseConnection();
-		}
-		
-		var input = inputArea.appendChild(document.createElement('input'));
-		input.type = 'text';
-		input.onkeypress = function(e) { if((e || event).keyCode == 13) { send(); }}
-	
-		var sendBtn = inputArea.appendChild(document.createElement('button'));
-		sendBtn.innerHTML = 'send';
-		sendBtn.onclick = send;
-		
-		function send() {
-			client.transport.write(input.value);
-			input.value = '';
-			input.focus();
-		}
-		
-	</script>
-	</body>
-</html>

File daemon/orbited/js_src/jsio/net/env/browser/postmessage.js

-jsio('import net.interfaces');
-jsio('from util.browser import $');
-
-exports.Listener = Class(net.interfaces.Listener, function(supr) {
-	var ID = 0;
-	
-	this.init = function() {
-		supr(this, 'init', arguments);
-		this._clients = {};
-		if (!this._opts.clientUrl) {
-			this._opts.clientUrl = jsio.__dir + '/networkConsole.html';
-		}
-	}
-
-	this.listen = function() {
-		$.onEvent(window, 'message', bind(this, '_onMessage'));
-	}
-
-	this.getButton = function(url, text) { 
-		var button = document.createElement('button');
-		button.className = 'clientButton';
-		button.innerHTML = text || 'launch client';
-		$.onEvent(button, 'click', bind(this, '_openWindow', url));
-		return button; 
-	}
-	
-	var uniqueId = 1;
-	this._openWindow = function(url) {
-		var options = { menubar: 'no', location: 'no', toolbar: 'no',