-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBroker.js
49 lines (41 loc) · 1.09 KB
/
Broker.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
const Debugger = require("./Debugger.js");
const parsing = require("./parsing.js");
function BROKER_LOG(message)
{
console.log(`Broker ${message}`);
}
module.exports =
class Broker
{
constructor()
{
this.debuggers = {}
}
// Process Application or UI initiated requests.
process(json)
{
var string = JSON.stringify(json, null, 2);
BROKER_LOG(`process: ${string}`);
// Convert incoming JSON to DebugPages.
const title = parsing.jsonToDebuggerTitle(json);
const pages = parsing.jsonToDebugPages(json);
var dbg = this.debugger(title);
// Process DebugPages.
for (var id in pages)
{
const page = pages[id];
dbg.processDebugPage(page);
}
// Return updated Debugger state as JSON.
return parsing.debuggerToJSON(title, dbg.pages);
}
// Get or create Debugger instance.
debugger(title)
{
if (!(title in this.debuggers))
{
this.debuggers[title] = new Debugger();
}
return this.debuggers[title];
}
}