ws-event.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const error_1 = require("../utils/error");
  4. const error_config_1 = require("../config/error.config");
  5. exports.CLOSE_EVENT_CODE_INFO = {
  6. 1000: {
  7. code: 1000,
  8. name: 'Normal Closure',
  9. description: 'Normal closure; the connection successfully completed whatever purpose for which it was created.'
  10. },
  11. 1001: {
  12. code: 1001,
  13. name: 'Going Away',
  14. description: 'The endpoint is going away, either because of a server failure or because the browser is navigating away from the page that opened the connection.'
  15. },
  16. 1002: {
  17. code: 1002,
  18. name: 'Protocol Error',
  19. description: 'The endpoint is terminating the connection due to a protocol error.'
  20. },
  21. 1003: {
  22. code: 1003,
  23. name: 'Unsupported Data',
  24. description: 'The connection is being terminated because the endpoint received data of a type it cannot accept (for example, a text-only endpoint received binary data).'
  25. },
  26. 1005: {
  27. code: 1005,
  28. name: 'No Status Received',
  29. description: 'Indicates that no status code was provided even though one was expected.'
  30. },
  31. 1006: {
  32. code: 1006,
  33. name: 'Abnormal Closure',
  34. description: 'Used to indicate that a connection was closed abnormally (that is, with no close frame being sent) when a status code is expected.'
  35. },
  36. 1007: {
  37. code: 1007,
  38. name: 'Invalid frame payload data',
  39. description: 'The endpoint is terminating the connection because a message was received that contained inconsistent data (e.g., non-UTF-8 data within a text message).'
  40. },
  41. 1008: {
  42. code: 1008,
  43. name: 'Policy Violation',
  44. description: 'The endpoint is terminating the connection because it received a message that violates its policy. This is a generic status code, used when codes 1003 and 1009 are not suitable.'
  45. },
  46. 1009: {
  47. code: 1009,
  48. name: 'Message too big',
  49. description: 'The endpoint is terminating the connection because a data frame was received that is too large.'
  50. },
  51. 1010: {
  52. code: 1010,
  53. name: 'Missing Extension',
  54. description: "The client is terminating the connection because it expected the server to negotiate one or more extension, but the server didn't."
  55. },
  56. 1011: {
  57. code: 1011,
  58. name: 'Internal Error',
  59. description: 'The server is terminating the connection because it encountered an unexpected condition that prevented it from fulfilling the request.'
  60. },
  61. 1012: {
  62. code: 1012,
  63. name: 'Service Restart',
  64. description: 'The server is terminating the connection because it is restarting.'
  65. },
  66. 1013: {
  67. code: 1013,
  68. name: 'Try Again Later',
  69. description: 'The server is terminating the connection due to a temporary condition, e.g. it is overloaded and is casting off some of its clients.'
  70. },
  71. 1014: {
  72. code: 1014,
  73. name: 'Bad Gateway',
  74. description: 'The server was acting as a gateway or proxy and received an invalid response from the upstream server. This is similar to 502 HTTP Status Code.'
  75. },
  76. 1015: {
  77. code: 1015,
  78. name: 'TLS Handshake',
  79. description: "Indicates that the connection was closed due to a failure to perform a TLS handshake (e.g., the server certificate can't be verified)."
  80. },
  81. 3000: {
  82. code: 3000,
  83. name: 'Reconnect WebSocket',
  84. description: 'The client is terminating the connection because it wants to reconnect'
  85. },
  86. 3001: {
  87. code: 3001,
  88. name: 'No Realtime Listeners',
  89. description: 'The client is terminating the connection because no more realtime listeners exist'
  90. },
  91. 3002: {
  92. code: 3002,
  93. name: 'Heartbeat Ping Error',
  94. description: 'The client is terminating the connection due to its failure in sending heartbeat messages'
  95. },
  96. 3003: {
  97. code: 3003,
  98. name: 'Heartbeat Pong Timeout Error',
  99. description: 'The client is terminating the connection because no heartbeat response is received from the server'
  100. },
  101. 3050: {
  102. code: 3050,
  103. name: 'Server Close',
  104. description: 'The client is terminating the connection because no heartbeat response is received from the server'
  105. }
  106. };
  107. var CLOSE_EVENT_CODE;
  108. (function (CLOSE_EVENT_CODE) {
  109. CLOSE_EVENT_CODE[CLOSE_EVENT_CODE["NormalClosure"] = 1000] = "NormalClosure";
  110. CLOSE_EVENT_CODE[CLOSE_EVENT_CODE["GoingAway"] = 1001] = "GoingAway";
  111. CLOSE_EVENT_CODE[CLOSE_EVENT_CODE["ProtocolError"] = 1002] = "ProtocolError";
  112. CLOSE_EVENT_CODE[CLOSE_EVENT_CODE["UnsupportedData"] = 1003] = "UnsupportedData";
  113. CLOSE_EVENT_CODE[CLOSE_EVENT_CODE["NoStatusReceived"] = 1005] = "NoStatusReceived";
  114. CLOSE_EVENT_CODE[CLOSE_EVENT_CODE["AbnormalClosure"] = 1006] = "AbnormalClosure";
  115. CLOSE_EVENT_CODE[CLOSE_EVENT_CODE["InvalidFramePayloadData"] = 1007] = "InvalidFramePayloadData";
  116. CLOSE_EVENT_CODE[CLOSE_EVENT_CODE["PolicyViolation"] = 1008] = "PolicyViolation";
  117. CLOSE_EVENT_CODE[CLOSE_EVENT_CODE["MessageTooBig"] = 1009] = "MessageTooBig";
  118. CLOSE_EVENT_CODE[CLOSE_EVENT_CODE["MissingExtension"] = 1010] = "MissingExtension";
  119. CLOSE_EVENT_CODE[CLOSE_EVENT_CODE["InternalError"] = 1011] = "InternalError";
  120. CLOSE_EVENT_CODE[CLOSE_EVENT_CODE["ServiceRestart"] = 1012] = "ServiceRestart";
  121. CLOSE_EVENT_CODE[CLOSE_EVENT_CODE["TryAgainLater"] = 1013] = "TryAgainLater";
  122. CLOSE_EVENT_CODE[CLOSE_EVENT_CODE["BadGateway"] = 1014] = "BadGateway";
  123. CLOSE_EVENT_CODE[CLOSE_EVENT_CODE["TLSHandshake"] = 1015] = "TLSHandshake";
  124. CLOSE_EVENT_CODE[CLOSE_EVENT_CODE["ReconnectWebSocket"] = 3000] = "ReconnectWebSocket";
  125. CLOSE_EVENT_CODE[CLOSE_EVENT_CODE["NoRealtimeListeners"] = 3001] = "NoRealtimeListeners";
  126. CLOSE_EVENT_CODE[CLOSE_EVENT_CODE["HeartbeatPingError"] = 3002] = "HeartbeatPingError";
  127. CLOSE_EVENT_CODE[CLOSE_EVENT_CODE["HeartbeatPongTimeoutError"] = 3003] = "HeartbeatPongTimeoutError";
  128. CLOSE_EVENT_CODE[CLOSE_EVENT_CODE["NoAuthentication"] = 3050] = "NoAuthentication";
  129. })(CLOSE_EVENT_CODE = exports.CLOSE_EVENT_CODE || (exports.CLOSE_EVENT_CODE = {}));
  130. exports.getWSCloseError = (code, reason) => {
  131. const info = exports.CLOSE_EVENT_CODE_INFO[code];
  132. const errMsg = !info
  133. ? `code ${code}`
  134. : `${info.name}, code ${code}, reason ${reason || info.description}`;
  135. return new error_1.CloudSDKError({
  136. errCode: error_config_1.ERR_CODE.SDK_DATABASE_REALTIME_LISTENER_WEBSOCKET_CONNECTION_CLOSED,
  137. errMsg
  138. });
  139. };