This commit is contained in:
Gregoire Parant 2020-06-06 20:13:30 +02:00 committed by David Négrier
parent eed5333d69
commit 6c1b8122ef

View File

@ -294,23 +294,13 @@ export class SimplePeer {
try {
let localStream: MediaStream | null = mediaManager.localStream;
let localScreenCapture: MediaStream | null = mediaManager.localScreenCapture;
let PeerConnection : any = this.PeerConnectionArray.get(userId);
if (PeerConnection === undefined) {
let PeerConnection = this.PeerConnectionArray.get(userId);
if (!PeerConnection || PeerConnection === undefined) {
throw new Error('While adding media, cannot find user with ID ' + userId);
}
PeerConnection.write(new Buffer(JSON.stringify(Object.assign(mediaManager.constraintsMedia, {screen: localScreenCapture !== null}))));
//remove current stream
try {
if (PeerConnection._pc) {
PeerConnection._pc.getRemoteStreams().forEach((stream: MediaStream) => {
stream.getTracks().forEach((track: MediaStreamTrack) => {
PeerConnection.removeTrack(track, stream);
});
});
}
}catch (e) {}
if (localScreenCapture !== null) {
for (const track of localScreenCapture.getTracks()) {
PeerConnection.addTrack(track, localScreenCapture);