npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@gmbl-games/webview-bridge

v1.0.2

Published

A lightweight bridge for communication between React Native WebViews and web content.

Readme

webview-bridge

A lightweight bridge for communication between React Native WebViews and web content.

Installation

npm install @gmbl-games/webview-bridge
# or
yarn add @gmbl-games/webview-bridge

Changelog

1.0.2

  • Improved README documentation

1.0.1

  • Enhanced message event handling for Android WebView compatibility

1.0.0

  • Initial release

Building

Run nx build webview-bridge to build the library.

Publish

From the libs/webview-bridge directory:

npm publish

This runs nx build webview-bridge automatically via the prepublishOnly hook before publishing to npm. Make sure to bump the version in package.json before publishing.

API Reference

Core Functions

  • parseWebViewMessage(event): Parses a message received either from the JS game or React Native. Returns null if the message is invalid.
  • sendMessageToApp(message): Sends a message from the JS game to React Native.
  • sendMessageToGame(message, webViewRef): Sends a message from React Native to the JS game.
  • createAppMessageEventListener(): Creates a listener manager for messages from React Native (use on the JS game). Returns { listenToAppMessage, destroyAppMessageListener }.

Types

  • GameConfig: Configuration object for the game.
    type GameConfig = {
      movingItemColor: string;
      staticItemColor: string;
    };
  • MessageType: Enum of available message types.
  • WebviewMessage: Typed message structure.

How to use

📁 RN Component (GameScreen.tsx)

import React, { useRef } from "react";
import { WebView } from "react-native-webview";
import {
  GameConfig,
  MessageType,
  parseWebViewMessage,
  sendMessageToGame,
} from "@gmbl-games/webview-bridge";

export default function GameScreen() {
  const webViewRef = useRef(null);

  const config: GameConfig = {
    movingItemColor: "#0f0",
    staticItemColor: "#f00",
  };

  const messageHandlers = {
    [MessageType.SESSION_STARTED]: () => console.log("🎮 Session started"),
    [MessageType.SESSION_ENDED]: () => console.log("🛑 Session ended"),
    [MessageType.SCORE_UPDATED]: (payload: { score: number }) =>
      console.log("📈 Score updated:", payload?.score),
    [MessageType.EXIT_GAME]: () => console.log("👋 Game exit requested"),
  };

  const handleMessage = (event: any) => {
    const message = parseWebViewMessage(event);
    if (!message) {
      return;
    }

    const handler = messageHandlers[message.type];
    if (handler) {
      handler(message.payload);
    }
  };

  const sendConfig = () => {
    sendMessageToGame(
      {
        type: MessageType.SEND_GAME_CONFIG,
        payload: config,
      },
      webViewRef
    );
  };

  return (
    <WebView
      ref={webViewRef}
      source={{ uri: "https://yourgame.com" }}
      onLoad={sendConfig} // send config when game loads
      onMessage={handleMessage} // handle messages from game
    />
  );
}

📁 Game (main.ts)

import {
  createAppMessageEventListener,
  sendMessageToApp,
  parseWebViewMessage,
  MessageType,
  GameConfig,
} from "@gmbl-games/webview-bridge";

// 1. Setup Listener
const { listenToAppMessage, destroyAppMessageListener } =
  createAppMessageEventListener();

listenToAppMessage((event) => {
  const message = parseWebViewMessage(event);
  if (!message) return;

  switch (message.type) {
    case MessageType.SEND_GAME_CONFIG:
      const config = message.payload as GameConfig;
      console.log("Received config:", config);
      // Initialize game with config...

      // Notify App that config is received
      sendMessageToApp({
        type: MessageType.GAME_CONFIG_RECEIVED,
        payload: config,
      });
      break;

    case MessageType.PAUSE_GAME:
      console.log("Pausing game...");
      sendMessageToApp({ type: MessageType.GAME_PAUSED });
      break;

    case MessageType.RESUME_GAME:
      console.log("Resuming game...");
      sendMessageToApp({ type: MessageType.GAME_RESUMED });
      break;
  }
});

// 2. Send messages to App
function updateScore(score: number) {
  sendMessageToApp({
    type: MessageType.SCORE_UPDATED,
    payload: { score },
  });
}

function exitGame() {
  sendMessageToApp({
    type: MessageType.EXIT_GAME,
  });
}

// Cleanup when needed
destroyAppMessageListener();