From 5f1cca5ab2a9ccaef8ed98af975fdb64e4f2030a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Mon, 26 Jul 2021 23:23:09 +0200 Subject: [PATCH] reconnector. --- src/component/internal/connection.ts | 16 +++++++------- .../types/{reconnecter.ts => reconnector.ts} | 2 +- src/component/types/state.ts | 8 +++---- .../utils/{reconnecter.ts => reconnector.ts} | 22 +++++++++---------- 4 files changed, 24 insertions(+), 24 deletions(-) rename src/component/types/{reconnecter.ts => reconnector.ts} (64%) rename src/component/utils/{reconnecter.ts => reconnector.ts} (86%) diff --git a/src/component/internal/connection.ts b/src/component/internal/connection.ts index 98f285e3..ef29c250 100644 --- a/src/component/internal/connection.ts +++ b/src/component/internal/connection.ts @@ -5,7 +5,7 @@ import * as EVENT from '../types/events' import { NekoWebSocket } from './websocket' import { NekoWebRTC } from './webrtc' import { Connection, WebRTCStats } from '../types/state' -import { Reconnecter, ReconnecterAbstract } from '../utils/reconnecter' +import { Reconnector, ReconnectorAbstract } from '../utils/reconnector' const WEBRTC_RECONN_MAX_LOSS = 25 const WEBRTC_RECONN_FAILED_ATTEMPTS = 5 @@ -14,7 +14,7 @@ export interface NekoConnectionEvents { disconnect: (error?: Error) => void } -class WebsocketReconnecter extends ReconnecterAbstract { +class WebsocketReconnector extends ReconnectorAbstract { private _state: Connection private _websocket: NekoWebSocket @@ -60,7 +60,7 @@ class WebsocketReconnecter extends ReconnecterAbstract { } } -class WebrtcReconnecter extends ReconnecterAbstract { +class WebrtcReconnector extends ReconnectorAbstract { private _state: Connection private _websocket: NekoWebSocket private _webrtc: NekoWebRTC @@ -106,18 +106,18 @@ export class NekoConnection extends EventEmitter { private _state: Connection public websocket = new NekoWebSocket() - public _websocket_reconn: Reconnecter + public _websocket_reconn: Reconnector public webrtc = new NekoWebRTC() - public _webrtc_reconn: Reconnecter + public _webrtc_reconn: Reconnector constructor(state: Connection) { super() this._state = state - this._websocket_reconn = new Reconnecter(new WebsocketReconnecter(state, this.websocket), state.websocket.config) - this._webrtc_reconn = new Reconnecter( - new WebrtcReconnecter(state, this.websocket, this.webrtc), + this._websocket_reconn = new Reconnector(new WebsocketReconnector(state, this.websocket), state.websocket.config) + this._webrtc_reconn = new Reconnector( + new WebrtcReconnector(state, this.websocket, this.webrtc), state.webrtc.config, ) diff --git a/src/component/types/reconnecter.ts b/src/component/types/reconnector.ts similarity index 64% rename from src/component/types/reconnecter.ts rename to src/component/types/reconnector.ts index 022df3e6..0f3bd330 100644 --- a/src/component/types/reconnecter.ts +++ b/src/component/types/reconnector.ts @@ -1,4 +1,4 @@ -export interface ReconnecterConfig { +export interface ReconnectorConfig { maxReconnects: number timeoutMs: number backoffMs: number diff --git a/src/component/types/state.ts b/src/component/types/state.ts index 3418fc71..e0d0a9f0 100644 --- a/src/component/types/state.ts +++ b/src/component/types/state.ts @@ -1,5 +1,5 @@ import * as webrtcTypes from './webrtc' -import * as reconnecterTypes from './reconnecter' +import * as reconnecterTypes from './reconnector' export default interface State { authenticated: boolean @@ -26,18 +26,18 @@ export interface Connection { } export interface WebSocket { - config: ReconnecterConfig + config: ReconnectorConfig } export interface WebRTC { - config: ReconnecterConfig + config: ReconnectorConfig stats: WebRTCStats | null video: string | null videos: string[] auto: boolean } -export interface ReconnecterConfig extends reconnecterTypes.ReconnecterConfig {} +export interface ReconnectorConfig extends reconnecterTypes.ReconnectorConfig {} export interface WebRTCStats extends webrtcTypes.WebRTCStats {} diff --git a/src/component/utils/reconnecter.ts b/src/component/utils/reconnector.ts similarity index 86% rename from src/component/utils/reconnecter.ts rename to src/component/utils/reconnector.ts index 58f21eca..b74ee414 100644 --- a/src/component/utils/reconnecter.ts +++ b/src/component/utils/reconnector.ts @@ -1,16 +1,16 @@ import EventEmitter from 'eventemitter3' -import { ReconnecterConfig } from '../types/reconnecter' +import { ReconnectorConfig } from '../types/reconnector' -export interface ReconnecterAbstractEvents { +export interface ReconnectorAbstractEvents { connect: () => void disconnect: (error?: Error) => void } -export abstract class ReconnecterAbstract extends EventEmitter { +export abstract class ReconnectorAbstract extends EventEmitter { constructor() { super() - if (this.constructor == ReconnecterAbstract) { + if (this.constructor == ReconnectorAbstract) { throw new Error("Abstract classes can't be instantiated.") } } @@ -22,16 +22,16 @@ export abstract class ReconnecterAbstract extends EventEmitter void connect: () => void disconnect: () => void close: (error?: Error) => void } -export class Reconnecter extends EventEmitter { - private _conn: ReconnecterAbstract - private _config: ReconnecterConfig +export class Reconnector extends EventEmitter { + private _conn: ReconnectorAbstract + private _config: ReconnectorConfig private _timeout?: number private _open = false @@ -41,7 +41,7 @@ export class Reconnecter extends EventEmitter { private _onConnectHandle: () => void private _onDisconnectHandle: (error?: Error) => void - constructor(conn: ReconnecterAbstract, config?: ReconnecterConfig) { + constructor(conn: ReconnectorAbstract, config?: ReconnectorConfig) { super() this._conn = conn @@ -101,11 +101,11 @@ export class Reconnecter extends EventEmitter { return this._last_connected } - public get config(): ReconnecterConfig { + public get config(): ReconnectorConfig { return { ...this._config } } - public set config(conf: ReconnecterConfig) { + public set config(conf: ReconnectorConfig) { this._config = { ...conf } if (this._config.maxReconnects > this._total_reconnects) {