June 2024
Beginner to intermediate
268 pages
6h 26m
English
Removing streaming media from a peer connection takes a little finesse and creativity. Let’s look at and then walk through the complete removeStreamingMedia() function—which we will follow up with a slight adjustment to how the shareFeatures() function works:
| | function removeStreamingMedia(id) { |
| | const peer = $peers.get(id); |
| | // Detect the senders on the connection; we need |
| | // them to remove tracks from the peer connection |
| | const senders = peer.connection.getSenders(); |
| | const senders_list = Object.keys(senders); |
| | // Loop through the senders, and pull the tracks |
| | // off them, one by one |
| | for (let sender of senders_list) { |
| | const track = senders[sender].track; ... |
Read now
Unlock full access