console.time('noflo-ui-init');
console.time('polymer-ready');


window.addEventListener('polymer-ready', function() {
  var noflo = require('noflo');
  var runtime = require('noflo-runtime-webrtc');

  var baseDir = '/noflo-ui';
  var mainGraph = 'noflo-ui/graphs/main.fbp';

  var loadGraphs = function(callback) {
    noflo.graph.loadJSON(require(mainGraph), function (g) {
      g.baseDir = baseDir;
      noflo.createNetwork(g, function (n) {
        n.on('process-error', function (err) {
          console.log(err);
        });
        return callback();
      });
    });
  };
  var loadGraphsDebuggable = function(callback) {
    noflo.graph.loadJSON(require(mainGraph), function (graph) {
      graph.baseDir = baseDir;
      var runtimeOptions = {
        defaultGraph: graph,
        baseDir: graph.baseDir
      };
      var rt = runtime(null, runtimeOptions, true);
      rt.start();
      var ide = 'http://app.flowhub.io';
      var debugUrl = ide+'#runtime/endpoint?'+encodeURIComponent('protocol=webrtc&address='+rt.signaller+'#'+rt.id);
      var debugLink = document.getElementById('flowhub_debug_url');
      if (debugLink) {
        debugLink.href = debugUrl;
      } else {
        console.log(debugUrl);
      }
      rt.network.on('addnetwork', function () {
        return callback();
      });
    });
  };

  console.timeEnd('polymer-ready');
  document.body.classList.remove('loading');
  window.nofloStarted = false;
  console.time('noflo-prepare');
  var load = (true) ? loadGraphsDebuggable : loadGraphs;
  load(function() {
      console.timeEnd('noflo-prepare');
      console.timeEnd('noflo-ui-init');
  });
});

@@ -619,32 +619,90 @@
 ion(callback) %7B%0A
+    var secret = Math.random().toString(36).substring(7);%0A
     noflo.graph.
@@ -868,24 +868,276 @@
 .baseDir
-%0A      %7D
+,%0A        permissions: %7B%7D%0A      %7D;%0A      runtimeOptions.permissions%5Bsecret%5D = %5B%0A        'protocol:component',%0A        'protocol:runtime',%0A        'protocol:graph',%0A        'protocol:network',%0A        'component:getsource',%0A        'component:setsource'%0A      %5D
 ;%0A      
@@ -1355,16 +1355,34 @@
 #'+rt.id
++'&secret='+secret
 );%0A     

Define a secret and provide capabilities for the WebRTC runtime