简体   繁体   English

在 twilio-video 中,如果我连接到自动订阅设置为 false 的房间,我以后如何订阅远程曲目?

[英]In twilio-video, how can I subscribe to remote tracks at later time if I connected to a room with automaticSubscription set to false?

Based on example provided in docs for twilio-video v2.x I can connect to a chat room without automatically subscribing to any tracks published by remote participants like this:根据twilio-video v2.x 文档中提供的示例,我可以连接到聊天室,而无需自动订阅远程参与者发布的任何曲目,如下所示:

  const { connect } = require('twilio-video');
  const room = await connect(token, {
    automaticSubscription: false
  });

If I do this then how can I subscribe to remote tracks at later time?如果我这样做,那么我以后如何订阅远程曲目?

You can check Twilio Track Subscription API .您可以查看Twilio Track Subscription API

or check below code for Updating Track subscription later.或检查下面的代码以稍后更新轨道订阅。

// Find your credentials at twilio.com/console
const API_KEY_SID = 'SKXXXX';
const API_KEY_SECRET = 'your_api_key_secret';
const ACCOUNT_SID = 'ACXXXX';

const Twilio = require('twilio');

const client = new Twilio(API_KEY_SID, API_KEY_SECRET, {accountSid: ACCOUNT_SID});

//-------------------------------------------------------------------------------
//1. At connect time Adam wants to receive all the tracks.
//   Done by default rule. No further actions required.


//-------------------------------------------------------------------------------
//2. After a while, Adam notices his bandwidth consumption is too high and
//   decides to unsubscribe from all video tracks

client.video.rooms('RMXXXX').participants.get('Adam')
.subscribeRules.update({
  rules: [
    {"type": "include", "kind": "audio"}
  ]
})
.then(result => {
  console.log('Subscribe Rules updated successfully')
})
.catch(error => {
  console.log('Error updating rules ' + error)
});

//-------------------------------------------------------------------------------
//3. Later, a video screenshare track with SID MTXXXX is published to the room
//   and Adam subscribes to it.

client.video.rooms('RMXXXX').participants.get('Adam')
.subscribeRules.update({
  rules: [
    {"type": "include", "kind": "audio"},
    {"type": "include", "track": "MTXXXX"}
  ]
})
.then(result => {
  console.log('Subscribe Rules updated successfully')
})
.catch(error => {
  console.log('Error updating rules ' + error)
});

//-------------------------------------------------------------------------------
//4. John, another participant, is in a noisy place and his audio track is
//   annoying. Adam decides to unsubscribe from it.

client.video.rooms('RMXXXX').participants.get('Adam')
.subscribeRules.update({
  rules: [
    {"type": "include", "kind": "audio"},
    {"type": "include", "track": "MTXXXX"},
    {"type": "exclude", "publisher": "John", "kind": "audio"}
  ]
})
.then(result => {
  console.log('Subscribe Rules updated successfully')
})
.catch(error => {
  console.log('Error updating rules ' + error)
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM