From 106c85c2f235c5f72c8e9c21eccef4183939e5b8 Mon Sep 17 00:00:00 2001 From: gnovos Date: Thu, 14 Jul 2016 23:47:20 -1000 Subject: [PATCH 01/26] composition server can be launched in express container --- express.js | 79 +++++++++ package.json | 8 + system/base/compositionclient.js | 9 + system/base/define.js | 2 +- system/server/staticserver.js | 295 +++++++++++++++++++++++++++++++ 5 files changed, 392 insertions(+), 1 deletion(-) create mode 100644 express.js create mode 100644 package.json create mode 100644 system/server/staticserver.js diff --git a/express.js b/express.js new file mode 100644 index 00000000..ddc9a110 --- /dev/null +++ b/express.js @@ -0,0 +1,79 @@ +/* DreemGL is a collaboration between Teeming Society & Samsung Electronics, sponsored by Samsung and others. + Copyright 2015-2016 Teeming Society. Licensed under the Apache License, Version 2.0 (the "License"); You may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License.*/ + +require = require('./system/base/define') + +define.paths = { + 'system':'$root/system', + 'resources':'$root/resources', + '3d':'$root/classes/3d', + 'behaviors':'$root/classes/behaviors', + 'server':'$root/classes/server', + 'ui':'$root/classes/ui', + 'flow':'$root/classes/flow', + 'testing':'$root/classes/testing', + 'widgets':'$root/classes/widgets', + 'sensors':'$root/classes/sensors', + 'iot':'$root/classes/iot', + 'examples':'$root/examples', + 'apps':'$root/apps', + 'docs':'$root/docs', + 'test':'$root/test' +} + +require('$system/base/math') + +Object.defineProperty(define, "$writefile", { + value: false, + writable: false +}); + +Object.defineProperty(define, "$unsafeorigin", { + value: false, + writable: false +}); + +define.$platform = 'nodejs' +for (var key in define.paths) { + define['$' + key] = define.paths[key] +} + +var StaticServer = require('$system/server/staticserver') + +var express = require('express'); +var app = express(); + +app.use('/system', express.static('system')); +app.use('/examples', express.static('examples')); +app.use('/apps', express.static('apps')); +app.use('/docs', express.static('docs')); +app.use('/resources', express.static('resources')); +app.use('/test', express.static('test')); +app.use('/ui', express.static('classes/ui')); +app.use('/3d', express.static('classes/3d')); +app.use('/server', express.static('classes/server')); +app.use('/behaviors', express.static('classes/behaviors')); +app.use('/flow', express.static('classes/flow')); +app.use('/testing', express.static('classes/testing')); +app.use('/widgets', express.static('classes/widgets')); +app.use('/iot', express.static('classes/iot')); +app.use('/sensors', express.static('classes/sensors')); + +app.get('/', function (req, res) { + console.log("got request") + + var compname = "$examples/sliders" + + var compositionserver = new StaticServer(compname, { + bus:{name:"dummybus", broadcast:function() { console.log("broadcasing:", arguments) }} + }) + + compositionserver.request(req, res) +}); + +app.listen(3000, function () { + console.log('Example app listening on port 3000!'); +}); diff --git a/package.json b/package.json new file mode 100644 index 00000000..44a69cde --- /dev/null +++ b/package.json @@ -0,0 +1,8 @@ +{ + "name": "DreemGLx", + "version": "0.0.1", + "devDependencies": {}, + "dependencies": { + "express": "^4.14.0" + } +} diff --git a/system/base/compositionclient.js b/system/base/compositionclient.js index d9258764..7ccff77c 100644 --- a/system/base/compositionclient.js +++ b/system/base/compositionclient.js @@ -68,6 +68,15 @@ define.class('./compositionbase', function(require, baseclass){ } if(previous || parent) this.doRender(previous, parent) + + if (typeof(define.$rendertimeout) !== "undefined") { + setTimeout(function() { + if (!this.rendered) { + this.doRender() + } + }.bind(this), define.$rendertimeout) + } + } this.doRender = function(previous, parent){ diff --git a/system/base/define.js b/system/base/define.js index 89981cb8..212165b7 100644 --- a/system/base/define.js +++ b/system/base/define.js @@ -178,7 +178,7 @@ define.expandVariables = function(str){ return define.cleanPath(str.replace(/(\$[a-zA-Z0-9]+[a-zA-Z0-9]*)/g, function(all, lut){ if(!(lut in define)){ - throw new Error("Cannot find " + lut + " used in require") + throw new Error("Cannot find " + lut + " used in require of " + Object.keys(define)) } return define.expandVariables(define[lut]) })) diff --git a/system/server/staticserver.js b/system/server/staticserver.js new file mode 100644 index 00000000..9a4832be --- /dev/null +++ b/system/server/staticserver.js @@ -0,0 +1,295 @@ +/* DreemGL is a collaboration between Teeming Society & Samsung Electronics, sponsored by Samsung and others. + Copyright 2015-2016 Teeming Society. Licensed under the Apache License, Version 2.0 (the "License"); You may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License.*/ + +// parse a color string into a [r,g,b] 0-1 float array + +define.class(function(require){ + + var fs = require('fs') + + this.atConstructor = function( + compname, //String: name of the composition + options){ //TeemServer: teem server object + + if (!options) { + options = {} + } + + this.compname = compname + + //xxx root server is now gone, deal with options + + this.busserver = options.bus + + if (!this.busserver) { + var BusServer = require('$system/rpc/busserver') + this.busserver = new BusServer() + } + + // lets give it a session + this.session = Math.random() * 1000000 + + this.components = {} + + this.paths = "" + this.pathset = '{' + + for(var key in define.paths){ + if (this.paths) { + this.paths += ',\n\t\t' + this.pathset += ',' + } + this.paths += '$'+key+':"$root/'+key+'"' + this.pathset += '"'+key+'":1' + } + this.pathset += '}' + + if (typeof(options.init) === "function") { + options.init.call(this) + } + + // + this.reload() + } + + // Called when any of the dependent files change for this composition + this.atChange = function(){ + } + + // Destroys all objects maintained by the composition + this.destroy = function(){ + if(this.mycomposition && this.mycomposition.destroy) this.mycomposition.destroy() + this.mycomposition = undefined + } + + this.loadComposition = function(){ + console.log("Reloading composition "+this.filename) + require.clearCache() + var Composition = require(define.expandVariables(this.filename)) //xxx load from external source, not just file system? + this.composition = new Composition(this.busserver, this.session, this.composition) + } + + this.reload = function(){ + this.destroy() + + // lets fill + require.clearCache() + + this.title = define.fileName(this.compname) + // lets see if our composition is a dir or a jsfile + var jsname = this.compname+'.js' + try{ + if(fs.existsSync(define.expandVariables(jsname))){ + this.filename = jsname + return this.loadComposition() + } + else{ + var jsname = this.compname + '/index.js' + if(fs.existsSync(define.expandVariables(jsname))){ + this.filename = jsname + return this.loadComposition() + } + } + } + catch(e){ + console.log(e.stack) + } + finally{ + } + } + + this.loadHTML = function(title, boot, paths, pathset){ + + // These rpc attributes we will write directly into the header so that they are available even before the screen connects + var preloadattrs = {}; + + var additionalHeader = ""; + + if (this.composition) { + + // preload_rpc_attributes can be `true` to include everything or an array of `rpcobj_rpcattr` identifiers + var preload = this.composition.preload_rpc_attributes; + if (preload === true) { + preloadattrs = this.composition.server_attributes; + } else if (Array.isArray(preload)) { + for (var i = 0; i< preload.length;i++) { + var key = preload[i]; + var attr = this.composition.server_attributes[key]; + if (attr) { + preloadattrs[key] = attr + } + } + } + additionalHeader = this.composition.headHTML || ""; + } + + + return '\n'+ //xxx make template + ' \n'+ + ' \n'+ + ' \n'+ + ' \n'+ + ' \n'+ + ' \n'+ + ' ' + title + '\n'+ + ' '+ + ' \n'+ + ' \n'+ + additionalHeader + + ' \n'+ + ' \n'+ + ' \n'+ + '\n' + } + + this.request = function(req, res){ + var base = req.url.split('?')[0] + //var app = base.split('/')[2] || 'browser' + // ok lets serve our Composition device + + if(req.method == 'POST'){ + // lets do an RPC call + + if(!define.$unsafeorigin && this.rootserver.addresses.indexOf(req.headers.origin) === -1){ //xxx + console.log("WRONG ORIGIN POST API RECEIVED" + req.headers.origin) + res.end() + return false + } + + var boundary; + if (req.headers && req.headers['content-type']) { + var type = req.headers['content-type']; + if (type) { + var m = /^multipart\/form-data; boundary=(.*)$/.exec(type) + + if (m) { + boundary = m[1]; + } + } + } + + var buffer; + req.on('data', function(data){ + if (boundary) { + if (!buffer) { + buffer = new Buffer(data) + } else { + buffer = Buffer.concat([buffer, data]) + } + } + }) + req.on('end', function(){ + + if (boundary && buffer && buffer.indexOf) { + + var cursor = buffer.indexOf(boundary) + boundary.length; + + cursor = buffer.indexOf("filename=", cursor) + "filename=".length; + var q = buffer[cursor]; + var filename = buffer.slice(cursor + 1, buffer.indexOf(q, cursor + 1)).toString(); + cursor = buffer.indexOf("\r\n\r\n", cursor) + "\r\n\r\n".length; + + var filedata = buffer.slice(cursor, buffer.indexOf("\r\n--" + boundary)); + + var compfile = this.composition.constructor.module.filename; + var compdir = compfile.substring(0, compfile.lastIndexOf('/')); + + filename = compdir + "/" + filename.replace(/[^A-Za-z0-9_.-]/g,''); + + if (!define.$writefile){ + console.log("writefile api disabled, use -writefile to turn it on. Writefile api is always limited to localhost origins.") + res.writeHead(501); + } else { + try{ + var fullname = define.expandVariables(filename); + fs.writeFile(fullname, filedata); + console.log("[UPLOAD] Wrote", filedata.length, "bytes to", fullname); + res.writeHead(200); + } + catch(e){ + res.writeHead(503); + } + } + + res.end(); + return + } else if (buffer) { + try{ + var json = JSON.parse(buffer.toString()) + this.composition.postAPI(json, {send:function(msg){ + res.writeHead(200, {"Content-Type":"text/json"}) + res.write(JSON.stringify(msg)) + res.end() + }}) + } + catch(e){ + res.writeHead(500, {"Content-Type": "text/html"}) + res.write('FAIL') + res.end() + return + } + } else { + res.writeHead(500, {"Content-Type": "text/html"}) + res.write('FAIL') + res.end() + return + } + }.bind(this)) + return + } // move up + + var header = { + "Cache-control": "max-age=0", + "Content-Type": "text/html" + } + //var screen = this.screens[app] + + // nodejs root + if(req.headers['client-type'] === 'nodejs'){ + res.writeHead(200, {"Content-type":"text/json"}) + res.write(JSON.stringify({title:this.title, boot:this.filename, paths:define.paths })) + res.end() + return + } + + if (! this.filename) { + res.writeHead(404, header) + res.write('Sorry, we could not find an application at that URL. Try reading the documentation?') + res.end() + return + } + var html = this.loadHTML(this.title, this.filename, this.paths, this.pathset) + res.writeHead(200, header) + res.write(html) + res.end() + } +}) From d75797f5675dada437f359768338ecb11c689ace Mon Sep 17 00:00:00 2001 From: gnovos Date: Thu, 21 Jul 2016 13:08:58 -1000 Subject: [PATCH 02/26] still a spaghetti code mess, but firebase-bus now fully works with RPC --- express.js | 15 ++- package.json | 3 +- system/base/define.js | 6 +- system/platform/webgl/compositionwebgl.js | 11 +- system/rpc/firebase.json | 12 ++ system/rpc/firebusclient.js | 81 +++++++++++++ system/rpc/firebusserver.js | 138 ++++++++++++++++++++++ system/server/staticserver.js | 116 ++---------------- test/firebus.js | 59 +++++++++ 9 files changed, 327 insertions(+), 114 deletions(-) create mode 100644 system/rpc/firebase.json create mode 100644 system/rpc/firebusclient.js create mode 100644 system/rpc/firebusserver.js create mode 100644 test/firebus.js diff --git a/express.js b/express.js index ddc9a110..9809bcd1 100644 --- a/express.js +++ b/express.js @@ -62,17 +62,22 @@ app.use('/widgets', express.static('classes/widgets')); app.use('/iot', express.static('classes/iot')); app.use('/sensors', express.static('classes/sensors')); +this.compservers = {} + app.get('/', function (req, res) { console.log("got request") - var compname = "$examples/sliders" + var compname = "$test/firebus" - var compositionserver = new StaticServer(compname, { - bus:{name:"dummybus", broadcast:function() { console.log("broadcasing:", arguments) }} - }) + var compositionserver = this.compservers[compname] + if (!compositionserver) { + this.compservers[compname] = compositionserver = new StaticServer(compname, { + busclass:'$system/rpc/firebusserver' + }) + } compositionserver.request(req, res) -}); +}.bind(this)); app.listen(3000, function () { console.log('Example app listening on port 3000!'); diff --git a/package.json b/package.json index 44a69cde..57d96b9f 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "0.0.1", "devDependencies": {}, "dependencies": { - "express": "^4.14.0" + "express": "^4.14.0", + "firebase": "^3.2.0" } } diff --git a/system/base/define.js b/system/base/define.js index 212165b7..0c196a08 100644 --- a/system/base/define.js +++ b/system/base/define.js @@ -1282,7 +1282,11 @@ } } } - define.autoreloadConnect() + + if (define.$autoreloadConnect !== false) { + define.autoreloadConnect() + } + } diff --git a/system/platform/webgl/compositionwebgl.js b/system/platform/webgl/compositionwebgl.js index bf373361..8c29077f 100644 --- a/system/platform/webgl/compositionwebgl.js +++ b/system/platform/webgl/compositionwebgl.js @@ -8,8 +8,10 @@ define.class('$system/base/compositionclient', function(require, baseclass){ var Device = require('$system/platform/$platform/device$platform') - var WebRTC = require('$system/rpc/webrtc') - var BusClient = require('$system/rpc/busclient') + var BusClients = { + '$system/rpc/busclient':require('$system/rpc/busclient'), + '$system/rpc/firebusclient':require('$system/rpc/firebusclient') + } this.atConstructor = function(previous, parent, precached, canvas){ window.composition = this @@ -29,7 +31,10 @@ define.class('$system/base/compositionclient', function(require, baseclass){ } this.createBus = function(){ - this.bus = new BusClient((location.href.indexOf('https') === 0?'wss://':'ws://')+location.host+location.pathname) + this.bus = new BusClients[define.$busclass || '$system/rpc/busclient']((location.href.indexOf('https') === 0?'wss://':'ws://')+location.host+location.pathname) + if (this.bus.connect) { + this.bus.connect() + } } this.doRender = function(previous, parent){ diff --git a/system/rpc/firebase.json b/system/rpc/firebase.json new file mode 100644 index 00000000..a60ab069 --- /dev/null +++ b/system/rpc/firebase.json @@ -0,0 +1,12 @@ +{ + "type": "service_account", + "project_id": "dreembase", + "private_key_id": "5d69d13612aa7ac75bd1e8a405a945f09b7b92cf", + "private_key": "-----BEGIN PRIVATE KEY-----\n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\naVNrxYl8FSd503nQ6vZFs/m8GMd2xQ==\n-----END PRIVATE KEY-----\n", + "client_email": "dreembase@dreembase.iam.gserviceaccount.com", + "client_id": "104362130042575267591", + "auth_uri": "https://accounts.google.com/o/oauth2/auth", + "token_uri": "https://accounts.google.com/o/oauth2/token", + "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", + "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/dreembase%40dreembase.iam.gserviceaccount.com" +} diff --git a/system/rpc/firebusclient.js b/system/rpc/firebusclient.js new file mode 100644 index 00000000..6ec8b121 --- /dev/null +++ b/system/rpc/firebusclient.js @@ -0,0 +1,81 @@ +/* DreemGL is a collaboration between Teeming Society & Samsung Electronics, sponsored by Samsung and others. + Copyright 2015-2016 Teeming Society. Licensed under the Apache License, Version 2.0 (the "License"); You may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License.*/ +// BusClient class, always available auto reconnecting socket + +define.class(function(require, exports){ + + this.atConstructor = function(url){ + this.url = url || '' + } + + this.connect = function() { + + firebase.initializeApp({ //xxx + apiKey: "AIzaSyDAsFR7KNvqOxBv3go8qWb1y7YRMwaw22U", + authDomain: "dreembase.firebaseapp.com", + databaseURL: "https://dreembase.firebaseio.com", + storageBucket: "dreembase.appspot.com" + }); + + var db = this.db = firebase.database(); + + this.clients = db.ref("clients"); + + this.reconnect() + } + + this.disconnect = function(){ + + if (this.clientid) { + console.log("disconnect fbcleint", this.clientid) + this.db.ref().child("clientQ" + this.clientid).remove() + this.clientid = undefined + } + } + + this.sendJSON = this.send = function(msg){ + console.log("sssend fbcleint", msg) + + var packet = { + client: this.clientid, + payload: JSON.stringify(msg) + } + + console.log("sending packet", packet) + + this.out.push(packet) + } + + // Reconnect to server (used internally and automatically) + this.reconnect = function(){ + this.disconnect() + if(!this.queue) this.queue = [] + + var clientid = this.clientid = this.clients.push({url:this.url}).key + + console.log("clientID", clientid) + + this.out = this.db.ref().child("serverQ"); + + this.messages = this.db.ref("clientQ" + clientid) + this.readyState = 1 + + this.messages.on("child_added", function(snap) { + var msg = snap.val() + snap.ref.remove() + console.log("client got incoming message", msg.key, msg) + this.atMessage(msg, this) + }.bind(this)) + + console.log("fbcleitn reconnect") + + } + + // Called when a message is received + this.atMessage = function(message){ + console.log("fbclient atmessage XX", message) + } +}) diff --git a/system/rpc/firebusserver.js b/system/rpc/firebusserver.js new file mode 100644 index 00000000..e99def25 --- /dev/null +++ b/system/rpc/firebusserver.js @@ -0,0 +1,138 @@ +/* DreemGL is a collaboration between Teeming Society & Samsung Electronics, sponsored by Samsung and others. + Copyright 2015-2016 Teeming Society. Licensed under the Apache License, Version 2.0 (the "License"); You may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License.*/ +// BusServer class, a package of websockets you can broadcast on (server side) + +define.class(function(require, exports){ + + var firebase = require("firebase"); + + // Initialize the app with a service account, granting admin privileges + firebase.initializeApp({ + databaseURL: "https://dreembase.firebaseio.com/", + serviceAccount: __dirname + "/firebase.json" + }); + + this.atConstructor = function(){ + this.clients = {} + + this.db = firebase.database(); + + this.db.ref().once("value", function(s){ + console.log("loks like", s.val()) + }) + + var q = this.q = this.db.ref("serverQ"); + q.on('child_added', function(msg) { + var message = msg.val() + msg.ref.remove() + console.log("incoming message:", message) + var clientid = message.client; + var data = JSON.parse(message.payload) + var client = this.clients[clientid]; + this.atMessage(data, client) + }.bind(this)) + + var connections = this.connections = this.db.ref("clients"); + connections.on('child_added', function(snapshot) { + var clientid = snapshot.key + var connection = snapshot.val() +// snapshot.ref.remove() + + console.log("got connection", clientid, connection) + + var clientQ = this.db.ref("clientQ" + clientid) + clientQ.sendJSON = clientQ.push + clientQ.readyState = 1 + + this.clients[clientid] = clientQ; + this.atConnect(clientQ) + + // var messages = this.messages = this.db.ref().child("serverQ"); + // messages.on('child_added', function(ss) { + // var message = ss.val() + // var cid = ss.ref.parent.key; + // console.log('cid', cid) + // var clientQ = this.db.ref("clientQ/" + cid) + // clientQ.sendJSON = clientQ.push + // ss.ref.remove() + // + // console.log("got qmessage FROM>", "FOR>", cid, message) + // + // this.atMessage(message, clientQ) + // }.bind(this)); + // + // var clientQ = this.db.ref().child("clientQ/" + clientid) + + }.bind(this)); + + } + + // called when a new message arrives + this.atMessage = function(message, socket){ + console.log("at message fbserver", message, socket) + } + + // called when a client disconnects + this.atClose = function(socket){ + console.log("at close fbserver", socket) + } + + // Called when a new socket appears on the bus + this.atConnect = function(message, socket){ + console.log("at connect fbserver", message, socket) + } + + this.broadcast = function(message, ignore){ + for(var i = 0;i>>", snapshot.val()); +// }); +// +// var screenData = { +// name: "default" +// }; +// +// setInterval(function () { +// ref.push({data:"connect"}) +// ref.push({data:"connect"}) +// ref.push({data:"connect"}) +// ref.push({data:"connect"}) +// }, 2000) diff --git a/system/server/staticserver.js b/system/server/staticserver.js index 9a4832be..32baea1a 100644 --- a/system/server/staticserver.js +++ b/system/server/staticserver.js @@ -9,6 +9,7 @@ define.class(function(require){ var fs = require('fs') + var path = require('path') this.atConstructor = function( compname, //String: name of the composition @@ -20,14 +21,13 @@ define.class(function(require){ this.compname = compname - //xxx root server is now gone, deal with options + this.rootdir = path.normalize(__dirname + "/../..") + console.log("rd", this.rootdir) - this.busserver = options.bus + //xxx root server is now gone, deal with options - if (!this.busserver) { - var BusServer = require('$system/rpc/busserver') - this.busserver = new BusServer() - } + var BusServer = require(options.busclass || '$system/rpc/busserver') + this.busserver = new BusServer() // lets give it a session this.session = Math.random() * 1000000 @@ -66,7 +66,7 @@ define.class(function(require){ } this.loadComposition = function(){ - console.log("Reloading composition "+this.filename) + console.log("Reloading composition "+this.filename, this.session) require.clearCache() var Composition = require(define.expandVariables(this.filename)) //xxx load from external source, not just file system? this.composition = new Composition(this.busserver, this.session, this.composition) @@ -143,9 +143,12 @@ define.class(function(require){ ' }\n'+ ' body {background-color:white;margin:0;padding:0;height:100%;overflow:hidden;}\n'+ ' '+ + '' + ' \n" + } + } + + if (this.options.defines) { + for (var defkey in this.options.defines) { + var defval = this.options.defines[defkey] + additionalDefines += '$' + defkey + ':' + defval + ',\n' + } + } + } + + return '\n'+ //TODO: xxx make this a template loadable from options ' \n'+ ' \n'+ ' \n'+ @@ -144,8 +174,10 @@ define.class(function(require){ ' }\n'+ ' body {background-color:white;margin:0;padding:0;height:100%;overflow:hidden;}\n'+ ' '+ + additionalScripts + ' \n" + additionalScripts += '\n' } } @@ -173,7 +173,7 @@ define.class(function(require){ ' -user-select: none;\n'+ ' }\n'+ ' body {background-color:white;margin:0;padding:0;height:100%;overflow:hidden;}\n'+ - ' '+ + ' \n'+ additionalScripts + ' ' + - ' \n'+ - ' \n'+ - additionalHeader + - ' \n'+ - ' \n'+ - ' \n'+ - '\n' - } - - this.request = function(req, res){ - var header = { - "Cache-control": "max-age=0", - "Content-Type": "text/html" - } - - // nodejs root - if(req.headers['client-type'] === 'nodejs'){ - res.writeHead(200, {"Content-type":"text/json"}) - res.write(JSON.stringify({title:this.title, boot:this.filename, paths:define.paths })) - res.end() - return - } - - if (!this.filename) { - res.writeHead(404, header) - res.write('Sorry, we could not find an application at that URL. Try reading the documentation?') - res.end() - return - } - var html = this.loadHTML(this.title, this.filename, this.paths, this.pathset) - res.writeHead(200, header) - res.write(html) - res.end() - } -}) From 8de13467769996d172ad36b171c7b51baa75ad5b Mon Sep 17 00:00:00 2001 From: gnovos Date: Fri, 5 Aug 2016 12:11:52 -1000 Subject: [PATCH 10/26] move firebase options up a level --- system/adapters/expressadapter.js | 30 +++++++++++++++++--------- system/{rpc => adapters}/firebase.json | 0 system/rpc/firebusclient.js | 10 ++++----- system/rpc/firebusserver.js | 6 +----- system/server/compositionserver.js | 4 ++++ 5 files changed, 30 insertions(+), 20 deletions(-) rename system/{rpc => adapters}/firebase.json (100%) diff --git a/system/adapters/expressadapter.js b/system/adapters/expressadapter.js index 98db16d9..d256ed83 100644 --- a/system/adapters/expressadapter.js +++ b/system/adapters/expressadapter.js @@ -20,6 +20,26 @@ define.paths = { 'test':'$root/test' } +// Initialize the app with a service account, granting admin privileges +define.$firebusConfig = { + databaseURL: "https://dreembase.firebaseio.com/", + serviceAccount: __dirname + "/firebase.json" +} + +var args = {} +var options = { + busclass: '$system/rpc/firebusserver', + scripts: ['https://www.gstatic.com/firebasejs/3.2.0/firebase.js'], + defines: { + autoreloadConnect:false, + busclass:"$system/rpc/firebusclient", + firebaseApiKey: "AIzaSyDAsFR7KNvqOxBv3go8qWb1y7YRMwaw22U", + firebaseAuthDomain: "dreembase.firebaseapp.com", + firebaseDatabaseURL: "https://dreembase.firebaseio.com", + firebaseStorageBucket: "dreembase.appspot.com" + } +} + for (var key in define.paths) { define['$' + key] = define.paths[key] } @@ -36,16 +56,6 @@ var CompositionServer = exports.server = require('$system/server/compositionserv CompositionServer.compservers = {} -var args = {} -var options = { - busclass: '$system/rpc/firebusserver', - scripts: ['https://www.gstatic.com/firebasejs/3.2.0/firebase.js'], - defines: { - autoreloadConnect:false, - busclass:'"$system/rpc/firebusclient"' - } -} - exports.requestHandler = function (req, res) { var compname = "$" + req.path.substr(1) diff --git a/system/rpc/firebase.json b/system/adapters/firebase.json similarity index 100% rename from system/rpc/firebase.json rename to system/adapters/firebase.json diff --git a/system/rpc/firebusclient.js b/system/rpc/firebusclient.js index 88f89d2a..31a4da0d 100644 --- a/system/rpc/firebusclient.js +++ b/system/rpc/firebusclient.js @@ -15,11 +15,11 @@ define.class(function(require, exports){ this.connect = function() { - firebase.initializeApp({ //xxx - apiKey: "AIzaSyDAsFR7KNvqOxBv3go8qWb1y7YRMwaw22U", - authDomain: "dreembase.firebaseapp.com", - databaseURL: "https://dreembase.firebaseio.com", - storageBucket: "dreembase.appspot.com" + firebase.initializeApp({ + apiKey: define.$firebaseApiKey, + authDomain: define.$firebaseAuthDomain, + databaseURL: define.$firebaseDatabaseURL, + storageBucket: define.$firebaseStorageBucket }); var db = this.db = firebase.database(); diff --git a/system/rpc/firebusserver.js b/system/rpc/firebusserver.js index b6301a15..09956ef9 100644 --- a/system/rpc/firebusserver.js +++ b/system/rpc/firebusserver.js @@ -9,11 +9,7 @@ define.class(function(require, exports){ var firebase = require("firebase"); - // Initialize the app with a service account, granting admin privileges - firebase.initializeApp({ - databaseURL: "https://dreembase.firebaseio.com/", - serviceAccount: __dirname + "/firebase.json" - }); + firebase.initializeApp(define.$firebusConfig); this.atConstructor = function(channel){ channel = channel.replace(/[\.\/$]/g, "_") diff --git a/system/server/compositionserver.js b/system/server/compositionserver.js index e0d108cd..2135360c 100644 --- a/system/server/compositionserver.js +++ b/system/server/compositionserver.js @@ -153,6 +153,10 @@ define.class(function(require){ if (this.options.defines) { for (var defkey in this.options.defines) { var defval = this.options.defines[defkey] + if (typeof (defval) === 'string') { + defval = '"' + defval +'"' + } + additionalDefines += '$' + defkey + ':' + defval + ',\n' } } From f6b23214246a55da3611cfe9e4aa7a67d8bd2aa6 Mon Sep 17 00:00:00 2001 From: gnovos Date: Fri, 5 Aug 2016 12:56:53 -1000 Subject: [PATCH 11/26] move options fully out of components into top level launcher --- express.js | 22 ++++++++++ .../adapters/firebase.json => firebase.json | 0 system/adapters/expressadapter.js | 41 +++++++++---------- 3 files changed, 41 insertions(+), 22 deletions(-) rename system/adapters/firebase.json => firebase.json (100%) diff --git a/express.js b/express.js index 41aca7ac..8a2ad3a6 100644 --- a/express.js +++ b/express.js @@ -9,8 +9,30 @@ var app = express(); var ExpressAdapter = require('./system/adapters/expressadapter') +// These options will be used when building composition servers, primarily used to configure the firebase bus +define.$compositionOptions = { + busclass: '$system/rpc/firebusserver', + scripts: ['https://www.gstatic.com/firebasejs/3.2.0/firebase.js'], + defines: { + autoreloadConnect:false, + busclass:"$system/rpc/firebusclient", + firebaseApiKey: "AIzaSyDAsFR7KNvqOxBv3go8qWb1y7YRMwaw22U", + firebaseAuthDomain: "dreembase.firebaseapp.com", + firebaseDatabaseURL: "https://dreembase.firebaseio.com", + firebaseStorageBucket: "dreembase.appspot.com" + } +} + +// Needed by the firebase server-side bus +define.$firebusConfig = { + databaseURL: "https://dreembase.firebaseio.com/", + serviceAccount: __dirname + "/firebase.json" +} + +// Configure serving the static JS ExpressAdapter.initStatic(express, app) +// Configure all requests to be handled by the ExpressAdapter.requestHandler app.get('/*', ExpressAdapter.requestHandler); app.listen(3000, function() { diff --git a/system/adapters/firebase.json b/firebase.json similarity index 100% rename from system/adapters/firebase.json rename to firebase.json diff --git a/system/adapters/expressadapter.js b/system/adapters/expressadapter.js index d256ed83..56676964 100644 --- a/system/adapters/expressadapter.js +++ b/system/adapters/expressadapter.js @@ -1,3 +1,19 @@ +// Proccess args +var args = {} +var argv = process.argv +for(var lastkey = '', arg, i = 0; i Date: Fri, 5 Aug 2016 13:22:01 -1000 Subject: [PATCH 12/26] express can handle write-back if option is enabled --- examples/usingtoolkit.js | 2 +- express.js | 2 ++ system/adapters/expressadapter.js | 12 ++++++++++++ system/server/compositionserver.js | 6 +++--- system/server/rootserver.js | 2 +- test/sandbox.js | 8 ++++---- 6 files changed, 23 insertions(+), 9 deletions(-) diff --git a/examples/usingtoolkit.js b/examples/usingtoolkit.js index e35f9f44..b97b3a7f 100644 --- a/examples/usingtoolkit.js +++ b/examples/usingtoolkit.js @@ -18,7 +18,7 @@ define.class("$server/composition",function(require,$ui$,icon,button,checkbox,la toolmove:false, toolrect:false }, - view({height:411,width:441,pickalpha:-1,bgcolor:'white',position:"absolute",x:179,y:156.99998474121094}) + view({height:436,width:207,pickalpha:-1,bgcolor:'white',position:"absolute",x:106,y:102}) ), toolkit({ name:"toolkit", diff --git a/express.js b/express.js index 8a2ad3a6..d9ffe1e0 100644 --- a/express.js +++ b/express.js @@ -11,6 +11,7 @@ var ExpressAdapter = require('./system/adapters/expressadapter') // These options will be used when building composition servers, primarily used to configure the firebase bus define.$compositionOptions = { + whitelist: ['http://0.0.0.0:3000', 'http://127.0.0.1:3000', 'http://localhost:3000'], busclass: '$system/rpc/firebusserver', scripts: ['https://www.gstatic.com/firebasejs/3.2.0/firebase.js'], defines: { @@ -34,6 +35,7 @@ ExpressAdapter.initStatic(express, app) // Configure all requests to be handled by the ExpressAdapter.requestHandler app.get('/*', ExpressAdapter.requestHandler); +app.post('/*', ExpressAdapter.requestHandler); app.listen(3000, function() { console.log("Started express server on port 3000") diff --git a/system/adapters/expressadapter.js b/system/adapters/expressadapter.js index 56676964..3aa2ada8 100644 --- a/system/adapters/expressadapter.js +++ b/system/adapters/expressadapter.js @@ -16,6 +16,18 @@ for(var lastkey = '', arg, i = 0; i Date: Fri, 5 Aug 2016 13:24:20 -1000 Subject: [PATCH 13/26] rename option --- express.js | 2 +- system/server/compositionserver.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/express.js b/express.js index d9ffe1e0..0451ad58 100644 --- a/express.js +++ b/express.js @@ -14,7 +14,7 @@ define.$compositionOptions = { whitelist: ['http://0.0.0.0:3000', 'http://127.0.0.1:3000', 'http://localhost:3000'], busclass: '$system/rpc/firebusserver', scripts: ['https://www.gstatic.com/firebasejs/3.2.0/firebase.js'], - defines: { + clientdefines: { autoreloadConnect:false, busclass:"$system/rpc/firebusclient", firebaseApiKey: "AIzaSyDAsFR7KNvqOxBv3go8qWb1y7YRMwaw22U", diff --git a/system/server/compositionserver.js b/system/server/compositionserver.js index 98a36b7a..e27a27be 100644 --- a/system/server/compositionserver.js +++ b/system/server/compositionserver.js @@ -150,9 +150,9 @@ define.class(function(require){ } } - if (this.options.defines) { - for (var defkey in this.options.defines) { - var defval = this.options.defines[defkey] + if (this.options.clientdefines) { + for (var defkey in this.options.clientdefines) { + var defval = this.options.clientdefines[defkey] if (typeof (defval) === 'string') { defval = '"' + defval +'"' } From 67f4660cea2b00e57043af89f0fd6b647a646ed6 Mon Sep 17 00:00:00 2001 From: gnovos Date: Fri, 5 Aug 2016 15:29:34 -1000 Subject: [PATCH 14/26] include a dummy bus that does nothing for serving serverless compostions --- express.js | 3 +++ system/base/compositionclient.js | 4 +++ system/platform/webgl/compositionwebgl.js | 1 + system/rpc/dummybusclient.js | 25 +++++++++++++++++++ system/rpc/dummybusserver.js | 30 +++++++++++++++++++++++ 5 files changed, 63 insertions(+) create mode 100644 system/rpc/dummybusclient.js create mode 100644 system/rpc/dummybusserver.js diff --git a/express.js b/express.js index 0451ad58..75eba51a 100644 --- a/express.js +++ b/express.js @@ -7,16 +7,19 @@ var express = require('express'); var app = express(); +// The ExpressAdapter helps configure DreemGl to work with express var ExpressAdapter = require('./system/adapters/expressadapter') // These options will be used when building composition servers, primarily used to configure the firebase bus define.$compositionOptions = { whitelist: ['http://0.0.0.0:3000', 'http://127.0.0.1:3000', 'http://localhost:3000'], busclass: '$system/rpc/firebusserver', +// busclass: '$system/rpc/dummybusserver', scripts: ['https://www.gstatic.com/firebasejs/3.2.0/firebase.js'], clientdefines: { autoreloadConnect:false, busclass:"$system/rpc/firebusclient", +// busclass:"$system/rpc/dummybusclient", firebaseApiKey: "AIzaSyDAsFR7KNvqOxBv3go8qWb1y7YRMwaw22U", firebaseAuthDomain: "dreembase.firebaseapp.com", firebaseDatabaseURL: "https://dreembase.firebaseio.com", diff --git a/system/base/compositionclient.js b/system/base/compositionclient.js index a8df1eef..7d392aa2 100644 --- a/system/base/compositionclient.js +++ b/system/base/compositionclient.js @@ -69,6 +69,10 @@ define.class('./compositionbase', function(require, baseclass){ if(previous || parent) this.doRender(previous, parent) + if (define.$busclass === "$system/rpc/dummybusclient" && !define.$rendertimeout) { + define.$rendertimeout = 0 + } + if (typeof(define.$rendertimeout) !== "undefined") { setTimeout(function() { if (!this.rendered) { diff --git a/system/platform/webgl/compositionwebgl.js b/system/platform/webgl/compositionwebgl.js index 8c29077f..6d0387eb 100644 --- a/system/platform/webgl/compositionwebgl.js +++ b/system/platform/webgl/compositionwebgl.js @@ -10,6 +10,7 @@ define.class('$system/base/compositionclient', function(require, baseclass){ var Device = require('$system/platform/$platform/device$platform') var BusClients = { '$system/rpc/busclient':require('$system/rpc/busclient'), + '$system/rpc/dummybusclient':require('$system/rpc/dummybusclient'), '$system/rpc/firebusclient':require('$system/rpc/firebusclient') } diff --git a/system/rpc/dummybusclient.js b/system/rpc/dummybusclient.js new file mode 100644 index 00000000..c9e7056a --- /dev/null +++ b/system/rpc/dummybusclient.js @@ -0,0 +1,25 @@ +/* DreemGL is a collaboration between Teeming Society & Samsung Electronics, sponsored by Samsung and others. + Copyright 2015-2016 Teeming Society. Licensed under the Apache License, Version 2.0 (the "License"); You may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License.*/ +// Dummy BusClient class, does nothing + +define.class(function(require, exports){ + + this.atConstructor = function(url){ + this.url = url || '' + } + + this.connect = function() { + } + + this.disconnect = function() { + } + + this.sendJSON = this.send = function(msg){ + } + + this.atMessage = function(message){ + } +}) diff --git a/system/rpc/dummybusserver.js b/system/rpc/dummybusserver.js new file mode 100644 index 00000000..6e4299ca --- /dev/null +++ b/system/rpc/dummybusserver.js @@ -0,0 +1,30 @@ +/* DreemGL is a collaboration between Teeming Society & Samsung Electronics, sponsored by Samsung and others. + Copyright 2015-2016 Teeming Society. Licensed under the Apache License, Version 2.0 (the "License"); You may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License.*/ +// Dummy BusServer class, does nothing + +define.class(function(require, exports){ + + this.atConstructor = function(channel){ + } + + // called when a new message arrives + this.atMessage = function(message, socket){ + } + + // called when a client disconnects + this.atClose = function(socket){ + } + + // Called when a new socket appears on the bus + this.atConnect = function(message, socket){ + } + + this.broadcast = function(message, ignore){ + } + + this.closeAll = function(){ + } +}) From 3cc71c96cc1e2e5a25fa382891654161b41f9620 Mon Sep 17 00:00:00 2001 From: gnovos Date: Fri, 5 Aug 2016 17:02:29 -1000 Subject: [PATCH 15/26] changes to support NPM --- dreemgl.js | 57 +++++++++++++++++++++++++++++++ express.js | 13 ++++--- firebase.json | 12 ------- package.json | 12 +++++-- system/adapters/expressadapter.js | 57 ++----------------------------- system/base/define.js | 3 +- 6 files changed, 78 insertions(+), 76 deletions(-) create mode 100644 dreemgl.js delete mode 100644 firebase.json diff --git a/dreemgl.js b/dreemgl.js new file mode 100644 index 00000000..66aab892 --- /dev/null +++ b/dreemgl.js @@ -0,0 +1,57 @@ +// Proccess args +var args = {} +var argv = process.argv +for(var lastkey = '', arg, i = 0; i (http://teem.nu)", + "license": "Apache-2.0" } diff --git a/system/adapters/expressadapter.js b/system/adapters/expressadapter.js index 3aa2ada8..49b688d4 100644 --- a/system/adapters/expressadapter.js +++ b/system/adapters/expressadapter.js @@ -1,58 +1,5 @@ -// Proccess args -var args = {} -var argv = process.argv -for(var lastkey = '', arg, i = 0; i Date: Fri, 5 Aug 2016 17:18:33 -1000 Subject: [PATCH 16/26] make express adapter a full dreemgl class --- express.js => examples/express.js | 6 ++--- package.json | 2 +- system/adapters/expressadapter.js | 38 +++++++++++++++++-------------- 3 files changed, 25 insertions(+), 21 deletions(-) rename express.js => examples/express.js (93%) diff --git a/express.js b/examples/express.js similarity index 93% rename from express.js rename to examples/express.js index a5e01dc3..04f0529f 100644 --- a/express.js +++ b/examples/express.js @@ -8,10 +8,10 @@ var express = require('express'); var app = express(); // Launch the platform setup -require = require(__dirname + '/dreemgl') +require = require(__dirname + '/../dreemgl') // The ExpressAdapter helps configure DreemGl to work with express -var ExpressAdapter = require('$system/adapters/expressadapter') +var ExpressAdapter = require('$system/adapters/expressadapter')() // These options will be used when building composition servers, primarily used to configure the firebase bus define.$compositionOptions = { @@ -37,7 +37,7 @@ define.$firebusConfig = { } // Configure serving the static JS -ExpressAdapter.initStatic(express, app) +ExpressAdapter.mountStatic(express, app) // Configure all requests to be handled by the ExpressAdapter.requestHandler app.get('/*', ExpressAdapter.requestHandler); diff --git a/package.json b/package.json index cd636593..a87d885d 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "dreemgl", "main": "dreemgl.js", - "version": "0.0.3", + "version": "0.0.4", "devDependencies": {}, "dependencies": { "express": "^4.14.0", diff --git a/system/adapters/expressadapter.js b/system/adapters/expressadapter.js index 49b688d4..7cecc71e 100644 --- a/system/adapters/expressadapter.js +++ b/system/adapters/expressadapter.js @@ -1,24 +1,28 @@ -// Launch the platform setup -require = require(__dirname + '/../../dreemgl') +define.class(function(require){ -// Serves all the static files in that DreemGL will likely ask for (from define.paths) -exports.initStatic = function(express, app) { - for (var use in define.paths) { - app.use('/' + use, express.static(define.expandVariables(define.paths[use]))); + // Serves all the static files in that DreemGL will likely ask for (from define.paths) + this.mountStatic = function(express, app) { + for (var use in define.paths) { + app.use('/' + use, express.static(define.expandVariables(define.paths[use]))); + } } -} -var CompositionServer = exports.server = require('$system/server/compositionserver') -CompositionServer.compservers = {} + var CompositionServer = require('$system/server/compositionserver') + CompositionServer.compservers = {} -// Request handler Express will use to serve DreemGL -exports.requestHandler = function (req, res) { - var compname = "$" + req.path.substr(1) + // Request handler Express will use to serve DreemGL + this.requestHandler = function (req, res) { + var compname = "$" + req.path.substr(1) - var compositionserver = CompositionServer.compservers[compname] - if (!compositionserver) { - CompositionServer.compservers[compname] = compositionserver = new CompositionServer(define.$args, compname, define.$compositionOptions) + var compositionserver = CompositionServer.compservers[compname] + if (!compositionserver) { + CompositionServer.compservers[compname] = compositionserver = new CompositionServer(define.$args, compname, define.$compositionOptions) + } + + compositionserver.request(req, res) } - compositionserver.request(req, res) -} +}) + + + From 3dcaf4e456da1741fa2f2d278fc07e7811597685 Mon Sep 17 00:00:00 2001 From: gnovos Date: Fri, 5 Aug 2016 17:31:41 -1000 Subject: [PATCH 17/26] more cleanup for NPM --- dreemgl.js | 10 +++++++++- examples/express.js | 2 +- package.json | 6 +++++- system/adapters/expressadapter.js | 19 +++++++++++++------ 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/dreemgl.js b/dreemgl.js index 66aab892..89a7c91c 100644 --- a/dreemgl.js +++ b/dreemgl.js @@ -1,3 +1,9 @@ +/* DreemGL is a collaboration between Teeming Society & Samsung Electronics, sponsored by Samsung and others. + Copyright 2015-2016 Teeming Society. Licensed under the Apache License, Version 2.0 (the "License"); You may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License.*/ + // Proccess args var args = {} var argv = process.argv @@ -49,7 +55,9 @@ define.paths = { } for (var key in define.paths) { - define['$' + key] = define.paths[key] + if (define.paths.hasOwnProperty(key)) { + define['$' + key] = define.paths[key] + } } require('$system/base/math') diff --git a/examples/express.js b/examples/express.js index 04f0529f..878c27d1 100644 --- a/examples/express.js +++ b/examples/express.js @@ -33,7 +33,7 @@ define.$compositionOptions = { // Needed by the firebase server-side bus define.$firebusConfig = { databaseURL: "https://dreembase.firebaseio.com/", - serviceAccount: __dirname + "/firebase.json" + serviceAccount: "firebase.json" } // Configure serving the static JS diff --git a/package.json b/package.json index a87d885d..a86a5ee1 100644 --- a/package.json +++ b/package.json @@ -7,8 +7,12 @@ "express": "^4.14.0", "firebase": "^3.2.0" }, + "repository": { + "type": "git", + "url" : "https://github.com/dreemproject/dreemgl.git" + }, "keywords": [ - "DreemGL" + "DreemGL", "WebGL", "prototyping", "multiscreen", "DALi" ], "author": "Dreem Teem (http://teem.nu)", "license": "Apache-2.0" diff --git a/system/adapters/expressadapter.js b/system/adapters/expressadapter.js index 7cecc71e..c5990b4d 100644 --- a/system/adapters/expressadapter.js +++ b/system/adapters/expressadapter.js @@ -1,26 +1,33 @@ +/* DreemGL is a collaboration between Teeming Society & Samsung Electronics, sponsored by Samsung and others. + Copyright 2015-2016 Teeming Society. Licensed under the Apache License, Version 2.0 (the "License"); You may not use this file except in compliance with the License. + You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and limitations under the License.*/ + define.class(function(require){ - // Serves all the static files in that DreemGL will likely ask for (from define.paths) + var CompositionServer = require('$system/server/compositionserver') + + // Serves all the static files in that DreemGL will likely ask for (from define.paths) this.mountStatic = function(express, app) { for (var use in define.paths) { app.use('/' + use, express.static(define.expandVariables(define.paths[use]))); } } - var CompositionServer = require('$system/server/compositionserver') - CompositionServer.compservers = {} + this.compservers = {} // Request handler Express will use to serve DreemGL this.requestHandler = function (req, res) { var compname = "$" + req.path.substr(1) - var compositionserver = CompositionServer.compservers[compname] + var compositionserver = this.compservers[compname] if (!compositionserver) { - CompositionServer.compservers[compname] = compositionserver = new CompositionServer(define.$args, compname, define.$compositionOptions) + this.compservers[compname] = compositionserver = new CompositionServer(define.$args, compname, define.$compositionOptions) } compositionserver.request(req, res) - } + }.bind(this) }) From 7bff4e379fa070ad695e40c8f51de5a25b1957af Mon Sep 17 00:00:00 2001 From: gnovos Date: Fri, 5 Aug 2016 17:52:18 -1000 Subject: [PATCH 18/26] rename file --- examples/{express.js => express+firebase.js} | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) rename examples/{express.js => express+firebase.js} (90%) diff --git a/examples/express.js b/examples/express+firebase.js similarity index 90% rename from examples/express.js rename to examples/express+firebase.js index 878c27d1..6a5896e3 100644 --- a/examples/express.js +++ b/examples/express+firebase.js @@ -16,13 +16,11 @@ var ExpressAdapter = require('$system/adapters/expressadapter')() // These options will be used when building composition servers, primarily used to configure the firebase bus define.$compositionOptions = { whitelist: ['http://0.0.0.0:3000', 'http://127.0.0.1:3000', 'http://localhost:3000'], -// busclass: '$system/rpc/firebusserver', - busclass: '$system/rpc/dummybusserver', + busclass: '$system/rpc/firebusserver', scripts: ['https://www.gstatic.com/firebasejs/3.2.0/firebase.js'], clientdefines: { autoreloadConnect:false, -// busclass:"$system/rpc/firebusclient", - busclass:"$system/rpc/dummybusclient", + busclass:"$system/rpc/firebusclient", firebaseApiKey: "AIzaSyDAsFR7KNvqOxBv3go8qWb1y7YRMwaw22U", firebaseAuthDomain: "dreembase.firebaseapp.com", firebaseDatabaseURL: "https://dreembase.firebaseio.com", @@ -33,7 +31,7 @@ define.$compositionOptions = { // Needed by the firebase server-side bus define.$firebusConfig = { databaseURL: "https://dreembase.firebaseio.com/", - serviceAccount: "firebase.json" + serviceAccount: process.env.HOME + "/firebase.json" } // Configure serving the static JS From 8a7a90d863c3a7f8a60ed101ffab5516db3a727d Mon Sep 17 00:00:00 2001 From: gnovos Date: Fri, 5 Aug 2016 19:16:04 -1000 Subject: [PATCH 19/26] checking if using img tag works better --- README.md | 2 ++ bin/dreemgl | 2 ++ package.json | 9 +++++++-- 3 files changed, 11 insertions(+), 2 deletions(-) create mode 100755 bin/dreemgl diff --git a/README.md b/README.md index cd1162b1..8019e358 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,8 @@ An overview of the DreemGL's architecture is: ![Architecture Image] (https://raw.githubusercontent.com/dreemproject/dreemgl/dev/docs/images/architecture.png) + + ## Getting Started with DreemGL The fastest way to get started with DreemGL is to walk through [DreemGL in 10 Minutes](http://docs.dreemproject.org/docs/api/index.html#!/guide/dreem_in_10_part1). diff --git a/bin/dreemgl b/bin/dreemgl new file mode 100755 index 00000000..1bc2e726 --- /dev/null +++ b/bin/dreemgl @@ -0,0 +1,2 @@ +#! /usr/bin/env node +console.log("yowza") diff --git a/package.json b/package.json index a86a5ee1..2b828301 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,12 @@ { "name": "dreemgl", "main": "dreemgl.js", - "version": "0.0.4", + "homepage":"https://dreemproject.org/", + "version": "0.0.5", + "preferGlobal": true, + "bin":{ + "dreemgl":"bin/dreemgl" + }, "devDependencies": {}, "dependencies": { "express": "^4.14.0", @@ -12,7 +17,7 @@ "url" : "https://github.com/dreemproject/dreemgl.git" }, "keywords": [ - "DreemGL", "WebGL", "prototyping", "multiscreen", "DALi" + "DreemGL", "WebGL", "prototyping", "multiscreen", "DALi", "IoT" ], "author": "Dreem Teem (http://teem.nu)", "license": "Apache-2.0" From ca3b80563469e066d27285006d419987a4c82660 Mon Sep 17 00:00:00 2001 From: gnovos Date: Fri, 5 Aug 2016 19:23:28 -1000 Subject: [PATCH 20/26] using img tag only --- README.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/README.md b/README.md index 8019e358..7374a6a9 100644 --- a/README.md +++ b/README.md @@ -8,10 +8,7 @@ As a toolkit for gpu-accelerated multiscreen development, DreemGL includes featu * Fast protoyping that allows designers to easily test compositions that connect multiple users in shared experiences on big screens or projections, while allowing each person to use the control tools and preferences they have configured. An overview of the DreemGL's architecture is: -![Architecture Image] -(https://raw.githubusercontent.com/dreemproject/dreemgl/dev/docs/images/architecture.png) - - +Architecture Image ## Getting Started with DreemGL The fastest way to get started with DreemGL is to walk through [DreemGL in 10 Minutes](http://docs.dreemproject.org/docs/api/index.html#!/guide/dreem_in_10_part1). From 71f3fda5633f9fc5fd3aba18d7be62d9994d90db Mon Sep 17 00:00:00 2001 From: gnovos Date: Sun, 7 Aug 2016 14:28:22 -1000 Subject: [PATCH 21/26] Add script to launch dreemgl file from current dir from command line --- README.md | 19 +++++++++ bin/dreemgl | 64 +++++++++++++++++++++++++++++- system/adapters/expressadapter.js | 12 ++++-- system/server/compositionserver.js | 3 +- 4 files changed, 93 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 7374a6a9..a5629093 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,25 @@ An overview of the DreemGL's architecture is: ## Getting Started with DreemGL The fastest way to get started with DreemGL is to walk through [DreemGL in 10 Minutes](http://docs.dreemproject.org/docs/api/index.html#!/guide/dreem_in_10_part1). +### Working with DreemGL NPM + +Install the DreemGl NPM globally to include the `dreemgl` command line standalone launcher. + +`npm install -g dreemgl` + +#### Serve DreemGL from directory + +Dreem can serve files directly from the disk + +`dreemgl -port 3000 ./app.js` + +`dreemgl -port 3000 ./appdir` + + +#### Serve DreemGL from expresss app + +### Working with DreemGL Repository + Once you have downloaded the source from the [master branch of dreemproject in Github](https://github.com/dreemproject/dreemgl), you can start DreemGL by typing: ```node server.js``` diff --git a/bin/dreemgl b/bin/dreemgl index 1bc2e726..dbec2332 100755 --- a/bin/dreemgl +++ b/bin/dreemgl @@ -1,2 +1,64 @@ #! /usr/bin/env node -console.log("yowza") + +var args = {} +var argv = process.argv +for (var lastkey = '', arg, i = 2; i Date: Sun, 7 Aug 2016 14:47:28 -1000 Subject: [PATCH 22/26] update readme to reflect latest features --- README.md | 55 ++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 46 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index a5629093..39502559 100644 --- a/README.md +++ b/README.md @@ -3,36 +3,67 @@ DreemGL is an open-source multi-screen prototyping framework for mediated environments, with a visual editor and shader styling for webGL and DALi runtimes written in JavaScript. As a toolkit for gpu-accelerated multiscreen development, DreemGL includes features such as: + * IoT Integration for Smart Environments that is elegantly simple * Visual layouts and compositions using real data from network services * Fast protoyping that allows designers to easily test compositions that connect multiple users in shared experiences on big screens or projections, while allowing each person to use the control tools and preferences they have configured. -An overview of the DreemGL's architecture is: +An overview of the DreemGL's architecture: Architecture Image ## Getting Started with DreemGL + The fastest way to get started with DreemGL is to walk through [DreemGL in 10 Minutes](http://docs.dreemproject.org/docs/api/index.html#!/guide/dreem_in_10_part1). ### Working with DreemGL NPM -Install the DreemGl NPM globally to include the `dreemgl` command line standalone launcher. +Install the DreemGl NPM globally to include the `dreemgl` command line standalone launcher: `npm install -g dreemgl` -#### Serve DreemGL from directory +#### Serve a single DreemGL composition + +The easiest way to get started quickly is to have DreemGL serve an individual composition using the standalong launcher: + +`dreemgl -port 3000 ./mydreemglapp.js` + +#### Serve DreemGL from within an expresss app + +It's easy to integrate the DreemGL runtime fromw ithin an express app: + +``` +// Create an express app +var express = require('express'); +var app = express(); + +// Init DreemGL setup +require = require('dreemgl') -Dreem can serve files directly from the disk +// These options will be used when building composition servers, use dummy bus for simplicity +define.$compositionOptions = { + busclass: '$system/rpc/dummybusserver', + clientdefines: { busclass:"$system/rpc/dummybusclient" } +} -`dreemgl -port 3000 ./app.js` +// The ExpressAdapter helps configure DreemGl to work with express easily +var ExpressAdapter = require('$system/adapters/expressadapter')() -`dreemgl -port 3000 ./appdir` +// Configure serving the static JS files that DreemGL will ask for +ExpressAdapter.mountStatic(express, app) +// Configure requests to be handled by the ExpressAdapter.requestHandler, in this case everything: +app.get('/*', ExpressAdapter.requestHandler); -#### Serve DreemGL from expresss app +// Start the server listening on port 3000 +app.listen(3000, function() { console.log("Started express server on port 3000") }); + +``` + +A more complex example using the firebase bus can be found in the DreemGL repository at `./examples/express+firebase.js` ### Working with DreemGL Repository -Once you have downloaded the source from the [master branch of dreemproject in Github](https://github.com/dreemproject/dreemgl), you can start DreemGL by typing: +For more complex usage, it's often easier to work outside of the NPM with the full DreemGL stack from the github repository. Once you have downloaded the source from the [master branch of dreemproject in Github](https://github.com/dreemproject/dreemgl), you can start DreemGL by typing: ```node server.js``` @@ -43,6 +74,7 @@ To try livecoding a shader open this: [./test/rendertest.js](/test/rendertest.js) in your editor and start typing away and saving, reload is live. ## Documentation + DreemGL provides an [API reference](http://docs.dreemproject.org/docs/api/index.html#!/api), a [Developer's Guide](http://docs.dreemproject.org/docs/api/index.html#!/guide/devguide), and guides for all components, including the visual layout toolkit, the @@ -54,18 +86,23 @@ DreemGL can generate documentation automatically from all the code in its system Instructions for adding documentation and rebuilding the documentation can be found in the [Developer's Guide](http://docs.dreemproject.org/docs/api/index.html#!/guide/devguide). ##Talk to Us -Have a question? Comment? Something cool to show people? We're all on Slack. Join us: + +Have a question? Comment? Something cool to show people? We're all on Slack. Join us! [![Slack Status](https://dreemproject.herokuapp.com/badge.svg)](https://dreemproject.herokuapp.com/) ## Contributing to DreemGL + Like DreemGL? Get involved. Find more information in the file ["Contributing.md"](https://github.com/dreemproject/dreemgl/blob/master/CONTRIBUTING.md), also in this directory. ### Filing Feature Requests and Bug Reports + DreemGl is an open-source project and uses [JIRA](https://dreem2.atlassian.net/secure/Dashboard.jspa) to track feature requests and bug reports. We encourage you to post your reports here. ## License + This software is licensed under the Apache License, Version 2.0. You will find the terms in the file named ["LICENSE.md"](https://github.com/dreemproject/dreemgl/blob/master/LICENSE.md), also in this directory. ## Attribution + DreemGL is produced in collaboration between [Teeming Society](http://teem.nu) and [Samsung Electronics](http://www.samsung.com/us/), sponsored by Samsung Electronics and others. From 0eb2c33504c3feaf1d9cb91075b293f56c3a0867 Mon Sep 17 00:00:00 2001 From: gnovos Date: Sun, 7 Aug 2016 14:57:49 -1000 Subject: [PATCH 23/26] cleanup some typos --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 39502559..21d48e6f 100644 --- a/README.md +++ b/README.md @@ -23,13 +23,13 @@ Install the DreemGl NPM globally to include the `dreemgl` command line standalon #### Serve a single DreemGL composition -The easiest way to get started quickly is to have DreemGL serve an individual composition using the standalong launcher: +The easiest way to get started quickly is to have DreemGL serve an individual composition using the standalone launcher: `dreemgl -port 3000 ./mydreemglapp.js` #### Serve DreemGL from within an expresss app -It's easy to integrate the DreemGL runtime fromw ithin an express app: +It's easy to integrate the DreemGL runtime from within an express app: ``` // Create an express app From 2ce6b6a7311675900f490f155a4c8128293bc86b Mon Sep 17 00:00:00 2001 From: gnovos Date: Sun, 7 Aug 2016 15:01:17 -1000 Subject: [PATCH 24/26] remove printout --- system/base/compositionclient.js | 1 - 1 file changed, 1 deletion(-) diff --git a/system/base/compositionclient.js b/system/base/compositionclient.js index 7d392aa2..0cb98044 100644 --- a/system/base/compositionclient.js +++ b/system/base/compositionclient.js @@ -121,7 +121,6 @@ define.class('./compositionbase', function(require, baseclass){ if(msg.type == 'sessionCheck'){ if(this.session != msg.session){ if(this.session) { - console.log("session broke?", this.session, msg.session) location.href = location.href } else { this.session = msg.session From 547738d57db57e6ffdb3aab3af656fe34376c7e9 Mon Sep 17 00:00:00 2001 From: gnovos Date: Sun, 7 Aug 2016 15:46:39 -1000 Subject: [PATCH 25/26] cleanup typos in readme --- README.md | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 21d48e6f..af272f5b 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ As a toolkit for gpu-accelerated multiscreen development, DreemGL includes featu * IoT Integration for Smart Environments that is elegantly simple * Visual layouts and compositions using real data from network services -* Fast protoyping that allows designers to easily test compositions that connect multiple users in shared experiences on big screens or projections, while allowing each person to use the control tools and preferences they have configured. +* Fast prototyping that allows designers to easily test compositions that connect multiple users in shared experiences on big screens or projections, while allowing each person to use the control tools and preferences they have configured. An overview of the DreemGL's architecture: Architecture Image diff --git a/package.json b/package.json index 2b828301..e28a78a0 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "dreemgl", "main": "dreemgl.js", "homepage":"https://dreemproject.org/", - "version": "0.0.5", + "version": "0.0.6", "preferGlobal": true, "bin":{ "dreemgl":"bin/dreemgl" From cf9e8704c6898310b2c775f1bf45aa19e51c06c6 Mon Sep 17 00:00:00 2001 From: gnovos Date: Tue, 16 Aug 2016 20:05:50 -1000 Subject: [PATCH 26/26] update email --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e28a78a0..f25a00cc 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,6 @@ "keywords": [ "DreemGL", "WebGL", "prototyping", "multiscreen", "DALi", "IoT" ], - "author": "Dreem Teem (http://teem.nu)", + "author": "Mason ", "license": "Apache-2.0" }