这是
实验性技术
检查
浏览器兼容性表格
要小心谨慎在生产中使用这之前。
过时
This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.
RTCPeerConnection.getStreamById()
方法返回
MediaStream
with the given id that is associated with local or remote end of the connection. If no stream matches, it returns
null
.
This property has been replaced with the
RTCPeerConnection.getLocalStreams
and
RTCPeerConnection.getRemoteStreams
properties. If you have code that uses
stream
, you will need to update, since browsers have begun to remove support for
stream
.
var mediaStream = pc.getStream(id);
DOMString
corresponding to the stream to return.
var stream = pc.getStreamById(myTrackId);
if (stream) {
console.log("Found stream: " + stream.id);
}
Running the following code before any other code will create
RTCPeerConnection.prototype.getStreamById()
if it's not natively available.
// from: https://bugs.chromium.org/p/chromium/issues/detail?id=698163&desc=5#c10
RTCPeerConnection.prototype.getStreamById = function(id) {
try {
var localStreams = this.getLocalStreams();
var remoteStreams = this.getRemoteStreams();
var i;
for (i = 0; i < localStreams.length; i++) {
if (localStreams[i].id == id)
return localStreams[i];
}
for (i = 0; i < remoteStreams.length; i++) {
if (remoteStreams[i].id == id)
return remoteStreams[i];
}
} catch(e) {}
return null;
}
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
getStreamById
弃用
非标
|
Chrome 56 — 62 | Edge 15 — 79 | Firefox 22 — 53 | IE No |
Opera
43
|
Safari ? | WebView Android 56 — 62 | Chrome Android 56 — 62 | Firefox Android 44 |
Opera Android
43
|
Safari iOS ? | Samsung Internet Android 6.0 — 8.0 |
完整支持
不支持
兼容性未知
非标。预期跨浏览器支持较差。
弃用。不要用于新网站。
见实现注意事项。
RTCPeerConnection
canTrickleIceCandidates
connectionState
currentLocalDescription
currentRemoteDescription
getDefaultIceServers()
iceConnectionState
iceGatheringState
localDescription
onaddstream
onconnectionstatechange
ondatachannel
onicecandidate
oniceconnectionstatechange
onicegatheringstatechange
onidentityresult
onidpassertionerror
onidpvalidationerror
onnegotiationneeded
onpeeridentity
onremovestream
onsignalingstatechange
ontrack
peerIdentity
pendingLocalDescription
pendingRemoteDescription
remoteDescription
sctp
signalingState
addIceCandidate()
addStream()
addTrack()
close()
createAnswer()
createDataChannel()
createOffer()
generateCertificate()
getConfiguration()
getIdentityAssertion()
getReceivers()
getSenders()
getStats()
getStreamById()
getTransceivers()
removeStream()
removeTrack()
restartIce()
setConfiguration()
setIdentityProvider()
setLocalDescription()
setRemoteDescription()