This package is a bridge designed to pass JSON-RPC 2.0 messages between a web application and a native web view.
To install:
npm install @podium/bridgeImport the bridge in your client-side bundle:
import'@podium/bridge';You should probably send messages via @podium/browser. That said, the bridge is available on window['@podium'].bridge.
/** @type {import("@podium/bridge").PodiumBridge} */constbridge=window['@podium'].bridge;// You can listen for incoming messages, which can either be RpcRequest or RpcResponsebridge.on('global/authentication',(message)=>{constrequest=/** @type {import("@podium/bridge").RpcRequest<{ token?: string }>} */(message);if(typeofrequest.token==='string'){// logged in}else{// logged out}});// You can trigger notifications (one-way messages)bridge.notification({method: 'global/authentication',params: {token: null},});// And you can call methods and await the response/** @type {import("@podium/bridge").RpcResponse<{ c: string }>} */constresponse=awaitbridge.call({method: 'document/native-feature',params: {a: 'foo',b: 'bar'},});Add a listener for incoming messages for a given method name.
import'@podium/bridge';/** @type {import("@podium/bridge").PodiumBridge} */constbridge=window['@podium'].bridge;bridge.on('global/authentication',(message)=>{constrequest=/** @type {import("@podium/bridge").RpcRequest<{ token?: string }>} */(message);if(typeofrequest.token==='string'){// logged in}else{// logged out}});Send a notification (one-way message).
import'@podium/bridge';/** @type {import("@podium/bridge").PodiumBridge} */constbridge=window['@podium'].bridge;bridge.notification({method: 'global/authentication',params: {token: null},});Send a request and await a response.
import'@podium/bridge';/** @type {import("@podium/bridge").PodiumBridge} */constbridge=window['@podium'].bridge;/** @type {import("@podium/bridge").RpcResponse<{ c: string }>} */constresponse=awaitbridge.call({method: 'document/native-feature',params: {a: 'foo',b: 'bar'},});