Skip to content

Commit

Permalink
Make redundant audio worker code generation script also work on Windo…
Browse files Browse the repository at this point in the history
…ws (#2913)

1. Use a common `tsc` path
2. Handle carriage returns in code string

Context in issue: #2779
  • Loading branch information
dinmin-amzn authored Jun 26, 2024
1 parent 3870262 commit 7e523c0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- Fixed rare race conditions with simulcast + server side network adaptation on third attendee join.
- Make redundant audio worker code generation script work on Windows

## [3.22.0] - 2024-03-15

Expand Down
11 changes: 8 additions & 3 deletions script/generate-red-worker-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { execSync } = require('child_process');
const fs = require('fs');
const path = require('path');

// Create a temporary tsconfig file to only transpile `RedundantAudioEncoder.ts`.
const configDir = 'config';
Expand All @@ -29,7 +30,10 @@ fs.writeFileSync(`${configDir}/${redTsconfig}`, redTsconfigContent);
// Run the `prebuild` script to generate `node_modules` since we will be using the `tsc` command from `node_modules`.
function runCommandWithLogs(command) {
try {
console.log(execSync(command).toString());
console.log(`Running command: ${command}`);
const output = execSync(command).toString();
console.log(output);
return output;
} catch (error) {
console.log(error.stdout.toString());
console.error(error.toString());
Expand All @@ -39,7 +43,8 @@ function runCommandWithLogs(command) {
runCommandWithLogs('npm run prebuild');

// Transpile `RedundantAudioEncoder.ts`.
runCommandWithLogs('./node_modules/typescript/bin/tsc --build config/tsconfig.red.json');
let tscPath = path.resolve(`${runCommandWithLogs('npm root').replace(/\n/g, "")}/.bin/tsc`);
runCommandWithLogs(`${tscPath} --build config/tsconfig.red.json`);

// Remove the temporary tsconfig file.
fs.unlinkSync(`${configDir}/${redTsconfig}`);
Expand All @@ -50,7 +55,7 @@ const redundantAudioEncoderWorkerCode = `${RedundantAudioEncoder.toString()}
RedundantAudioEncoder.shouldLog = true;
RedundantAudioEncoder.shouldReportStats = true;
RedundantAudioEncoder.initializeWorker();
`.replace(/"/g, '\'').replace(/\n/g, "\\n")
`.replace(/"/g, '\'').replace(/\n/g, "\\n").replace(/\r/g, "\\r");

const workerFileContent = `// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
Expand Down

0 comments on commit 7e523c0

Please sign in to comment.