From 7fab51877e6854f7fbbf5e2afd7fb6bed782aa14 Mon Sep 17 00:00:00 2001 From: GyeongHo Kim Date: Mon, 10 Jun 2024 21:40:04 +0900 Subject: [PATCH 1/3] Add IDE settings on .gitignore --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index 79d06e9..3d6977c 100644 --- a/.gitignore +++ b/.gitignore @@ -29,3 +29,7 @@ node_modules # Debug files debug .DS_Store + +# IDE settings +.idea +.vscode From 8a2760b412612fbb0b1b804d9af94fd430cbab4c Mon Sep 17 00:00:00 2001 From: GyeongHo Kim Date: Mon, 10 Jun 2024 21:45:38 +0900 Subject: [PATCH 2/3] Add postConnectErrorListener - listen and emit error that occurs when network error or unexpected RTP server errors - for example it handles ECONNRESET --- lib/RTSPClient.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/RTSPClient.ts b/lib/RTSPClient.ts index 62d03a0..aa317be 100644 --- a/lib/RTSPClient.ts +++ b/lib/RTSPClient.ts @@ -156,6 +156,12 @@ export default class RTSPClient extends EventEmitter { reject(err); }; + const postConnectErrorListener = (err: any) => { + client.removeListener("error", postConnectErrorListener); + this.emit("error", err); + reject(err); + }; + const closeListener = () => { client.removeListener("close", closeListener); this.close(true); @@ -183,6 +189,7 @@ export default class RTSPClient extends EventEmitter { this._client = client; client.removeListener("error", errorListener); + client.on("error", postConnectErrorListener); this.on("response", responseListener); resolve(this); @@ -671,7 +678,7 @@ export default class RTSPClient extends EventEmitter { if (!this._client) { return; } - + if (!isImmediate) { await this.request("TEARDOWN", { Session: this._session, From 90a6976626ecf66e987cba5f917d96f967916df0 Mon Sep 17 00:00:00 2001 From: GyeongHo Kim Date: Mon, 10 Jun 2024 21:49:49 +0900 Subject: [PATCH 3/3] Emit close event when RTSPClient close --- lib/RTSPClient.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/RTSPClient.ts b/lib/RTSPClient.ts index aa317be..ee729d5 100644 --- a/lib/RTSPClient.ts +++ b/lib/RTSPClient.ts @@ -164,6 +164,7 @@ export default class RTSPClient extends EventEmitter { const closeListener = () => { client.removeListener("close", closeListener); + this.emit("close"); this.close(true); };