@24i/bigscreen-sdk 1.0.34-alpha.2566 → 1.0.34-alpha.2568

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@24i/bigscreen-sdk",
3
- "version": "1.0.34-alpha.2566",
3
+ "version": "1.0.34-alpha.2568",
4
4
  "description": "SmartApps BIGscreen SDK monorepo",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -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,12 @@ 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
+
24
+ const CHECK_STATE_URL = 'https://8.8.8.8/';
25
+
19
26
  export abstract class DeviceBase<
20
27
  CustomEventMap extends EventMapType = {},
21
28
  EventMap extends EventMapType = DeviceEventMap & CustomEventMap,
@@ -41,6 +48,10 @@ export abstract class DeviceBase<
41
48
 
42
49
  screenSize: ScreenSize = 'unknown';
43
50
 
51
+ pollingInterval: number = DEFAULT_POLLING_INTERVAL;
52
+
53
+ pollingTimeout: number = DEFAULT_POLLING_TIMEOUT;
54
+
44
55
  // MARK: Initialization
45
56
 
46
57
  /**
@@ -65,12 +76,41 @@ export abstract class DeviceBase<
65
76
  async internalInit() {
66
77
  if (!this.initializer) {
67
78
  this.initializer = this.initDevice();
79
+ this.checkNetworkConnection();
68
80
  await this.initializer;
69
81
  return this.initializer;
70
82
  }
71
83
  return this.initializer;
72
84
  }
73
85
 
86
+ doOnlineCheck = () => {
87
+ const http = new XMLHttpRequest();
88
+ http.open('HEAD', `${CHECK_STATE_URL}?param=${Date.now()}`);
89
+ http.timeout = this.pollingTimeout || DEFAULT_POLLING_TIMEOUT;
90
+ http.onreadystatechange = () => {
91
+ const isConnected = http.status === SUCCESS_STATUS_CODE;
92
+ if (http.readyState === XMLHttpRequest.DONE) {
93
+ this.triggerEvent('networkchange',
94
+ { isConnected } as any);
95
+ }
96
+ };
97
+ http.ontimeout = () => {
98
+ this.triggerEvent('networkchange',
99
+ { isConnected: false } as any);
100
+ };
101
+ http.send();
102
+ };
103
+
104
+ checkNetworkConnection() {
105
+ const networkConfig: any = config.get('network.checkConnection');
106
+ this.pollingInterval = Number(networkConfig?.pollingInterval);
107
+ this.pollingTimeout = Number(networkConfig?.pollingTimeout);
108
+ window.setInterval(
109
+ this.doOnlineCheck,
110
+ this.pollingInterval || DEFAULT_POLLING_INTERVAL,
111
+ );
112
+ }
113
+
74
114
  // MARK: Interface implemented by individual platform-specific drivers
75
115
 
76
116
  abstract initDevice(): Promise<void>;