🎉 黑五狂欢:使用优惠码 PRO40,Pro 年度方案享6折!点击查看详情

🎉 黑五狂欢:使用优惠码 PRO40,Pro 年度方案享6折!点击查看详情

🎉 黑五狂欢:使用优惠码 PRO40,Pro 年度方案享6折!点击查看详情

行业

汽车

航空

金融

游戏

医疗科技

物联网

数字产品

使用场景

面向企业

面向个人

面向团队

用于教育

主要特点

硬件与系统集成

ProtoPie MCP

多设备原型设计

交互逻辑

开发交接

ProtoPie AI

用户测试

产品

Connect Omni

插件

Figma

Sketch

Adobe XD

洞见与灵感

博客

白皮书

客户成功案例

活动与网络研讨会

ProtoPie 画廊

产品学习与支持

ProtoPie 学堂

下载 ProtoPie

产品文档

社区

行业

汽车

航空

金融

游戏

医疗科技

物联网

数字产品

使用场景

面向企业

面向个人

面向团队

用于教育

主要特点

硬件与系统集成

ProtoPie MCP

多设备原型设计

交互逻辑

开发交接

ProtoPie AI

用户测试

产品

Connect Omni

插件

Figma

Sketch

Adobe XD

洞见与灵感

博客

白皮书

客户成功案例

活动与网络研讨会

ProtoPie 画廊

产品学习与支持

ProtoPie 学堂

下载 ProtoPie

产品文档

社区

菜单


连接 Omni Adapter 与消息

Adapter 用于将正在运行的应用程序连接到 Stage。它负责处理身份验证、消息传递和重新连接。您的应用程序仍然需要具备自己的逻辑来发送消息并对接收到的消息做出反应。

支持的语言

如果您正在使用 AI 编程工具,请先参阅 Connect Omni Adapter AI 指南。您的 AI 工具可以利用该指南为您的项目选择并安装相应的 Adapter 软件包。

如需手动设置,请选择您项目的编程语言并在下方安装对应的软件包。

语言

典型用途

安装

TypeScript / JavaScript

Web 应用、Node.js

npm install @studioxid/omni-adapter

Python

模拟器与脚本

pip install omni-adapter

C#

Unity 与 .NET

.NET:

dotnet add package StudioXid.OmniAdapter

Unity:安装 NuGetForUnity,然后从

StudioXid.OmniAdapter

NuGet → Manage NuGet Packages 添加。

Dart

Flutter

flutter pub add omni_adapter

Swift

Apple 平台应用

.package(url: "<https://github.com/ProtoPie/omni-adapter-swift>", from: "0.1.0") (Swift Package Manager)

Kotlin

Android 应用

implementation("com.studioxid:omni-adapter:0.1.0") (Gradle)

这些软件包需添加到您自己的项目中,而非导入至 Connect Omni。安装要求和支持的功能可能因语言和版本而异。

有关安装说明、API 用法和示例,请参阅软件包文档:

若要在 Stage 上直接显示 Unity WebGL 构建版本,请参阅 在 Stage 上显示应用 → Unity 图层。若要通过 C# Adapter 连接 Unity 应用程序,请使用上述安装说明。

配置 Adapter

每个应用程序都需要:

  • Adapter Key 用于连接到 Stage。请妥善保存,例如保存在环境变量(CONNECT_TOKEN)或机密管理器(Secret Manager)中。

  • Adapter Name (displayName) 用于在 Backstage 中标识该应用程序。使用独特的名称以便更容易识别连接。

您还可以声明应用程序发送和接收的频道(Channel)。这些频道会显示在 Backstage 中,但默认情况下不会限制消息传递。若仅接收已声明的频道,请启用选择性接收。

其他可选设置包括备用实例、屏幕广播和重新连接。

消息与频道

