在连接之前检查Twilio视频室的参与者
我有一个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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论