简体   繁体   English

WebRTC - 找出 MediaStreamTrack 类型?

[英]WebRTC - Find out MediaStreamTrack Type?

I want to find out if the VideoTrack contains a screenshare or webcam stream.我想知道 VideoTrack 是否包含屏幕共享或网络摄像头流。 I can't find any attribute and also no fitting contraint I could apply to the track and read out later.我找不到任何属性,也没有合适的约束可以应用于轨道并稍后读出。

Someone knows a smart way to do that?有人知道这样做的聪明方法吗?

I want to avoid sending the streamId with the type over the dataChannel.我想避免通过 dataChannel 发送带有类型的 streamId。

Thanks:)谢谢:)

EDIT1: So far no solution... so I have to send the streamType and StreamId over the datachannel EDIT1:到目前为止没有解决方案......所以我必须通过数据通道发送 streamType 和 StreamId

The process works like this (using MediaStreamTrack as an example):这个过程是这样的(以 MediaStreamTrack 为例):

  1. If needed, call MediaDevices.getSupportedConstraints() to get the list of supported constraints, which tells you what constrainable properties the browser knows about.如果需要,调用MediaDevices.getSupportedConstraints()以获取支持的约束列表,它会告诉您浏览器知道哪些可约束属性。 This isn't always necessary, since any that aren't known will simply be ignored when you specify them—but if you have any that you can't get by without, you can start by checking to be sure they're on the list.这并不总是必要的,因为当你指定它们时,任何未知的都会被忽略——但如果你有任何你不能没有的,你可以首先检查以确保它们在列表。

  2. Once the script knows whether the property or properties it wishes to use are supported, it can then check the capabilities of the API and its implementation by examining the object returned by the track's getCapabilities() method;一旦脚本知道它希望使用的一个或多个属性是否受支持,它就可以通过检查轨道的getCapabilities()方法返回的对象来检查 API 的功能及其实现; this object lists each supported constraint and the values or range of values which are supported.该对象列出了每个受支持的约束以及受支持的值或值范围。

  3. nally, the track's applyConstraints() method is called to configure the API as desired by specifying the values or ranges of values it wishes to use for any of the constrainable properties about which it has a preference.最后,track 的applyConstraints()方法被调用以根据需要配置 API,方法是指定它希望用于它有偏好的任何可约束属性的值或值范围。

  4. The track's getConstraints() method returns the set of constraints passed into the most recent call to applyConstraints() .轨道的getConstraints()方法返回传递给最近调用applyConstraints()的一组约束。 This may not represent the actual current state of the track, due to properties whose requested values had to be adjusted and because platform default values aren't represented.这可能不代表轨道的实际当前状态,因为必须调整其请求值的属性,并且因为平台默认值未表示。 For a complete representation of the track's current configuration, use getSettings() .要完整表示轨道的当前配置,请使用getSettings()

In the Media Stream API, both MediaStream and MediaStreamTrack have constrainable properties.在 Media Stream API 中,MediaStream 和 MediaStreamTrack 都具有可约束的属性。

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

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