-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathindex.js
67 lines (61 loc) · 1.43 KB
/
index.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
var defaultNode;
module.exports.options = null;
function node() {
defaultNode = defaultNode || require('./lib/Router')(module.exports.options);
return defaultNode;
};
var requireWhenAccessed = function(names) {
for(var i=0; i<names.length; i++) {
(function(entry) {
var name = entry[0];
var file = entry[1];
Object.defineProperty(exports, name, {
get: function() {
return require(file)
}
});
})(names[i]);
}
};
var functions = {};
function getFunction(name) {
//functions[name] = functions[name] || node()[name].bind(node());
functions[name] = functions[name] || function() {return node()[name].apply(node(), arguments);};
return functions[name];
};
var bindWhenAccessed = function(names) {
for(var i=0; i<names.length; i++) {
(function(name) {
Object.defineProperty(exports, name, {
get: function() {
return getFunction(name);
}
});
})(names[i]);
}
};
bindWhenAccessed([
'listenForPeers',
'connectToPeer',
'addPeer',
'setupPeering',
'createServer',
'connect',
'newKey',
'on',
'stop'
]);
requireWhenAccessed([
['Router', './lib/Router'],
['Peer', './lib/Peer'],
['AESSocket', './lib/AESSocket'],
['KeyExchanger', './lib/KeyExchanger']
]);
Object.defineProperty(exports, 'tracer', {
get: function() {
return node().tracer;
},
set: function(value) {
require('./lib/Router').tracer = value;
}
});