mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
use readonly constructor props.
This commit is contained in:
parent
fcc57bf2fc
commit
79856e29a1
@ -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 },
|
||||
})
|
||||
|
@ -22,7 +22,6 @@ export interface NekoConnectionEvents {
|
||||
}
|
||||
|
||||
export class NekoConnection extends EventEmitter<NekoConnectionEvents> {
|
||||
private _state: Connection
|
||||
private _open = false
|
||||
|
||||
public websocket = new NekoWebSocket()
|
||||
@ -40,13 +39,15 @@ export class NekoConnection extends EventEmitter<NekoConnectionEvents> {
|
||||
|
||||
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 = () => {
|
||||
|
@ -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) {
|
||||
|
@ -42,18 +42,18 @@ export interface NekoEvents {
|
||||
}
|
||||
|
||||
export class NekoMessages extends EventEmitter<NekoEvents> {
|
||||
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
|
||||
|
@ -31,7 +31,6 @@ export interface ReconnectorEvents {
|
||||
}
|
||||
|
||||
export class Reconnector extends EventEmitter<ReconnectorEvents> {
|
||||
private _conn: ReconnectorAbstract
|
||||
private _config: ReconnectorConfig
|
||||
private _timeout?: number
|
||||
|
||||
@ -42,10 +41,13 @@ export class Reconnector extends EventEmitter<ReconnectorEvents> {
|
||||
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,
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
@ -33,13 +33,13 @@ export class NekoWebRTC extends EventEmitter<NekoWebRTCEvents> {
|
||||
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() {
|
||||
|
@ -10,12 +10,12 @@ export interface NekoWebSocketEvents {
|
||||
|
||||
export class NekoWebSocket extends EventEmitter<NekoWebSocketEvents> {
|
||||
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() {
|
||||
|
@ -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<string, any>) {
|
||||
let t = ''
|
||||
|
Loading…
Reference in New Issue
Block a user