constants.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. 'use strict'
  2. /**
  3. * This is a Globally Unique Identifier unique used to validate that the
  4. * endpoint accepts websocket connections.
  5. * @see https://www.rfc-editor.org/rfc/rfc6455.html#section-1.3
  6. * @type {'258EAFA5-E914-47DA-95CA-C5AB0DC85B11'}
  7. */
  8. const uid = '258EAFA5-E914-47DA-95CA-C5AB0DC85B11'
  9. /**
  10. * @type {PropertyDescriptor}
  11. */
  12. const staticPropertyDescriptors = {
  13. enumerable: true,
  14. writable: false,
  15. configurable: false
  16. }
  17. /**
  18. * The states of the WebSocket connection.
  19. *
  20. * @readonly
  21. * @enum
  22. * @property {0} CONNECTING
  23. * @property {1} OPEN
  24. * @property {2} CLOSING
  25. * @property {3} CLOSED
  26. */
  27. const states = {
  28. CONNECTING: 0,
  29. OPEN: 1,
  30. CLOSING: 2,
  31. CLOSED: 3
  32. }
  33. /**
  34. * @readonly
  35. * @enum
  36. * @property {0} NOT_SENT
  37. * @property {1} PROCESSING
  38. * @property {2} SENT
  39. */
  40. const sentCloseFrameState = {
  41. SENT: 1,
  42. RECEIVED: 2
  43. }
  44. /**
  45. * The WebSocket opcodes.
  46. *
  47. * @readonly
  48. * @enum
  49. * @property {0x0} CONTINUATION
  50. * @property {0x1} TEXT
  51. * @property {0x2} BINARY
  52. * @property {0x8} CLOSE
  53. * @property {0x9} PING
  54. * @property {0xA} PONG
  55. * @see https://datatracker.ietf.org/doc/html/rfc6455#section-5.2
  56. */
  57. const opcodes = {
  58. CONTINUATION: 0x0,
  59. TEXT: 0x1,
  60. BINARY: 0x2,
  61. CLOSE: 0x8,
  62. PING: 0x9,
  63. PONG: 0xA
  64. }
  65. /**
  66. * The maximum value for an unsigned 16-bit integer.
  67. *
  68. * @type {65535} 2 ** 16 - 1
  69. */
  70. const maxUnsigned16Bit = 65535
  71. /**
  72. * The states of the parser.
  73. *
  74. * @readonly
  75. * @enum
  76. * @property {0} INFO
  77. * @property {2} PAYLOADLENGTH_16
  78. * @property {3} PAYLOADLENGTH_64
  79. * @property {4} READ_DATA
  80. */
  81. const parserStates = {
  82. INFO: 0,
  83. PAYLOADLENGTH_16: 2,
  84. PAYLOADLENGTH_64: 3,
  85. READ_DATA: 4
  86. }
  87. /**
  88. * An empty buffer.
  89. *
  90. * @type {Buffer}
  91. */
  92. const emptyBuffer = Buffer.allocUnsafe(0)
  93. /**
  94. * @readonly
  95. * @property {1} text
  96. * @property {2} typedArray
  97. * @property {3} arrayBuffer
  98. * @property {4} blob
  99. */
  100. const sendHints = {
  101. text: 1,
  102. typedArray: 2,
  103. arrayBuffer: 3,
  104. blob: 4
  105. }
  106. module.exports = {
  107. uid,
  108. sentCloseFrameState,
  109. staticPropertyDescriptors,
  110. states,
  111. opcodes,
  112. maxUnsigned16Bit,
  113. parserStates,
  114. emptyBuffer,
  115. sendHints
  116. }