Skip to content
This repository has been archived by the owner on Jul 20, 2024. It is now read-only.

Commit

Permalink
Feature: Add Log Level option for session (#41)
Browse files Browse the repository at this point in the history
* feat: log level

* fix rpc test
  • Loading branch information
luongngocminh authored Dec 19, 2023
1 parent 28eef02 commit 02d2658
Show file tree
Hide file tree
Showing 7 changed files with 205 additions and 61 deletions.
199 changes: 150 additions & 49 deletions coverage/cobertura-coverage.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" ?>
<!DOCTYPE coverage SYSTEM "http://cobertura.sourceforge.net/xml/coverage-04.dtd">
<coverage lines-valid="373" lines-covered="287" line-rate="0.7694" branches-valid="135" branches-covered="95" branch-rate="0.7037" timestamp="1702351363770" complexity="0" version="0.1">
<coverage lines-valid="402" lines-covered="304" line-rate="0.7562000000000001" branches-valid="146" branches-covered="99" branch-rate="0.6779999999999999" timestamp="1702960068514" complexity="0" version="0.1">
<sources>
<source>/Users/luongminh/workspace/bluesea/media-sdk-js</source>
</sources>
Expand Down Expand Up @@ -582,8 +582,18 @@
</class>
</classes>
</package>
<package name="lib.utils" line-rate="0.7058" branch-rate="0.7261">
<package name="lib.utils" line-rate="0.6848000000000001" branch-rate="0.6842">
<classes>
<class name="index.ts" filename="src/lib/utils/index.ts" line-rate="1" branch-rate="1">
<methods>
</methods>
<lines>
<line number="1" hits="1" branch="false"/>
<line number="2" hits="1" branch="false"/>
<line number="3" hits="1" branch="false"/>
<line number="4" hits="1" branch="false"/>
</lines>
</class>
<class name="latency-mode.ts" filename="src/lib/utils/latency-mode.ts" line-rate="0.0857" branch-rate="0">
<methods>
<method name="configPeerLatencyMode" hits="0" signature="()V">
Expand Down Expand Up @@ -635,47 +645,61 @@
<line number="52" hits="0" branch="false"/>
</lines>
</class>
<class name="logger.ts" filename="src/lib/utils/logger.ts" line-rate="0.7142000000000001" branch-rate="1">
<class name="logger.ts" filename="src/lib/utils/logger.ts" line-rate="0.6875" branch-rate="0.4">
<methods>
<method name="getLogger" hits="28" signature="()V">
<method name="setLogLevel" hits="14" signature="()V">
<lines>
<line number="2" hits="28"/>
<line number="5" hits="14"/>
</lines>
</method>
<method name="(anonymous_1)" hits="24" signature="()V">
<method name="getLogger" hits="28" signature="()V">
<lines>
<line number="4" hits="24"/>
<line number="10" hits="28"/>
</lines>
</method>
<method name="(anonymous_2)" hits="3" signature="()V">
<method name="(anonymous_2)" hits="24" signature="()V">
<lines>
<line number="5" hits="3"/>
<line number="12" hits="24"/>
</lines>
</method>
<method name="(anonymous_3)" hits="3" signature="()V">
<lines>
<line number="6" hits="3"/>
<line number="17" hits="3"/>
</lines>
</method>
<method name="(anonymous_4)" hits="0" signature="()V">
<method name="(anonymous_4)" hits="3" signature="()V">
<lines>
<line number="7" hits="0"/>
<line number="22" hits="3"/>
</lines>
</method>
<method name="(anonymous_5)" hits="0" signature="()V">
<lines>
<line number="8" hits="0"/>
<line number="27" hits="0"/>
</lines>
</method>
<method name="(anonymous_6)" hits="0" signature="()V">
<lines>
<line number="32" hits="0"/>
</lines>
</method>
</methods>
<lines>
<line number="2" hits="3" branch="false"/>
<line number="3" hits="28" branch="false"/>
<line number="4" hits="24" branch="false"/>
<line number="1" hits="3" branch="false"/>
<line number="3" hits="3" branch="false"/>
<line number="5" hits="3" branch="false"/>
<line number="6" hits="3" branch="false"/>
<line number="7" hits="0" branch="false"/>
<line number="8" hits="0" branch="false"/>
<line number="6" hits="14" branch="false"/>
<line number="10" hits="3" branch="false"/>
<line number="11" hits="28" branch="false"/>
<line number="13" hits="24" branch="true" condition-coverage="100% (1/1)"/>
<line number="14" hits="9" branch="false"/>
<line number="18" hits="3" branch="true" condition-coverage="0% (0/1)"/>
<line number="19" hits="0" branch="false"/>
<line number="23" hits="3" branch="true" condition-coverage="100% (1/1)"/>
<line number="24" hits="1" branch="false"/>
<line number="28" hits="0" branch="true" condition-coverage="0% (0/1)"/>
<line number="29" hits="0" branch="false"/>
<line number="33" hits="0" branch="true" condition-coverage="0% (0/1)"/>
<line number="34" hits="0" branch="false"/>
</lines>
</class>
<class name="mocks.ts" filename="src/lib/utils/mocks.ts" line-rate="0.8" branch-rate="1">
Expand Down Expand Up @@ -719,6 +743,72 @@
<line number="29" hits="0" branch="false"/>
</lines>
</class>
<class name="simple-event-emiiter.ts" filename="src/lib/utils/simple-event-emiiter.ts" line-rate="0.1" branch-rate="0">
<methods>
<method name="(anonymous_0)" hits="0" signature="()V">
<lines>
<line number="2" hits="0"/>
</lines>
</method>
<method name="(anonymous_1)" hits="0" signature="()V">
<lines>
<line number="5" hits="0"/>
</lines>
</method>
<method name="(anonymous_2)" hits="0" signature="()V">
<lines>
<line number="11" hits="0"/>
</lines>
</method>
<method name="(anonymous_3)" hits="0" signature="()V">
<lines>
<line number="13" hits="0"/>
</lines>
</method>
<method name="(anonymous_4)" hits="0" signature="()V">
<lines>
<line number="13" hits="0"/>
</lines>
</method>
<method name="(anonymous_5)" hits="0" signature="()V">
<lines>
<line number="16" hits="0"/>
</lines>
</method>
<method name="(anonymous_6)" hits="0" signature="()V">
<lines>
<line number="17" hits="0"/>
</lines>
</method>
<method name="(anonymous_7)" hits="0" signature="()V">
<lines>
<line number="20" hits="0"/>
</lines>
</method>
<method name="(anonymous_8)" hits="0" signature="()V">
<lines>
<line number="24" hits="0"/>
</lines>
</method>
<method name="(anonymous_9)" hits="0" signature="()V">
<lines>
<line number="28" hits="0"/>
</lines>
</method>
</methods>
<lines>
<line number="2" hits="1" branch="false"/>
<line number="3" hits="0" branch="false"/>
<line number="6" hits="0" branch="true" condition-coverage="0% (0/2)"/>
<line number="7" hits="0" branch="false"/>
<line number="12" hits="0" branch="true" condition-coverage="0% (0/2)"/>
<line number="13" hits="0" branch="false"/>
<line number="17" hits="0" branch="false"/>
<line number="21" hits="0" branch="false"/>
<line number="25" hits="0" branch="false"/>
<line number="29" hits="0" branch="false"/>
</lines>
</class>
<class name="transceiver.ts" filename="src/lib/utils/transceiver.ts" line-rate="0.8887999999999999" branch-rate="0.7843000000000001">
<methods>
<method name="addTransceiverSimulcast" hits="2" signature="()V">
Expand Down Expand Up @@ -872,78 +962,89 @@
</method>
<method name="(anonymous_1)" hits="5" signature="()V">
<lines>
<line number="8" hits="5"/>
<line number="11" hits="5"/>
</lines>
</method>
<method name="(anonymous_2)" hits="5" signature="()V">
<lines>
<line number="15" hits="5"/>
<line number="16" hits="5"/>
</lines>
</method>
<method name="(anonymous_3)" hits="5" signature="()V">
<lines>
<line number="24" hits="5"/>
<line number="23" hits="5"/>
</lines>
</method>
<method name="(anonymous_4)" hits="5" signature="()V">
<lines>
<line number="34" hits="5"/>
<line number="32" hits="5"/>
</lines>
</method>
<method name="(anonymous_5)" hits="5" signature="()V">
<lines>
<line number="40" hits="5"/>
<line number="42" hits="5"/>
</lines>
</method>
<method name="(anonymous_6)" hits="5" signature="()V">
<lines>
<line number="45" hits="5"/>
<line number="48" hits="5"/>
</lines>
</method>
<method name="(anonymous_7)" hits="5" signature="()V">
<lines>
<line number="51" hits="5"/>
<line number="53" hits="5"/>
</lines>
</method>
<method name="(anonymous_8)" hits="5" signature="()V">
<lines>
<line number="59" hits="5"/>
</lines>
</method>
</methods>
<lines>
<line number="3" hits="5" branch="true" condition-coverage="100% (2/2)"/>
<line number="4" hits="5" branch="false"/>
<line number="5" hits="5" branch="false"/>
<line number="8" hits="5" branch="true" condition-coverage="100% (2/2)"/>
<line number="9" hits="5" branch="false"/>
<line number="10" hits="5" branch="false"/>
<line number="11" hits="5" branch="false"/>
<line number="6" hits="5" branch="false"/>
<line number="7" hits="5" branch="false"/>
<line number="8" hits="5" branch="false"/>
<line number="11" hits="5" branch="true" condition-coverage="100% (2/2)"/>
<line number="12" hits="5" branch="false"/>
<line number="15" hits="5" branch="true" condition-coverage="100% (2/2)"/>
<line number="16" hits="5" branch="false"/>
<line number="13" hits="5" branch="false"/>
<line number="16" hits="5" branch="true" condition-coverage="100% (2/2)"/>
<line number="17" hits="5" branch="false"/>
<line number="18" hits="5" branch="false"/>
<line number="24" hits="5" branch="true" condition-coverage="100% (2/2)"/>
<line number="19" hits="5" branch="false"/>
<line number="20" hits="5" branch="false"/>
<line number="23" hits="5" branch="true" condition-coverage="100% (2/2)"/>
<line number="24" hits="5" branch="false"/>
<line number="25" hits="5" branch="false"/>
<line number="26" hits="5" branch="false"/>
<line number="27" hits="5" branch="false"/>
<line number="28" hits="5" branch="false"/>
<line number="29" hits="5" branch="false"/>
<line number="30" hits="5" branch="false"/>
<line number="31" hits="5" branch="false"/>
<line number="34" hits="5" branch="true" condition-coverage="100% (2/2)"/>
<line number="32" hits="5" branch="true" condition-coverage="100% (2/2)"/>
<line number="33" hits="5" branch="false"/>
<line number="34" hits="5" branch="false"/>
<line number="35" hits="5" branch="false"/>
<line number="36" hits="5" branch="false"/>
<line number="37" hits="5" branch="false"/>
<line number="40" hits="5" branch="true" condition-coverage="100% (2/2)"/>
<line number="41" hits="5" branch="false"/>
<line number="42" hits="5" branch="false"/>
<line number="45" hits="5" branch="true" condition-coverage="100% (2/2)"/>
<line number="46" hits="5" branch="false"/>
<line number="47" hits="5" branch="false"/>
<line number="48" hits="5" branch="false"/>
<line number="51" hits="5" branch="true" condition-coverage="100% (2/2)"/>
<line number="52" hits="5" branch="false"/>
<line number="53" hits="5" branch="false"/>
<line number="38" hits="5" branch="false"/>
<line number="39" hits="5" branch="false"/>
<line number="42" hits="5" branch="true" condition-coverage="100% (2/2)"/>
<line number="43" hits="5" branch="false"/>
<line number="44" hits="5" branch="false"/>
<line number="45" hits="5" branch="false"/>
<line number="48" hits="5" branch="true" condition-coverage="100% (2/2)"/>
<line number="49" hits="5" branch="false"/>
<line number="50" hits="5" branch="false"/>
<line number="53" hits="5" branch="true" condition-coverage="100% (2/2)"/>
<line number="54" hits="5" branch="false"/>
<line number="55" hits="5" branch="false"/>
<line number="56" hits="5" branch="false"/>
<line number="59" hits="5" branch="true" condition-coverage="100% (2/2)"/>
<line number="60" hits="5" branch="false"/>
<line number="61" hits="5" branch="false"/>
<line number="62" hits="5" branch="false"/>
<line number="63" hits="5" branch="false"/>
<line number="64" hits="5" branch="false"/>
</lines>
</class>
</classes>
Expand Down
6 changes: 1 addition & 5 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import resolve from '@rollup/plugin-node-resolve';
*/
const banner = `/*!
* ${packageJSON.name} v${packageJSON.version}
* (c) ${packageJSON.author.name}
* (c) ${packageJSON.author}
* Released under the ${packageJSON.license} License.
*/
`;
Expand Down Expand Up @@ -39,7 +39,6 @@ const options = {
createOutputOptions({
file: './dist/index.js',
format: 'commonjs',
// plugins: [resolve()],
}),
createOutputOptions({
file: './dist/index.cjs',
Expand All @@ -54,12 +53,10 @@ const options = {
createOutputOptions({
file: './dist/index.esm.js',
format: 'esm',
// plugins: [resolve()],
}),
createOutputOptions({
file: './dist/index.umd.js',
format: 'umd',
// plugins: [resolve()],
}),
createOutputOptions({
file: './dist/index.umd.min.js',
Expand All @@ -69,7 +66,6 @@ const options = {
createOutputOptions({
file: './dist/index.iife.js',
format: 'iife',
// plugins: [resolve()],
}),
createOutputOptions({
file: './dist/index.iife.min.js',
Expand Down
2 changes: 2 additions & 0 deletions src/lib/core/rpc.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import type { IRealtimeSocket } from '../interfaces';
import { setLogLevel } from '../utils';
import { MockRTSocket } from '../utils/mocks';
import { RPC, RpcRequest } from './rpc';

Expand Down Expand Up @@ -50,6 +51,7 @@ describe('RPC', () => {
// Mock the socket object
socketMock = new MockRTSocket();
rpc = new RPC(socketMock);
setLogLevel(4);
});

afterEach(() => {
Expand Down
7 changes: 6 additions & 1 deletion src/lib/interfaces/session.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { StreamRemote } from '../remote';
import type { LatencyMode, Codecs, MixMinusMode, BitrateControlMode } from '../utils/types';
import type { LatencyMode, Codecs, MixMinusMode, BitrateControlMode, LogLevel } from '../utils/types';
import type { RealtimeSocketState } from './rtsocket';
import type { SenderConfig } from './sender';

Expand Down Expand Up @@ -146,4 +146,9 @@ export interface ISessionConfig {
* Optional bitrate control mode for the session.
*/
bitrateControlMode?: BitrateControlMode;

/**
* Log level for the session.
*/
logLevel?: LogLevel;
}
6 changes: 5 additions & 1 deletion src/lib/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { StreamSender } from './sender';
import { StreamKinds } from './utils/types';
import { debounce } from 'ts-debounce';
import { TypedEventEmitter } from './utils/typed-event-emitter';
import { getLogger } from './utils/logger';
import { getLogger, setLogLevel } from './utils/logger';
import type { IRPC } from './interfaces/rpc';
import { RPC } from './core/rpc';
import type { IMediaGatewayConnector } from './interfaces/gateway';
Expand Down Expand Up @@ -38,6 +38,10 @@ export class Session extends TypedEventEmitter<ISessionCallbacks> {
private _connector: IMediaGatewayConnector,
) {
super();
if (this._cfg.logLevel) {
this.logger.log('set log level:', this._cfg.logLevel);
setLogLevel(this._cfg.logLevel);
}
this._socket.on('peer_state', (state) => {
this.emit('peer_state', state);
switch (state) {
Expand Down
Loading

0 comments on commit 02d2658

Please sign in to comment.