Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

track事件笔记 #1

Open
vaakian opened this issue Feb 24, 2022 · 4 comments
Open

track事件笔记 #1

vaakian opened this issue Feb 24, 2022 · 4 comments

Comments

@vaakian
Copy link
Owner

vaakian commented Feb 24, 2022

if (sdp.indexOf(`[user/${track.id}]`) !== -1) {

在通过修改sdp来辨别track的类型时,需要注意以下情况

首次协商,推多个track(video/audio)

次多个track仅在首次协商发生,此时trackId双端保持一致。

类型匹配:不能单匹配display/user字段,因为同一个sdp中有多个tag被打上。此时需要类型/ID来匹配。

后期变动产生新的协商,推单个track

后期track有任何变化(添加、移除),都是单个track,且双端trackId不一致。

类型匹配:只匹配display/user字段,不匹配id。

MDN Official notes:

Note: Adding a track to a connection triggers renegotiation by firing a negotiationneeded event. See Starting negotiation in Signaling and video calling for details.

相关:
How to handle removing and re-adding remote streams/tracks - possible ID collisions?

@vaakian
Copy link
Owner Author

vaakian commented Feb 24, 2022

潜在的BUG

进入房间,A首次单推视频流,对方B拿到视频流。
然后A再修改constraints为视频声音,包含两个track,重新推流,对方B拿到这两个流如何判定:

  1. 直接删除已有的重复track
  2. 非首次,推多个流,trackId是双端否一致?

MDN 说明:

如果指定的track已经存在于流的track set里的话,该方法不会产生作用。

TODO:那么通过constraint重新获取到的video track和上次的video track是否一致?

@vaakian
Copy link
Owner Author

vaakian commented Feb 24, 2022

获得track/stream时,到底用哪个?

用stream:当获得同时具有audio & video的流时,接收方会接收到两次track事件。那么如果直接使用stream来接收远端流,两次重复添加,可能会导致一次闪屏,需要做进一步判断:虽然两次给的mediaStream引用不相同,但id相同,所以可以对id进行判断,如果相同就不做任何更改。
好处是重新协商之后,无需做多余判断。如果id变更,直接覆盖mediaStream即可。
image

用track:与以上相反

pc.addTrack(track, stream)
官方文档释义:

track
A MediaStreamTrack object representing the media track to add to the peer connection.

stream
One or more local MediaStream objects to which the track should be added.

The specified track doesn't necessarily have to already be part of any of the specified streams. Instead, the streams are a way to group tracks together on the receiving end of the connection, making sure they are synchronized. Any tracks that are added to the same stream on the local end of the connection will be on the same stream on the remote end.

注意这句话:

Any tracks that are added to the same stream on the local end of the connection will be on the same stream on the remote end.

@vaakian
Copy link
Owner Author

vaakian commented Feb 24, 2022

可参考的项目

以下项目都值得深入研究
simple-peer
peerjs

@vipcxj
Copy link

vipcxj commented Nov 1, 2023

track id的问题有啥解决思路吗?真是惊了,什么腊鸡标准~ track id两端竟然能够不一致,更坑的是,理论上除了这玩意没有任何办法绑定双端的track。那票制定标准的人是以何种脑回路搞出这样的玩意的?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants