Skip to content

PubSub

The PubSub plugin adds a publish/subscribe interface between the host app and Player’s content.

Usage

Add the plugin to Player:

import { Player } from "@player-ui/player";
import { PubSubPlugin } from "@player-ui/pub-sub-plugin";
const pubsub = new PubSubPlugin();
const token = pubsub.subscribe("some-event", () => {
// Callback
});
const player = new Player({
plugins: [pubsub],
});

To unsubscribe:

pubsub.unsubscribe(token);

Publish Expression

To trigger an event to be published, use the publish() expression in Player’s content:

{
"asset": {
"id": "sample",
"type": "action",
"exp": "@[ publish('some-event', 'some optional data') ]@""
}
}