constants.js 881 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. 'use strict'
  2. // This is a Globally Unique Identifier unique used
  3. // to validate that the endpoint accepts websocket
  4. // connections.
  5. // See https://www.rfc-editor.org/rfc/rfc6455.html#section-1.3
  6. const uid = '258EAFA5-E914-47DA-95CA-C5AB0DC85B11'
  7. /** @type {PropertyDescriptor} */
  8. const staticPropertyDescriptors = {
  9. enumerable: true,
  10. writable: false,
  11. configurable: false
  12. }
  13. const states = {
  14. CONNECTING: 0,
  15. OPEN: 1,
  16. CLOSING: 2,
  17. CLOSED: 3
  18. }
  19. const opcodes = {
  20. CONTINUATION: 0x0,
  21. TEXT: 0x1,
  22. BINARY: 0x2,
  23. CLOSE: 0x8,
  24. PING: 0x9,
  25. PONG: 0xA
  26. }
  27. const maxUnsigned16Bit = 2 ** 16 - 1 // 65535
  28. const parserStates = {
  29. INFO: 0,
  30. PAYLOADLENGTH_16: 2,
  31. PAYLOADLENGTH_64: 3,
  32. READ_DATA: 4
  33. }
  34. const emptyBuffer = Buffer.allocUnsafe(0)
  35. module.exports = {
  36. uid,
  37. staticPropertyDescriptors,
  38. states,
  39. opcodes,
  40. maxUnsigned16Bit,
  41. parserStates,
  42. emptyBuffer
  43. }