【问题标题】:Twilio Video sizing in FirefoxFirefox 中的 Twilio 视频大小调整
【发布时间】:2020-10-07 23:57:47
【问题描述】:

我正在尝试让特定尺寸的视频面板正常工作,但我很难让它在 Chrome 以外的浏览器中正常工作。我的堆栈是 Angular 5、Twilio Video(1.10.0 使用 npm i twilio-video)和 Twilio 库 1.13(来自这里://media.twiliocdn.com/taskrouter/js/v1.13/taskrouter.min.js)

我有以下代码(基于 QuickStart 项目:https://github.com/twilio/video-quickstart-js),它在 Chrome 中运行良好,并为我提供了一个 195 宽的窗口,但是当我在 Firefox 中运行相同的代码时,我得到了一个视频640x480 的窗口。在这里的任何帮助将不胜感激!

import { connect, Room, Track } from 'twilio-video';

makeConnection(token: string, roomName: string): void {
  connect(token,
    {
      audio: true,
      name: roomName,
      video: { width: 195 }
    }
  ).then(room => {
    this.room = room;

    this.roomJoined(room);
  }, error => {
    this.error = error;
  });
}

roomJoined(room) {
  // Attach LocalParticipant's Tracks, if not already attached.
  let previewContainer = document.getElementById('local-media');
  if (!previewContainer.querySelector('video')) {
    console.log("Adding preview");
    this.attachParticipantTracks(room.localParticipant, previewContainer);
  }

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

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

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

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

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

  // Once the LocalParticipant leaves the room, detach the Tracks
  // of all Participants, including that of the LocalParticipant.
  room.on('disconnected', () => {
    console.log('Left');
    if (this.previewTracks) {
      this.previewTracks.forEach( (track) => {
        track.stop();
      });
    }
    room.participants.forEach(participant => this.detachParticipantTracks(participant));
  });
}

// Attach the Tracks to the DOM.
attachTracks(tracks, container) {
  tracks.forEach(track => {
    container.appendChild(track.attach());
  });
}

// Attach the Participant's Tracks to the DOM.
attachParticipantTracks(participant, container) {
  let tracks = Array.from(participant.tracks.values());
  this.attachTracks(tracks, container);
}

// Detach the Tracks from the DOM.
detachTracks(tracks) {
  tracks.forEach(track => {
    track.detach().forEach( (detachedElement) => {
      detachedElement.remove();
    });
  });
}

// Detach the Participant's Tracks from the DOM.
detachParticipantTracks(participant) {
  let tracks = Array.from(participant.tracks.values());
  this.detachTracks(tracks);
}

disconnectFromRoom(): void {
  console.log("Disconnecting");
  this.room.disconnect();
}

【问题讨论】:

    标签: angular firefox twilio


    【解决方案1】:

    您可以像这样添加视频大小

     function attachTracks(tracks, container) {
    
       tracks.forEach(function(track) {
        container.appendChild(track.attach());
       });
    
       $('#remote-media > video').css({'width': '100%'});
      $('#local-media > video').css({'width': '100%', 'margin-left': '0px'});
    }
    

    【讨论】:

    • 对于 Twilio 用户来说,调整你想要的任何大小是更好的解决方案......谢谢......
    【解决方案2】:

    这里是 Twilio 开发者宣传员。

    经过一些自我测试后,我发现 Firefox 不喜欢 width 的许多值作为媒体约束的一部分。

    如果你从

    切换你的约束
    video: {
      width: 195
    }
    

    video: {
      width: {
        exact: 195
      }
    }
    

    然后尝试获取相机流,它将失败并显示消息“约束可能不满足”。在这种情况下,Firefox 之前忽略了 195,因为它是一个建议,当使用 exact 时,它要么必须遵守,要么失败,并且失败了。

    我的建议是为浏览器可以从中选择最佳选项的宽度提供一系列约束。在您的情况下,理想的宽度是 195,但如果 Firefox 不支持它,我们应该给它一个可接受的宽度范围。比如:

    video: {
      width: {
        ideal: 195,
        min: 160,
        max: 320
      }
    }
    

    然后,我建议您使用 CSS 调整生成的 <video> 元素的大小,使其也适合您想要的大小。

    你可以阅读更多关于setting media constraints and ranges on MDN的信息。

    让我知道这是否有帮助。

    【讨论】:

    • 感谢您的反馈!我尝试了您的建议,但现在在 Firefox 中出现以下错误:MediaStreamError { name: "OverconstrainedError", message: "Constraints could not be compatible.", constraint: "width", stack: "" }.
    • 您使用了哪些约束导致出现该错误?
    • 你推荐的那个:video: { width: { Ideal: 195, min: 160, max: 320 } }
    • 嗯,我没有收到错误。您可能必须探索哪些约束适合您的系统。然而,由于我发布的那些在我的机器上工作,你可能不得不比你在自己的浏览器上找到的更宽容。理想情况下,我们可以访问 MediaStreamTrack.getCapabilities() 方法,但该方法仍在开发中,因此目前处于反复试验阶段。
    • 感谢菲尔的帮助,我想你给了我足够的帮助。
    【解决方案3】:

    以防万一有人遇到相同的行为:我一直遇到问题,Firefox 忽略了特定相机(确切地说是 Microsoft LifeCam HD-3000)的 aspectRatio 设置,并且总是创建一个 4 :3 图像,尽管纵横比设置为 16:9。我的代码看起来像这样:

    createLocalVideoTrack({
      height: 720,
      aspectRatio: 16/9,
      deviceId,
    })
    

    这在除 Firefox 之外的所有浏览器中都能正常工作。修复它的唯一方法是专门提供 width 属性:

    createLocalVideoTrack({
      height: 720,
      width: 720 * (16/9)
      aspectRatio: 16/9,
      deviceId,
    })
    

    【讨论】:

      猜你喜欢
      • 2014-04-03
      • 2023-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多