Stability simple peer
This commit is contained in:
parent
39f44b8a9d
commit
9b01dd0041
1 changed files with 18 additions and 7 deletions
|
@ -148,14 +148,13 @@ export class SimplePeer {
|
||||||
|
|
||||||
peer.on('data', (chunk: Buffer) => {
|
peer.on('data', (chunk: Buffer) => {
|
||||||
let constraint = JSON.parse(chunk.toString('utf8'));
|
let constraint = JSON.parse(chunk.toString('utf8'));
|
||||||
|
|
||||||
if (constraint.audio) {
|
if (constraint.audio) {
|
||||||
this.MediaManager.enabledMicrophoneByUserId(user.userId);
|
this.MediaManager.enabledMicrophoneByUserId(user.userId);
|
||||||
} else {
|
} else {
|
||||||
this.MediaManager.disabledMicrophoneByUserId(user.userId);
|
this.MediaManager.disabledMicrophoneByUserId(user.userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (constraint.video) {
|
if (constraint.video || constraint.screen) {
|
||||||
this.MediaManager.enabledVideoByUserId(user.userId);
|
this.MediaManager.enabledVideoByUserId(user.userId);
|
||||||
} else {
|
} else {
|
||||||
this.stream(user.userId);
|
this.stream(user.userId);
|
||||||
|
@ -232,18 +231,30 @@ export class SimplePeer {
|
||||||
try {
|
try {
|
||||||
let localStream: MediaStream | null = this.MediaManager.localStream;
|
let localStream: MediaStream | null = this.MediaManager.localStream;
|
||||||
let localScreenCapture: MediaStream | null = this.MediaManager.localScreenCapture;
|
let localScreenCapture: MediaStream | null = this.MediaManager.localScreenCapture;
|
||||||
let peer = this.PeerConnectionArray.get(userId);
|
let PeerConnection : any = this.PeerConnectionArray.get(userId);
|
||||||
if (peer === undefined) {
|
if (PeerConnection === undefined) {
|
||||||
throw new Error('While adding media, cannot find user with ID ' + userId);
|
throw new Error('While adding media, cannot find user with ID ' + userId);
|
||||||
}
|
}
|
||||||
peer.write(new Buffer(JSON.stringify(this.MediaManager.constraintsMedia)));
|
PeerConnection.write(new Buffer(JSON.stringify(Object.assign(this.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) {
|
if (localScreenCapture !== null) {
|
||||||
for (const track of localScreenCapture.getTracks()) {
|
for (const track of localScreenCapture.getTracks()) {
|
||||||
peer.addTrack(track, localScreenCapture);
|
PeerConnection.addTrack(track, localScreenCapture);
|
||||||
}
|
}
|
||||||
} else if (localStream) {
|
} else if (localStream) {
|
||||||
for (const track of localStream.getTracks()) {
|
for (const track of localStream.getTracks()) {
|
||||||
peer.addTrack(track, localStream);
|
PeerConnection.addTrack(track, localStream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}catch (e) {
|
}catch (e) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue