Usage with Listeners

Using the npm package allows you to utilize listener functions which are invoked when an event occurs. These are similar to on-page JavaScript callback functions but are easier to implement.

Add listener

Register listener, function will be called when the corresponding event is triggered.

App Resumed Event

const listenerId = Median.appResumed.addListener(() => {
    console.log("App resumed listener");
});

OneSignal plugin

Documentation

const listenerId = Median.oneSignalPushOpened.addListener((data) => {
    console.log(JSON.stringify(data));
});

Share into app plugin

Documentation

const listenerId = Median.shareToApp.addListener((data) => {
    console.log(data.url, data.subject);
});

Haptics plugin

Documentation

const listenerId = Median.deviceShake.addListener(() => {
    console.log("Device shake listener");
});

Remove listener

Remove a specific listener so that it will no longer be called when the corresponding event is triggered

Median.deviceShake.removeListener(listenerId);