86 lines
3.2 KiB
HTML
86 lines
3.2 KiB
HTML
<html>
|
|
|
|
<head>
|
|
<script id="floGlobals">
|
|
/* Constants for FLO blockchain operations !!Make sure to add this at begining!! */
|
|
const floGlobals = {
|
|
blockchain: "FLO",
|
|
adminID: "FKAEdnPfjXLHSYwrXQu377ugN4tXU7VGdf",
|
|
webAppURL: "<website_url/ip_addr>:<port>",
|
|
application: "TEST_MODE"
|
|
}
|
|
</script>
|
|
</head>
|
|
|
|
<body>
|
|
TEST_MODE (use console)
|
|
<script id="webAppClient">
|
|
//Add this to the client script to request data from floWebappServer
|
|
const webAppClient = {
|
|
util: {
|
|
|
|
requestData(request = []) {
|
|
return new Promise((resolve, reject) => {
|
|
var websocket = new WebSocket("wss://" + floGlobals.webAppURL + "/ws");
|
|
websocket.onmessage = (evt => {
|
|
if (evt.data == '$+') {
|
|
websocket.send(`?${JSON.stringify(request)}`);
|
|
} else if (evt.data == '$-') {
|
|
reject(`webApp not available`)
|
|
websocket.close()
|
|
} else {
|
|
resolve(JSON.parse(evt.data));
|
|
websocket.close();
|
|
}
|
|
})
|
|
websocket.onerror = (evt) => {
|
|
reject(`webApp server not found`)
|
|
};
|
|
})
|
|
}
|
|
},
|
|
|
|
requestGeneralData: function (type, vectorClock = '0') {
|
|
if (typeof vectorClock !== 'string')
|
|
vectorClock.toString()
|
|
return new Promise((resolve, reject) => {
|
|
this.util.requestData([floGlobals.application, 'generalData', type, vectorClock])
|
|
.then(
|
|
result => {
|
|
if (result[0])
|
|
resolve(result[1])
|
|
else
|
|
reject(result[1])
|
|
}).catch(error => reject(error))
|
|
})
|
|
},
|
|
|
|
requestObjectData: function (keyPath) {
|
|
return new Promise((resolve, reject) => {
|
|
this.util.requestData([floGlobals.application, 'appObjects'].concat(keyPath)).then(
|
|
result => {
|
|
if (result[0])
|
|
resolve(result[1])
|
|
else
|
|
reject(result[1])
|
|
}).catch(error => reject(error))
|
|
})
|
|
},
|
|
|
|
requestSubAdminList: function(){
|
|
return new Promise((resolve, reject) => {
|
|
this.util.requestData([floGlobals.application, 'subAdmins']).then(
|
|
result => {
|
|
if (result[0])
|
|
resolve(result[1])
|
|
else
|
|
reject(result[1])
|
|
}).catch(error => reject(error))
|
|
})
|
|
}
|
|
}
|
|
</script>
|
|
</body>
|
|
|
|
</html>
|