constants.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 sentCloseFrameState = {
  20. NOT_SENT: 0,
  21. PROCESSING: 1,
  22. SENT: 2
  23. }
  24. const opcodes = {
  25. CONTINUATION: 0x0,
  26. TEXT: 0x1,
  27. BINARY: 0x2,
  28. CLOSE: 0x8,
  29. PING: 0x9,
  30. PONG: 0xA
  31. }
  32. const maxUnsigned16Bit = 2 ** 16 - 1 // 65535
  33. const parserStates = {
  34. INFO: 0,
  35. PAYLOADLENGTH_16: 2,
  36. PAYLOADLENGTH_64: 3,
  37. READ_DATA: 4
  38. }
  39. const emptyBuffer = Buffer.allocUnsafe(0)
  40. const sendHints = {
  41. string: 1,
  42. typedArray: 2,
  43. arrayBuffer: 3,
  44. blob: 4
  45. }
  46. module.exports = {
  47. uid,
  48. sentCloseFrameState,
  49. staticPropertyDescriptors,
  50. states,
  51. opcodes,
  52. maxUnsigned16Bit,
  53. parserStates,
  54. emptyBuffer,
  55. sendHints
  56. }