index.d.ts 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /**
  2. * Current protocol version.
  3. */
  4. export declare const protocol = 3;
  5. /**
  6. * Packet types.
  7. */
  8. export declare const packets: {
  9. open: number;
  10. close: number;
  11. ping: number;
  12. pong: number;
  13. message: number;
  14. upgrade: number;
  15. noop: number;
  16. };
  17. /**
  18. * Encodes a packet.
  19. *
  20. * <packet type id> [ <data> ]
  21. *
  22. * Example:
  23. *
  24. * 5hello world
  25. * 3
  26. * 4
  27. *
  28. * Binary is encoded in an identical principle
  29. *
  30. * @api private
  31. */
  32. export declare function encodePacket(packet: any, supportsBinary: any, utf8encode: any, callback: any): any;
  33. /**
  34. * Encodes a packet with binary data in a base64 string
  35. *
  36. * @param {Object} packet, has `type` and `data`
  37. * @return {String} base64 encoded message
  38. */
  39. export declare function encodeBase64Packet(packet: any, callback: any): any;
  40. /**
  41. * Decodes a packet. Data also available as an ArrayBuffer if requested.
  42. *
  43. * @return {Object} with `type` and `data` (if any)
  44. * @api private
  45. */
  46. export declare function decodePacket(data: any, binaryType: any, utf8decode: any): {
  47. type: string;
  48. data: any;
  49. } | {
  50. type: string;
  51. data?: undefined;
  52. };
  53. /**
  54. * Decodes a packet encoded in a base64 string.
  55. *
  56. * @param {String} base64 encoded message
  57. * @return {Object} with `type` and `data` (if any)
  58. */
  59. export declare function decodeBase64Packet(msg: any, binaryType: any): {
  60. type: string;
  61. data: Buffer;
  62. };
  63. /**
  64. * Encodes multiple messages (payload).
  65. *
  66. * <length>:data
  67. *
  68. * Example:
  69. *
  70. * 11:hello world2:hi
  71. *
  72. * If any contents are binary, they will be encoded as base64 strings. Base64
  73. * encoded strings are marked with a b before the length specifier
  74. *
  75. * @param {Array} packets
  76. * @api private
  77. */
  78. export declare function encodePayload(packets: any, supportsBinary: any, callback: any): any;
  79. export declare function decodePayload(data: any, binaryType: any, callback: any): any;
  80. /**
  81. * Encodes multiple messages (payload) as binary.
  82. *
  83. * <1 = binary, 0 = string><number from 0-9><number from 0-9>[...]<number
  84. * 255><data>
  85. *
  86. * Example:
  87. * 1 3 255 1 2 3, if the binary contents are interpreted as 8 bit integers
  88. *
  89. * @param {Array} packets
  90. * @return {Buffer} encoded payload
  91. * @api private
  92. */
  93. export declare function encodePayloadAsBinary(packets: any, callback: any): any;
  94. export declare function decodePayloadAsBinary(data: any, binaryType: any, callback: any): any;