Как в twilio-video я могу подписаться на удаленные треки позже, если я подключился к комнате с автоматической подпиской, установленной на false?

На основе примера, приведенного в документации для twilio-video v2.x, я могу подключиться к чату без автоматической подписки на какие-либо треки, опубликованные удаленными участниками, например:

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

Если я сделаю это, как я могу подписаться на удаленные треки позже?

1 ответ

Вы можете проверить API подписки Twilio Track.

или проверьте код ниже для обновления подписки на трек позже.

// 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)
});
Другие вопросы по тегам