23 lines
809 B
JavaScript
23 lines
809 B
JavaScript
window.networkStatus = {
|
|
dotNetHelper: null,
|
|
initialize: function (dotNetHelper) {
|
|
this.dotNetHelper = dotNetHelper;
|
|
window.addEventListener('online', this.handleStatusChange.bind(this));
|
|
window.addEventListener('offline', this.handleStatusChange.bind(this));
|
|
return navigator.onLine;
|
|
},
|
|
handleStatusChange: function () {
|
|
if (this.dotNetHelper) {
|
|
this.dotNetHelper.invokeMethodAsync('SetOnlineStatus', navigator.onLine);
|
|
}
|
|
},
|
|
isOnline: function () {
|
|
return navigator.onLine;
|
|
},
|
|
dispose: function () {
|
|
window.removeEventListener('online', this.handleStatusChange.bind(this));
|
|
window.removeEventListener('offline', this.handleStatusChange.bind(this));
|
|
this.dotNetHelper = null;
|
|
}
|
|
};
|