Basic Usage

Median NPM Examples

NPM Library Usage

👍

Median not median when using NPM package

When importing the Median JavaScript Bridge via the NPM package, always use the capitalized Median object to access methods. The lowercase median is reserved for the injected JavaScript bridge in native environments.

To avoid semantic errors and enable intelligent code completion, ensure your IDE is configured to support type hinting for the Median object.

Example: Importing and Using Median with React

import Median from "median-js-bridge";
import React, { useEffect } from "react";

const App: React.FC = () => {
    useEffect(() => {
        Median.onReady(() => {
            window.alert("Median app ready!");
        });
    }, []);
}

Example Commands

The following methods are available when using the median-js-bridge NPM package:

Check if Running in a Native App

↔️Median JavaScript Bridge

Median.isNativeApp(); 
// Returns: true or false

Retrieve the Current Platform

↔️Median JavaScript Bridge

Median.getPlatform();
// Returns a promise that resolves to: 'web' | 'android' | 'ios'

OneSignal example demonstrating login and oneSignalId retrieval

Use the following example to integrate OneSignal with Median, enabling user login and retrieving the oneSignalId.

useEffect(() => {
 Median.onReady(async () => {
   const result = await Median.onesignal.login('test-user');
   if (result?.success) {
     const info = await Median.onesignal.info();
     console.log(info?.oneSignalId);
      // Store or use the oneSignalId as needed
   }})
}, []);