-
Notifications
You must be signed in to change notification settings - Fork 175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix replacestream #12
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I commented, can you confirm these case?
- both video and audio -> only audio
- audio -> both video and audio
- both video and audio -> both video and audio // As regression
src/peer/negotiator.js
Outdated
@@ -114,6 +114,23 @@ class Negotiator extends EventEmitter { | |||
} | |||
}); | |||
|
|||
if (this._pc.getSenders().every(sender => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
About L:117-130, what happens in the use case described below?
- The user has both an audio and a video track; which means, _pc.getSenders() should return the array including 2 rtpSender.
- Then user wants to stop sending the video track to reduce bandwidth, so s/he calls
replaceStream(newStream)
wherenewStream
contains only the audio track. - Does the user can successfully create an offer SDP and communicate with the other party after negotiation as the user expects?
src/peer/negotiator.js
Outdated
@@ -114,6 +114,23 @@ class Negotiator extends EventEmitter { | |||
} | |||
}); | |||
|
|||
if (this._pc.getSenders().every(sender => { | |||
return sender.track.kind !== 'audio'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally I prefer extracting this condition to another method like,
Before
if (this._pc.getSenders().every(sender => {
return sender.track.kind !== 'audio';
}))
After
if (_onlyVideoTracksExist(this._pc)) { ...}
This explains what we're doing in the condition.
0c12526
to
44b7f99
Compare
@@ -407,6 +366,7 @@ class Negotiator extends EventEmitter { | |||
return this._pc.setLocalDescription(answer) | |||
.then(() => { | |||
logger.log('Set localDescription: answer'); | |||
logger.log(`Setting local description ${JSON.stringify(answer.sdp)}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even if user set log level to 0, JSON.stringify()
is called.
Is it ok?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JSON.stringify()
is called at _setRemoteDescription
too. So I think it is ok.
src/peer/negotiator.js
Outdated
this._pc.addTrack(track, newStream); | ||
} else { | ||
// need to check id before replace..? | ||
vSenders[idx].replaceTrack(track); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I commented here, what will happen when trying to replace track A with track A?
this._pc.removeStream(localStreams[0]); | ||
} | ||
|
||
this._replaceStreamCalled = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line should be placed after this._pc.addStream(newStream);
for naming..?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_replaceStreamCalled
is true after replaceStream
and is false after onnegotiationneeded
.
_replaceStreamCalled
is used to check if onnegotiationneeded
event has finished or not.
If it is placed after addStream
, _replaceStreamCalled
becomes true after onnegotiationneeded
.
@@ -477,6 +438,77 @@ class Negotiator extends EventEmitter { | |||
} | |||
|
|||
/** | |||
* Replace the stream being sent with a new one. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add comments to differentiate _replacePerTrack()
and _replacePerStream()
?
NOTE: more discussion here: https://gist.github.com/leader22/fb538265d7f24217dada1d6b8a8d2380 |
tests/peer/negotiator.js
Outdated
it('should not call addTrack for audio sender', () => { | ||
negotiator.replaceStream(newStream); | ||
|
||
console.log(negotiator._pc.getSenders()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you get rid of this?
I'm assuming it's for debugging
return; | ||
} | ||
// if track was not replaced, do nothing | ||
if (sender.track.id === track.id) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this test, both stubs of senders and stubs of tracks do not have id
key. So I think this statement is always true because it is undefined === undefined
.
The direction of the code looks good. Thanks! 👍 |
LGTM! 👍 |
LGTM! |
|
371e893
to
d8b5be6
Compare
I checked on Chrome and Firefox. |
…replaceStream If `getSenders` is not defined, `addTrack` will not be defined either. If broweser dosen't support `getSenders`, stream is replaced by stream. Otherwise stream is replaced per stream. We assume that there are at most 1 audio and at most 1 video in local stream.
d8b5be6
to
e9d7bce
Compare
LGTM! |
this._replaceStreamCalled = true; | ||
|
||
// a chance to trigger (and do nothing) on removeStream. | ||
setTimeout(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add setTimeout
before addStream
to fix state error on chrome
In Firefox, even if a client who is only sending audio uses
replaceStream
to add video, the client can not send video. This PR fixes it.Multi track will be implemented after Chrome uses
Unified Plan SDP
.