在连接之前检查Twilio视频室的参与者

发布于 2025-01-20 15:43:20 字数 1228 浏览 0 评论 0原文

我有一个1:1人的房间场景,我想确保他们在进入之前没有意外连接。 因此,一个人只能有1个实例,而人2只能有一个实例。最近打开的实例取代了以前的实例,并断开了以前的实例。 我正在使用twilio-video npm软件包,下一个JS和我的房间都像这样工作了。

async function connectToRoom(roomId, userType, tracks) {
  //Create a Access Token to connect to the room
  const credsP1 = await getRoomCredentials(roomId + '-' + userType)
  const room = await Video.connect(credsP1.token, {
    name: roomId,
    audio: { name: 'microphone' },
    video: { name: 'camera' },
    tracks: tracks,
  }).catch((error) => {
    if ('code' in error) {
      // Handle connection error here.
      console.error('Failed to join Room:', error.code, error.message)
    }
  })
}

在我的中,useeffect()下一个JS函数如何检查我是否已经连接? I would be able to use the userType keyword to check if I am PersonA or PersonB

I can't quite get this code translated to the twilio-video I am using

  client.video.rooms(roomId)
        .fetch()
        .then(room => console.log("check users and do my stuff here"));

Can anyone帮助使此功能正常工作?

谢谢

I have a 1:1 person to person room scenario where I want to make sure that they haven't accidentally connected already before entering.
So Person A can only have 1 instance and person 2 can only have one instance. The most recently opened instance supersedes the previous and disconnects their previous one.
I am using twilio-video npm package and Next JS and I have the rooms all working great like this.

async function connectToRoom(roomId, userType, tracks) {
  //Create a Access Token to connect to the room
  const credsP1 = await getRoomCredentials(roomId + '-' + userType)
  const room = await Video.connect(credsP1.token, {
    name: roomId,
    audio: { name: 'microphone' },
    video: { name: 'camera' },
    tracks: tracks,
  }).catch((error) => {
    if ('code' in error) {
      // Handle connection error here.
      console.error('Failed to join Room:', error.code, error.message)
    }
  })
}

In my useEffect() Next JS function how can I check to see if I have already connected? I would be able to use the userType keyword to check if I am PersonA or PersonB

I can't quite get this code translated to the twilio-video I am using

  client.video.rooms(roomId)
        .fetch()
        .then(room => console.log("check users and do my stuff here"));

Can anyone help get this function working?

Thanks

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文