@player-ui/beacon-plugin 0.3.1-next.1 → 0.3.1
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/dist/beacon-plugin.dev.js +10706 -0
- package/dist/beacon-plugin.prod.js +2 -0
- package/dist/index.cjs.js +23 -21
- package/dist/index.d.ts +1 -2
- package/dist/index.esm.js +18 -16
- package/package.json +14 -5
- package/src/beacon.ts +22 -23
package/src/beacon.ts
CHANGED
|
@@ -3,8 +3,6 @@ import type {
|
|
|
3
3
|
Player,
|
|
4
4
|
PlayerPlugin,
|
|
5
5
|
PlayerFlowState,
|
|
6
|
-
DataController,
|
|
7
|
-
ExpressionEvaluator,
|
|
8
6
|
Logger,
|
|
9
7
|
} from '@player-ui/player';
|
|
10
8
|
import { resolveDataRefs } from '@player-ui/player';
|
|
@@ -81,8 +79,7 @@ export class BeaconPlugin implements PlayerPlugin {
|
|
|
81
79
|
view: undefined,
|
|
82
80
|
};
|
|
83
81
|
|
|
84
|
-
private
|
|
85
|
-
private expressionEvaluator?: ExpressionEvaluator;
|
|
82
|
+
private resolveDataRefs?: <T>(data: T) => T;
|
|
86
83
|
|
|
87
84
|
public hooks = {
|
|
88
85
|
buildBeacon: new AsyncSeriesWaterfallHook<[unknown, HookArgs]>(),
|
|
@@ -110,12 +107,14 @@ export class BeaconPlugin implements PlayerPlugin {
|
|
|
110
107
|
this.player = player;
|
|
111
108
|
this.logger = player.logger;
|
|
112
109
|
|
|
113
|
-
player.hooks.
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
110
|
+
player.hooks.state.tap(this.name, (playerState) => {
|
|
111
|
+
if (playerState.status === 'in-progress') {
|
|
112
|
+
this.resolveDataRefs = (data) =>
|
|
113
|
+
resolveDataRefs(data, {
|
|
114
|
+
model: playerState.controllers.data,
|
|
115
|
+
evaluate: playerState.controllers.expression.evaluate,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
119
118
|
});
|
|
120
119
|
|
|
121
120
|
player.hooks.viewController.tap(this.name, (vc) => {
|
|
@@ -185,7 +184,9 @@ export class BeaconPlugin implements PlayerPlugin {
|
|
|
185
184
|
const { action, element, asset, view } = event;
|
|
186
185
|
const { view: currentView } = this.beaconContext;
|
|
187
186
|
setTimeout(async () => {
|
|
188
|
-
const
|
|
187
|
+
const unresolvedData = event?.data || event.asset?.metaData?.beacon;
|
|
188
|
+
|
|
189
|
+
const data = this.resolveDataRefs?.(unresolvedData) ?? unresolvedData;
|
|
189
190
|
|
|
190
191
|
const defaultBeacon = {
|
|
191
192
|
action,
|
|
@@ -199,25 +200,23 @@ export class BeaconPlugin implements PlayerPlugin {
|
|
|
199
200
|
...event,
|
|
200
201
|
data,
|
|
201
202
|
state,
|
|
202
|
-
view: view
|
|
203
|
+
view: view ?? currentView,
|
|
203
204
|
logger: this.logger as Logger,
|
|
204
205
|
};
|
|
205
|
-
|
|
206
|
+
let beacon =
|
|
206
207
|
(await this.hooks.buildBeacon.call(defaultBeacon, hookArgs)) ||
|
|
207
208
|
defaultBeacon;
|
|
209
|
+
|
|
210
|
+
// Re-resolve data refs in case the hook modified the beacon and introduced more
|
|
211
|
+
if (beacon !== defaultBeacon && this.resolveDataRefs) {
|
|
212
|
+
beacon = this.resolveDataRefs(beacon);
|
|
213
|
+
}
|
|
214
|
+
|
|
208
215
|
const shouldCancel = this.hooks.cancelBeacon.call(hookArgs) || false;
|
|
209
216
|
|
|
210
217
|
if (!shouldCancel) {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
? resolveDataRefs(beacon, {
|
|
214
|
-
model: this.dataController,
|
|
215
|
-
evaluate: this.expressionEvaluator.evaluate,
|
|
216
|
-
})
|
|
217
|
-
: beacon;
|
|
218
|
-
|
|
219
|
-
this.logger?.debug('Sending beacon event', resolvedBeacon);
|
|
220
|
-
this.hooks.publishBeacon.call(resolvedBeacon);
|
|
218
|
+
this.logger?.debug('Sending beacon event', beacon);
|
|
219
|
+
this.hooks.publishBeacon.call(beacon);
|
|
221
220
|
}
|
|
222
221
|
}, 0);
|
|
223
222
|
}
|