@sprucelabs/spruce-heartwood-utils 22.0.0 → 24.0.0
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/README.md
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import EventEmitter from 'events';
|
|
2
|
-
import { CachedValue, Device } from '@sprucelabs/heartwood-view-controllers';
|
|
2
|
+
import { CachedValue, Device, TheaterSettingValueTypes, TheatreSettingName } from '@sprucelabs/heartwood-view-controllers';
|
|
3
3
|
import { Orientation } from '../types/heartwood.types';
|
|
4
4
|
export declare class HeartwoodDevice extends EventEmitter implements Device {
|
|
5
5
|
private storage;
|
|
6
6
|
private orientation;
|
|
7
|
+
private isGettingKiosk;
|
|
7
8
|
protected constructor(storage: Storage);
|
|
8
9
|
openUrl(url: string): void;
|
|
9
10
|
static Device(storage: Storage): HeartwoodDevice;
|
|
@@ -15,5 +16,7 @@ export declare class HeartwoodDevice extends EventEmitter implements Device {
|
|
|
15
16
|
getOrientation(): Orientation;
|
|
16
17
|
enablePushNotifications(): void;
|
|
17
18
|
signalSkillViewLoaded(): void;
|
|
18
|
-
sendCommand(command: string, payload?: Record<string, any>):
|
|
19
|
+
sendCommand(command: string, payload?: Record<string, any>): void;
|
|
20
|
+
setTheatreSetting<N extends TheatreSettingName>(name: N, value: TheaterSettingValueTypes[N]): void;
|
|
21
|
+
getTheatreSetting<N extends TheatreSettingName>(_name: N): Promise<TheaterSettingValueTypes[N] | null>;
|
|
19
22
|
}
|
|
@@ -10,6 +10,7 @@ class HeartwoodDevice extends events_1.default {
|
|
|
10
10
|
constructor(storage) {
|
|
11
11
|
super();
|
|
12
12
|
this.orientation = 'unknown-orientation';
|
|
13
|
+
this.isGettingKiosk = false;
|
|
13
14
|
this.storage = storage;
|
|
14
15
|
}
|
|
15
16
|
openUrl(url) {
|
|
@@ -45,26 +46,55 @@ class HeartwoodDevice extends events_1.default {
|
|
|
45
46
|
return this.orientation;
|
|
46
47
|
}
|
|
47
48
|
enablePushNotifications() {
|
|
48
|
-
|
|
49
|
+
this.sendCommand('enablePushNotifications');
|
|
49
50
|
}
|
|
50
51
|
signalSkillViewLoaded() {
|
|
51
|
-
|
|
52
|
+
this.sendCommand('skillViewLoaded');
|
|
52
53
|
}
|
|
53
|
-
|
|
54
|
+
sendCommand(command, payload) {
|
|
54
55
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
55
56
|
const options = {
|
|
56
57
|
command,
|
|
57
58
|
payload,
|
|
58
59
|
};
|
|
59
60
|
const message = JSON.stringify(options);
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
if (!this.isGettingKiosk) {
|
|
62
|
+
//@ts-ignore
|
|
63
|
+
(_d = (_c = (_b = (_a = window.webkit) === null || _a === void 0 ? void 0 : _a.messageHandlers) === null || _b === void 0 ? void 0 : _b.messages) === null || _c === void 0 ? void 0 : _c.postMessage) === null || _d === void 0 ? void 0 : _d.call(_c, message);
|
|
64
|
+
// @ts-ignore
|
|
65
|
+
(_e = window.AndroidInterface) === null || _e === void 0 ? void 0 : _e.postMessage(message);
|
|
66
|
+
}
|
|
64
67
|
//@ts-ignore
|
|
65
68
|
(_g = (_f = window.api) === null || _f === void 0 ? void 0 : _f.postMessage) === null || _g === void 0 ? void 0 : _g.call(_f, message);
|
|
66
69
|
this.emit('command', command, payload);
|
|
67
70
|
}
|
|
71
|
+
setTheatreSetting(name, value) {
|
|
72
|
+
this.sendCommand('setTheatreSetting', {
|
|
73
|
+
name,
|
|
74
|
+
value,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
async getTheatreSetting(_name) {
|
|
78
|
+
//@ts-ignore
|
|
79
|
+
if (window.api) {
|
|
80
|
+
this.isGettingKiosk = true;
|
|
81
|
+
this.sendCommand('getIsKioskModeEnabled');
|
|
82
|
+
this.isGettingKiosk = false;
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
return new Promise((resolve) => {
|
|
88
|
+
var _a, _b;
|
|
89
|
+
let timeout = setTimeout(() => resolve(false), 250);
|
|
90
|
+
//@ts-ignore
|
|
91
|
+
(_b = (_a = window.api) === null || _a === void 0 ? void 0 : _a.onMessage) === null || _b === void 0 ? void 0 : _b.call(_a, (json) => {
|
|
92
|
+
const { value } = JSON.parse(json);
|
|
93
|
+
clearTimeout(timeout);
|
|
94
|
+
resolve(value);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
}
|
|
68
98
|
}
|
|
69
99
|
exports.HeartwoodDevice = HeartwoodDevice;
|
|
70
100
|
//# sourceMappingURL=HeartwoodDevice.js.map
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import EventEmitter from 'events';
|
|
2
|
-
import { CachedValue, Device } from '@sprucelabs/heartwood-view-controllers';
|
|
2
|
+
import { CachedValue, Device, TheaterSettingValueTypes, TheatreSettingName } from '@sprucelabs/heartwood-view-controllers';
|
|
3
3
|
import { Orientation } from '../types/heartwood.types';
|
|
4
4
|
export declare class HeartwoodDevice extends EventEmitter implements Device {
|
|
5
5
|
private storage;
|
|
6
6
|
private orientation;
|
|
7
|
+
private isGettingKiosk;
|
|
7
8
|
protected constructor(storage: Storage);
|
|
8
9
|
openUrl(url: string): void;
|
|
9
10
|
static Device(storage: Storage): HeartwoodDevice;
|
|
@@ -15,5 +16,7 @@ export declare class HeartwoodDevice extends EventEmitter implements Device {
|
|
|
15
16
|
getOrientation(): Orientation;
|
|
16
17
|
enablePushNotifications(): void;
|
|
17
18
|
signalSkillViewLoaded(): void;
|
|
18
|
-
sendCommand(command: string, payload?: Record<string, any>):
|
|
19
|
+
sendCommand(command: string, payload?: Record<string, any>): void;
|
|
20
|
+
setTheatreSetting<N extends TheatreSettingName>(name: N, value: TheaterSettingValueTypes[N]): void;
|
|
21
|
+
getTheatreSetting<N extends TheatreSettingName>(_name: N): Promise<TheaterSettingValueTypes[N] | null>;
|
|
19
22
|
}
|
|
@@ -13,6 +13,7 @@ export class HeartwoodDevice extends EventEmitter {
|
|
|
13
13
|
constructor(storage) {
|
|
14
14
|
super();
|
|
15
15
|
this.orientation = 'unknown-orientation';
|
|
16
|
+
this.isGettingKiosk = false;
|
|
16
17
|
this.storage = storage;
|
|
17
18
|
}
|
|
18
19
|
openUrl(url) {
|
|
@@ -48,26 +49,55 @@ export class HeartwoodDevice extends EventEmitter {
|
|
|
48
49
|
return this.orientation;
|
|
49
50
|
}
|
|
50
51
|
enablePushNotifications() {
|
|
51
|
-
|
|
52
|
+
this.sendCommand('enablePushNotifications');
|
|
52
53
|
}
|
|
53
54
|
signalSkillViewLoaded() {
|
|
54
|
-
|
|
55
|
+
this.sendCommand('skillViewLoaded');
|
|
55
56
|
}
|
|
56
57
|
sendCommand(command, payload) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
58
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
59
|
+
const options = {
|
|
60
|
+
command,
|
|
61
|
+
payload,
|
|
62
|
+
};
|
|
63
|
+
const message = JSON.stringify(options);
|
|
64
|
+
if (!this.isGettingKiosk) {
|
|
64
65
|
//@ts-ignore
|
|
65
66
|
(_d = (_c = (_b = (_a = window.webkit) === null || _a === void 0 ? void 0 : _a.messageHandlers) === null || _b === void 0 ? void 0 : _b.messages) === null || _c === void 0 ? void 0 : _c.postMessage) === null || _d === void 0 ? void 0 : _d.call(_c, message);
|
|
66
67
|
// @ts-ignore
|
|
67
68
|
(_e = window.AndroidInterface) === null || _e === void 0 ? void 0 : _e.postMessage(message);
|
|
69
|
+
}
|
|
70
|
+
//@ts-ignore
|
|
71
|
+
(_g = (_f = window.api) === null || _f === void 0 ? void 0 : _f.postMessage) === null || _g === void 0 ? void 0 : _g.call(_f, message);
|
|
72
|
+
this.emit('command', command, payload);
|
|
73
|
+
}
|
|
74
|
+
setTheatreSetting(name, value) {
|
|
75
|
+
this.sendCommand('setTheatreSetting', {
|
|
76
|
+
name,
|
|
77
|
+
value,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
getTheatreSetting(_name) {
|
|
81
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
68
82
|
//@ts-ignore
|
|
69
|
-
|
|
70
|
-
|
|
83
|
+
if (window.api) {
|
|
84
|
+
this.isGettingKiosk = true;
|
|
85
|
+
this.sendCommand('getIsKioskModeEnabled');
|
|
86
|
+
this.isGettingKiosk = false;
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
return new Promise((resolve) => {
|
|
92
|
+
var _a, _b;
|
|
93
|
+
let timeout = setTimeout(() => resolve(false), 250);
|
|
94
|
+
//@ts-ignore
|
|
95
|
+
(_b = (_a = window.api) === null || _a === void 0 ? void 0 : _a.onMessage) === null || _b === void 0 ? void 0 : _b.call(_a, (json) => {
|
|
96
|
+
const { value } = JSON.parse(json);
|
|
97
|
+
clearTimeout(timeout);
|
|
98
|
+
resolve(value);
|
|
99
|
+
});
|
|
100
|
+
});
|
|
71
101
|
});
|
|
72
102
|
}
|
|
73
103
|
}
|