简体   繁体   English

在Twilio Video上将本地曲目静音吗?

[英]Muting local tracks on Twilio Video?

Following guides, I'm attempting to disable and enable localAudioTracks . 按照指南,我尝试禁用和启用localAudioTracks

Within the roomJoined function, I have these two functions: roomJoined函数中,我具有以下两个函数:

      document.getElementById("audio-toggle-off").onclick = function() {
    console.log("muting this users audio");
    room.localParticipant.audioTracks.forEach(function(trackId, track) {
      track.disable();
    });
  };

  document.getElementById("audio-toggle-on").onclick = function() {
    console.log("enabling this users audio");
    room.localParticipant.audioTracks.forEach(function(trackId, track) {
      track.enable();
    });
  };

But on clicking these, I get the error that: 但是在单击这些时,出现以下错误:

VideoChat.js:241 Uncaught TypeError: track.enable is not a function
at VideoChat.js:241
at Map.forEach (<anonymous>)
at HTMLButtonElement.document.getElementById.onclick (VideoChat.js:240)

Any ideas? 有任何想法吗? For reference, I'm including the full roomJoined function below: 作为参考,我将以下完整的roomJoined函数包括在内:

    function roomJoined(room) {
  window.room = activeRoom = room;

  log("Joined as '" + identity + "'");

  if (hide) {
    return;
  }

  // document.getElementById("button-join").style.display = "none";
  // document.getElementById("button-leave").style.display = "inline";

  // Attach LocalParticipant's Tracks, if not already attached.
  var previewContainer = document.getElementById("local-media");

  if (previewContainer && !previewContainer.querySelector("video")) {
    attachParticipantTracks(room.localParticipant, previewContainer);
  }

  // Attach the Tracks of the Room's Participants.
  room.participants.forEach(function(participant) {
    log("Already in Room: '" + participant.identity + "'");
    var previewContainer = document.getElementById("remote-media");
    attachParticipantTracks(participant, previewContainer);
  });

  // When a Participant joins the Room, log the event.
  room.on("participantConnected", function(participant) {
    log("Joining: '" + participant.identity + "'");
  });

  // When a Participant adds a Track, attach it to the DOM.
  room.on("trackAdded", function(track, participant) {
    log(participant.identity + " added track: " + track.kind);
    var previewContainer = document.getElementById("remote-media");
    attachTracks([track], previewContainer);
  });

  // When a Participant removes a Track, detach it from the DOM.
  room.on("trackRemoved", function(track, participant) {
    log(participant.identity + " removed track: " + track.kind);
    detachTracks([track]);
  });

  // When a Participant leaves the Room, detach its Tracks.
  room.on("participantDisconnected", function(participant) {
    log("Participant '" + participant.identity + "' left the room");
    detachParticipantTracks(participant);
  });

  // Once the LocalParticipant leaves the room, detach the Tracks
  // of all Participants, including that of the LocalParticipant.
  room.on("disconnected", function() {
    log("Left");
    if (previewTracks) {
      previewTracks.forEach(function(track) {
        track.stop();
      });
    }
    detachParticipantTracks(room.localParticipant);
    room.participants.forEach(detachParticipantTracks);
    activeRoom = null;
    document.getElementById("button-join").style.display = "inline";
    document.getElementById("button-leave").style.display = "none";
  });

  document.getElementById("audio-toggle-off").onclick = function() {
    console.log("muting this users audio");
    room.localParticipant.audioTracks.forEach(function(trackId, track) {
      track.disable();
    });
  };

  document.getElementById("audio-toggle-on").onclick = function() {
    console.log("enabling this users audio");
    room.localParticipant.audioTracks.forEach(function(trackId, track) {
      track.enable();
    });
  };
}

So it looks like this was able to work: 所以看起来这可以工作:

  document.getElementById("audio-toggle-off").onclick = function() {
    room.localParticipant.audioTracks.forEach(function(
      audioTrack,
      key,
      map
    ) {
      console.log("muting this users audio");
      audioTrack.disable();
    });

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

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