-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
121 lines (92 loc) · 3.54 KB
/
index.js
File metadata and controls
121 lines (92 loc) · 3.54 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
//############################################################
//
//
// Lizenz & Credits von BenTwi hier
//
//
//############################################################
let domains;
let BENTWI = {
useLocal: true,
config: {},
useInlineConfig: (val) => {
if(val == true || val == false){
BENTWI.useLocal = !val
setTimeout(() => { log("debug", "BenTwi will: " + BENTWI.useLocal ? "use the file as config" : "use the script as config", "MAIN") }, 5000)
} else {
log("error", `setInlineBenTwiConfig() needs an boolean of true or false instead of ${val}`, "MAIN")
}
},
versions: {
bdk: "v0.0",
backend: "v0.0",
frontend: "v0.0"
},
events: {
events: {},
on: function(event, callback) {
if (!this.events[event]) {
this.events[event] = [];
}
this.events[event].push(callback);
},
emit: function(event, ...args) {
if (this.events[event]) {
this.events[event].forEach(callback => callback(...args));
}
}
}
};
function loadDependencys(){
const dependencys = ['logger', 'utils', 'mappings', 'environment', 'sessionControll', 'connector', 'config', 'api', 'alertManager', 'version']
dependencys.forEach(dependency => {
const depSrc = document.createElement('script')
depSrc.src = `https://bentwi.skykopf.com/dev-kit/dependencies/${dependency}.js`;
document.body.appendChild(depSrc)
setTimeout(() => {
log("log", `Loaded dependency "${dependency}"`, "MAIN")
}, 2500)
if (dependency === "mappings") {
if (typeof preRegisterMappings !== "function") {
setTimeout(() => { log("log", `No preRegisterMappings function found, skipped!`, "MAPPINGS"); }, 2000)
} else {
setTimeout(() => preRegisterMappings(), 2000);
}
}
})
fetch('https://bentwi.skykopf.com/dev-kit/config/domains.json').then(response => {
return response.json();
}).then(data => {
setTimeout(() => { log("log", "Successfully loaded domains", "MAIN") }, 1000)
BENTWI.domains = data;
}).catch(err => {
log("critical", `Cannot load domains from backend server: ${JSON.stringify(err)}`, "MAIN")
});
setTimeout(() => {
setTimeout(loadBenTwiDotJSON, 1000)
setTimeout(newSession, 4000)
}, 3500)
}
function loadBenTwiDotJSON(){
log("log", "Trying to load bentwi.json", "MAIN")
if(BENTWI.useLocal){
log("warn", "Hey! In this version BenTwi can't use a local BenTwi.json file.", "MAIN")
BENTWI.useInlineConfig(true)
setTimeout(loadBenTwiDotJSON, 1000)
return;
log("log", "Loaded BenTwi.json in Local mode", "MAIN")
} else {
log("log", "Fetching default BenTwi.json from Backend Server", "MAIN")
fetch('https://bentwi.skykopf.com/dev-kit/bentwi.json').then(response => {
return response.json();
}).then(data => {
BENTWI.config = { ...BENTWI.config, ...data };
if(log) log("log", "Loaded BenTwi.json in Inline mode", "MAIN")
}).catch(err => {
err = JSON.stringify(err)
if(err == "{}") return;
log("critical", `Cannot load bentwi default from backend server: ${err}`, "MAIN")
});
}
}
setTimeout(loadDependencys, 500)