每条消息都包含一个频道(其名称)和一个值。例如,仪表板发送 climate.temperature.request = 23,模拟器回复 climate.temperature = 23。

  • 值可以是字符串、数字、布尔值或 null。发送结构化数据请使用 JSON 字符串。

  • 从 Console 发送的值将作为字符串送达。在将其作为数字使用之前,请在应用程序中先进行转换。

  • 默认情况下,应用程序会接收来自 Stage 上其他参与者的消息。开启选择性接收将仅接收与应用程序所声明频道完全匹配的消息。

  • 未声明频道的应用程序仍可正常连接并交换消息,只是其 Backstage 节点不会显示频道标签。

Adapter Key

  • 在 Share → Adapter keys → Create key 中创建密钥。该密钥仅显示一次。

  • 尽量为每个程序使用单独的密钥。

  • 如果应用程序需要在没有 Editor 的情况下启动并保持会话(Session)运行,请启用 Let adapters start a session。

  • 当某个应用程序不再需要连接时,请吊销相应密钥。使用该密钥的应用程序将收到 AuthRevoked。

  • Adapter Key 用于连接程序,分享链接用于邀请人员。切勿将二者混用。

重新连接与状态

  • Adapter 会自动重试,并在离线时将最多 1,000 条发送消息加入队列。重连后,较早排队的值可能会陆续送达。

  • 一个 Session 最多保留 1,000 条近期消息。应用程序可以利用该历史记录恢复最新的已知值,但 Connect Omni 不会自动恢复其状态。历史命令不会作为新操作重放。

  • 新 Session 启动时为空。重新连接或启动新 Session 后,各应用程序需自行负责恢复并发布其当前状态。

  • 每个程序每秒最多可发送 60 条消息。Connect Omni 专为交互式测试而设计,并非用于安全关键型控制。

Web View 集成

在 Web View 图层中显示的 Web 应用程序通过该图层的 Send 和 Receive 规则交换消息,无需在浏览器代码中暴露 Adapter Key。有关设置,请参阅 在 Stage 上显示应用 → Web View。

手动集成示例:仪表板与模拟器

TypeScript:仪表板连接 (Node.js)

import { connect } from '@studioxid/omni-adapter';

const client = await connect({
  secretKey: process.env.CONNECT_TOKEN!,
  displayName: 'smart-home-dashboard',
  sends: ['climate.temperature.request'],
  receives: ['climate.temperature'],
});

// Receive the confirmed temperature.
client.on('climate.temperature', (msg) => {
  console.log('Confirmed temperature:', msg.value);
  // Update the dashboard through your app's UI logic.
});

// Call this from your server-side handler
// when the user changes the temperature.
export async function requestTemperature(value: number) {
  await client.send('climate.temperature.request', value);
}

client.on('error', (err) => {
  console.error(`[${err.code}] ${err.hint ?? err.message}`);
});

for (const signal of ['SIGINT', 'SIGTERM'] as const) {
  process.once(signal, () => void client.close());
}
import { connect } from '@studioxid/omni-adapter';

const client = await connect({
  secretKey: process.env.CONNECT_TOKEN!,
  displayName: 'smart-home-dashboard',
  sends: ['climate.temperature.request'],
  receives: ['climate.temperature'],
});

// Receive the confirmed temperature.
client.on('climate.temperature', (msg) => {
  console.log('Confirmed temperature:', msg.value);
  // Update the dashboard through your app's UI logic.
});

// Call this from your server-side handler
// when the user changes the temperature.
export async function requestTemperature(value: number) {
  await client.send('climate.temperature.request', value);
}

client.on('error', (err) => {
  console.error(`[${err.code}] ${err.hint ?? err.message}`);
});

for (const signal of ['SIGINT', 'SIGTERM'] as const) {
  process.once(signal, () => void client.close());
}
import { connect } from '@studioxid/omni-adapter';

const client = await connect({
  secretKey: process.env.CONNECT_TOKEN!,
  displayName: 'smart-home-dashboard',
  sends: ['climate.temperature.request'],
  receives: ['climate.temperature'],
});

// Receive the confirmed temperature.
client.on('climate.temperature', (msg) => {
  console.log('Confirmed temperature:', msg.value);
  // Update the dashboard through your app's UI logic.
});

