diffusion
Version:
Diffusion JavaScript client
254 lines (253 loc) • 11.4 kB
JavaScript
"use strict";
/**
* @module diffusion.clients
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.ClientCloseReason = exports.CloseReasonEnum = void 0;
var close_reason_1 = require("./../internal/client/close-reason");
var enumerize_1 = require("./../internal/util/enumerize");
/**
* Enum representing the reason that the session has been closed.
*
* **Example:**
* ```
* diffusion.connect({...}).then(function(session) {...}, function(err) {
* switch(err) {
* case diffusion.clients.CloseReason.CLOSED_BY_CLIENT:
* // Do something
* case diffusion.clients.CloseReason.ACCESS_DENIED:
* // Do something else
* ...
* }
* });
* ```
*
*/ // eslint-disable-next-line @typescript-eslint/naming-convention
exports.CloseReasonEnum = {
/**
* The client requested close. Not recoverable.
*/
CLOSED_BY_CLIENT: new close_reason_1.CloseReasonImpl(0, 'The session was closed by the client', false),
/**
* The session has been closed by the server, or another session using the
* {@link ClientControl} feature.
*/
CLOSED_BY_SERVER: new close_reason_1.CloseReasonImpl(1, 'The session was closed by the server', false),
/**
* Whilst disconnected, the client explicitly aborted a reconnect attempt.
*/
RECONNECT_ABORTED: new close_reason_1.CloseReasonImpl(2, 'Client aborted a reconnect attempt', false),
/**
* The connection attempt timed out, waiting for a response from the server.
*
* The reconnection timeout can be controlled by the {@link
* Options.reconnect reconnect} options.
*/
CONNECTION_TIMEOUT: new close_reason_1.CloseReasonImpl(3, 'The connection attempt timed out', false),
/**
* The connection handshake was rejected by the server.
*
* The server responded with an unknown error code when the client attempted
* to connect.
*/
HANDSHAKE_REJECTED: new close_reason_1.CloseReasonImpl(4, 'The connection handshake was rejected by the server', false),
/**
* There was an error parsing the handshake response.
*
* The client received a handshake response from the server but the response
* was malformed and could not be deserialised.
*/
HANDSHAKE_ERROR: new close_reason_1.CloseReasonImpl(5, 'There was an error parsing the handshake response', false),
/**
* There was an unexpected error with the network connection.
*
* The underlying transport (Websocket, XHR) received an error that could
* not be handled.
*/
TRANSPORT_ERROR: new close_reason_1.CloseReasonImpl(6, 'There was an unexpected error with the connection', true),
/**
* The client could not establish a connection to the server.
*
* An error was thrown while the client was attempting to connect to the
* server.
*/
CONNECTION_ERROR: new close_reason_1.CloseReasonImpl(7, 'The client could not establish a connection to the server', true),
/**
* The client detected that the connection was idle.
*
* The client has not received a ping message from the server for an
* extended period of time.
*/
IDLE_CONNECTION: new close_reason_1.CloseReasonImpl(8, 'The activity monitor detected the connection was idle', true),
/**
* Loss of messages from the client has been detected. For example,
* whilst waiting for the arrival of missing messages in a sequence of
* messages a timeout has occurred.
*
* HTTP based transports use multiple TCP connections. This can cause
* the messages to be received out of order. To reorder the messages
* those sent to the server may contain a sequence number indicating the
* correct order.
*
* If a message is received out of order there is a short time for the
* earlier messages to be received. If the messages are not received in
* this time the client is closed.
*
* Missing, invalid or duplicate sequence numbers will also close the
* client for this reason.
*
* This cannot be recovered from as the client and the server are in
* inconsistent states.
*/
LOST_MESSAGES: new close_reason_1.CloseReasonImpl(16, 'Loss of messages has been detected', false),
/**
* The handshake response contained an incompatible protocol version.
*
* The server does not support the client's protocol version.
*
* The client version is later than the server version
*/
PROTOCOL_VERSION_MISMATCH: new close_reason_1.CloseReasonImpl(17, 'Client version rejected : Client should be downgraded to use server compatible version ' +
'or server upgraded to client version in use', false),
/**
* The connection request was rejected because the license limit was reached.
*/
LICENSE_EXCEEDED: new close_reason_1.CloseReasonImpl(18, 'The license limit was exceeded', false),
/**
* The connection attempt failed due to a security restraint or due to
* invalid credentials.
*/
ACCESS_DENIED: new close_reason_1.CloseReasonImpl(99, 'The connection attempt was rejected by the server because authentication failed', false)
};
enumerize_1.enumerize(exports.CloseReasonEnum);
/**
* The server's view of why a client session was closed.
*/
var ClientCloseReason;
(function (ClientCloseReason) {
/**
* The connection to the client was lost - possibly dropped by the client.
* Recoverable.
*
* A client may be closed for may reasons that are presented as
* CONNECTION_LOST.
*
* During connection the connection can be lost. The server might have
* received a connection or reconnection request from a client already
* connected. The server might have received a reconnection request without
* a client ID. The connection may not have been authorised because the
* credentials are wrong. The maximum number of clients might already be
* connected.
*
* Once connected the connection can be lost for different reasons. If the
* client closes its connection while the server is writing a message to the
* client. With the chunked encoding based connection the HTTP response is
* completed by the server. If the client does not open a new request within
* a timeout the client will be closed. If a poll request times out and the
* server finds that the connection has already been closed by the client.
*/
ClientCloseReason[ClientCloseReason["CONNECTION_LOST"] = 0] = "CONNECTION_LOST";
/**
* An unexpected IO Exception occurred. Recoverable.
*
* While trying to perform an I/O operation an exception was generated. This
* often means that Diffusion attempted to read from a closed TCP
* connection.
*
* When Diffusion is handling SSL connections if there is a problem
* encrypting or decrypting a message the client will be closed for this
* reason.
*/
ClientCloseReason[ClientCloseReason["IO_EXCEPTION"] = 1] = "IO_EXCEPTION";
/**
* The client had become unresponsive. Recoverable.
*
* The client has either failed to respond to a ping message in a timely
* manner or the client has failed to open an HTTP poll for messages. The
* client does not appear to be receiving messages.
*/
ClientCloseReason[ClientCloseReason["CLIENT_UNRESPONSIVE"] = 2] = "CLIENT_UNRESPONSIVE";
/**
* The maximum outbound queue size was reached for the client. Not
* recoverable.
*
* Messages sent to the client are placed in a queue. This queue has a
* maximum allowed size. If the queue limit is reached the client is closed
* and the queue discarded. The queue is intended to protect against slow
* patches, reaching the queue limit is taken to mean that the client cannot
* keep up with the number of messages sent to it.
*/
ClientCloseReason[ClientCloseReason["MESSAGE_QUEUE_LIMIT_REACHED"] = 3] = "MESSAGE_QUEUE_LIMIT_REACHED";
/**
* The client requested close. Not recoverable (unless TEST_RECONNECT is
* true).
*/
ClientCloseReason[ClientCloseReason["CLOSED_BY_CLIENT"] = 4] = "CLOSED_BY_CLIENT";
/**
* The client sent a message that exceeded the maximum message size.
*
* The server has a maximum message size. If a client sends a message larger
* than this the server is unable to process it. When this happens the
* message is discarded and the client is closed.
*/
ClientCloseReason[ClientCloseReason["MESSAGE_TOO_LARGE"] = 5] = "MESSAGE_TOO_LARGE";
/**
* An internal error occurred.
*/
ClientCloseReason[ClientCloseReason["INTERNAL_ERROR"] = 6] = "INTERNAL_ERROR";
/**
* An inbound message with an invalid format was received.
*
* A message received by the server is not a valid Diffusion message. The
* server is unable to process this and closes the client that sent it.
*/
ClientCloseReason[ClientCloseReason["INVALID_INBOUND_MESSAGE"] = 7] = "INVALID_INBOUND_MESSAGE";
/**
* The client connection was aborted by the server, possibly because the
* connection was disallowed.
*
* This may be because the connection was disallowed. Abort messages are
* also sent to clients that have unrecognised client IDs. This may be
* because the server closed the client previously but the client is unaware
* of this and tried to continue interacting with the server.
*/
ClientCloseReason[ClientCloseReason["ABORTED"] = 8] = "ABORTED";
/**
* Loss of messages from the client has been detected. For example, whilst
* waiting for the arrival of missing messages in a sequence of messages a
* timeout has occurred.
*
* HTTP based transports use multiple TCP connections. This can cause the
* messages to be received out of order. To reorder the messages those sent
* to the server may contain a sequence number indicating the correct order.
*
* If a message is received out of order there is a short time for the
* earlier messages to be received. If the messages are not received in this
* time the client is closed.
*
* Missing, invalid or duplicate sequence numbers will also close the client
* for this reason.
*
* This cannot be recovered from as the client and the server are in
* inconsistent states.
*/
ClientCloseReason[ClientCloseReason["LOST_MESSAGES"] = 9] = "LOST_MESSAGES";
/**
* A control session initiated the client close.
*/
ClientCloseReason[ClientCloseReason["CLOSED_BY_CONTROLLER"] = 10] = "CLOSED_BY_CONTROLLER";
/**
* The client has failed over to a different server.
* <P>
* The session is still open but is now connected to a different Diffusion
* server. This server has evicted its view of the client from its set of
* local clients.
*/
ClientCloseReason[ClientCloseReason["FAILED_OVER"] = 11] = "FAILED_OVER";
/**
* The session has been closed to make way for a new session.
*
* This is used by MQTT. See MQTT-3.1.4-3.
*/
ClientCloseReason[ClientCloseReason["SESSION_TAKEN_OVER"] = 12] = "SESSION_TAKEN_OVER";
})(ClientCloseReason = exports.ClientCloseReason || (exports.ClientCloseReason = {}));