@24i/bigscreen-sdk 1.0.34-alpha.2566 → 1.0.34-alpha.2567
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Storage } from '@24i/bigscreen-sdk/storage';
|
|
2
|
+
import { config } from '@24i/bigscreen-sdk/runtime-config';
|
|
2
3
|
import { generateUuid } from '@24i/bigscreen-sdk/utils/generateUuid';
|
|
3
4
|
import { EventsManager, IEvents, EventMapType } from '@24i/bigscreen-sdk/events-manager';
|
|
4
5
|
import { isRtl } from '@24i/bigscreen-sdk/i18n';
|
|
@@ -16,6 +17,10 @@ import { LEFT, RIGHT, UP, DOWN, ENTER, BACK, ESC } from './KeyMap';
|
|
|
16
17
|
|
|
17
18
|
export const STORAGE_UUID_KEY = '__UUID__';
|
|
18
19
|
|
|
20
|
+
const DEFAULT_POLLING_INTERVAL = 15000;
|
|
21
|
+
const DEFAULT_POLLING_TIMEOUT = 10000;
|
|
22
|
+
const SUCCESS_STATUS_CODE = 200;
|
|
23
|
+
|
|
19
24
|
export abstract class DeviceBase<
|
|
20
25
|
CustomEventMap extends EventMapType = {},
|
|
21
26
|
EventMap extends EventMapType = DeviceEventMap & CustomEventMap,
|
|
@@ -41,6 +46,10 @@ export abstract class DeviceBase<
|
|
|
41
46
|
|
|
42
47
|
screenSize: ScreenSize = 'unknown';
|
|
43
48
|
|
|
49
|
+
pollingInterval: number = DEFAULT_POLLING_INTERVAL;
|
|
50
|
+
|
|
51
|
+
pollingTimeout: number = DEFAULT_POLLING_TIMEOUT;
|
|
52
|
+
|
|
44
53
|
// MARK: Initialization
|
|
45
54
|
|
|
46
55
|
/**
|
|
@@ -65,12 +74,41 @@ export abstract class DeviceBase<
|
|
|
65
74
|
async internalInit() {
|
|
66
75
|
if (!this.initializer) {
|
|
67
76
|
this.initializer = this.initDevice();
|
|
77
|
+
this.checkNetworkConnection();
|
|
68
78
|
await this.initializer;
|
|
69
79
|
return this.initializer;
|
|
70
80
|
}
|
|
71
81
|
return this.initializer;
|
|
72
82
|
}
|
|
73
83
|
|
|
84
|
+
doOnlineCheck = () => {
|
|
85
|
+
const http = new XMLHttpRequest();
|
|
86
|
+
http.open('HEAD', `${document.location.pathname}?param=${Date.now()}`);
|
|
87
|
+
http.timeout = this.pollingTimeout || DEFAULT_POLLING_TIMEOUT;
|
|
88
|
+
http.onreadystatechange = () => {
|
|
89
|
+
const isConnected = http.status === SUCCESS_STATUS_CODE;
|
|
90
|
+
if (http.readyState === XMLHttpRequest.DONE) {
|
|
91
|
+
this.triggerEvent('networkchange',
|
|
92
|
+
{ isConnected } as any);
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
http.ontimeout = () => {
|
|
96
|
+
this.triggerEvent('networkchange',
|
|
97
|
+
{ isConnected: false } as any);
|
|
98
|
+
};
|
|
99
|
+
http.send();
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
checkNetworkConnection() {
|
|
103
|
+
const networkConfig: any = config.get('network.checkConnection');
|
|
104
|
+
this.pollingInterval = Number(networkConfig?.pollingInterval);
|
|
105
|
+
this.pollingTimeout = Number(networkConfig?.pollingTimeout);
|
|
106
|
+
window.setInterval(
|
|
107
|
+
this.doOnlineCheck,
|
|
108
|
+
this.pollingInterval || DEFAULT_POLLING_INTERVAL,
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
74
112
|
// MARK: Interface implemented by individual platform-specific drivers
|
|
75
113
|
|
|
76
114
|
abstract initDevice(): Promise<void>;
|