// ----------------------------------------------------------------------------- // HTML5 video streaming server // - Uses WebSockets, C++, Node.js and HTML5 JavaScript // var Symple = { // Return an array of nested objects matching // the given key/value strings. filterObject: function(obj, key, value) { // (Object[, String, String]) var r = [] for (var k in obj) { if (obj.hasOwnProperty(k)) { var v = obj[k]; if ((!key || k == key) && (!value || v == value)) { r.push(obj) } else if (typeof v === 'object') { var a = Symple.filterObject(v, key, value); if (a) r = r.concat(a); } } } return r; }, // Delete nested objects with properties // that match the given key/value strings. deleteNested: function(obj, key, value) { // (Object[, String, String]) for (var k in obj) { var v = obj[k]; if ((!key || k == key) && (!value || v == value)) { delete obj[k]; } else if (typeof v === 'object') Symple.deleteNested(v, key); } }, // Count nested object properties which // match the given key/value strings. countNested: function(obj, key, value, count) { if (count === undefined) count = 0; for (var k in obj) { if (obj.hasOwnProperty(k)) { var v = obj[k]; if ((!key || k == key) && (!value || v == value)) { count++; } else if (typeof(v) === 'object') { //else if (v instanceof Object) { count = Symple.countNested(v, key, value, count); } } } return count; }, // Traverse an objects nested properties traverse: function(obj, fn) { // (Object, Function) for (var k in obj) { if (obj.hasOwnProperty(k)) { var v = obj[k]; fn(k, v); if (typeof v === 'object') Symple.traverse(v, fn); } } }, // Generate a random string randomString: function(n) { return Math.random().toString(36).slice(2) //Math.random().toString(36).substring(n || 7); }, // Recursively merge object properties of r into l merge: function(l, r) { // (Object, Object) for (var p in r) { try { // Property in destination object set; update its value. //if (typeof r[p] == "object") { if (r[p].constructor == Object) { l[p] = merge(l[p], r[p]); } else { l[p] = r[p]; } } catch(e) { // Property in destination object not set; // create it and set its value. l[p] = r[p]; } } return l; }, // Object extend functionality extend: function() { var process = function(destination, source) { for (var key in source) { if (hasOwnProperty.call(source, key)) { destination[key] = source[key]; } } return destination; }; var result = arguments[0]; for(var i=1; i