@24i/bigscreen-sdk 1.0.34-alpha.2570 → 1.0.34-alpha.2571
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
|
@@ -19,7 +19,7 @@ export const STORAGE_UUID_KEY = '__UUID__';
|
|
|
19
19
|
|
|
20
20
|
const DEFAULT_POLLING_INTERVAL = 15000;
|
|
21
21
|
|
|
22
|
-
const CHECKED_URL = '
|
|
22
|
+
const CHECKED_URL = '//www.google-analytics.com/__utm.gif';
|
|
23
23
|
|
|
24
24
|
export abstract class DeviceBase<
|
|
25
25
|
CustomEventMap extends EventMapType = {},
|
|
@@ -48,6 +48,8 @@ export abstract class DeviceBase<
|
|
|
48
48
|
|
|
49
49
|
pollingInterval: number = DEFAULT_POLLING_INTERVAL;
|
|
50
50
|
|
|
51
|
+
isOffline: boolean = false;
|
|
52
|
+
|
|
51
53
|
// MARK: Initialization
|
|
52
54
|
|
|
53
55
|
/**
|
|
@@ -59,6 +61,7 @@ export abstract class DeviceBase<
|
|
|
59
61
|
if (!this.isInitialized) {
|
|
60
62
|
this.bindPreventDefaultEvents(rootElement);
|
|
61
63
|
const initializer = await this.internalInit();
|
|
64
|
+
this.checkNetworkConnection();
|
|
62
65
|
this.isInitialized = true;
|
|
63
66
|
return initializer;
|
|
64
67
|
}
|
|
@@ -72,7 +75,6 @@ export abstract class DeviceBase<
|
|
|
72
75
|
async internalInit() {
|
|
73
76
|
if (!this.initializer) {
|
|
74
77
|
this.initializer = this.initDevice();
|
|
75
|
-
this.checkNetworkConnection();
|
|
76
78
|
await this.initializer;
|
|
77
79
|
return this.initializer;
|
|
78
80
|
}
|
|
@@ -80,29 +82,37 @@ export abstract class DeviceBase<
|
|
|
80
82
|
}
|
|
81
83
|
|
|
82
84
|
doOnlineCheck = () => {
|
|
85
|
+
const protocol = window.location.protocol === 'http:' ? 'http:' : 'https:';
|
|
83
86
|
const tester = new Image();
|
|
84
87
|
tester.onload = this.connectionFound;
|
|
85
88
|
tester.onerror = this.connectionNotFound;
|
|
86
|
-
tester.src = `${CHECKED_URL}?ts=${Date.now()}`;
|
|
89
|
+
tester.src = `${protocol}${CHECKED_URL}?ts=${Date.now()}`;
|
|
87
90
|
};
|
|
88
91
|
|
|
89
92
|
connectionFound = () => {
|
|
93
|
+
if (!this.isOffline) return;
|
|
90
94
|
this.triggerEvent('networkchange',
|
|
91
95
|
{ isConnected: true } as any);
|
|
96
|
+
this.isOffline = false;
|
|
92
97
|
};
|
|
93
98
|
|
|
94
99
|
connectionNotFound = () => {
|
|
100
|
+
if (this.isOffline) return;
|
|
95
101
|
this.triggerEvent('networkchange',
|
|
96
102
|
{ isConnected: false } as any);
|
|
103
|
+
this.isOffline = true;
|
|
97
104
|
};
|
|
98
105
|
|
|
99
106
|
checkNetworkConnection() {
|
|
100
107
|
const networkConfig: any = config.get('network.checkConnection');
|
|
101
108
|
this.pollingInterval = Number(networkConfig?.pollingInterval);
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
109
|
+
const enableCheckNetwork: any = Boolean(networkConfig?.enableCheckNetwork) ?? false;
|
|
110
|
+
if (enableCheckNetwork) {
|
|
111
|
+
window.setInterval(
|
|
112
|
+
this.doOnlineCheck,
|
|
113
|
+
this.pollingInterval || DEFAULT_POLLING_INTERVAL,
|
|
114
|
+
);
|
|
115
|
+
}
|
|
106
116
|
}
|
|
107
117
|
|
|
108
118
|
// MARK: Interface implemented by individual platform-specific drivers
|