/
main.js
95 lines (90 loc) · 2.67 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
var exported = {
noflo: require('noflo'),
underscore: require('underscore'),
'coffee-script': require('coffee-script'),
'child_process': null,
'uuid': require('uuid'),
'flowhub-registry': require('flowhub-registry'),
'noflo-ui/src/JournalStore': require('../src/JournalStore'),
'noflo-ui/runtimeinfo': require('../runtimeinfo/index.coffee')
};
window.require = function (moduleName) {
if (typeof exported[moduleName] !== 'undefined') {
return exported[moduleName];
}
throw new Error('Module ' + moduleName + ' not available');
};
window.addEventListener('WebComponentsReady', function() {
var noflo = require('noflo');
var runtime = require('noflo-runtime-webrtc');
var baseDir = '/noflo-ui';
var mainGraph = require('../graphs/main.fbp');
var loadGraphs = function(callback) {
noflo.graph.loadJSON(mainGraph, function (err, g) {
if (err) {
callback(err);
return;
}
g.baseDir = baseDir;
noflo.createNetwork(g, function (err, n) {
if (err) {
callback(err);
return;
}
n.on('process-error', function (err) {
console.log(err);
});
return callback();
});
});
};
var loadGraphsDebuggable = function(callback) {
var secret = Math.random().toString(36).substring(7);
noflo.graph.loadJSON(mainGraph, function (err, graph) {
if (err) {
callback(err);
return;
}
graph.baseDir = baseDir;
var runtimeOptions = {
defaultGraph: graph,
baseDir: graph.baseDir,
permissions: {}
};
runtimeOptions.permissions[secret] = [
'protocol:component',
'protocol:runtime',
'protocol:graph',
'protocol:network',
'component:getsource',
'component:setsource'
];
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+'&secret='+secret);
var debugLink = document.getElementById('flowhub_debug_url');
if (debugLink) {
debugLink.href = debugUrl;
} else {
console.log(debugUrl);
}
rt.network.on('addnetwork', function () {
return callback();
});
});
};
window.nofloStarted = false;
var load = (false) ? loadGraphsDebuggable : loadGraphs;
load(function(err) {
if (err) {
throw err;
}
document.body.classList.remove('loading');
window.nofloStarted = true;
setTimeout(function () {
var loader = document.getElementById('loading');
document.body.removeChild(loader);
}, 400);
});
});