Skip to content

Modernize #1513

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

Merged
merged 3 commits into from
Mar 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# EditorConfig is awesome: https://editorconfig.org

root = true

[*]
indent_style = tab
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.{ts,mts,mjs,cjs,js}]
indent_style = tab

[*.json]
indent_style = tab

[*.md]
indent_style = tab
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### NEXT

- CI: Remove redundant hosts `macos-14` and `windows-2022` from `mediasoup-worker-prebuild` job ([PR #1506](https://github.com/versatica/mediasoup/pull/1506)).
- Node: Modernize code ([PR #1513](https://github.com/versatica/mediasoup/pull/1513)).

### 3.15.6

Expand Down
17 changes: 11 additions & 6 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const config = tsEslint.config(
{
languageOptions: {
sourceType: 'module',
globals: { ...globals.nodeBuiltin },
globals: { ...globals.node },
},
linterOptions: {
noInlineConfig: false,
Expand Down Expand Up @@ -108,18 +108,20 @@ const config = tsEslint.config(
yoda: 2,
},
},
// NOTE: We need to apply this only to .ts files (and not to .mjs files).
// NOTE: We need to apply this only to .ts source files (and not to .mjs
// files).
...tsEslint.configs.recommendedTypeChecked.map(item => ({
...item,
files: ['node/src/**/*.ts'],
})),
// NOTE: We need to apply this only to .ts files (and not to .mjs files).
// NOTE: We need to apply this only to .ts source files (and not to .mjs
// files).
...tsEslint.configs.stylisticTypeChecked.map(item => ({
...item,
files: ['node/src/**/*.ts'],
})),
{
name: 'mediasoup .ts files',
name: '.ts source files',
files: ['node/src/**/*.ts'],
languageOptions: {
parserOptions: {
Expand Down Expand Up @@ -153,7 +155,10 @@ const config = tsEslint.config(
],
// Sorry, we need many `any` usage.
'@typescript-eslint/no-explicit-any': 0,
'@typescript-eslint/explicit-function-return-type': 2,
'@typescript-eslint/explicit-function-return-type': [
2,
{ allowExpressions: true },
],
'@typescript-eslint/no-unsafe-member-access': 0,
'@typescript-eslint/no-unsafe-assignment': 0,
'@typescript-eslint/no-unsafe-call': 0,
Expand All @@ -169,7 +174,7 @@ const config = tsEslint.config(
},
},
{
name: 'mediasoup .ts test files',
name: '.ts test files',
...jestEslint.configs['flat/recommended'],
files: ['node/src/test/**/*.ts'],
rules: {
Expand Down
18 changes: 18 additions & 0 deletions jest.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const config = {
verbose: true,
testEnvironment: 'node',
testRegex: 'node/src/test/test-.*\\.ts',
transform: {
'^.+\\.ts?$': ['ts-jest'],
},
coveragePathIgnorePatterns: [
'node/src/Logger.ts',
'node/src/enhancedEvents.ts',
'node/src/fbs',
'node/src/test',
],
modulePathIgnorePatterns: ['worker', 'rust', 'target'],
cacheDirectory: '.cache/jest',
};

export default config;
2 changes: 1 addition & 1 deletion node/src/ActiveSpeakerObserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class ActiveSpeakerObserverImpl<
return 'activespeaker';
}

get observer(): ActiveSpeakerObserverObserver {
override get observer(): ActiveSpeakerObserverObserver {
return super.observer;
}

Expand Down
2 changes: 1 addition & 1 deletion node/src/AudioLevelObserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class AudioLevelObserverImpl<
return 'audiolevel';
}

get observer(): AudioLevelObserverObserver {
override get observer(): AudioLevelObserverObserver {
return super.observer;
}

Expand Down
2 changes: 1 addition & 1 deletion node/src/Channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class Channel extends EnhancedEventEmitter {
readonly #sents: Map<number, Sent> = new Map();

// Buffer for reading messages from the worker.
#recvBuffer = Buffer.alloc(0);
#recvBuffer: Buffer = Buffer.alloc(0);

// flatbuffers builder.
#bufferBuilder: flatbuffers.Builder = new flatbuffers.Builder(1024);
Expand Down
12 changes: 6 additions & 6 deletions node/src/DirectTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,19 @@ export class DirectTransportImpl<
return 'direct';
}

get observer(): DirectTransportObserver {
override get observer(): DirectTransportObserver {
return super.observer;
}

close(): void {
override close(): void {
if (this.closed) {
return;
}

super.close();
}

routerClosed(): void {
override routerClosed(): void {
if (this.closed) {
return;
}
Expand Down Expand Up @@ -134,21 +134,21 @@ export class DirectTransportImpl<
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/require-await
async setMaxIncomingBitrate(bitrate: number): Promise<void> {
override async setMaxIncomingBitrate(bitrate: number): Promise<void> {
throw new UnsupportedError(
'setMaxIncomingBitrate() not implemented in DirectTransport'
);
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/require-await
async setMaxOutgoingBitrate(bitrate: number): Promise<void> {
override async setMaxOutgoingBitrate(bitrate: number): Promise<void> {
throw new UnsupportedError(
'setMaxOutgoingBitrate() not implemented in DirectTransport'
);
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/require-await
async setMinOutgoingBitrate(bitrate: number): Promise<void> {
override async setMinOutgoingBitrate(bitrate: number): Promise<void> {
throw new UnsupportedError(
'setMinOutgoingBitrate() not implemented in DirectTransport'
);
Expand Down
8 changes: 4 additions & 4 deletions node/src/PipeTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export class PipeTransportImpl<PipeTransportAppData extends AppData = AppData>
return 'pipe';
}

get observer(): PipeTransportObserver {
override get observer(): PipeTransportObserver {
return super.observer;
}

Expand All @@ -116,7 +116,7 @@ export class PipeTransportImpl<PipeTransportAppData extends AppData = AppData>
return this.#data.srtpParameters;
}

close(): void {
override close(): void {
if (this.closed) {
return;
}
Expand All @@ -128,7 +128,7 @@ export class PipeTransportImpl<PipeTransportAppData extends AppData = AppData>
super.close();
}

routerClosed(): void {
override routerClosed(): void {
if (this.closed) {
return;
}
Expand Down Expand Up @@ -213,7 +213,7 @@ export class PipeTransportImpl<PipeTransportAppData extends AppData = AppData>
}
}

async consume<ConsumerAppData extends AppData = AppData>({
override async consume<ConsumerAppData extends AppData = AppData>({
producerId,
appData,
}: PipeConsumerOptions<ConsumerAppData>): Promise<Consumer<ConsumerAppData>> {
Expand Down
6 changes: 3 additions & 3 deletions node/src/PlainTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export class PlainTransportImpl<PlainTransportAppData extends AppData = AppData>
return 'plain';
}

get observer(): PlainTransportObserver {
override get observer(): PlainTransportObserver {
return super.observer;
}

Expand All @@ -113,7 +113,7 @@ export class PlainTransportImpl<PlainTransportAppData extends AppData = AppData>
return this.#data.srtpParameters;
}

close(): void {
override close(): void {
if (this.closed) {
return;
}
Expand All @@ -125,7 +125,7 @@ export class PlainTransportImpl<PlainTransportAppData extends AppData = AppData>
super.close();
}

routerClosed(): void {
override routerClosed(): void {
if (this.closed) {
return;
}
Expand Down
6 changes: 3 additions & 3 deletions node/src/Router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -985,8 +985,8 @@ export class RouterImpl<RouterAppData extends AppData = AppData>

if (pipeTransportPairPromise) {
pipeTransportPair = await pipeTransportPairPromise;
localPipeTransport = pipeTransportPair[this.id];
remotePipeTransport = pipeTransportPair[router.id];
localPipeTransport = pipeTransportPair[this.id]!;
remotePipeTransport = pipeTransportPair[router.id]!;
} else {
pipeTransportPairPromise = new Promise((resolve, reject) => {
Promise.all([
Expand Down Expand Up @@ -1190,7 +1190,7 @@ export class RouterImpl<RouterAppData extends AppData = AppData>

pipeTransportPairPromise
.then(pipeTransportPair => {
const localPipeTransport = pipeTransportPair[this.id];
const localPipeTransport = pipeTransportPair[this.id]!;

// NOTE: No need to do any other cleanup here since that is done by the
// Router calling this method on us.
Expand Down
8 changes: 4 additions & 4 deletions node/src/WebRtcTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export class WebRtcTransportImpl<
return 'webrtc';
}

get observer(): WebRtcTransportObserver {
override get observer(): WebRtcTransportObserver {
return super.observer;
}

Expand Down Expand Up @@ -156,7 +156,7 @@ export class WebRtcTransportImpl<
return this.#data.sctpState;
}

close(): void {
override close(): void {
if (this.closed) {
return;
}
Expand All @@ -172,7 +172,7 @@ export class WebRtcTransportImpl<
super.close();
}

routerClosed(): void {
override routerClosed(): void {
if (this.closed) {
return;
}
Expand All @@ -188,7 +188,7 @@ export class WebRtcTransportImpl<
super.routerClosed();
}

listenServerClosed(): void {
override listenServerClosed(): void {
if (this.closed) {
return;
}
Expand Down
14 changes: 7 additions & 7 deletions node/src/Worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ import { Protocol as FbsTransportProtocol } from './fbs/transport/protocol';
// If env MEDIASOUP_WORKER_BIN is given, use it as worker binary.
// Otherwise if env MEDIASOUP_BUILDTYPE is 'Debug' use the Debug binary.
// Otherwise use the Release binary.
export const workerBin = process.env.MEDIASOUP_WORKER_BIN
? process.env.MEDIASOUP_WORKER_BIN
: process.env.MEDIASOUP_BUILDTYPE === 'Debug'
export const workerBin = process.env['MEDIASOUP_WORKER_BIN']
? process.env['MEDIASOUP_WORKER_BIN']
: process.env['MEDIASOUP_BUILDTYPE'] === 'Debug'
? path.join(
__dirname,
'..',
Expand Down Expand Up @@ -112,12 +112,12 @@ export class WorkerImpl<WorkerAppData extends AppData = AppData>
let spawnBin = workerBin;
let spawnArgs: string[] = [];

if (process.env.MEDIASOUP_USE_VALGRIND === 'true') {
spawnBin = process.env.MEDIASOUP_VALGRIND_BIN ?? 'valgrind';
if (process.env['MEDIASOUP_USE_VALGRIND'] === 'true') {
spawnBin = process.env['MEDIASOUP_VALGRIND_BIN'] ?? 'valgrind';

if (process.env.MEDIASOUP_VALGRIND_OPTIONS) {
if (process.env['MEDIASOUP_VALGRIND_OPTIONS']) {
spawnArgs = spawnArgs.concat(
process.env.MEDIASOUP_VALGRIND_OPTIONS.split(/\s+/)
process.env['MEDIASOUP_VALGRIND_OPTIONS'].split(/\s+/)
);
}

Expand Down
Loading