87 lines
2.0 KiB
JavaScript
87 lines
2.0 KiB
JavaScript
var LNProvider = (function(){
|
|
|
|
class LNProvider
|
|
{
|
|
constructor(options){
|
|
let self = this;
|
|
|
|
this.serverString = "N/A";
|
|
this.serverTime = "N/A";
|
|
|
|
this.lagDetector = null;
|
|
|
|
this.IPAllocations = [];
|
|
}
|
|
|
|
initialize(){
|
|
return Promise.all(LNProvider.initializers);
|
|
}
|
|
|
|
loadIPAllocations(){
|
|
let self = this;
|
|
console.log("loadIPAllocations()");
|
|
LN().rpc("ippool","GetAllocations",[],function(r,e){
|
|
self.IPAllocations = r;
|
|
console.log("IPA: " + JSON.stringify(r));
|
|
});
|
|
}
|
|
|
|
allocate(type,cidr,maskWidth,zone,usage,splitZone){
|
|
let self = this;
|
|
|
|
if (type == 0)
|
|
{
|
|
|
|
} else if (type == 1)
|
|
{
|
|
LN().rpc("ippool","AllocateCIDR",[zone,cidr,usage,splitZone],function(r,e){
|
|
if (e){
|
|
alert("Error: \n" + JSON.stringify(e));
|
|
} else {
|
|
self.IPAllocations.push(r);
|
|
}
|
|
});
|
|
}
|
|
|
|
}
|
|
|
|
wsUpdate(state)
|
|
{
|
|
try
|
|
{
|
|
if (this.lagDetector)
|
|
clearTimeout(this.lagDetector);
|
|
|
|
this.serverTime = moment(state.currentTime).format();
|
|
|
|
this.lagDetector = setTimeout(function(){
|
|
this.serverTime = "Server lag detected";
|
|
}, 2000);
|
|
|
|
} catch (e)
|
|
{
|
|
console.log(e);
|
|
}
|
|
}
|
|
wsError(e){
|
|
this.serverTime = "WebSocket: Error: " + JSON.stringify(e);
|
|
}
|
|
wsClose(e){
|
|
this.serverTime = "WebSocket: Connection lost";
|
|
setTimeout(function(){
|
|
LN().connect();
|
|
}, 2500 );
|
|
}
|
|
}
|
|
|
|
LNProvider.routes = [];
|
|
LNProvider.initializers = [];
|
|
|
|
|
|
return LNProvider;
|
|
})();
|
|
|
|
|
|
|
|
|