@24i/bigscreen-sdk 0.9.9-alpha.2148 → 0.9.9-alpha.2149

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.
Files changed (58) hide show
  1. package/package.json +1 -1
  2. package/packages/developer-tools/src/DeveloperConsole/utils/formatTime.ts +13 -0
  3. package/packages/developer-tools/src/DeveloperConsole/utils/index.ts +3 -0
  4. package/packages/developer-tools/src/DeveloperConsole/utils/stringify.ts +10 -0
  5. package/packages/developer-tools/src/DeveloperConsole/utils/styles.ts +24 -0
  6. package/packages/developer-tools/src/EnvironmentSelection/utils/format.ts +4 -0
  7. package/packages/developer-tools/src/TechnicalInfo/utils/eme01bSupport.ts +58 -0
  8. package/packages/developer-tools/src/TechnicalInfo/utils/emeSupport.ts +80 -0
  9. package/packages/developer-tools/src/TechnicalInfo/utils/formatTimezone.ts +15 -0
  10. package/packages/developer-tools/src/TechnicalInfo/utils/mseSupport.ts +14 -0
  11. package/packages/developer-tools/src/utils/reload.ts +6 -0
  12. package/packages/keyboard/src/utils/caret.ts +48 -0
  13. package/packages/keyboard/src/utils/generateFocusMatrixFromStringMatrix.ts +12 -0
  14. package/packages/keyboard/src/utils/input.ts +40 -0
  15. package/packages/list/utils/index.ts +1 -0
  16. package/packages/logger/src/utils/deviceInfo.ts +25 -0
  17. package/packages/logger/src/utils/index.ts +1 -0
  18. package/packages/utils/README.md +336 -0
  19. package/packages/utils/src/addClass.ts +9 -0
  20. package/packages/utils/src/counter.ts +47 -0
  21. package/packages/utils/src/debounce.ts +54 -0
  22. package/packages/utils/src/displayToggler.scss +3 -0
  23. package/packages/utils/src/displayToggler.ts +38 -0
  24. package/packages/utils/src/elementUtils.ts +58 -0
  25. package/packages/utils/src/generateUuid.ts +19 -0
  26. package/packages/utils/src/index.ts +35 -0
  27. package/packages/utils/src/memoryInfo.ts +21 -0
  28. package/packages/utils/src/nTimes.ts +9 -0
  29. package/packages/utils/src/noop.ts +1 -0
  30. package/packages/utils/src/offsetPosition.ts +56 -0
  31. package/packages/utils/src/removeClass.ts +9 -0
  32. package/packages/utils/src/scaledImage.ts +21 -0
  33. package/packages/utils/src/stopEvent.ts +10 -0
  34. package/packages/utils/src/timeConstants.ts +11 -0
  35. package/packages/utils/src/timers/createInterval.ts +19 -0
  36. package/packages/utils/src/timers/createTimeout.ts +22 -0
  37. package/packages/utils/src/timers/index.ts +4 -0
  38. package/packages/utils/src/timers/runAsync.ts +3 -0
  39. package/packages/utils/src/timers/types.ts +9 -0
  40. package/packages/utils/src/wait.ts +1 -0
  41. package/packages/utils/src/xhr/index.ts +11 -0
  42. package/packages/utils/src/xhr/xhrSend.ts +139 -0
  43. package/packages/utils/src/xhr/xhrSendRetry.ts +77 -0
  44. package/utils/create-export-maps/index.ts +3 -0
  45. package/utils/create-export-maps/src/__tests__/createExportMaps.spec.ts +50 -0
  46. package/utils/create-export-maps/src/createExportMaps.ts +61 -0
  47. package/utils/create-package/README.md +40 -0
  48. package/utils/create-package/src/createPackage.ts +72 -0
  49. package/utils/create-package/src/index.ts +3 -0
  50. package/utils/create-package/src/questionnaire/questions.ts +19 -0
  51. package/utils/create-package/src/settings/Settings.ts +5 -0
  52. package/utils/create-package/src/types.ts +4 -0
  53. package/utils/create-package/templates/typescript/README.md +9 -0
  54. package/utils/create-package/templates/typescript/exports.json +6 -0
  55. package/utils/create-package/templates/typescript/src/index.ts +0 -0
  56. package/utils/run-scripts/index.ts +3 -0
  57. package/utils/run-scripts/src/__tests__/runScripts.spec.ts +45 -0
  58. package/utils/run-scripts/src/runScripts.ts +20 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@24i/bigscreen-sdk",
