如何将触摸事件从一个应用程序发送到另一个应用程序

发布于 2025-01-18 06:00:35 字数 88 浏览 2 评论 0原文

我已经开发了屏幕铸造应用程序。我正在使用Twilio建立连接,但我想将接收器(参与者)与发件人(主机)作为实时数据共享触摸事件。有什么可能简化这一点的解决方案吗?

I have developed screen casting app. I am making connection using twilio but I want to share touch events from receiver(participant) to sender(host) as a live data. Is there any possible solution to simplify this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云雾 2025-01-25 06:00:35

如果您使用 Twilio Video 进行此连接,则可以使用 DataTrack API 通过您的连接发送任意数据。

您可以创建一个 LocalDataTrack 对象:

const { LocalDataTrack } = require(`twilio-video`);
const dataTrack = new LocalDataTrack();

将其连接到房间,方法是在连接时将其作为 tracks 选项的一部分发送,或者在连接后将其发布到房间已经做了。

const { connect } = require('twilio-video');

const room = await connect('$TOKEN', {
  name: 'my-chat-room',
  tracks: [dataTrack]
});

消息发布后,您可以沿着数据轨道发送消息:

dataTrack.send(message)

并且您可以通过订阅轨道并侦听 message 事件来接收数据轨道消息:

participant.on('trackSubscribed', track => {
  console.log(`Participant "${participant.identity}" added ${track.kind} Track ${track.sid}`);
  if (track.kind === 'data') {
    track.on('message', data => {
      console.log(data);
    });
  }
});

请参阅 文档了解更多详细信息。

If you are using Twilio Video for this connection then you can use the DataTrack API to send arbitrary data over your connection.

You can create a LocalDataTrack object:

const { LocalDataTrack } = require(`twilio-video`);
const dataTrack = new LocalDataTrack();

Connect it to a room, either by sending it as part of the tracks option when connecting, or by publishing it to the room after a connection has been made.

const { connect } = require('twilio-video');

const room = await connect('$TOKEN', {
  name: 'my-chat-room',
  tracks: [dataTrack]
});

You can send a message down the data track once it is published:

dataTrack.send(message)

And you can receive data track messages by subscribing to the track and listening for the message event:

participant.on('trackSubscribed', track => {
  console.log(`Participant "${participant.identity}" added ${track.kind} Track ${track.sid}`);
  if (track.kind === 'data') {
    track.on('message', data => {
      console.log(data);
    });
  }
});

See the documentation for more detail.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文