-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathsample_contentBrowser.js
More file actions
137 lines (109 loc) · 3.58 KB
/
sample_contentBrowser.js
File metadata and controls
137 lines (109 loc) · 3.58 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
const Readline = require('readline');
var Raumkernel = require('./lib/lib.raumkernel');
setWelcomeScreen();
var idStack = [];
var tp0;
var tpDuration;
var raumkernel = new Raumkernel();
raumkernel.createLogger(1, "logs");
raumkernel.init();
function perfMeassure(_start) {
if ( !_start ) return process.hrtime();
var end = process.hrtime(_start);
return Math.round((end[0]*1000) + (end[1]/1000000));
}
// set up a callback to show the "reading state" of a media list that is beeing read
// of course this will be called on any browse wherer the "emit" parameter is active
raumkernel.on("mediaListDataPackageReady", function(_id, _mediaListDataPkg, _pkgIdx, _pgkIdxEnd, _pkgDataCount)
{
console.log('\033[2J');
console.log("--------------------------------");
console.log("Reading Data: " + (_pgkIdxEnd+1).toString());
console.log("--------------------------------");
});
// browse to root when system is ready
raumkernel.on("systemReady", function(_ready){
browse("0");
});
function browse(_id, _backwards = false, _addToStack = true)
{
setLoadingScreen(_id);
if(_backwards)
idStack.pop();
else if(_addToStack)
idStack.push(_id);
tp0 = perfMeassure();
raumkernel.managerDisposer.mediaListManager.getMediaList(_id, _id, "", true, true, 25).then(function(_data){
tpDuration = perfMeassure(tp0);
viewBrowseResult(_id, _data);
}).catch(function(_data){
viewError(_data);
});
}
function viewBrowseResult(_id, _data)
{
console.log('\033[2J');
console.log(JSON.stringify(idStack) + " --> " + _id);
console.log("--------------------------------");
if(_data && _data.length)
{
for(var i=0; i<_data.length; i++)
{
console.log(i.toString() + " - " + _data[i].title + " (" + _data[i].id + ")");
}
}
else
{
console.log("# No data available");
}
console.log("--------------------------------");
console.log("Loading time: " + (tpDuration) + " ms");
console.log("--------------------------------");
console.log("x BROWSE BACK");
console.log("--------------------------------");
var readLine1 = Readline.createInterface({input: process.stdin, output: process.stdout});
readLine1.question('Choose ID: ', (_input) => {
readLine1.close();
if(_data && _data[_input])
{
browse(_data[_input].id);
}
else
{
if(_input.toLowerCase() == "x" && idStack.length > 1)
{
var parentId = idStack[idStack.length-2];
browse(parentId, true);
}
else
{
browse(_id, false, false);
}
}
});
}
function viewError(_data)
{
console.log('\033[2J');
console.log('Error occured: ' + _data);
var readLine1 = Readline.createInterface({input: process.stdin, output: process.stdout});
readLine1.question("Press [ENTER] to start at root again!", (_input) => {
readLine1.close();
idStack = [];
browse("0");
});
}
function setLoadingScreen(_id)
{
console.log('\033[2J');
console.log("Loading list for id :" + _id);
console.log("Please wait! Certain id's can take a lot of time!");
}
function setWelcomeScreen()
{
console.log('\033[2J');
console.log("Please wait till the raumfeld system is found!")
}
function execute(){
}
setInterval(execute,1000);