3
- "version": "0.9.9-alpha.2148",
3
+ "version": "0.9.9-alpha.2149",
4
4
  "description": "SmartApps BIGscreen SDK monorepo",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -0,0 +1,13 @@
1
+ export const formatTimeToHMS = (timestamp: number) => {
2
+ if (!timestamp) {
3
+ return '00:00:00';
4
+ }
5
+ const date = new Date(timestamp);
6
+ const lastTwoChars = -2;
7
+
8
+ const hours = (`0${date.getHours()}`).slice(lastTwoChars);
9
+ const minutes = (`0${date.getMinutes()}`).slice(lastTwoChars);
10
+ const seconds = (`0${date.getSeconds()}`).slice(lastTwoChars);
11
+
12
+ return `${hours}:${minutes}:${seconds}`;
13
+ };
@@ -0,0 +1,3 @@
1
+ export { formatTimeToHMS } from './formatTime';
2
+ export { getStatusCodeClass } from './styles';
3
+ export { stringifyObjectData } from './stringify';
@@ -0,0 +1,10 @@
1
+ export const stringifyObjectData = (data: any) => {
2
+ if (typeof data === 'object') {
3
+ try {
4
+ return JSON.stringify(data);
5
+ } catch (error) {
6
+ return '';
7
+ }
8
+ }
9
+ return data || '';
10
+ };
@@ -0,0 +1,24 @@
1
+ const HttpStatusCodesLevels = {
2
+ LEVEL_2XX: '2',
3
+ LEVEL_3XX: '3',
4
+ LEVEL_4XX: '4',
5
+ LEVEL_5XX: '5',
6
+ };
7
+
8
+ export const getStatusCodeClass = (statusCode: number) => {
9
+ const { LEVEL_2XX, LEVEL_3XX, LEVEL_4XX, LEVEL_5XX } = HttpStatusCodesLevels;
10
+ const stringStatusCode = String(statusCode);
11
+ if (stringStatusCode.startsWith(LEVEL_2XX)) {
12
+ return 'status-ok';
13
+ }
14
+ if (stringStatusCode.startsWith(LEVEL_3XX)) {
15
+ return 'status-redirect';
16
+ }
17
+ if (stringStatusCode.startsWith(LEVEL_4XX)) {
18
+ return 'status-client-error';
19
+ }
20
+ if (stringStatusCode.startsWith(LEVEL_5XX)) {
21
+ return 'status-server-error';
22
+ }
23
+ return '';
24
+ };
@@ -0,0 +1,4 @@
1
+ export const capitalizeFirstLetter = (string: string) => {
2
+ if (typeof string !== 'string' || string.length === 0) return string;
3
+ return string.charAt(0).toUpperCase() + string.substring(1);
4
+ };
@@ -0,0 +1,58 @@
1
+ /**
2
+ * To detect Encrypted Media Extensions (EME) and Content Decryption Module (CDM)
3
+ * support in a browser for various DRM technologies.
4
+ *
5
+ * Encrypted Media Extensions v0.1b (draft proposal)
6
+ * - The EME v0.1b is implemented on old devices like Tizen 2016, LG webOS 3.0
7
+ */
8
+
9
+ /**
10
+ * Check the Encrypted Media Extensions v0.1b is supported in
11
+ */
12
+ function hasEMESupport() {
13
+ const videoEl = document.createElement('video');
14
+ // any because the method is defined in EME v0.1b
15
+ const addKey = (videoEl as any).webkitAddKey;
16
+ return !!addKey;
17
+ }
18
+
19
+ /**
20
+ * @param videoEl Video element
21
+ * @param keySystem Key System Identifier of a content protection (DRM) mechanism.
22
+ * @returns A boolean indicating whether key system is supported
23
+ */
24
+ function isKeySystemSupported(videoEl: HTMLVideoElement, keySystem: string) {
25
+ // @ts-ignore - the optional second parameter is defined in EME v0.1b
26
+ return !!videoEl.canPlayType('video/mp4;codecs="avc1.42E01E"', keySystem);
27
+ }
28
+
29
+ const KeySystems = {
30
+ 'webkit-org.w3.clearkey': { name: 'W3C Clear Key' }, // prefixed for EME v0.1b
31
+ 'org.w3.clearkey': { name: 'W3C Clear Key' },
32
+ 'com.microsoft.playready': { name: 'Microsoft PlayReady' },
33
+ 'com.youtube.playready': { name: 'YouTube PlayReady' },
34
+ 'com.widevine.alpha': { name: 'Google Widevine' },
35
+ 'com.apple.fairplay': { name: 'Apple FairPlay' },
36
+ 'com.adobe.access': { name: 'Adobe Access' },
37
+ };
38
+
39
+ /**
40
+ * Get list of supported DRM/CDM
41
+ */
42
+ async function getListOfSupportedDRM() {
43
+ const keySystems = Object.keys(KeySystems) as Array<keyof typeof KeySystems>;
44
+ const videoEl = document.createElement('video');
45
+
46
+ const supportedSystems = [];
47
+ for (let i = 0; i < keySystems.length; i++) {
48
+ const keySystem = keySystems[i];
49
+ const isSupported = isKeySystemSupported(videoEl, keySystem);
50
+ if (isSupported) {
51
+ supportedSystems.push({ id: keySystem, name: KeySystems[keySystem].name });
52
+ }
53
+ }
54
+
55
+ return supportedSystems;
56
+ }
57
+
58
+ export { hasEMESupport, getListOfSupportedDRM };
@@ -0,0 +1,80 @@
1
+ /**
2
+ * To detect Encrypted Media Extensions (EME) and Content Decryption Module (CDM)
3
+ * support in a browser for various DRM technologies.
4
+ */
5
+
6
+ /**
7
+ * Check the EME (Encrypted Media Extensions API) is supported in
8
+ */
9
+ function hasEMESupport() {
10
+ // verified only "window.MediaKeys", other prefixed keys were not tested
11
+ const eme = window.MediaKeys || (window as any).MSMediaKeys || (window as any).WebKitMediaKeys;
12
+ return !!eme;
13
+ }
14
+
15
+ /**
16
+ * Check the navigator.requestMediaKeySystemAccess method is supported in
17
+ * Note: it can be used for EME support check, alternatively instead of hasEMESupport.
18
+ */
19
+ function hasRMKSASupport() {
20
+ const rmksa = window.navigator.requestMediaKeySystemAccess;
21
+ return !!rmksa;
22
+ }
23
+
24
+ /**
25
+ * @param keySystem Key System Identifier of a content protection (DRM) mechanism.
26
+ * @param config A non-empty array of MediaKeySystemConfiguration objects.
27
+ */
28
+ function isKeySystemSupported(keySystem: string, config: MediaKeySystemConfiguration[])
29
+ : Promise<boolean> {
30
+ return new Promise((resolve) => {
31
+ try {
32
+ window.navigator.requestMediaKeySystemAccess(keySystem, config)
33
+ .then(() => { resolve(true); })
34
+ .catch(() => { resolve(false); });
35
+ } catch (e) {
36
+ resolve(false);
37
+ }
38
+ });
39
+ }
40
+
41
+ const KeySystems = {
42
+ // 'webkit-org.w3.clearkey': { name: 'W3C Clear Key' }, // only EME v0.1b
43
+ 'org.w3.clearkey': { name: 'W3C Clear Key' },
44
+ 'com.microsoft.playready': { name: 'Microsoft PlayReady' },
45
+ 'com.youtube.playready': { name: 'YouTube PlayReady' },
46
+ 'com.widevine.alpha': { name: 'Google Widevine' },
47
+ 'com.apple.fairplay': { name: 'Apple FairPlay' },
48
+ 'com.adobe.access': { name: 'Adobe Access' },
49
+ };
50
+
51
+ /**
52
+ * Get list of supported DRM/CDM
53
+ */
54
+ async function getListOfSupportedDRM() {
55
+ const keySystems = Object.keys(KeySystems) as Array<keyof typeof KeySystems>;
56
+
57
+ const keySystemConfig = [{
58
+ initDataTypes: ['cenc'],
59
+ audioCapabilities: [{
60
+ contentType: 'audio/mp4;codecs="mp4a.40.2"',
61
+ }],
62
+ videoCapabilities: [{
63
+ contentType: 'video/mp4;codecs="avc1.42E01E"',
64
+ }],
65
+ }];
66
+
67
+ const supportedSystems = [];
68
+ for (let i = 0; i < keySystems.length; i++) {
69
+ const keySystem = keySystems[i];
70
+ // eslint-disable-next-line no-await-in-loop
71
+ const isSupported = await isKeySystemSupported(keySystem, keySystemConfig);
72
+ if (isSupported) {
73
+ supportedSystems.push({ id: keySystem, name: KeySystems[keySystem].name });
74
+ }
75
+ }
76
+
77
+ return supportedSystems;
78
+ }
79
+
80
+ export { hasEMESupport, hasRMKSASupport, getListOfSupportedDRM };
@@ -0,0 +1,15 @@
1
+ const MINUTES_PER_HOUR = 60;
2
+
3
+ /**
4
+ * @param timezoneOffsetInMinutes The time-zone offset, in minutes, from local time to UTC.
5
+ * @returns time-zone string in RFC 822 4-digit time zone format, e.g. "+0100"
6
+ */
7
+ function formatTimezone(timezoneOffsetInMinutes = 0) {
8
+ const hours = Math.floor(Math.abs(timezoneOffsetInMinutes / MINUTES_PER_HOUR));
9
+ const minutes = timezoneOffsetInMinutes % MINUTES_PER_HOUR;
10
+ const formattedHours = `0${hours}`.slice(-2); // eslint-disable-line no-magic-numbers
11
+ const formattedMinutes = `0${minutes}`.slice(-2); // eslint-disable-line no-magic-numbers
12
+ return `${timezoneOffsetInMinutes > 0 ? '-' : '+'}${formattedHours}${formattedMinutes}`;
13
+ }
14
+
15
+ export { formatTimezone };
@@ -0,0 +1,14 @@
1
+ /**
2
+ * To detect Media Source Extensions API (MSE) support in a browser.
3
+ */
4
+
5
+ /**
6
+ * Check the MSE (Media Source Extensions API) is supported in
7
+ */
8
+ function hasMSESupport() {
9
+ // any because webkit-prefixed key needed on old devices like LG webOS 1.0 (2014)
10
+ const mse = window.MediaSource || (window as any).WebKitMediaSource;
11
+ return !!mse;
12
+ }
13
+
14
+ export { hasMSESupport };
@@ -0,0 +1,6 @@
1
+ export const reloadApp = () => {
2
+ let rootPath = '';
3
+ const splitUrl = window.location.href.split('#');
4
+ if (splitUrl.length > 1) rootPath = splitUrl[0];
5
+ window.location.href = rootPath;
6
+ };
@@ -0,0 +1,48 @@
1
+ const updateCaretPosition = (input: HTMLInputElement, position: number) => {
2
+ input.selectionStart = position;
3
+ input.selectionEnd = position;
4
+ };
5
+
6
+ export const caretLeft = (input: HTMLInputElement | null): false | number => {
7
+ if (!input) return false;
8
+ const selectionStart = input.selectionStart!;
9
+ if (selectionStart > 0) {
10
+ const newPosition = selectionStart - 1;
11
+ updateCaretPosition(input, newPosition);
12
+ return newPosition;
13
+ }
14
+ return false;
15
+ };
16
+
17
+ export const caretRight = (input: HTMLInputElement | null): false | number => {
18
+ if (!input) return false;
19
+ const { value } = input;
20
+ const selectionStart = input.selectionStart!;
21
+ if (selectionStart < value.length) {
22
+ const newPosition = selectionStart + 1;
23
+ updateCaretPosition(input, newPosition);
24
+ return newPosition;
25
+ }
26
+ return false;
27
+ };
28
+
29
+ export const caretHome = (input: HTMLInputElement | null): false | number => {
30
+ if (!input) return false;
31
+ const selectionStart = input.selectionStart!;
32
+ if (selectionStart > 0) {
33
+ updateCaretPosition(input, 0);
34
+ return 0;
35
+ }
36
+ return false;
37
+ };
38
+
39
+ export const caretEnd = (input: HTMLInputElement | null): false | number => {
40
+ if (!input) return false;
41
+ const { value: { length } } = input;
42
+ const selectionStart = input.selectionStart!;
43
+ if (selectionStart < length) {
44
+ updateCaretPosition(input, length);
45
+ return length;
46
+ }
47
+ return false;
48
+ };
@@ -0,0 +1,12 @@
1
+ import { createRef, Reference } from '@24i/bigscreen-sdk/jsx';
2
+ import { map } from '@24i/bigscreen-sdk/perf-utils/array';
3
+
4
+ export const generateFocusMatrixFromStringMatrix = (
5
+ refs: { [key: string]: Reference<HTMLDivElement> },
6
+ matrix: Array<Array<string | null>>,
7
+ ): Array<Array<Reference<HTMLDivElement>>> => map(matrix, (row) => (
8
+ map(row, (key) => {
9
+ if (!refs[key!]) refs[key!] = createRef();
10
+ return refs[key!];
11
+ })
12
+ ));
@@ -0,0 +1,40 @@
1
+ export const insertCharAtCaret = (input: HTMLInputElement | null, char: string): false | string => {
2
+ if (!input) return false;
3
+ const { value } = input;
4
+ const selectionStart = input.selectionStart!;
5
+ const preCaret = value.substring(0, selectionStart);
6
+ const postCaret = value.substring(selectionStart);
7
+ input.value = `${preCaret}${char}${postCaret}`;
8
+ const newCaretPosition = selectionStart + char.length;
9
+ input.selectionStart = newCaretPosition;
10
+ input.selectionEnd = newCaretPosition;
11
+ return input.value;
12
+ };
13
+
14
+ export const backspace = (input: HTMLInputElement): false | string => {
15
+ if (!input) return false;
16
+ const { value } = input;
17
+ const selectionStart = input.selectionStart!;
18
+ if (selectionStart === 0) return false;
19
+ const preCaret = value.substring(0, selectionStart - 1);
20
+ const postCaret = value.substring(selectionStart);
21
+ input.value = `${preCaret}${postCaret}`;
22
+ const newCaretPosition = selectionStart - 1;
23
+ input.selectionStart = newCaretPosition;
24
+ input.selectionEnd = newCaretPosition;
25
+ return input.value;
26
+ };
27
+
28
+ export const del = (input: HTMLInputElement): false | string => {
29
+ if (!input) return false;
30
+ const { value } = input;
31
+ const selectionStart = input.selectionStart!;
32
+ if (selectionStart === value.length) return false;
33
+ const preCaret = value.substring(0, selectionStart);
34
+ const postCaret = value.substring(selectionStart + 1);
35
+ input.value = `${preCaret}${postCaret}`;
36
+ const newCaretPosition = selectionStart;
37
+ input.selectionStart = newCaretPosition;
38
+ input.selectionEnd = newCaretPosition;
39
+ return input.value;
40
+ };
@@ -0,0 +1 @@
1
+ export { calcVisibleItemCount } from '../src/utils';
@@ -0,0 +1,25 @@
1
+ import { IStorage } from '@24i/bigscreen-sdk/storage';
2
+ import { getUsedJSHeapSize, getTotalJSHeapSize } from '@24i/bigscreen-sdk/utils/memoryInfo';
3
+
4
+ const B_IN_KB = 1024;
5
+
6
+ const toKilobytes = (bytes: number) => Math.floor(bytes / B_IN_KB);
7
+
8
+ export const getFormattedMemoryHeapInfo = () => {
9
+ const usedSizeKB = toKilobytes(getUsedJSHeapSize());
10
+ const totalSizeKB = toKilobytes(getTotalJSHeapSize());
11
+ return `${usedSizeKB} kB / ${totalSizeKB} kB`;
12
+ };
13
+
14
+ export const getFormattedUsedLocalStorageSize = async (storage: IStorage) => {
15
+ if (storage) {
16
+ try {
17
+ const usedSize = await storage.getUsedSize();
18
+ const usedSizeKB = toKilobytes(usedSize);
19
+ return `${usedSizeKB} kB`;
20
+ } catch (e) {
21
+ return 'error';
22
+ }
23
+ }
24
+ return 'unknown';
25
+ };
@@ -0,0 +1 @@
1
+ export { getFormattedMemoryHeapInfo, getFormattedUsedLocalStorageSize } from './deviceInfo';