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

ue-webview-bridge

v1.0.0

Published

UE WebView Bridge - A bidirectional communication bridge between Unreal Engine and Web View

Downloads

85

Readme

ue-webview-bridge

UE WebView Bridge 核心库,提供 Unreal Engine 与 Web View 之间的双向通信桥梁。

📦 安装

npm install ue-webview-bridge

💡 推荐使用方式

强烈推荐搭配 ue-webview-bridge-vite 插件使用:

npm install ue-webview-bridge ue-webview-bridge-vite

使用 Vite 插件后,无需手动初始化,插件会自动处理所有配置和初始化工作。

⚠️ 重要提示: 如果你的项目使用了路由(如 Vue Router、React Router 等),必须使用哈希模式(Hash Mode),而不是 History 模式。这是因为 UE WebView 环境的限制。

如果不使用 Vite 或需要手动集成,请继续阅读下面的手动初始化说明。

🚀 快速开始

方式一:使用 Vite 插件(推荐)

vite.config.ts 中配置插件:

import { defineConfig } from 'vite';
import ueWebViewBridge from 'ue-webview-bridge-vite';

export default defineConfig({
  plugins: [ueWebViewBridge()],
});

然后直接在代码中使用 API:

import { sendToGame, registerGameInterface } from 'ue-webview-bridge';

// 直接使用,无需初始化
sendToGame('PlayerAction', { action: 'jump' });

方式二:手动集成

如果不使用 Vite 插件,需要在页面中手动引入 jstoue.js 初始化脚本(由 ue-webview-bridge-vite 包提供),然后使用 API:

import { sendToGame, registerGameInterface } from 'ue-webview-bridge';

sendToGame('PlayerAction', { action: 'jump' });

发送消息到 UE

使用 sendToGame 向 Unreal Engine 发送消息:

import { sendToGame } from 'ue-webview-bridge';

// 发送简单事件
sendToGame('PlayerAction');

// 发送带数据的事件
sendToGame('UpdateScore', { score: 100, level: 5 });

// 发送带回调的事件
sendToGame('QueryData', { id: 1 }, (result) => {
  console.log('UE 返回:', result);
});

接收来自 UE 的消息

使用 registerGameInterface 注册回调函数来接收 UE 发送的消息:

import { registerGameInterface, unregisterGameInterface } from 'ue-webview-bridge';

// 注册接口
registerGameInterface('OnGameStateChanged', (data) => {
  console.log('游戏状态改变:', data);
});

// 取消注册
unregisterGameInterface('OnGameStateChanged');

📖 API 文档

isUEAvailable(): boolean

检查 UE WebView 接口是否可用。

返回值: boolean - UE 接口就绪时返回 true


sendToGame(eventName: string, data?: Record<string, unknown>, callback?: unknown, timeout?: number): void

向 Unreal Engine 发送消息。

参数:

  • eventName - 事件名称
  • data - 可选的数据负载,会与 eventName 合并后发送
  • callback - 可选的回调函数,接收 UE 的返回数据
  • timeout - 可选的回调超时时间(秒),默认 6 秒

示例:

sendToGame('PlayerJump');
sendToGame('UpdateInventory', { itemId: 123, count: 5 });
sendToGame('QueryPlayerInfo', {}, (data) => console.log(data), 10);

registerGameInterface<T>(eventName: string, callback: (data: T) => void): string

注册一个接口函数,用于接收来自 UE 的调用。

参数:

  • eventName - 事件名称,需要与 UE 端调用的名称一致
  • callback - 处理函数,接收来自 UE 的数据,支持自动 JSON 解析

返回值: string - 注册的事件名称

示例:

registerGameInterface('OnPlayerDeath', (data) => {
  console.log('玩家死亡:', data);
});

unregisterGameInterface(eventName: string): void

取消注册接口函数。

参数:

  • eventName - 要取消注册的事件名称

示例:

unregisterGameInterface('OnPlayerDeath');

🔧 工作原理

该库通过以下方式实现 Web View 与 UE 的通信:

  1. 初始化阶段: 由 jstoue.js(随 ue-webview-bridge-vite 提供)在页面加载时自动初始化 window.ue 及 WebView 通信通道
  2. 发送消息: 调用 ue.call(type, json, callback, timeout) 向 UE 发送消息,支持异步回调
  3. 接收消息: UE 通过调用 window.ue.interface 上注册的函数向 Web View 发送消息,数据自动完成 JSON 解析

📝 TypeScript 支持

本库完全使用 TypeScript 编写,提供完整的类型定义:

declare global {
  interface Window {
    ue: {
      call: (type: string, json: unknown, callback?: unknown, timeout?: number) => void;
      webview?: unknown;
      interface?: Record<string, (data: unknown) => void>;
      [key: string]: unknown;
    };
    ue4: (type: string, json: unknown, callback?: unknown, timeout?: number) => void;
  }
}

🔗 相关项目

📄 许可证

GPL-3.0 © kongziming