New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@podium/bridge

Package Overview
Dependencies
Maintainers
6
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@podium/bridge

This package is a bridge designed to pass [JSON-RPC 2.0](https://www.jsonrpc.org/specification) messages between a web application and a native web view.

latest
Source
npmnpm
Version
1.2.5
Version published
Weekly downloads
73
-32.41%
Maintainers
6
Weekly downloads
 
Created
Source

@podium/bridge

This package is a bridge designed to pass JSON-RPC 2.0 messages between a web application and a native web view.

Usage

To install:

npm install @podium/bridge

Import 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} */
const bridge = window['@podium'].bridge;

// You can listen for incoming messages, which can either be RpcRequest or RpcResponse
bridge.on('global/authentication', (message) => {
	const request =
		/** @type {import("@podium/bridge").RpcRequest<{ token?: string }>} */ (
			message
		);

	if (typeof request.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 }>} */
const response = await bridge.call({
	method: 'document/native-feature',
	params: { a: 'foo', b: 'bar' },
});

API

bridge.on

Add a listener for incoming messages for a given method name.

import '@podium/bridge';

/** @type {import("@podium/bridge").PodiumBridge} */
const bridge = window['@podium'].bridge;

bridge.on('global/authentication', (message) => {
	const request =
		/** @type {import("@podium/bridge").RpcRequest<{ token?: string }>} */ (
			message
		);

	if (typeof request.token === 'string') {
		// logged in
	} else {
		// logged out
	}
});

bridge.notification

Send a notification (one-way message).

import '@podium/bridge';

/** @type {import("@podium/bridge").PodiumBridge} */
const bridge = window['@podium'].bridge;

bridge.notification({
	method: 'global/authentication',
	params: { token: null },
});

bridge.call

Send a request and await a response.

import '@podium/bridge';

/** @type {import("@podium/bridge").PodiumBridge} */
const bridge = window['@podium'].bridge;

/** @type {import("@podium/bridge").RpcResponse<{ c: string }>} */
const response = await bridge.call({
	method: 'document/native-feature',
	params: { a: 'foo', b: 'bar' },
});

FAQs

Package last updated on 30 Sep 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts