Skip to content

Commit

Permalink
Use our own Logger
Browse files Browse the repository at this point in the history
  • Loading branch information
ibc committed Sep 15, 2023
1 parent 69b2dfb commit 157b19c
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 9 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
"cacheDirectory": ".cache/jest"
},
"dependencies": {
"@types/debug": "^4.1.8",
"debug": "^4.3.4",
"event-target-shim": "^6.0.2",
"fake-mediastreamtrack": "^1.2.0",
"mediasoup-client": "^3.6.100",
Expand Down
4 changes: 2 additions & 2 deletions src/Channel.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Duplex } from 'stream';
// @ts-ignore
import * as netstring from 'netstring';
import { Logger } from 'mediasoup-client/lib/Logger';
import { EnhancedEventEmitter } from 'mediasoup-client/lib/EnhancedEventEmitter';
import { InvalidStateError } from 'mediasoup-client/lib/errors';
import { Logger } from './Logger';

// netstring length for a 4194304 bytes payload.
const NS_MESSAGE_MAX_LEN = 4194313;
const NS_PAYLOAD_MAX_LEN = 4194304;

const logger = new Logger('aiortc:Channel');
const logger = new Logger('Channel');

interface Sent
{
Expand Down
4 changes: 2 additions & 2 deletions src/FakeRTCDataChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import {
getEventAttributeValue,
setEventAttributeValue
} from 'event-target-shim';
import { Logger } from 'mediasoup-client/lib/Logger';
import { InvalidStateError } from 'mediasoup-client/lib/errors';
import { Logger } from './Logger';
import { Channel } from './Channel';

const logger = new Logger('aiortc:FakeRTCDataChannel');
const logger = new Logger('FakeRTCDataChannel');

export type FakeRTCDataChannelOptions =
{
Expand Down
4 changes: 2 additions & 2 deletions src/Handler.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { v4 as uuidv4 } from 'uuid';
import * as sdpTransform from 'sdp-transform';
import { FakeMediaStreamTrack } from 'fake-mediastreamtrack';
import { Logger } from 'mediasoup-client/lib/Logger';
import { UnsupportedError } from 'mediasoup-client/lib/errors';
import * as utils from 'mediasoup-client/lib/utils';
import * as ortc from 'mediasoup-client/lib/ortc';
Expand All @@ -28,11 +27,12 @@ import {
SctpCapabilities,
SctpStreamParameters
} from 'mediasoup-client/lib/types';
import { Logger } from './Logger';
import { Channel } from './Channel';
import { FakeRTCStatsReport } from './FakeRTCStatsReport';
import { FakeRTCDataChannel } from './FakeRTCDataChannel';

const logger = new Logger('aiortc:Handler');
const logger = new Logger('Handler');

const SCTP_NUM_STREAMS = { OS: 65535, MIS: 65535 };

Expand Down
47 changes: 47 additions & 0 deletions src/Logger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import debug from 'debug';

const APP_NAME = 'mediasoup-client-aiortc';

export class Logger
{
private readonly _debug: debug.Debugger;
private readonly _warn: debug.Debugger;
private readonly _error: debug.Debugger;

constructor(prefix?: string)
{
if (prefix)
{
this._debug = debug(`${APP_NAME}:${prefix}`);
this._warn = debug(`${APP_NAME}:WARN:${prefix}`);
this._error = debug(`${APP_NAME}:ERROR:${prefix}`);
}
else
{
this._debug = debug(APP_NAME);
this._warn = debug(`${APP_NAME}:WARN`);
this._error = debug(`${APP_NAME}:ERROR`);
}

/* eslint-disable no-console */
this._debug.log = console.info.bind(console);
this._warn.log = console.warn.bind(console);
this._error.log = console.error.bind(console);
/* eslint-enable no-console */
}

get debug(): debug.Debugger
{
return this._debug;
}

get warn(): debug.Debugger
{
return this._warn;
}

get error(): debug.Debugger
{
return this._error;
}
}
2 changes: 1 addition & 1 deletion src/Worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { Handler } from './Handler';
// stdout and stderr.
const PYTHON_LOG_VIA_PIPE = process.env.PYTHON_LOG_TO_STDOUT !== 'true';

const logger = new Logger('aiortc:Worker');
const logger = new Logger('Worker');

export type WorkerSettings =
{
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Logger } from 'mediasoup-client/lib/Logger';
import { Logger } from './Logger';
import {
Worker,
WorkerSettings,
Expand All @@ -10,7 +10,7 @@ import {
AiortcMediaTrackConstraints
} from './media';

const logger = new Logger('aiortc');
const logger = new Logger();

/**
* Expose version.
Expand Down

0 comments on commit 157b19c

Please sign in to comment.