Skip to content

Commit

Permalink
ice-restart: fix functionality
Browse files Browse the repository at this point in the history
by listening to the transport selectedcandidatepairchange event.
This sample has been relying on the somewhat buggy but useful behavior
of the "legacy" iceconnectionstatechange firing a "connected" event even
if the previous state was already connected.

This behavior is no longer supported in the spec iceconnectionstatechange
event. Alternatively listen to the selectedcandidatepairchange event and
determine the availability of new candidates based on that
  • Loading branch information
fippo committed Apr 6, 2022
1 parent 61fa9fa commit ef0b55f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
],
"devDependencies": {
"chai": "^4.3.6",
"chromedriver": "^98.0.1",
"chromedriver": ">98.0.1",
"eslint": "^8.9.0",
"eslint-config-google": "^0.14.0",
"geckodriver": "^3.0.1",
Expand Down
23 changes: 19 additions & 4 deletions src/content/peerconnection/restart-ice/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ remoteVideo.addEventListener('loadedmetadata', function() {
console.log(`Remote video videoWidth: ${this.videoWidth}px, videoHeight: ${this.videoHeight}px`);
});

const useSelectedCandidatePairChange = window.RTCIceTransport && 'onselectedcandidatepairchange' in RTCIceTransport.prototype;

remoteVideo.onresize = () => {
console.log(`Remote video size changed to ${remoteVideo.videoWidth}x${remoteVideo.videoHeight}`);
// We'll use the first onsize callback as an indication that video has started
Expand Down Expand Up @@ -170,6 +172,18 @@ function onCreateAnswerSuccess(desc) {
pc2.setLocalDescription(desc).then(() => onSetLocalSuccess(pc2), onSetSessionDescriptionError);
console.log('pc1 setRemoteDescription start');
pc1.setRemoteDescription(desc).then(() => onSetRemoteSuccess(pc1), onSetSessionDescriptionError);

if (useSelectedCandidatePairChange) {
pc1.getSenders()[0].transport.iceTransport.onselectedcandidatepairchange = () => {
checkStats(pc1);
if (pc1.iceConnectionState === 'connected') {
restartButton.disabled = false;
}
};
pc2.getSenders()[0].transport.iceTransport.onselectedcandidatepairchange = () => {
checkStats(pc2);
};
}
}

function onIceCandidate(pc, event) {
Expand All @@ -191,10 +205,11 @@ function onIceStateChange(pc, event) {
if (pc) {
console.log(`${getName(pc)} ICE state: ${pc.iceConnectionState}`);
console.log('ICE state change event: ', event);
// TODO: get rid of this in favor of http://w3c.github.io/webrtc-pc/#widl-RTCIceTransport-onselectedcandidatepairchange
if (pc.iceConnectionState === 'connected' ||
pc.iceConnectionState === 'completed') {
checkStats(pc);
if (!useSelectedCandidatePairChange) {
if (pc.iceConnectionState === 'connected' ||
pc.iceConnectionState === 'completed') {
checkStats(pc);
}
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/content/peerconnection/restart-ice/js/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ let driver;
const path = '/src/content/peerconnection/restart-ice/index.html';
const url = `${process.env.BASEURL ? process.env.BASEURL : ('file://' + process.cwd())}${path}`;

describe.skip('peerconnection ice restart', () => {
describe('peerconnection ice restart', () => {
before(() => {
driver = seleniumHelpers.buildDriver();
});
Expand Down Expand Up @@ -58,7 +58,6 @@ describe.skip('peerconnection ice restart', () => {
await driver.wait(() => driver.findElement(webdriver.By.id('restartButton')).isEnabled());
await driver.findElement(webdriver.By.id('restartButton')).click();

await driver.wait(() => !driver.findElement(webdriver.By.id('restartButton')).isEnabled());
await driver.wait(() => driver.findElement(webdriver.By.id('restartButton')).isEnabled());

const secondCandidateIds = await Promise.all([
Expand Down

0 comments on commit ef0b55f

Please sign in to comment.