I am trying to refactor an old react-native webrtc code to the latest version.
when closePeerConnection is called i am removing remote stream from a map.
setRemoteStreams((value: any) => {
const val = { ...value };
const streams = [...remotePeerConnection[streamId].getLocalStreams()];
streams.forEach((stream) => {
if (localStream.current?.toURL() !== stream.toURL()) {
delete val[stream.toURL()];
}
});
return val;
});
setRemoteStreamsMapped((value: any) => {
const val = { ...value };
const streams = [...remotePeerConnection[streamId].getLocalStreams()];
streams.forEach((stream) => {
if (localStream.current?.toURL() !== stream.toURL()) {
delete val[streamId];
}
});
return val;
});
as you know getLocalStreams() is deprecated. I’ve tried to use getRecievers instead like below:
const receivers = remotePeerConnection[streamId].getReceivers();
receivers.forEach((receiver) => {
const track = receiver.track;
if (track && localStream.current?.id !== track.id) {
delete val[track.id];
}
});
return val;
Content of val object looks like this:
{“streamTest15”:{“active”:true,“_tracks”:[{“label”:“”,“_constraints”:{},“_enabled”:true,“_settings”:{},“_muted”:false,“_peerConnectionId”:0,“_readyState”:“lıve”,“id”:“349fdbd8-ecf9-479f-b6c1-9c729d05f178”,“kind”:“audio”,“remote”:true},{“label”:“”,“_constraints”:{},“_enabled”:true,“_settings”:{},“_muted”:false,“_peerConnectionId”:0,“_readyState”:“lıve”,“id”:“9f870d07-2c84-48b1-ac42-fc4303d3fc12”,“kind”:“video”,“remote”:true}],“id”:“2577bbbc-8707-4397-8878-6cbc321f3d0d”,“_reactTag”:“83a46493-fe99-4aaa-b11a-f0a5e9cd8253”},“2577bbbc-8707-4397-8878-6cbc321f3d0d”:{“active”:true,“_tracks”:[{“label”:“”,“_constraints”:{},“_enabled”:true,“_settings”:{},“_muted”:false,“_peerConnectionId”:0,“_readyState”:“lıve”,“id”:“349fdbd8-ecf9-479f-b6c1-9c729d05f178”,“kind”:“audio”,“remote”:true},{“label”:“”,“_constraints”:{},“_enabled”:true,“_settings”:{},“_muted”:false,“_peerConnectionId”:0,“_readyState”:“lıve”,“id”:“9f870d07-2c84-48b1-ac42-fc4303d3fc12”,“kind”:“video”,“remote”:true}],“id”:“2577bbbc-8707-4397-8878-6cbc321f3d0d”,“_reactTag”:“83a46493-fe99-4aaa-b11a-f0a5e9cd8253”}}
Did approach did not work. I am wondering if i am doing correct refactorization. Looking for advice