UNPKG

king

Version:

A powerful server infrastructure management platform - "The King of your Nodes"

1,587 lines (1,363 loc) 428 kB
;(function(e,t,n){function i(n,s){if(!t[n]){if(!e[n]){var o=typeof require=="function"&&require;if(!s&&o)return o(n,!0);if(r)return r(n,!0);throw new Error("Cannot find module '"+n+"'")}var u=t[n]={exports:{}};e[n][0].call(u.exports,function(t){var r=e[n][1][t];return i(r?r:t)},u,u.exports)}return t[n].exports}var r=typeof require=="function"&&require;for(var s=0;s<n.length;s++)i(n[s]);return i})({1:[function(require,module,exports){ window.shoe = require('shoe'); window.dnode = require('dnode'); window.levelup = require('levelup'); window.leveljs = require('level-js'); },{"shoe":2,"dnode":3,"levelup":4,"level-js":5}],6:[function(require,module,exports){ // shim for using process in browser var process = module.exports = {}; process.nextTick = (function () { var canSetImmediate = typeof window !== 'undefined' && window.setImmediate; var canPost = typeof window !== 'undefined' && window.postMessage && window.addEventListener ; if (canSetImmediate) { return function (f) { return window.setImmediate(f) }; } if (canPost) { var queue = []; window.addEventListener('message', function (ev) { if (ev.source === window && ev.data === 'process-tick') { ev.stopPropagation(); if (queue.length > 0) { var fn = queue.shift(); fn(); } } }, true); return function nextTick(fn) { queue.push(fn); window.postMessage('process-tick', '*'); }; } return function nextTick(fn) { setTimeout(fn, 0); }; })(); process.title = 'browser'; process.browser = true; process.env = {}; process.argv = []; process.binding = function (name) { throw new Error('process.binding is not supported'); } // TODO(shtylman) process.cwd = function () { return '/' }; process.chdir = function (dir) { throw new Error('process.chdir is not supported'); }; },{}],7:[function(require,module,exports){ (function(process){if (!process.EventEmitter) process.EventEmitter = function () {}; var EventEmitter = exports.EventEmitter = process.EventEmitter; var isArray = typeof Array.isArray === 'function' ? Array.isArray : function (xs) { return Object.prototype.toString.call(xs) === '[object Array]' } ; function indexOf (xs, x) { if (xs.indexOf) return xs.indexOf(x); for (var i = 0; i < xs.length; i++) { if (x === xs[i]) return i; } return -1; } // By default EventEmitters will print a warning if more than // 10 listeners are added to it. This is a useful default which // helps finding memory leaks. // // Obviously not all Emitters should be limited to 10. This function allows // that to be increased. Set to zero for unlimited. var defaultMaxListeners = 10; EventEmitter.prototype.setMaxListeners = function(n) { if (!this._events) this._events = {}; this._events.maxListeners = n; }; EventEmitter.prototype.emit = function(type) { // If there is no 'error' event listener then throw. if (type === 'error') { if (!this._events || !this._events.error || (isArray(this._events.error) && !this._events.error.length)) { if (arguments[1] instanceof Error) { throw arguments[1]; // Unhandled 'error' event } else { throw new Error("Uncaught, unspecified 'error' event."); } return false; } } if (!this._events) return false; var handler = this._events[type]; if (!handler) return false; if (typeof handler == 'function') { switch (arguments.length) { // fast cases case 1: handler.call(this); break; case 2: handler.call(this, arguments[1]); break; case 3: handler.call(this, arguments[1], arguments[2]); break; // slower default: var args = Array.prototype.slice.call(arguments, 1); handler.apply(this, args); } return true; } else if (isArray(handler)) { var args = Array.prototype.slice.call(arguments, 1); var listeners = handler.slice(); for (var i = 0, l = listeners.length; i < l; i++) { listeners[i].apply(this, args); } return true; } else { return false; } }; // EventEmitter is defined in src/node_events.cc // EventEmitter.prototype.emit() is also defined there. EventEmitter.prototype.addListener = function(type, listener) { if ('function' !== typeof listener) { throw new Error('addListener only takes instances of Function'); } if (!this._events) this._events = {}; // To avoid recursion in the case that type == "newListeners"! Before // adding it to the listeners, first emit "newListeners". this.emit('newListener', type, listener); if (!this._events[type]) { // Optimize the case of one listener. Don't need the extra array object. this._events[type] = listener; } else if (isArray(this._events[type])) { // Check for listener leak if (!this._events[type].warned) { var m; if (this._events.maxListeners !== undefined) { m = this._events.maxListeners; } else { m = defaultMaxListeners; } if (m && m > 0 && this._events[type].length > m) { this._events[type].warned = true; console.error('(node) warning: possible EventEmitter memory ' + 'leak detected. %d listeners added. ' + 'Use emitter.setMaxListeners() to increase limit.', this._events[type].length); console.trace(); } } // If we've already got an array, just append. this._events[type].push(listener); } else { // Adding the second element, need to change to array. this._events[type] = [this._events[type], listener]; } return this; }; EventEmitter.prototype.on = EventEmitter.prototype.addListener; EventEmitter.prototype.once = function(type, listener) { var self = this; self.on(type, function g() { self.removeListener(type, g); listener.apply(this, arguments); }); return this; }; EventEmitter.prototype.removeListener = function(type, listener) { if ('function' !== typeof listener) { throw new Error('removeListener only takes instances of Function'); } // does not use listeners(), so no side effect of creating _events[type] if (!this._events || !this._events[type]) return this; var list = this._events[type]; if (isArray(list)) { var i = indexOf(list, listener); if (i < 0) return this; list.splice(i, 1); if (list.length == 0) delete this._events[type]; } else if (this._events[type] === listener) { delete this._events[type]; } return this; }; EventEmitter.prototype.removeAllListeners = function(type) { if (arguments.length === 0) { this._events = {}; return this; } // does not use listeners(), so no side effect of creating _events[type] if (type && this._events && this._events[type]) this._events[type] = null; return this; }; EventEmitter.prototype.listeners = function(type) { if (!this._events) this._events = {}; if (!this._events[type]) this._events[type] = []; if (!isArray(this._events[type])) { this._events[type] = [this._events[type]]; } return this._events[type]; }; })(require("__browserify_process")) },{"__browserify_process":6}],8:[function(require,module,exports){ var events = require('events'); var util = require('util'); function Stream() { events.EventEmitter.call(this); } util.inherits(Stream, events.EventEmitter); module.exports = Stream; // Backwards-compat with node 0.4.x Stream.Stream = Stream; Stream.prototype.pipe = function(dest, options) { var source = this; function ondata(chunk) { if (dest.writable) { if (false === dest.write(chunk) && source.pause) { source.pause(); } } } source.on('data', ondata); function ondrain() { if (source.readable && source.resume) { source.resume(); } } dest.on('drain', ondrain); // If the 'end' option is not supplied, dest.end() will be called when // source gets the 'end' or 'close' events. Only dest.end() once, and // only when all sources have ended. if (!dest._isStdio && (!options || options.end !== false)) { dest._pipeCount = dest._pipeCount || 0; dest._pipeCount++; source.on('end', onend); source.on('close', onclose); } var didOnEnd = false; function onend() { if (didOnEnd) return; didOnEnd = true; dest._pipeCount--; // remove the listeners cleanup(); if (dest._pipeCount > 0) { // waiting for other incoming streams to end. return; } dest.end(); } function onclose() { if (didOnEnd) return; didOnEnd = true; dest._pipeCount--; // remove the listeners cleanup(); if (dest._pipeCount > 0) { // waiting for other incoming streams to end. return; } dest.destroy(); } // don't leave dangling pipes when there are errors. function onerror(er) { cleanup(); if (this.listeners('error').length === 0) { throw er; // Unhandled stream error in pipe. } } source.on('error', onerror); dest.on('error', onerror); // remove all the event listeners that were added. function cleanup() { source.removeListener('data', ondata); dest.removeListener('drain', ondrain); source.removeListener('end', onend); source.removeListener('close', onclose); source.removeListener('error', onerror); dest.removeListener('error', onerror); source.removeListener('end', cleanup); source.removeListener('close', cleanup); dest.removeListener('end', cleanup); dest.removeListener('close', cleanup); } source.on('end', cleanup); source.on('close', cleanup); dest.on('end', cleanup); dest.on('close', cleanup); dest.emit('pipe', source); // Allow for unix-like usage: A.pipe(B).pipe(C) return dest; }; },{"events":7,"util":9}],3:[function(require,module,exports){ var dnode = require('./lib/dnode'); module.exports = function (cons, opts) { return new dnode(cons, opts); }; },{"./lib/dnode":10}],9:[function(require,module,exports){ var events = require('events'); exports.isArray = isArray; exports.isDate = function(obj){return Object.prototype.toString.call(obj) === '[object Date]'}; exports.isRegExp = function(obj){return Object.prototype.toString.call(obj) === '[object RegExp]'}; exports.print = function () {}; exports.puts = function () {}; exports.debug = function() {}; exports.inspect = function(obj, showHidden, depth, colors) { var seen = []; var stylize = function(str, styleType) { // http://en.wikipedia.org/wiki/ANSI_escape_code#graphics var styles = { 'bold' : [1, 22], 'italic' : [3, 23], 'underline' : [4, 24], 'inverse' : [7, 27], 'white' : [37, 39], 'grey' : [90, 39], 'black' : [30, 39], 'blue' : [34, 39], 'cyan' : [36, 39], 'green' : [32, 39], 'magenta' : [35, 39], 'red' : [31, 39], 'yellow' : [33, 39] }; var style = { 'special': 'cyan', 'number': 'blue', 'boolean': 'yellow', 'undefined': 'grey', 'null': 'bold', 'string': 'green', 'date': 'magenta', // "name": intentionally not styling 'regexp': 'red' }[styleType]; if (style) { return '\033[' + styles[style][0] + 'm' + str + '\033[' + styles[style][1] + 'm'; } else { return str; } }; if (! colors) { stylize = function(str, styleType) { return str; }; } function format(value, recurseTimes) { // Provide a hook for user-specified inspect functions. // Check that value is an object with an inspect function on it if (value && typeof value.inspect === 'function' && // Filter out the util module, it's inspect function is special value !== exports && // Also filter out any prototype objects using the circular check. !(value.constructor && value.constructor.prototype === value)) { return value.inspect(recurseTimes); } // Primitive types cannot have properties switch (typeof value) { case 'undefined': return stylize('undefined', 'undefined'); case 'string': var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '') .replace(/'/g, "\\'") .replace(/\\"/g, '"') + '\''; return stylize(simple, 'string'); case 'number': return stylize('' + value, 'number'); case 'boolean': return stylize('' + value, 'boolean'); } // For some reason typeof null is "object", so special case here. if (value === null) { return stylize('null', 'null'); } // Look up the keys of the object. var visible_keys = Object_keys(value); var keys = showHidden ? Object_getOwnPropertyNames(value) : visible_keys; // Functions without properties can be shortcutted. if (typeof value === 'function' && keys.length === 0) { if (isRegExp(value)) { return stylize('' + value, 'regexp'); } else { var name = value.name ? ': ' + value.name : ''; return stylize('[Function' + name + ']', 'special'); } } // Dates without properties can be shortcutted if (isDate(value) && keys.length === 0) { return stylize(value.toUTCString(), 'date'); } var base, type, braces; // Determine the object type if (isArray(value)) { type = 'Array'; braces = ['[', ']']; } else { type = 'Object'; braces = ['{', '}']; } // Make functions say that they are functions if (typeof value === 'function') { var n = value.name ? ': ' + value.name : ''; base = (isRegExp(value)) ? ' ' + value : ' [Function' + n + ']'; } else { base = ''; } // Make dates with properties first say the date if (isDate(value)) { base = ' ' + value.toUTCString(); } if (keys.length === 0) { return braces[0] + base + braces[1]; } if (recurseTimes < 0) { if (isRegExp(value)) { return stylize('' + value, 'regexp'); } else { return stylize('[Object]', 'special'); } } seen.push(value); var output = keys.map(function(key) { var name, str; if (value.__lookupGetter__) { if (value.__lookupGetter__(key)) { if (value.__lookupSetter__(key)) { str = stylize('[Getter/Setter]', 'special'); } else { str = stylize('[Getter]', 'special'); } } else { if (value.__lookupSetter__(key)) { str = stylize('[Setter]', 'special'); } } } if (visible_keys.indexOf(key) < 0) { name = '[' + key + ']'; } if (!str) { if (seen.indexOf(value[key]) < 0) { if (recurseTimes === null) { str = format(value[key]); } else { str = format(value[key], recurseTimes - 1); } if (str.indexOf('\n') > -1) { if (isArray(value)) { str = str.split('\n').map(function(line) { return ' ' + line; }).join('\n').substr(2); } else { str = '\n' + str.split('\n').map(function(line) { return ' ' + line; }).join('\n'); } } } else { str = stylize('[Circular]', 'special'); } } if (typeof name === 'undefined') { if (type === 'Array' && key.match(/^\d+$/)) { return str; } name = JSON.stringify('' + key); if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) { name = name.substr(1, name.length - 2); name = stylize(name, 'name'); } else { name = name.replace(/'/g, "\\'") .replace(/\\"/g, '"') .replace(/(^"|"$)/g, "'"); name = stylize(name, 'string'); } } return name + ': ' + str; }); seen.pop(); var numLinesEst = 0; var length = output.reduce(function(prev, cur) { numLinesEst++; if (cur.indexOf('\n') >= 0) numLinesEst++; return prev + cur.length + 1; }, 0); if (length > 50) { output = braces[0] + (base === '' ? '' : base + '\n ') + ' ' + output.join(',\n ') + ' ' + braces[1]; } else { output = braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1]; } return output; } return format(obj, (typeof depth === 'undefined' ? 2 : depth)); }; function isArray(ar) { return ar instanceof Array || Array.isArray(ar) || (ar && ar !== Object.prototype && isArray(ar.__proto__)); } function isRegExp(re) { return re instanceof RegExp || (typeof re === 'object' && Object.prototype.toString.call(re) === '[object RegExp]'); } function isDate(d) { if (d instanceof Date) return true; if (typeof d !== 'object') return false; var properties = Date.prototype && Object_getOwnPropertyNames(Date.prototype); var proto = d.__proto__ && Object_getOwnPropertyNames(d.__proto__); return JSON.stringify(proto) === JSON.stringify(properties); } function pad(n) { return n < 10 ? '0' + n.toString(10) : n.toString(10); } var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; // 26 Feb 16:19:34 function timestamp() { var d = new Date(); var time = [pad(d.getHours()), pad(d.getMinutes()), pad(d.getSeconds())].join(':'); return [d.getDate(), months[d.getMonth()], time].join(' '); } exports.log = function (msg) {}; exports.pump = null; var Object_keys = Object.keys || function (obj) { var res = []; for (var key in obj) res.push(key); return res; }; var Object_getOwnPropertyNames = Object.getOwnPropertyNames || function (obj) { var res = []; for (var key in obj) { if (Object.hasOwnProperty.call(obj, key)) res.push(key); } return res; }; var Object_create = Object.create || function (prototype, properties) { // from es5-shim var object; if (prototype === null) { object = { '__proto__' : null }; } else { if (typeof prototype !== 'object') { throw new TypeError( 'typeof prototype[' + (typeof prototype) + '] != \'object\'' ); } var Type = function () {}; Type.prototype = prototype; object = new Type(); object.__proto__ = prototype; } if (typeof properties !== 'undefined' && Object.defineProperties) { Object.defineProperties(object, properties); } return object; }; exports.inherits = function(ctor, superCtor) { ctor.super_ = superCtor; ctor.prototype = Object_create(superCtor.prototype, { constructor: { value: ctor, enumerable: false, writable: true, configurable: true } }); }; var formatRegExp = /%[sdj%]/g; exports.format = function(f) { if (typeof f !== 'string') { var objects = []; for (var i = 0; i < arguments.length; i++) { objects.push(exports.inspect(arguments[i])); } return objects.join(' '); } var i = 1; var args = arguments; var len = args.length; var str = String(f).replace(formatRegExp, function(x) { if (x === '%%') return '%'; if (i >= len) return x; switch (x) { case '%s': return String(args[i++]); case '%d': return Number(args[i++]); case '%j': return JSON.stringify(args[i++]); default: return x; } }); for(var x = args[i]; i < len; x = args[++i]){ if (x === null || typeof x !== 'object') { str += ' ' + x; } else { str += ' ' + exports.inspect(x); } } return str; }; },{"events":7}],2:[function(require,module,exports){ var Stream = require('stream'); var sockjs = require('sockjs-client'); module.exports = function (uri, cb) { if (/^\/\/[^\/]+\//.test(uri)) { uri = window.location.protocol + uri; } else if (!/^https?:\/\//.test(uri)) { uri = window.location.protocol + '//' + window.location.host + (/^\//.test(uri) ? uri : '/' + uri) ; } var stream = new Stream; stream.readable = true; stream.writable = true; var ready = false; var buffer = []; var sock = sockjs(uri); stream.sock = sock; stream.write = function (msg) { if (!ready || buffer.length) buffer.push(msg) else sock.send(msg) }; stream.end = function (msg) { if (msg !== undefined) stream.write(msg); if (!ready) { stream._ended = true; return; } stream.writable = false; sock.close(); }; stream.destroy = function () { stream._ended = true; stream.writable = stream.readable = false; buffer.length = 0 sock.close(); }; sock.onopen = function () { if (typeof cb === 'function') cb(); ready = true; for (var i = 0; i < buffer.length; i++) { sock.send(buffer[i]); } buffer = []; stream.emit('connect'); if (stream._ended) stream.end(); }; sock.onmessage = function (e) { stream.emit('data', e.data); }; sock.onclose = function () { stream.emit('end'); stream.writable = false; stream.readable = false; }; return stream; }; },{"stream":8,"sockjs-client":11}],5:[function(require,module,exports){ module.exports = Level var IDB = require('idb-wrapper') var AbstractLevelDOWN = require('abstract-leveldown').AbstractLevelDOWN var util = require('util') var Iterator = require('./iterator') var isBuffer = require('isbuffer') function Level(location) { if (!(this instanceof Level)) return new Level(location) if (!location) throw new Error("constructor requires at least a location argument") this.location = location } util.inherits(Level, AbstractLevelDOWN) Level.prototype._open = function(options, callback) { var self = this this.idb = new IDB({ storeName: this.location, autoIncrement: false, keyPath: null, onStoreReady: function () { callback && callback(null, self.idb) }, onError: function(err) { callback && callback(err) } }) } Level.prototype._get = function (key, options, callback) { this.idb.get(key, function (value) { if (value === undefined) { // 'NotFound' error, consistent with LevelDOWN API return callback(new Error('NotFound')) } if (options.asBuffer !== false && !isBuffer(value)) value = StringToArrayBuffer(String(value)) return callback(null, value, key) }, callback) } Level.prototype._del = function(id, options, callback) { this.idb.remove(id, callback, callback) } Level.prototype._put = function (key, value, options, callback) { this.idb.put(key, value, function() { callback() }, callback) } Level.prototype.iterator = function (options) { if (typeof options !== 'object') options = {} return new Iterator(this.idb, options) } Level.prototype._batch = function (array, options, callback) { return this.idb.batch(array, function(){ callback() }, callback) } Level.prototype._close = function (callback) { this.idb.db.close() callback() } Level.prototype._approximateSize = function() { throw new Error('Not implemented') } Level.prototype._isBuffer = isBuffer var checkKeyValue = Level.prototype._checkKeyValue = function (obj, type) { if (obj === null || obj === undefined) return new Error(type + ' cannot be `null` or `undefined`') if (obj === null || obj === undefined) return new Error(type + ' cannot be `null` or `undefined`') if (isBuffer(obj) && obj.byteLength === 0) return new Error(type + ' cannot be an empty ArrayBuffer') if (String(obj) === '') return new Error(type + ' cannot be an empty String') if (obj.length === 0) return new Error(type + ' cannot be an empty Array') } function ArrayBufferToString(buf) { return String.fromCharCode.apply(null, new Uint16Array(buf)) } function StringToArrayBuffer(str) { var buf = new ArrayBuffer(str.length * 2) // 2 bytes for each char var bufView = new Uint16Array(buf) for (var i = 0, strLen = str.length; i < strLen; i++) { bufView[i] = str.charCodeAt(i) } return buf } },{"util":9,"./iterator":12,"abstract-leveldown":13,"isbuffer":14,"idb-wrapper":15}],11:[function(require,module,exports){ (function(){/* SockJS client, version 0.3.1.7.ga67f.dirty, http://sockjs.org, MIT License Copyright (c) 2011-2012 VMware, Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ // JSON2 by Douglas Crockford (minified). var JSON;JSON||(JSON={}),function(){function str(a,b){var c,d,e,f,g=gap,h,i=b[a];i&&typeof i=="object"&&typeof i.toJSON=="function"&&(i=i.toJSON(a)),typeof rep=="function"&&(i=rep.call(b,a,i));switch(typeof i){case"string":return quote(i);case"number":return isFinite(i)?String(i):"null";case"boolean":case"null":return String(i);case"object":if(!i)return"null";gap+=indent,h=[];if(Object.prototype.toString.apply(i)==="[object Array]"){f=i.length;for(c=0;c<f;c+=1)h[c]=str(c,i)||"null";e=h.length===0?"[]":gap?"[\n"+gap+h.join(",\n"+gap)+"\n"+g+"]":"["+h.join(",")+"]",gap=g;return e}if(rep&&typeof rep=="object"){f=rep.length;for(c=0;c<f;c+=1)typeof rep[c]=="string"&&(d=rep[c],e=str(d,i),e&&h.push(quote(d)+(gap?": ":":")+e))}else for(d in i)Object.prototype.hasOwnProperty.call(i,d)&&(e=str(d,i),e&&h.push(quote(d)+(gap?": ":":")+e));e=h.length===0?"{}":gap?"{\n"+gap+h.join(",\n"+gap)+"\n"+g+"}":"{"+h.join(",")+"}",gap=g;return e}}function quote(a){escapable.lastIndex=0;return escapable.test(a)?'"'+a.replace(escapable,function(a){var b=meta[a];return typeof b=="string"?b:"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+a+'"'}function f(a){return a<10?"0"+a:a}"use strict",typeof Date.prototype.toJSON!="function"&&(Date.prototype.toJSON=function(a){return isFinite(this.valueOf())?this.getUTCFullYear()+"-"+f(this.getUTCMonth()+1)+"-"+f(this.getUTCDate())+"T"+f(this.getUTCHours())+":"+f(this.getUTCMinutes())+":"+f(this.getUTCSeconds())+"Z":null},String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(a){return this.valueOf()});var cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,escapable=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,gap,indent,meta={"\b":"\\b","\t":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},rep;typeof JSON.stringify!="function"&&(JSON.stringify=function(a,b,c){var d;gap="",indent="";if(typeof c=="number")for(d=0;d<c;d+=1)indent+=" ";else typeof c=="string"&&(indent=c);rep=b;if(!b||typeof b=="function"||typeof b=="object"&&typeof b.length=="number")return str("",{"":a});throw new Error("JSON.stringify")}),typeof JSON.parse!="function"&&(JSON.parse=function(text,reviver){function walk(a,b){var c,d,e=a[b];if(e&&typeof e=="object")for(c in e)Object.prototype.hasOwnProperty.call(e,c)&&(d=walk(e,c),d!==undefined?e[c]=d:delete e[c]);return reviver.call(a,b,e)}var j;text=String(text),cx.lastIndex=0,cx.test(text)&&(text=text.replace(cx,function(a){return"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)}));if(/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,"@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,"]").replace(/(?:^|:|,)(?:\s*\[)+/g,""))){j=eval("("+text+")");return typeof reviver=="function"?walk({"":j},""):j}throw new SyntaxError("JSON.parse")})}() // [*] Including lib/index.js // Public object var SockJS = (function(){ var _document = document; var _window = window; var utils = {}; // [*] Including lib/reventtarget.js /* * ***** BEGIN LICENSE BLOCK ***** * Copyright (c) 2011-2012 VMware, Inc. * * For the license see COPYING. * ***** END LICENSE BLOCK ***** */ /* Simplified implementation of DOM2 EventTarget. * http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-EventTarget */ var REventTarget = function() {}; REventTarget.prototype.addEventListener = function (eventType, listener) { if(!this._listeners) { this._listeners = {}; } if(!(eventType in this._listeners)) { this._listeners[eventType] = []; } var arr = this._listeners[eventType]; if(utils.arrIndexOf(arr, listener) === -1) { arr.push(listener); } return; }; REventTarget.prototype.removeEventListener = function (eventType, listener) { if(!(this._listeners && (eventType in this._listeners))) { return; } var arr = this._listeners[eventType]; var idx = utils.arrIndexOf(arr, listener); if (idx !== -1) { if(arr.length > 1) { this._listeners[eventType] = arr.slice(0, idx).concat( arr.slice(idx+1) ); } else { delete this._listeners[eventType]; } return; } return; }; REventTarget.prototype.dispatchEvent = function (event) { var t = event.type; var args = Array.prototype.slice.call(arguments, 0); if (this['on'+t]) { this['on'+t].apply(this, args); } if (this._listeners && t in this._listeners) { for(var i=0; i < this._listeners[t].length; i++) { this._listeners[t][i].apply(this, args); } } }; // [*] End of lib/reventtarget.js // [*] Including lib/simpleevent.js /* * ***** BEGIN LICENSE BLOCK ***** * Copyright (c) 2011-2012 VMware, Inc. * * For the license see COPYING. * ***** END LICENSE BLOCK ***** */ var SimpleEvent = function(type, obj) { this.type = type; if (typeof obj !== 'undefined') { for(var k in obj) { if (!obj.hasOwnProperty(k)) continue; this[k] = obj[k]; } } }; SimpleEvent.prototype.toString = function() { var r = []; for(var k in this) { if (!this.hasOwnProperty(k)) continue; var v = this[k]; if (typeof v === 'function') v = '[function]'; r.push(k + '=' + v); } return 'SimpleEvent(' + r.join(', ') + ')'; }; // [*] End of lib/simpleevent.js // [*] Including lib/eventemitter.js /* * ***** BEGIN LICENSE BLOCK ***** * Copyright (c) 2011-2012 VMware, Inc. * * For the license see COPYING. * ***** END LICENSE BLOCK ***** */ var EventEmitter = function(events) { this.events = events || []; }; EventEmitter.prototype.emit = function(type) { var that = this; var args = Array.prototype.slice.call(arguments, 1); if (!that.nuked && that['on'+type]) { that['on'+type].apply(that, args); } if (utils.arrIndexOf(that.events, type) === -1) { utils.log('Event ' + JSON.stringify(type) + ' not listed ' + JSON.stringify(that.events) + ' in ' + that); } }; EventEmitter.prototype.nuke = function(type) { var that = this; that.nuked = true; for(var i=0; i<that.events.length; i++) { delete that[that.events[i]]; } }; // [*] End of lib/eventemitter.js // [*] Including lib/utils.js /* * ***** BEGIN LICENSE BLOCK ***** * Copyright (c) 2011-2012 VMware, Inc. * * For the license see COPYING. * ***** END LICENSE BLOCK ***** */ var random_string_chars = 'abcdefghijklmnopqrstuvwxyz0123456789_'; utils.random_string = function(length, max) { max = max || random_string_chars.length; var i, ret = []; for(i=0; i < length; i++) { ret.push( random_string_chars.substr(Math.floor(Math.random() * max),1) ); } return ret.join(''); }; utils.random_number = function(max) { return Math.floor(Math.random() * max); }; utils.random_number_string = function(max) { var t = (''+(max - 1)).length; var p = Array(t+1).join('0'); return (p + utils.random_number(max)).slice(-t); }; // Assuming that url looks like: http://asdasd:111/asd utils.getOrigin = function(url) { url += '/'; var parts = url.split('/').slice(0, 3); return parts.join('/'); }; utils.isSameOriginUrl = function(url_a, url_b) { // location.origin would do, but it's not always available. if (!url_b) url_b = _window.location.href; return (url_a.split('/').slice(0,3).join('/') === url_b.split('/').slice(0,3).join('/')); }; utils.getParentDomain = function(url) { // ipv4 ip address if (/^[0-9.]*$/.test(url)) return url; // ipv6 ip address if (/^\[/.test(url)) return url; // no dots if (!(/[.]/.test(url))) return url; var parts = url.split('.').slice(1); return parts.join('.'); }; utils.objectExtend = function(dst, src) { for(var k in src) { if (src.hasOwnProperty(k)) { dst[k] = src[k]; } } return dst; }; var WPrefix = '_jp'; utils.polluteGlobalNamespace = function() { if (!(WPrefix in _window)) { _window[WPrefix] = {}; } }; utils.closeFrame = function (code, reason) { return 'c'+JSON.stringify([code, reason]); }; utils.userSetCode = function (code) { return code === 1000 || (code >= 3000 && code <= 4999); }; // See: http://www.erg.abdn.ac.uk/~gerrit/dccp/notes/ccid2/rto_estimator/ // and RFC 2988. utils.countRTO = function (rtt) { var rto; if (rtt > 100) { rto = 3 * rtt; // rto > 300msec } else { rto = rtt + 200; // 200msec < rto <= 300msec } return rto; } utils.log = function() { if (_window.console && console.log && console.log.apply) { console.log.apply(console, arguments); } }; utils.bind = function(fun, that) { if (fun.bind) { return fun.bind(that); } else { return function() { return fun.apply(that, arguments); }; } }; utils.flatUrl = function(url) { return url.indexOf('?') === -1 && url.indexOf('#') === -1; }; utils.amendUrl = function(url) { var dl = _document.location; if (!url) { throw new Error('Wrong url for SockJS'); } if (!utils.flatUrl(url)) { throw new Error('Only basic urls are supported in SockJS'); } // '//abc' --> 'http://abc' if (url.indexOf('//') === 0) { url = dl.protocol + url; } // '/abc' --> 'http://localhost:80/abc' if (url.indexOf('/') === 0) { url = dl.protocol + '//' + dl.host + url; } // strip trailing slashes url = url.replace(/[/]+$/,''); return url; }; // IE doesn't support [].indexOf. utils.arrIndexOf = function(arr, obj){ for(var i=0; i < arr.length; i++){ if(arr[i] === obj){ return i; } } return -1; }; utils.arrSkip = function(arr, obj) { var idx = utils.arrIndexOf(arr, obj); if (idx === -1) { return arr.slice(); } else { var dst = arr.slice(0, idx); return dst.concat(arr.slice(idx+1)); } }; // Via: https://gist.github.com/1133122/2121c601c5549155483f50be3da5305e83b8c5df utils.isArray = Array.isArray || function(value) { return {}.toString.call(value).indexOf('Array') >= 0 }; utils.delay = function(t, fun) { if(typeof t === 'function') { fun = t; t = 0; } return setTimeout(fun, t); }; // Chars worth escaping, as defined by Douglas Crockford: // https://github.com/douglascrockford/JSON-js/blob/47a9882cddeb1e8529e07af9736218075372b8ac/json2.js#L196 var json_escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, json_lookup = { "\u0000":"\\u0000","\u0001":"\\u0001","\u0002":"\\u0002","\u0003":"\\u0003", "\u0004":"\\u0004","\u0005":"\\u0005","\u0006":"\\u0006","\u0007":"\\u0007", "\b":"\\b","\t":"\\t","\n":"\\n","\u000b":"\\u000b","\f":"\\f","\r":"\\r", "\u000e":"\\u000e","\u000f":"\\u000f","\u0010":"\\u0010","\u0011":"\\u0011", "\u0012":"\\u0012","\u0013":"\\u0013","\u0014":"\\u0014","\u0015":"\\u0015", "\u0016":"\\u0016","\u0017":"\\u0017","\u0018":"\\u0018","\u0019":"\\u0019", "\u001a":"\\u001a","\u001b":"\\u001b","\u001c":"\\u001c","\u001d":"\\u001d", "\u001e":"\\u001e","\u001f":"\\u001f","\"":"\\\"","\\":"\\\\", "\u007f":"\\u007f","\u0080":"\\u0080","\u0081":"\\u0081","\u0082":"\\u0082", "\u0083":"\\u0083","\u0084":"\\u0084","\u0085":"\\u0085","\u0086":"\\u0086", "\u0087":"\\u0087","\u0088":"\\u0088","\u0089":"\\u0089","\u008a":"\\u008a", "\u008b":"\\u008b","\u008c":"\\u008c","\u008d":"\\u008d","\u008e":"\\u008e", "\u008f":"\\u008f","\u0090":"\\u0090","\u0091":"\\u0091","\u0092":"\\u0092", "\u0093":"\\u0093","\u0094":"\\u0094","\u0095":"\\u0095","\u0096":"\\u0096", "\u0097":"\\u0097","\u0098":"\\u0098","\u0099":"\\u0099","\u009a":"\\u009a", "\u009b":"\\u009b","\u009c":"\\u009c","\u009d":"\\u009d","\u009e":"\\u009e", "\u009f":"\\u009f","\u00ad":"\\u00ad","\u0600":"\\u0600","\u0601":"\\u0601", "\u0602":"\\u0602","\u0603":"\\u0603","\u0604":"\\u0604","\u070f":"\\u070f", "\u17b4":"\\u17b4","\u17b5":"\\u17b5","\u200c":"\\u200c","\u200d":"\\u200d", "\u200e":"\\u200e","\u200f":"\\u200f","\u2028":"\\u2028","\u2029":"\\u2029", "\u202a":"\\u202a","\u202b":"\\u202b","\u202c":"\\u202c","\u202d":"\\u202d", "\u202e":"\\u202e","\u202f":"\\u202f","\u2060":"\\u2060","\u2061":"\\u2061", "\u2062":"\\u2062","\u2063":"\\u2063","\u2064":"\\u2064","\u2065":"\\u2065", "\u2066":"\\u2066","\u2067":"\\u2067","\u2068":"\\u2068","\u2069":"\\u2069", "\u206a":"\\u206a","\u206b":"\\u206b","\u206c":"\\u206c","\u206d":"\\u206d", "\u206e":"\\u206e","\u206f":"\\u206f","\ufeff":"\\ufeff","\ufff0":"\\ufff0", "\ufff1":"\\ufff1","\ufff2":"\\ufff2","\ufff3":"\\ufff3","\ufff4":"\\ufff4", "\ufff5":"\\ufff5","\ufff6":"\\ufff6","\ufff7":"\\ufff7","\ufff8":"\\ufff8", "\ufff9":"\\ufff9","\ufffa":"\\ufffa","\ufffb":"\\ufffb","\ufffc":"\\ufffc", "\ufffd":"\\ufffd","\ufffe":"\\ufffe","\uffff":"\\uffff"}; // Some extra characters that Chrome gets wrong, and substitutes with // something else on the wire. var extra_escapable = /[\x00-\x1f\ud800-\udfff\ufffe\uffff\u0300-\u0333\u033d-\u0346\u034a-\u034c\u0350-\u0352\u0357-\u0358\u035c-\u0362\u0374\u037e\u0387\u0591-\u05af\u05c4\u0610-\u0617\u0653-\u0654\u0657-\u065b\u065d-\u065e\u06df-\u06e2\u06eb-\u06ec\u0730\u0732-\u0733\u0735-\u0736\u073a\u073d\u073f-\u0741\u0743\u0745\u0747\u07eb-\u07f1\u0951\u0958-\u095f\u09dc-\u09dd\u09df\u0a33\u0a36\u0a59-\u0a5b\u0a5e\u0b5c-\u0b5d\u0e38-\u0e39\u0f43\u0f4d\u0f52\u0f57\u0f5c\u0f69\u0f72-\u0f76\u0f78\u0f80-\u0f83\u0f93\u0f9d\u0fa2\u0fa7\u0fac\u0fb9\u1939-\u193a\u1a17\u1b6b\u1cda-\u1cdb\u1dc0-\u1dcf\u1dfc\u1dfe\u1f71\u1f73\u1f75\u1f77\u1f79\u1f7b\u1f7d\u1fbb\u1fbe\u1fc9\u1fcb\u1fd3\u1fdb\u1fe3\u1feb\u1fee-\u1fef\u1ff9\u1ffb\u1ffd\u2000-\u2001\u20d0-\u20d1\u20d4-\u20d7\u20e7-\u20e9\u2126\u212a-\u212b\u2329-\u232a\u2adc\u302b-\u302c\uaab2-\uaab3\uf900-\ufa0d\ufa10\ufa12\ufa15-\ufa1e\ufa20\ufa22\ufa25-\ufa26\ufa2a-\ufa2d\ufa30-\ufa6d\ufa70-\ufad9\ufb1d\ufb1f\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40-\ufb41\ufb43-\ufb44\ufb46-\ufb4e\ufff0-\uffff]/g, extra_lookup; // JSON Quote string. Use native implementation when possible. var JSONQuote = (JSON && JSON.stringify) || function(string) { json_escapable.lastIndex = 0; if (json_escapable.test(string)) { string = string.replace(json_escapable, function(a) { return json_lookup[a]; }); } return '"' + string + '"'; }; // This may be quite slow, so let's delay until user actually uses bad // characters. var unroll_lookup = function(escapable) { var i; var unrolled = {} var c = [] for(i=0; i<65536; i++) { c.push( String.fromCharCode(i) ); } escapable.lastIndex = 0; c.join('').replace(escapable, function (a) { unrolled[ a ] = '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4); return ''; }); escapable.lastIndex = 0; return unrolled; }; // Quote string, also taking care of unicode characters that browsers // often break. Especially, take care of unicode surrogates: // http://en.wikipedia.org/wiki/Mapping_of_Unicode_characters#Surrogates utils.quote = function(string) { var quoted = JSONQuote(string); // In most cases this should be very fast and good enough. extra_escapable.lastIndex = 0; if(!extra_escapable.test(quoted)) { return quoted; } if(!extra_lookup) extra_lookup = unroll_lookup(extra_escapable); return quoted.replace(extra_escapable, function(a) { return extra_lookup[a]; }); } var _all_protocols = ['websocket', 'xdr-streaming', 'xhr-streaming', 'iframe-eventsource', 'iframe-htmlfile', 'xdr-polling', 'xhr-polling', 'iframe-xhr-polling', 'jsonp-polling']; utils.probeProtocols = function() { var probed = {}; for(var i=0; i<_all_protocols.length; i++) { var protocol = _all_protocols[i]; // User can have a typo in protocol name. probed[protocol] = SockJS[protocol] && SockJS[protocol].enabled(); } return probed; }; utils.detectProtocols = function(probed, protocols_whitelist, info) { var pe = {}, protocols = []; if (!protocols_whitelist) protocols_whitelist = _all_protocols; for(var i=0; i<protocols_whitelist.length; i++) { var protocol = protocols_whitelist[i]; pe[protocol] = probed[protocol]; } var maybe_push = function(protos) { var proto = protos.shift(); if (pe[proto]) { protocols.push(proto); } else { if (protos.length > 0) { maybe_push(protos); } } } // 1. Websocket if (info.websocket !== false) { maybe_push(['websocket']); } // 2. Streaming if (pe['xhr-streaming'] && !info.null_origin) { protocols.push('xhr-streaming'); } else { if (pe['xdr-streaming'] && !info.cookie_needed && !info.null_origin) { protocols.push('xdr-streaming'); } else { maybe_push(['iframe-eventsource', 'iframe-htmlfile']); } } // 3. Polling if (pe['xhr-polling'] && !info.null_origin) { protocols.push('xhr-polling'); } else { if (pe['xdr-polling'] && !info.cookie_needed && !info.null_origin) { protocols.push('xdr-polling'); } else { maybe_push(['iframe-xhr-polling', 'jsonp-polling']); } } return protocols; } // [*] End of lib/utils.js // [*] Including lib/dom.js /* * ***** BEGIN LICENSE BLOCK ***** * Copyright (c) 2011-2012 VMware, Inc. * * For the license see COPYING. * ***** END LICENSE BLOCK ***** */ // May be used by htmlfile jsonp and transports. var MPrefix = '_sockjs_global'; utils.createHook = function() { var window_id = 'a' + utils.random_string(8); if (!(MPrefix in _window)) { var map = {}; _window[MPrefix] = function(window_id) { if (!(window_id in map)) { map[window_id] = { id: window_id, del: function() {delete map[window_id];} }; } return map[window_id]; } } return _window[MPrefix](window_id); }; utils.attachMessage = function(listener) { utils.attachEvent('message', listener); }; utils.attachEvent = function(event, listener) { if (typeof _window.addEventListener !== 'undefined') { _window.addEventListener(event, listener, false); } else { // IE quirks. // According to: http://stevesouders.com/misc/test-postmessage.php // the message gets delivered only to 'document', not 'window'. _document.attachEvent("on" + event, listener); // I get 'window' for ie8. _window.attachEvent("on" + event, listener); } }; utils.detachMessage = function(listener) { utils.detachEvent('message', listener); }; utils.detachEvent = function(event, listener) { if (typeof _window.addEventListener !== 'undefined') { _window.removeEventListener(event, listener, false); } else { _document.detachEvent("on" + event, listener); _window.detachEvent("on" + event, listener); } }; var on_unload = {}; // Things registered after beforeunload are to be called immediately. var after_unload = false; var trigger_unload_callbacks = function() { for(var ref in on_unload) { on_unload[ref](); delete on_unload[ref]; }; }; var unload_triggered = function() { if(after_unload) return; after_unload = true; trigger_unload_callbacks(); }; // Onbeforeunload alone is not reliable. We could use only 'unload' // but it's not working in opera within an iframe. Let's use both. utils.attachEvent('beforeunload', unload_triggered); utils.attachEvent('unload', unload_triggered); utils.unload_add = function(listener) { var ref = utils.random_string(8); on_unload[ref] = listener; if (after_unload) { utils.delay(trigger_unload_callbacks); } return ref; }; utils.unload_del = function(ref) { if (ref in on_unload) delete on_unload[ref]; }; utils.createIframe = function (iframe_url, error_callback) { var iframe = _document.createElement('iframe'); var tref, unload_ref; var unattach = function() { clearTimeout(tref); // Explorer had problems with that. try {iframe.onload = null;} catch (x) {} iframe.onerror = null; }; var cleanup = function() { if (iframe) { unattach(); // This timeout makes chrome fire onbeforeunload event // within iframe. Without the timeout it goes straight to // onunload. setTimeout(function() { if(iframe) { iframe.parentNode.removeChild(iframe); } iframe = null; }, 0); utils.unload_del(unload_ref); } }; var onerror = function(r) { if (iframe) { cleanup(); error_callback(r); } }; var post = function(msg, origin) { try { // When the iframe is not loaded, IE raises an exception // on 'contentWindow'. if (iframe && iframe.contentWindow) { iframe.contentWindow.postMessage(msg, origin); } } catch (x) {}; }; iframe.src = iframe_url; iframe.style.display = 'none'; iframe.style.position = 'absolute'; iframe.onerror = function(){onerror('onerror');}; iframe.onload = function() { // `onload` is triggered before scripts on the iframe are // executed. Give it few seconds to actually load stuff. clearTimeout(tref); tref = setTimeout(function(){onerror('onload timeout');}, 2000); }; _document.body.appendChild(iframe); tref = setTimeout(function(){onerror('timeout');}, 15000); unload_ref = utils.unload_add(cleanup); return { post: post, cleanup: cleanup, loaded: unattach }; }; utils.createHtmlfile = function (iframe_url, error_callback) { var doc = new ActiveXObject('htmlfile'); var tref, unload_ref; var iframe; var unattach = function() { clearTimeout(tref); }; var cleanup = function() { if (doc) { unattach(); utils.unload_del(unload_ref); iframe.parentNode.removeChild(iframe); iframe = doc = null; CollectGarbage(); } }; var onerror = function(r) { if (doc) { cleanup(); error_callback(r); } }; var post = function(msg, origin) { try { // When the iframe is not loaded, IE raises an exception // on 'contentWindow'. if (iframe && iframe.contentWindow) { iframe.contentWindow.postMessage(msg, origin); } } catch (x) {}; }; doc.open(); doc.write('<html><s' + 'cript>' + 'document.domain="' + document.domain + '";' + '</s' + 'cript></html>'); doc.close(); doc.parentWindow[WPrefix] = _window[WPrefix]; var c = doc.createElement('div'); doc.body.appendChild(c); iframe = doc.createElement('iframe'); c.appendChild(iframe); iframe.src = iframe_url; tref = setTimeout(function(){onerror(