diffusion
Version:
Diffusion JavaScript client
55 lines (54 loc) • 1.93 kB
JavaScript
;
/**
* @module Protocol
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.isSuccess = exports.responseCodes = void 0;
var enumerize_1 = require("./../util/enumerize");
/**
* Create a new response code
*
* @param id the respnse code id
* @param message the message
* @return a new response code
*/
function code(id, message) {
return {
id: id,
message: message
};
}
/**
* Connection handshake response codes
*/
exports.responseCodes = {
OK: code(100, 'Connected successfully'),
DOWNGRADE: code(102, 'Server does not support the requested protocol level'),
RECONNECTED: code(105, 'Reconnected successfully'),
RECONNECTED_WITH_MESSAGE_LOSS: code(106, 'Reconnected with message loss'),
LICENSE_EXCEEDED: code(113, 'Connection rejected due to license limit'),
RECONNECTION_UNSUPPORTED: code(114, 'Reconnection not supported by connector'),
CONNECTION_PROTOCOL_ERROR: code(115, 'Connection failed - protocol error'),
AUTHENTICATION_FAILED: code(116, 'Connection failed - authentication failed'),
UNKNOWN_SESSION: code(117, 'Reconnection failed - the session is unknown'),
RECONNECTION_FAILED_MESSAGE_LOSS: code(118, 'Reconnection failed due to message loss'),
REJECTED_SERVER_INITIALISING: code(119, 'Connection rejected because the server is not ready')
};
enumerize_1.enumerize(exports.responseCodes);
/**
* Check if the response code indicates a success
*
* @param responseCode the response code
* @return `true` if the response code indicates a success
*/
function isSuccess(responseCode) {
switch (responseCode) {
case exports.responseCodes.OK:
case exports.responseCodes.RECONNECTED:
case exports.responseCodes.RECONNECTED_WITH_MESSAGE_LOSS:
return true;
default:
return false;
}
}
exports.isSuccess = isSuccess;