// Call this from your server-side handler
// when the user changes the temperature.
export async function requestTemperature(value: number) {
  await client.send('climate.temperature.request', value);
}

client.on('error', (err) => {
  console.error(`[${err.code}] ${err.hint ?? err.message}`);
});

for (const signal of ['SIGINT', 'SIGTERM'] as const) {
  process.once(signal, () => void client.close());
}
import { connect } from '@studioxid/omni-adapter';

const client = await connect({
  secretKey: process.env.CONNECT_TOKEN!,
  displayName: 'smart-home-dashboard',
  sends: ['climate.temperature.request'],
  receives: ['climate.temperature'],
});

// Receive the confirmed temperature.
client.on('climate.temperature', (msg) => {
  console.log('Confirmed temperature:', msg.value);
  // Update the dashboard through your app's UI logic.
});

// Call this from your server-side handler
// when the user changes the temperature.
export async function requestTemperature(value: number) {
  await client.send('climate.temperature.request', value);
}

client.on('error', (err) => {
  console.error(`[${err.code}] ${err.hint ?? err.message}`);
});

for (const signal of ['SIGINT', 'SIGTERM'] as const) {
  process.once(signal, () => void client.close());
}
import { connect } from '@studioxid/omni-adapter';

const client = await connect({
  secretKey: process.env.CONNECT_TOKEN!,
  displayName: 'smart-home-dashboard',
  sends: ['climate.temperature.request'],
  receives: ['climate.temperature'],
});

// Receive the confirmed temperature.
client.on('climate.temperature', (msg) => {
  console.log('Confirmed temperature:', msg.value);
  // Update the dashboard through your app's UI logic.
});

// Call this from your server-side handler
// when the user changes the temperature.
export async function requestTemperature(value: number) {
  await client.send('climate.temperature.request', value);
}

client.on('error', (err) => {
  console.error(`[${err.code}] ${err.hint ?? err.message}`);
});

for (const signal of ['SIGINT', 'SIGTERM'] as const) {
  process.once(signal, () => void client.close());
}

此示例运行在仪表板的 Node.js 后端。将 requestTemperature() 以及接收到的值连接到您现有的 UI 逻辑。切勿在浏览器端代码中暴露 CONNECT_TOKEN。

对于在 Connect Omni Web View 图层中展示的纯浏览器仪表板,请改用 Adapter 的 Engine 配置。请参阅 在 Stage 上显示应用。

Python:模拟器

import asyncio
import os
import omni_adapter

async def main():
    client = await omni_adapter.connect(
        secret_key=os.environ["CONNECT_TOKEN"],
        display_name="smart-home-simulator",
        receives=["climate.temperature.request"],
        sends=["climate.temperature"],
    )

    temperature = 22.0
    stop = asyncio.Event()

    @client.on("climate.temperature.request")
    async def on_request(msg):
        nonlocal temperature

        try:
            temperature = float(msg.value)
        except (TypeError, ValueError):
            print("Invalid temperature:", msg.value)
            return

        print("Temperature updated:", temperature)
        await client.send("climate.temperature", temperature)

    client.on("error", lambda err: print(
        f"[{err.code}] {err.hint or err.message}"
    ))

    with omni_adapter.stop_on_signals(stop.set):
        try:
            # Publish the initial state.
            await client.send("climate.temperature", temperature)
            await stop.wait()
        finally:
            await client.close()

if __name__ == "__main__":
    try:
        asyncio.run(main())
    except KeyboardInterrupt:
        pass
import asyncio
import os
import omni_adapter

async def main():
    client = await omni_adapter.connect(
        secret_key=os.environ["CONNECT_TOKEN"],
        display_name="smart-home-simulator",
        receives=["climate.temperature.request"],
        sends=["climate.temperature"],
    )

    temperature = 22.0
    stop = asyncio.Event()

    @client.on("climate.temperature.request")
    async def on_request(msg):
        nonlocal temperature

        try:
            temperature = float(msg.value)
        except (TypeError, ValueError):
            print("Invalid temperature:", msg.value)
            return

        print("Temperature updated:", temperature)
        await client.send("climate.temperature", temperature)

    client.on("error", lambda err: print(
        f"[{err.code}] {err.hint or err.message}"
    ))

    with omni_adapter.stop_on_signals(stop.set):
        try:
            # Publish the initial state.
            await client.send("climate.temperature", temperature)
            await stop.wait()
        finally:
            await client.close()

