From b60df56157ee1fd0bd4938799bac05a62fda91a1 Mon Sep 17 00:00:00 2001 From: lookshe Date: Sat, 14 Mar 2015 20:45:20 +0100 Subject: initial commit from working version --- client-website/js/symple.js | 385 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 385 insertions(+) create mode 100644 client-website/js/symple.js (limited to 'client-website/js/symple.js') diff --git a/client-website/js/symple.js b/client-website/js/symple.js new file mode 100644 index 0000000..8a3171c --- /dev/null +++ b/client-website/js/symple.js @@ -0,0 +1,385 @@ +// ----------------------------------------------------------------------------- +// 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