@d-fischer/connection
Advanced tools
Comparing version
@@ -14,4 +14,4 @@ import type { Logger } from '@d-fischer/logger'; | ||
readonly onConnect: import("@d-fischer/typed-event-emitter").EventBinder<[]>; | ||
readonly onDisconnect: import("@d-fischer/typed-event-emitter").EventBinder<[boolean, (Error | undefined)?]>; | ||
readonly onEnd: import("@d-fischer/typed-event-emitter").EventBinder<[boolean, (Error | undefined)?]>; | ||
readonly onDisconnect: import("@d-fischer/typed-event-emitter").EventBinder<[onDemand: boolean, error?: Error | undefined]>; | ||
readonly onEnd: import("@d-fischer/typed-event-emitter").EventBinder<[onDemand: boolean, error?: Error | undefined]>; | ||
constructor({ lineBased, logger, additionalOptions }?: ConnectionOptions<Options>); | ||
@@ -18,0 +18,0 @@ get isConnecting(): boolean; |
@@ -9,4 +9,4 @@ import type { Logger } from '@d-fischer/logger'; | ||
readonly onConnect: EventBinder<[]>; | ||
readonly onDisconnect: EventBinder<[boolean, Error?]>; | ||
readonly onEnd: EventBinder<[boolean, Error?]>; | ||
readonly onDisconnect: EventBinder<[onDemand: boolean, error?: Error]>; | ||
readonly onEnd: EventBinder<[onDemand: boolean, error?: Error]>; | ||
connect: () => void; | ||
@@ -13,0 +13,0 @@ disconnect: () => void; |
@@ -5,2 +5,4 @@ import { AbstractConnection } from './AbstractConnection'; | ||
private _socket; | ||
private _closingOnDemand; | ||
private _hadError; | ||
protected readonly _host: string; | ||
@@ -7,0 +9,0 @@ protected readonly _port: number; |
@@ -12,2 +12,4 @@ "use strict"; | ||
this._socket = null; | ||
this._closingOnDemand = false; | ||
this._hadError = false; | ||
if (!target.hostName || !target.port) { | ||
@@ -43,2 +45,4 @@ throw new Error('DirectConnection requires hostName and port to be set'); | ||
this._connected = true; | ||
this._closingOnDemand = false; | ||
this._hadError = false; | ||
this.emit(this.onConnect); | ||
@@ -52,2 +56,3 @@ }); | ||
this.emit(this.onDisconnect, false, err); | ||
this._hadError = true; | ||
}); | ||
@@ -57,10 +62,12 @@ this._socket.on('data', (data) => { | ||
}); | ||
this._socket.on('close', (hadError) => { | ||
this._socket.on('close', () => { | ||
var _a; | ||
(_a = this._logger) === null || _a === void 0 ? void 0 : _a.trace(`DirectConnection onClose hadError:${hadError.toString()}`); | ||
if (!hadError) { | ||
(_a = this._logger) === null || _a === void 0 ? void 0 : _a.trace(`DirectConnection onClose closingOnDemand:${this._closingOnDemand.toString()} hadError:${this._hadError.toString()}`); | ||
if (!this._hadError) { | ||
this._connected = false; | ||
this._connecting = false; | ||
this.emit(this.onDisconnect, true); | ||
this.emit(this.onDisconnect, this._closingOnDemand); | ||
} | ||
this._closingOnDemand = false; | ||
this._hadError = false; | ||
this.clearSocket(); | ||
@@ -72,2 +79,3 @@ }); | ||
(_a = this._logger) === null || _a === void 0 ? void 0 : _a.trace('DirectConnection disconnect'); | ||
this._closingOnDemand = true; | ||
(_b = this._socket) === null || _b === void 0 ? void 0 : _b.end(); | ||
@@ -74,0 +82,0 @@ } |
@@ -10,4 +10,4 @@ /// <reference types="ws" /> | ||
private _socket; | ||
private _closingOnDemand; | ||
private readonly _url; | ||
private _closingOnDemand; | ||
constructor(target: ConnectionTarget, options?: ConnectionOptions<WebSocketConnectionOptions>); | ||
@@ -14,0 +14,0 @@ get hasSocket(): boolean; |
@@ -38,2 +38,3 @@ "use strict"; | ||
this._connecting = false; | ||
this._closingOnDemand = false; | ||
this.emit(this.onConnect); | ||
@@ -56,3 +57,3 @@ }; | ||
this._connecting = false; | ||
if (e.wasClean || this._closingOnDemand) { | ||
if (this._closingOnDemand) { | ||
this._closingOnDemand = false; | ||
@@ -59,0 +60,0 @@ this.emit(this.onDisconnect, true); |
{ | ||
"name": "@d-fischer/connection", | ||
"version": "8.0.6", | ||
"version": "9.0.0", | ||
"description": "Abstraction for packet-based connections.", | ||
@@ -5,0 +5,0 @@ "keywords": [], |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
43348
2.18%928
2.2%