Skip to content

Commit

Permalink
Add postConnectErrorListener
Browse files Browse the repository at this point in the history
 - listen and emit error that occurs when network error or unexpected RTP server errors
 - for example it handles ECONNRESET
  • Loading branch information
GyeongHoKim committed Jun 10, 2024
1 parent 7fab518 commit 8a2760b
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/RTSPClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -671,7 +678,7 @@ export default class RTSPClient extends EventEmitter {
if (!this._client) {
return;
}

if (!isImmediate) {
await this.request("TEARDOWN", {
Session: this._session,
Expand Down

0 comments on commit 8a2760b

Please sign in to comment.