Skip to content
Branch: master
Find file History

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
index.html
package.json
readme.md
server.js
websocket_server.js

readme.md

track API 注意点

  • addTrack
  • removeTrack
  • replaceTrack
  • ontrack事件

addTrack需要两个参数。

let track = stream.getTracks()[0]
sender = PeerConnection.addTrack(track,stream)

removeTrack的参数必须为RTCRtpSender类型,如 PeerConnection.addTrack的返回值,还可以通过PeerConnection.getSenders()得到。

let track = stream.getTracks()[0]
sender = PeerConnection.addTrack(track,stream)
PeerConnection.removeTrack(sender)

replaceTrack是一个神器啊,replaceTrack可以轻松地替换媒体流,而不需要negotiation,唯一的要求就是替换的媒体流类型相同(audio, video, etc)。

同样的,replaceTrack是一个RTCRtpSender原型方法,所以sender必须是RTCRtpSender实例对象。

let track = stream.getTracks()[0]
sender.replaceTrack(track).then(()=>{
    console.log('replace track success...')
})            

获取流,streams是一个数组对象。

PeerConnection.ontrack = function (event) {
    video.srcObject = event.streams[0]
}
You can’t perform that action at this time.