Skip to content
This repository was archived by the owner on Oct 25, 2024. It is now read-only.

Commit a718051

Browse files
committed
Fix stream stop event on Firefox.
1 parent 8f14570 commit a718051

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

src/sdk/p2p/peerconnection-channel.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,22 @@ class P2PPeerConnectionChannel extends EventDispatcher {
972972
};
973973
}
974974

975+
// Returns all MediaStreams it belongs to.
976+
_getStreamByTrack(mediaStreamTrack) {
977+
const streams = [];
978+
for (const [id, info] of this._remoteStreamInfo) {
979+
if (!info.stream || !info.stream.mediaStream) {
980+
continue;
981+
}
982+
for (const track of info.stream.mediaStream.getTracks()) {
983+
if (mediaStreamTrack === track) {
984+
streams.push(info.stream.mediaStream);
985+
}
986+
}
987+
}
988+
return streams;
989+
}
990+
975991
_areAllTracksEnded(mediaStream) {
976992
for (const track of mediaStream.getTracks()) {
977993
if (track.readyState === 'live') {
@@ -1061,9 +1077,12 @@ class P2PPeerConnectionChannel extends EventDispatcher {
10611077
});
10621078
if (this._isUnifiedPlan()) {
10631079
for (const track of info.mediaStream.getTracks()) {
1064-
track.addEventListener('ended', () => {
1065-
if (self._areAllTracksEnded(info.mediaStream)) {
1066-
self._onRemoteStreamRemoved(info.stream);
1080+
track.addEventListener('ended', (event) => {
1081+
const mediaStreams = this._getStreamByTrack(event.target);
1082+
for (const mediaStream of mediaStreams) {
1083+
if (this._areAllTracksEnded(mediaStream)) {
1084+
this._onRemoteStreamRemoved(mediaStream);
1085+
}
10671086
}
10681087
});
10691088
}

0 commit comments

Comments
 (0)