if __name__ == "__main__":
    try:
        asyncio.run(main())
    except KeyboardInterrupt:
        pass
import asyncio
import os
import omni_adapter

async def main():
    client = await omni_adapter.connect(
        secret_key=os.environ["CONNECT_TOKEN"],
        display_name="smart-home-simulator",
        receives=["climate.temperature.request"],
        sends=["climate.temperature"],
    )

    temperature = 22.0
    stop = asyncio.Event()

    @client.on("climate.temperature.request")
    async def on_request(msg):
        nonlocal temperature

        try:
            temperature = float(msg.value)
        except (TypeError, ValueError):
            print("Invalid temperature:", msg.value)
            return

        print("Temperature updated:", temperature)
        await client.send("climate.temperature", temperature)

    client.on("error", lambda err: print(
        f"[{err.code}] {err.hint or err.message}"
    ))

    with omni_adapter.stop_on_signals(stop.set):
        try:
            # Publish the initial state.
            await client.send("climate.temperature", temperature)
            await stop.wait()
        finally:
            await client.close()

if __name__ == "__main__":
    try:
        asyncio.run(main())
    except KeyboardInterrupt:
        pass
import asyncio
import os
import omni_adapter

async def main():
    client = await omni_adapter.connect(
        secret_key=os.environ["CONNECT_TOKEN"],
        display_name="smart-home-simulator",
        receives=["climate.temperature.request"],
        sends=["climate.temperature"],
    )

    temperature = 22.0
    stop = asyncio.Event()

    @client.on("climate.temperature.request")
    async def on_request(msg):
        nonlocal temperature

        try:
            temperature = float(msg.value)
        except (TypeError, ValueError):
            print("Invalid temperature:", msg.value)
            return

        print("Temperature updated:", temperature)
        await client.send("climate.temperature", temperature)

    client.on("error", lambda err: print(
        f"[{err.code}] {err.hint or err.message}"
    ))

    with omni_adapter.stop_on_signals(stop.set):
        try:
            # Publish the initial state.
            await client.send("climate.temperature", temperature)
            await stop.wait()
        finally:
            await client.close()

if __name__ == "__main__":
    try:
        asyncio.run(main())
    except KeyboardInterrupt:
        pass
import asyncio
import os
import omni_adapter

async def main():
    client = await omni_adapter.connect(
        secret_key=os.environ["CONNECT_TOKEN"],
        display_name="smart-home-simulator",
        receives=["climate.temperature.request"],
        sends=["climate.temperature"],
    )

    temperature = 22.0
    stop = asyncio.Event()

    @client.on("climate.temperature.request")
    async def on_request(msg):
        nonlocal temperature

        try:
            temperature = float(msg.value)
        except (TypeError, ValueError):
            print("Invalid temperature:", msg.value)
            return

        print("Temperature updated:", temperature)
        await client.send("climate.temperature", temperature)

    client.on("error", lambda err: print(
        f"[{err.code}] {err.hint or err.message}"
    ))

    with omni_adapter.stop_on_signals(stop.set):
        try:
            # Publish the initial state.
            await client.send("climate.temperature", temperature)
            await stop.wait()
        finally:
            await client.close()

if __name__ == "__main__":
    try:
        asyncio.run(main())
    except KeyboardInterrupt:
        pass

在环境中配置 CONNECT_TOKEN 后运行模拟器。

这些示例展示了如何与 Connect Omni 交换消息,并未实现仪表板的 UI。请将发送和接收处理程序连接到应用程序的控件和显示界面。有关更多实现示例,请参阅上面链接的软件包文档。

当两个应用程序都运行后,更改仪表板的温度应会发送 climate.temperature.request。模拟器处理该请求并发布带有确认值的 climate.temperature。