Guides

Host features

Listen to host events and use device controls such as orientation, haptics and the deposit modal.

Listen to host events

import { WalletBridgeClient } from '@hydraone-sdk/core';

export function listen(client: WalletBridgeClient) {
  const offTheme = client.onThemeChanged((theme) => console.log('theme', theme));
  const offAudio = client.onAudioMutedChanged((muted) => console.log('muted', muted));
  const offCustom = client.on<{ foo: string }>('CUSTOM_EVENT', (p) => console.log(p.foo));
  return () => {
    offTheme();
    offAudio();
    offCustom();
  };
}

Every subscription returns an unsubscribe function. Call client.destroy() when the game shuts down; it removes all listeners.

Device and host controls

These calls ask the host shell to act:

import { WalletBridgeClient } from '@hydraone-sdk/core';

export async function device(client: WalletBridgeClient) {
  await client.setOrientation('landscape');
  await client.triggerHaptic('success');
  await client.requestDepositModal({ token: 'ADA', minAmount: 10 });
  const profile = await client.getPlayerProfile();
  return profile.nickname;
}
CallOutside the App Center iframe
setOrientationUses the browser API and ignores failures.
triggerHapticUses the browser API and ignores failures.
requestDepositModalNeeds the host. Outside the App Center iframe it rejects with ERR_NOT_IN_IFRAME.
getPlayerProfileAsks the host for the player profile.

Use unlockOrientation to release a lock you set earlier.

Next steps