diff --git a/src/component/internal/api.ts b/src/component/internal/api.ts index 9e97a48e..5275cf25 100644 --- a/src/component/internal/api.ts +++ b/src/component/internal/api.ts @@ -1,7 +1,7 @@ import * as Api from '../api' export class NekoApi { - private _config = new Api.Configuration({ + private readonly _config = new Api.Configuration({ basePath: location.href.replace(/\/+$/, ''), baseOptions: { withCredentials: true }, }) diff --git a/src/component/internal/connection.ts b/src/component/internal/connection.ts index 8ef73810..97861b26 100644 --- a/src/component/internal/connection.ts +++ b/src/component/internal/connection.ts @@ -22,7 +22,6 @@ export interface NekoConnectionEvents { } export class NekoConnection extends EventEmitter { - private _state: Connection private _open = false public websocket = new NekoWebSocket() @@ -40,13 +39,15 @@ export class NekoConnection extends EventEmitter { private _webrtcCongestionControlHandle: (stats: WebRTCStats) => void - constructor(state: Connection) { + // eslint-disable-next-line + constructor( + private readonly _state: Connection, + ) { super() - this._state = state this._reconnector = { - websocket: new Reconnector(new WebsocketReconnector(state, this.websocket), state.websocket.config), - webrtc: new Reconnector(new WebrtcReconnector(state, this.websocket, this.webrtc), state.webrtc.config), + websocket: new Reconnector(new WebsocketReconnector(_state, this.websocket), _state.websocket.config), + webrtc: new Reconnector(new WebrtcReconnector(_state, this.websocket, this.webrtc), _state.webrtc.config), } this._onConnectHandle = () => { diff --git a/src/component/internal/logger.ts b/src/component/internal/logger.ts index c03f12ba..31c128cb 100644 --- a/src/component/internal/logger.ts +++ b/src/component/internal/logger.ts @@ -8,14 +8,14 @@ const FLUSH_TIMEOUT_MS = 250 const RETRY_INTERVAL_MS = 2500 export class NekoLoggerFactory { - private _ws: NekoWebSocket private _logs: message.SystemLog[] = [] private _timeout: number | null = null private _interval: number | null = null - constructor(websocket: NekoWebSocket) { - this._ws = websocket - } + // eslint-disable-next-line + constructor( + private readonly _ws: NekoWebSocket, + ) {} private _flush() { if (this._logs.length > 0) { diff --git a/src/component/internal/messages.ts b/src/component/internal/messages.ts index 7c38f313..7d4d87ca 100644 --- a/src/component/internal/messages.ts +++ b/src/component/internal/messages.ts @@ -42,18 +42,18 @@ export interface NekoEvents { } export class NekoMessages extends EventEmitter { - private _connection: NekoConnection - private _state: NekoState private _localLog: Logger private _remoteLog: Logger - constructor(connection: NekoConnection, state: NekoState) { + // eslint-disable-next-line + constructor( + private readonly _connection: NekoConnection, + private readonly _state: NekoState, + ) { super() - this._connection = connection - this._state = state this._localLog = new Logger('messages') - this._remoteLog = connection.getLogger('messages') + this._remoteLog = _connection.getLogger('messages') this._connection.websocket.on('message', async (event: string, payload: any) => { // @ts-ignore diff --git a/src/component/internal/reconnector/index.ts b/src/component/internal/reconnector/index.ts index 6f8875c0..50310c56 100644 --- a/src/component/internal/reconnector/index.ts +++ b/src/component/internal/reconnector/index.ts @@ -31,7 +31,6 @@ export interface ReconnectorEvents { } export class Reconnector extends EventEmitter { - private _conn: ReconnectorAbstract private _config: ReconnectorConfig private _timeout?: number @@ -42,10 +41,13 @@ export class Reconnector extends EventEmitter { private _onConnectHandle: () => void private _onDisconnectHandle: (error?: Error) => void - constructor(conn: ReconnectorAbstract, config?: ReconnectorConfig) { + // eslint-disable-next-line + constructor( + private readonly _conn: ReconnectorAbstract, + config?: ReconnectorConfig, + ) { super() - this._conn = conn this._config = { max_reconnects: 10, timeout_ms: 1500, diff --git a/src/component/internal/reconnector/webrtc.ts b/src/component/internal/reconnector/webrtc.ts index 12ad444b..587df0d4 100644 --- a/src/component/internal/reconnector/webrtc.ts +++ b/src/component/internal/reconnector/webrtc.ts @@ -7,20 +7,17 @@ import { NekoWebRTC } from '../webrtc' import { ReconnectorAbstract } from '.' export class WebrtcReconnector extends ReconnectorAbstract { - private _state: Connection - private _websocket: NekoWebSocket - private _webrtc: NekoWebRTC - private _onConnectHandle: () => void private _onDisconnectHandle: (error?: Error) => void - constructor(state: Connection, websocket: NekoWebSocket, webrtc: NekoWebRTC) { + // eslint-disable-next-line + constructor( + private readonly _state: Connection, + private readonly _websocket: NekoWebSocket, + private readonly _webrtc: NekoWebRTC, + ) { super() - this._state = state - this._websocket = websocket - this._webrtc = webrtc - this._onConnectHandle = () => this.emit('connect') this._webrtc.on('connected', this._onConnectHandle) diff --git a/src/component/internal/reconnector/websocket.ts b/src/component/internal/reconnector/websocket.ts index 378d2898..73970852 100644 --- a/src/component/internal/reconnector/websocket.ts +++ b/src/component/internal/reconnector/websocket.ts @@ -5,18 +5,16 @@ import { NekoWebSocket } from '../websocket' import { ReconnectorAbstract } from '.' export class WebsocketReconnector extends ReconnectorAbstract { - private _state: Connection - private _websocket: NekoWebSocket - private _onConnectHandle: () => void private _onDisconnectHandle: (error?: Error) => void - constructor(state: Connection, websocket: NekoWebSocket) { + // eslint-disable-next-line + constructor( + private readonly _state: Connection, + private readonly _websocket: NekoWebSocket, + ) { super() - this._state = state - this._websocket = websocket - this._onConnectHandle = () => this.emit('connect') this._websocket.on('connected', this._onConnectHandle) diff --git a/src/component/internal/webrtc.ts b/src/component/internal/webrtc.ts index 2a76b969..c477890f 100644 --- a/src/component/internal/webrtc.ts +++ b/src/component/internal/webrtc.ts @@ -33,13 +33,13 @@ export class NekoWebRTC extends EventEmitter { private _track?: MediaStreamTrack private _state: RTCIceConnectionState = 'disconnected' private _candidates: RTCIceCandidateInit[] = [] - private _log: Logger private _statsStop?: () => void - constructor(logger?: Logger) { + // eslint-disable-next-line + constructor( + private readonly _log: Logger = new Logger('webrtc'), + ) { super() - - this._log = logger || new Logger('webrtc') } get supported() { diff --git a/src/component/internal/websocket.ts b/src/component/internal/websocket.ts index c54cb108..181cd8bd 100644 --- a/src/component/internal/websocket.ts +++ b/src/component/internal/websocket.ts @@ -10,12 +10,12 @@ export interface NekoWebSocketEvents { export class NekoWebSocket extends EventEmitter { private _ws?: WebSocket - private _log: Logger - constructor(logger?: Logger) { + // eslint-disable-next-line + constructor( + private readonly _log: Logger = new Logger('websocket'), + ) { super() - - this._log = logger || new Logger('websocket') } get supported() { diff --git a/src/component/utils/logger.ts b/src/component/utils/logger.ts index d1869d7a..54c54df4 100644 --- a/src/component/utils/logger.ts +++ b/src/component/utils/logger.ts @@ -1,11 +1,8 @@ export class Logger { - protected _scope: string = 'main' - - constructor(scope?: string) { - if (scope) { - this._scope = scope - } - } + // eslint-disable-next-line + constructor( + protected readonly _scope: string = 'main', + ) {} protected _console(level: string, m: string, fields?: Record) { let t = ''