chore(call-e2e): hold the guest to Opus, check the app joined
- Teams web offers audio/L16 109 first; headless Chrome discards every packet of it, so the guest strips it and gets Opus - Fails early when the app is not in the call after --join - SECOND_GUEST=1 adds a second guest for codec comparisons Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@@ -137,6 +137,38 @@ const LOCATE = (step) => `(() => {
137
137
target.click();
138
138
return label(target).slice(0, 80);
139
139
})()`;
140
141
// Teams web offers audio/L16 109 first; headless Chrome decodes none of it, so the guest is held to Opus.
142
const NO_L16 = `(() => {
143
const strip = (sdp) => {
144
if (!sdp) return sdp;
145
const payload = (sdp.match(/a=rtpmap:(\\d+) L16\\//) || [])[1];
146
if (!payload) return sdp;
147
return sdp.split('\\r\\n').filter((line) => !line.startsWith('a=rtpmap:' + payload + ' ') && !line.startsWith('a=fmtp:' + payload + ' ') && !line.startsWith('a=rtcp-fb:' + payload + ' '))
148
.map((line) => line.startsWith('m=audio') ? line.split(' ').filter((part, index) => index < 3 || part !== payload).join(' ') : line).join('\\r\\n');
149
};
150
const prototype = RTCPeerConnection.prototype;
151
for (const name of ['createOffer', 'createAnswer']) {
152
const original = prototype[name];
153
prototype[name] = async function (...args) { const description = await original.apply(this, args); return { type: description.type, sdp: strip(description.sdp) }; };
154
}
155
const setLocal = prototype.setLocalDescription;
156
prototype.setLocalDescription = function (description) { return description && description.sdp ? setLocal.call(this, { type: description.type, sdp: strip(description.sdp) }) : setLocal.apply(this, arguments); };
157
})();`;
158
159
const AUDIO_DECODER = `(async () => {
160
const out = [];
161
for (const peer of window.__pcs || []) {
162
const stats = await peer.getStats();
163
stats.forEach((entry) => {
164
if (entry.type !== 'inbound-rtp' || entry.kind !== 'audio') return;
165
const codec = entry.codecId && stats.get(entry.codecId);
166
out.push({ ssrc: entry.ssrc, mid: entry.mid, packets: entry.packetsReceived, discarded: entry.packetsDiscarded, lost: entry.packetsLost, samples: entry.totalSamplesReceived, concealed: entry.concealedSamples, emitted: entry.jitterBufferEmittedCount, decoder: entry.decoderImplementation, codec: codec ? codec.mimeType + '/' + codec.payloadType : null, bytes: entry.bytesReceived });
167
});
168
out.push({ transforms: peer.getReceivers().map((receiver) => receiver.track && receiver.track.kind + ':' + Boolean(receiver.transform)) });
169
}
170
return out;
171
})()`;
140
172
const CONNECTED = `(window.__pcs || []).some((peer) => peer.connectionState === 'connected')`;
141
173
const TEAMS_ORIGINS = ['https://teams.cloud.microsoft', 'https://teams.microsoft.com'];
142
174
@@ -152,6 +184,7 @@ class GuestTab {
152
184
await this.browser.send('Page.enable', {}, sessionId);
153
185
await this.browser.send('Runtime.enable', {}, sessionId);
154
186
await this.browser.send('Page.addScriptToEvaluateOnNewDocument', { source: PEER_HOOK }, sessionId);
187
await this.browser.send('Page.addScriptToEvaluateOnNewDocument', { source: NO_L16 }, sessionId);
155
188
await this.browser.send('Page.addScriptToEvaluateOnNewDocument', { source: REMOTE_AUDIO_TAP }, sessionId);
156
189
await this.browser.send('Page.addScriptToEvaluateOnNewDocument', { source: FAKE_MEDIA(speechDataUrl()) }, sessionId);
157
190
for (const origin of TEAMS_ORIGINS) {
@@ -357,6 +390,7 @@ const restoreCapture = () => defaultAudio('set', 'capture', savedCapture);
357
390
for (const signal of ['SIGINT', 'SIGTERM']) process.on(signal, () => { restoreCapture(); process.exit(130); });
358
391
const browser = await new Browser(OWN_ENDPOINT).connect();
359
392
const tab = new GuestTab(browser);
393
const secondTab = process.env.SECOND_GUEST ? new GuestTab(browser) : null;
360
394
try {
361
395
if (!teamsProcessId()) {
362
396
log(`starting the app, waiting ${APP_START_WAIT_MS / 1000}s`);
@@ -373,9 +407,21 @@ try {
373
407
runTeams('--join', link);
374
408
log(`app joining, waiting ${APP_JOIN_WAIT_MS / 1000}s`);
375
409
await delay(APP_JOIN_WAIT_MS);
410
const joined = await appStats(workDir).catch(() => ({ inCall: false }));
411
if (!joined.inCall) throw new Error('the app is not in the call after --join');
376
412
await tab.open(link);
377
413
const admitting = setInterval(() => runTeams('--admit-all'), ADMIT_INTERVAL_MS);
378
414
report.webJoined = await tab.join().finally(() => clearInterval(admitting));
415
if (secondTab) {
416
await secondTab.open(link);
417
const admittingSecond = setInterval(() => runTeams('--admit-all'), ADMIT_INTERVAL_MS);
418
report.secondJoined = await secondTab.join().finally(() => clearInterval(admittingSecond));
419
log(`second guest joined: ${report.secondJoined}`);
420
runTeams('--call', 'mute');
421
await delay(10_000);
422
report.secondHearsFirstOnly = await secondTab.evaluate(AUDIO_DECODER).catch((error) => error.message);
423
report.firstWhileAppMuted = await tab.evaluate(AUDIO_DECODER).catch((error) => error.message);
424
}
379
425
log(`web guest joined: ${report.webJoined}`);
380
426
if (!report.webJoined) {
381
427
await tab.shot(workDir + '/web-join.png');
@@ -392,6 +438,12 @@ try {
392
438
]);
393
439
report.guestSending = await tab.evaluate(GUEST_SENDING).catch((error) => error.message);
394
440
report.guestPlayback = await tab.playbackState();
441
report.guestAudioDecoder = await tab.evaluate(AUDIO_DECODER).catch((error) => error.message);
442
report.guestSourceLevels = [];
443
for (let sample = 0; sample < 10; sample++) {
444
report.guestSourceLevels.push(await tab.evaluate(`(window.__pcs || []).flatMap((peer) => peer.getReceivers().filter((receiver) => receiver.track && receiver.track.kind === 'audio').flatMap((receiver) => receiver.getSynchronizationSources().map((source) => Number((source.audioLevel || 0).toFixed(3)))))`).catch((error) => error.message));
445
await delay(500);
446
}
395
447
report.guestReceiving = await tab.evaluate(PEER_STATS).then((stats) => ({ peers: stats.peers, audioIn: stats.audioIn })).catch((error) => error.message);
396
448
report.appToWeb = judge(webLevels, WEB_THRESHOLD);
397
449
report.webToApp = judge(JSON.parse(recorded).rms, APP_THRESHOLD);
@@ -405,6 +457,7 @@ try {
405
457
} finally {
406
458
if (teamsProcessId()) runTeams('--hang-up');
407
459
await tab.close();
460
if (secondTab) await secondTab.close();
408
461
restoreCapture();
409
462
log('default mic restored');
410
463
browser.socket.close();
@@ -413,5 +466,5 @@ const scenariosPass = Object.values(report.scenarios ?? {}).every((entry) => ent
413
466
report.pass = Boolean(report.appToWeb?.pass && report.webToApp?.pass && scenariosPass);
414
467
writeFileSync(workDir + '/report.json', JSON.stringify(report, null, 2));
415
468
const scenarioSummary = Object.fromEntries(Object.entries(report.scenarios ?? {}).map(([name, entry]) => [name, entry.pass ? 'pass' : `FAIL ${entry.error ?? ''}`.trim()]));
416
console.log(JSON.stringify({ pass: report.pass, guestPlayback: report.guestPlayback, guestReceiving: report.guestReceiving, appToWeb: report.appToWeb, webToApp: report.webToApp, scenarios: scenarioSummary, guestSending: report.guestSending, error: report.error }));
469
console.log(JSON.stringify({ pass: report.pass, secondHearsFirstOnly: report.secondHearsFirstOnly, firstWhileAppMuted: report.firstWhileAppMuted, guestAudioDecoder: report.guestAudioDecoder, guestPlayback: report.guestPlayback, guestReceiving: report.guestReceiving, appToWeb: report.appToWeb, webToApp: report.webToApp, scenarios: scenarioSummary, guestSending: report.guestSending, error: report.error }));
417
470
process.exit(report.pass ? 0 : 1);
@@ -137,6 +137,38 @@ const LOCATE = (step) => `(() => {137
target.click();137
target.click();138
return label(target).slice(0, 80);138
return label(target).slice(0, 80);139
})()`;139
})()`;140
141
// Teams web offers audio/L16 109 first; headless Chrome decodes none of it, so the guest is held to Opus.142
const NO_L16 = `(() => {143
const strip = (sdp) => {144
if (!sdp) return sdp;145
const payload = (sdp.match(/a=rtpmap:(\\d+) L16\\//) || [])[1];146
if (!payload) return sdp;147
return sdp.split('\\r\\n').filter((line) => !line.startsWith('a=rtpmap:' + payload + ' ') && !line.startsWith('a=fmtp:' + payload + ' ') && !line.startsWith('a=rtcp-fb:' + payload + ' '))148
.map((line) => line.startsWith('m=audio') ? line.split(' ').filter((part, index) => index < 3 || part !== payload).join(' ') : line).join('\\r\\n');149
};150
const prototype = RTCPeerConnection.prototype;151
for (const name of ['createOffer', 'createAnswer']) {152
const original = prototype[name];153
prototype[name] = async function (...args) { const description = await original.apply(this, args); return { type: description.type, sdp: strip(description.sdp) }; };154
}155
const setLocal = prototype.setLocalDescription;156
prototype.setLocalDescription = function (description) { return description && description.sdp ? setLocal.call(this, { type: description.type, sdp: strip(description.sdp) }) : setLocal.apply(this, arguments); };157
})();`;158
159
const AUDIO_DECODER = `(async () => {160
const out = [];161
for (const peer of window.__pcs || []) {162
const stats = await peer.getStats();163
stats.forEach((entry) => {164
if (entry.type !== 'inbound-rtp' || entry.kind !== 'audio') return;165
const codec = entry.codecId && stats.get(entry.codecId);166
out.push({ ssrc: entry.ssrc, mid: entry.mid, packets: entry.packetsReceived, discarded: entry.packetsDiscarded, lost: entry.packetsLost, samples: entry.totalSamplesReceived, concealed: entry.concealedSamples, emitted: entry.jitterBufferEmittedCount, decoder: entry.decoderImplementation, codec: codec ? codec.mimeType + '/' + codec.payloadType : null, bytes: entry.bytesReceived });167
});168
out.push({ transforms: peer.getReceivers().map((receiver) => receiver.track && receiver.track.kind + ':' + Boolean(receiver.transform)) });169
}170
return out;171
})()`;140
const CONNECTED = `(window.__pcs || []).some((peer) => peer.connectionState === 'connected')`;172
const CONNECTED = `(window.__pcs || []).some((peer) => peer.connectionState === 'connected')`;141
const TEAMS_ORIGINS = ['https://teams.cloud.microsoft', 'https://teams.microsoft.com'];173
const TEAMS_ORIGINS = ['https://teams.cloud.microsoft', 'https://teams.microsoft.com'];142
174
@@ -152,6 +184,7 @@ class GuestTab {152
await this.browser.send('Page.enable', {}, sessionId);184
await this.browser.send('Page.enable', {}, sessionId);153
await this.browser.send('Runtime.enable', {}, sessionId);185
await this.browser.send('Runtime.enable', {}, sessionId);154
await this.browser.send('Page.addScriptToEvaluateOnNewDocument', { source: PEER_HOOK }, sessionId);186
await this.browser.send('Page.addScriptToEvaluateOnNewDocument', { source: PEER_HOOK }, sessionId);187
await this.browser.send('Page.addScriptToEvaluateOnNewDocument', { source: NO_L16 }, sessionId);155
await this.browser.send('Page.addScriptToEvaluateOnNewDocument', { source: REMOTE_AUDIO_TAP }, sessionId);188
await this.browser.send('Page.addScriptToEvaluateOnNewDocument', { source: REMOTE_AUDIO_TAP }, sessionId);156
await this.browser.send('Page.addScriptToEvaluateOnNewDocument', { source: FAKE_MEDIA(speechDataUrl()) }, sessionId);189
await this.browser.send('Page.addScriptToEvaluateOnNewDocument', { source: FAKE_MEDIA(speechDataUrl()) }, sessionId);157
for (const origin of TEAMS_ORIGINS) {190
for (const origin of TEAMS_ORIGINS) {@@ -357,6 +390,7 @@ const restoreCapture = () => defaultAudio('set', 'capture', savedCapture);357
for (const signal of ['SIGINT', 'SIGTERM']) process.on(signal, () => { restoreCapture(); process.exit(130); });390
for (const signal of ['SIGINT', 'SIGTERM']) process.on(signal, () => { restoreCapture(); process.exit(130); });358
const browser = await new Browser(OWN_ENDPOINT).connect();391
const browser = await new Browser(OWN_ENDPOINT).connect();359
const tab = new GuestTab(browser);392
const tab = new GuestTab(browser);393
const secondTab = process.env.SECOND_GUEST ? new GuestTab(browser) : null;360
try {394
try {361
if (!teamsProcessId()) {395
if (!teamsProcessId()) {362
log(`starting the app, waiting ${APP_START_WAIT_MS / 1000}s`);396
log(`starting the app, waiting ${APP_START_WAIT_MS / 1000}s`);@@ -373,9 +407,21 @@ try {373
runTeams('--join', link);407
runTeams('--join', link);374
log(`app joining, waiting ${APP_JOIN_WAIT_MS / 1000}s`);408
log(`app joining, waiting ${APP_JOIN_WAIT_MS / 1000}s`);375
await delay(APP_JOIN_WAIT_MS);409
await delay(APP_JOIN_WAIT_MS);410
const joined = await appStats(workDir).catch(() => ({ inCall: false }));411
if (!joined.inCall) throw new Error('the app is not in the call after --join');376
await tab.open(link);412
await tab.open(link);377
const admitting = setInterval(() => runTeams('--admit-all'), ADMIT_INTERVAL_MS);413
const admitting = setInterval(() => runTeams('--admit-all'), ADMIT_INTERVAL_MS);378
report.webJoined = await tab.join().finally(() => clearInterval(admitting));414
report.webJoined = await tab.join().finally(() => clearInterval(admitting));415
if (secondTab) {416
await secondTab.open(link);417
const admittingSecond = setInterval(() => runTeams('--admit-all'), ADMIT_INTERVAL_MS);418
report.secondJoined = await secondTab.join().finally(() => clearInterval(admittingSecond));419
log(`second guest joined: ${report.secondJoined}`);420
runTeams('--call', 'mute');421
await delay(10_000);422
report.secondHearsFirstOnly = await secondTab.evaluate(AUDIO_DECODER).catch((error) => error.message);423
report.firstWhileAppMuted = await tab.evaluate(AUDIO_DECODER).catch((error) => error.message);424
}379
log(`web guest joined: ${report.webJoined}`);425
log(`web guest joined: ${report.webJoined}`);380
if (!report.webJoined) {426
if (!report.webJoined) {381
await tab.shot(workDir + '/web-join.png');427
await tab.shot(workDir + '/web-join.png');@@ -392,6 +438,12 @@ try {392
]);438
]);393
report.guestSending = await tab.evaluate(GUEST_SENDING).catch((error) => error.message);439
report.guestSending = await tab.evaluate(GUEST_SENDING).catch((error) => error.message);394
report.guestPlayback = await tab.playbackState();440
report.guestPlayback = await tab.playbackState();441
report.guestAudioDecoder = await tab.evaluate(AUDIO_DECODER).catch((error) => error.message);442
report.guestSourceLevels = [];443
for (let sample = 0; sample < 10; sample++) {444
report.guestSourceLevels.push(await tab.evaluate(`(window.__pcs || []).flatMap((peer) => peer.getReceivers().filter((receiver) => receiver.track && receiver.track.kind === 'audio').flatMap((receiver) => receiver.getSynchronizationSources().map((source) => Number((source.audioLevel || 0).toFixed(3)))))`).catch((error) => error.message));445
await delay(500);446
}395
report.guestReceiving = await tab.evaluate(PEER_STATS).then((stats) => ({ peers: stats.peers, audioIn: stats.audioIn })).catch((error) => error.message);447
report.guestReceiving = await tab.evaluate(PEER_STATS).then((stats) => ({ peers: stats.peers, audioIn: stats.audioIn })).catch((error) => error.message);396
report.appToWeb = judge(webLevels, WEB_THRESHOLD);448
report.appToWeb = judge(webLevels, WEB_THRESHOLD);397
report.webToApp = judge(JSON.parse(recorded).rms, APP_THRESHOLD);449
report.webToApp = judge(JSON.parse(recorded).rms, APP_THRESHOLD);@@ -405,6 +457,7 @@ try {405
} finally {457
} finally {406
if (teamsProcessId()) runTeams('--hang-up');458
if (teamsProcessId()) runTeams('--hang-up');407
await tab.close();459
await tab.close();460
if (secondTab) await secondTab.close();408
restoreCapture();461
restoreCapture();409
log('default mic restored');462
log('default mic restored');410
browser.socket.close();463
browser.socket.close();@@ -413,5 +466,5 @@ const scenariosPass = Object.values(report.scenarios ?? {}).every((entry) => ent413
report.pass = Boolean(report.appToWeb?.pass && report.webToApp?.pass && scenariosPass);466
report.pass = Boolean(report.appToWeb?.pass && report.webToApp?.pass && scenariosPass);414
writeFileSync(workDir + '/report.json', JSON.stringify(report, null, 2));467
writeFileSync(workDir + '/report.json', JSON.stringify(report, null, 2));415
const scenarioSummary = Object.fromEntries(Object.entries(report.scenarios ?? {}).map(([name, entry]) => [name, entry.pass ? 'pass' : `FAIL ${entry.error ?? ''}`.trim()]));468
const scenarioSummary = Object.fromEntries(Object.entries(report.scenarios ?? {}).map(([name, entry]) => [name, entry.pass ? 'pass' : `FAIL ${entry.error ?? ''}`.trim()]));416
console.log(JSON.stringify({ pass: report.pass, guestPlayback: report.guestPlayback, guestReceiving: report.guestReceiving, appToWeb: report.appToWeb, webToApp: report.webToApp, scenarios: scenarioSummary, guestSending: report.guestSending, error: report.error }));469
console.log(JSON.stringify({ pass: report.pass, secondHearsFirstOnly: report.secondHearsFirstOnly, firstWhileAppMuted: report.firstWhileAppMuted, guestAudioDecoder: report.guestAudioDecoder, guestPlayback: report.guestPlayback, guestReceiving: report.guestReceiving, appToWeb: report.appToWeb, webToApp: report.webToApp, scenarios: scenarioSummary, guestSending: report.guestSending, error: report.error }));417
process.exit(report.pass ? 0 : 1);470
process.exit(report.pass ? 0 : 1);