openportal 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (182) hide show
  1. package/README.md +113 -0
  2. package/package.json +1 -1
  3. package/web/.next/static/{A7pW-dtFIbPCSkvE8uenX → Im7EdK1Q3oOmTznohTOr5}/_buildManifest.js +4 -9
  4. package/web/.next/static/chunks/{2e7bfb90c343ca96.js → 35cc9dbdc670c73c.js} +4 -4
  5. package/web/.next/static/chunks/4147ffc67a7b837c.css +1 -0
  6. package/web/.next/static/chunks/{21ab2574b84ad2d1.js → 52b90bc1740162c2.js} +2 -2
  7. package/web/.next/static/chunks/{9b265e2198b5525f.js → 8644d68bf325ff24.js} +3 -3
  8. package/web/.next/static/chunks/{03e1846335a31354.js → 9865709466b09f79.js} +3 -3
  9. package/web/.next/static/chunks/{c20ae04df8cc28be.js → 9ba9a5774c9421bd.js} +3 -3
  10. package/web/.next/static/chunks/{967a1e0002fe9ae6.js → b5caad256518cb33.js} +3 -3
  11. package/web/.next/static/chunks/{turbopack-27558c851386934e.js → turbopack-26af71e419c11487.js} +1 -1
  12. package/web/.next/static/chunks/{turbopack-f4c0881f9723f5a5.js → turbopack-4ad0df7330c00c8d.js} +1 -1
  13. package/web/.next/static/chunks/{turbopack-26688626142ac58f.js → turbopack-8e653f3ad3a8ed18.js} +1 -1
  14. package/web/.next/static/chunks/{turbopack-c40ec6674624f1d7.js → turbopack-d5098189d63fd7b8.js} +1 -1
  15. package/web/apps/web/.next/BUILD_ID +1 -1
  16. package/web/apps/web/.next/build-manifest.json +14 -24
  17. package/web/apps/web/.next/routes-manifest.json +0 -12
  18. package/web/apps/web/.next/server/chunks/[root-of-the-server]__f366ca98._.js +358 -0
  19. package/web/apps/web/.next/server/chunks/ssr/{[root-of-the-server]__dfeaf8cf._.js → [root-of-the-server]__1a54ba1e._.js} +3 -3
  20. package/web/apps/web/.next/server/middleware-build-manifest.js +12 -22
  21. package/web/apps/web/.next/server/next-font-manifest.js +1 -1
  22. package/web/apps/web/.next/server/next-font-manifest.json +0 -4
  23. package/web/apps/web/.next/server/pages/404.html +1 -1
  24. package/web/apps/web/.next/server/pages/500.html +1 -1
  25. package/web/apps/web/.next/server/pages/_app/build-manifest.json +3 -3
  26. package/web/apps/web/.next/server/pages/_app/client-build-manifest.json +1 -1
  27. package/web/apps/web/.next/server/pages/api/[[...slugs]].js +1 -2
  28. package/web/apps/web/.next/server/pages/api/[[...slugs]].js.nft.json +1 -1
  29. package/web/apps/web/.next/server/pages/index/build-manifest.json +3 -3
  30. package/web/apps/web/.next/server/pages/index/client-build-manifest.json +1 -1
  31. package/web/apps/web/.next/server/pages/index.html +1 -1
  32. package/web/apps/web/.next/server/pages/index.js.nft.json +1 -1
  33. package/web/apps/web/.next/server/pages/session/[id]/build-manifest.json +4 -4
  34. package/web/apps/web/.next/server/pages/session/[id]/client-build-manifest.json +1 -1
  35. package/web/apps/web/.next/server/pages/session/[id].html +1 -1
  36. package/web/apps/web/.next/server/pages/session/[id].js.nft.json +1 -1
  37. package/web/apps/web/.next/server/pages/settings/build-manifest.json +3 -3
  38. package/web/apps/web/.next/server/pages/settings/client-build-manifest.json +1 -1
  39. package/web/apps/web/.next/server/pages/settings.html +1 -1
  40. package/web/apps/web/.next/server/pages/settings.js.nft.json +1 -1
  41. package/web/apps/web/.next/server/pages-manifest.json +0 -2
  42. package/web/apps/web/package.json +1 -9
  43. package/web/.next/static/chunks/04d4692d75696297.css +0 -1
  44. package/web/.next/static/chunks/553710f60e2f2b11.js +0 -1
  45. package/web/.next/static/chunks/58acbbb4090e3362.js +0 -3
  46. package/web/.next/static/chunks/6ce1e2f08f961db5.js +0 -2
  47. package/web/.next/static/chunks/d316d63225992c76.js +0 -10
  48. package/web/.next/static/chunks/e0c97552ba7a9e3d.js +0 -1
  49. package/web/.next/static/chunks/fc9c4f2dabfb4e0e.css +0 -1
  50. package/web/.next/static/chunks/turbopack-1837909a677d116b.js +0 -3
  51. package/web/apps/web/.next/server/chunks/[root-of-the-server]__0f75905d._.js +0 -3
  52. package/web/apps/web/.next/server/chunks/[root-of-the-server]__89e85365._.js +0 -358
  53. package/web/apps/web/.next/server/chunks/[root-of-the-server]__ae1361d0._.js +0 -3
  54. package/web/apps/web/.next/server/pages/api/terminal/ws/pages-manifest.json +0 -3
  55. package/web/apps/web/.next/server/pages/api/terminal/ws.js +0 -5
  56. package/web/apps/web/.next/server/pages/api/terminal/ws.js.map +0 -5
  57. package/web/apps/web/.next/server/pages/api/terminal/ws.js.nft.json +0 -1
  58. package/web/apps/web/.next/server/pages/terminal/build-manifest.json +0 -20
  59. package/web/apps/web/.next/server/pages/terminal/client-build-manifest.json +0 -5
  60. package/web/apps/web/.next/server/pages/terminal/next-font-manifest.json +0 -11
  61. package/web/apps/web/.next/server/pages/terminal/pages-manifest.json +0 -3
  62. package/web/apps/web/.next/server/pages/terminal/react-loadable-manifest.json +0 -1
  63. package/web/apps/web/.next/server/pages/terminal.html +0 -1
  64. package/web/apps/web/.next/server/pages/terminal.js.map +0 -5
  65. package/web/apps/web/.next/server/pages/terminal.js.nft.json +0 -1
  66. package/web/node_modules/.bun/@socket.io+component-emitter@3.1.2/node_modules/@socket.io/component-emitter/lib/cjs/index.js +0 -176
  67. package/web/node_modules/.bun/@socket.io+component-emitter@3.1.2/node_modules/@socket.io/component-emitter/lib/cjs/package.json +0 -4
  68. package/web/node_modules/.bun/@socket.io+component-emitter@3.1.2/node_modules/@socket.io/component-emitter/package.json +0 -28
  69. package/web/node_modules/.bun/accepts@1.3.8/node_modules/accepts/index.js +0 -238
  70. package/web/node_modules/.bun/accepts@1.3.8/node_modules/accepts/package.json +0 -47
  71. package/web/node_modules/.bun/base64id@2.0.0/node_modules/base64id/lib/base64id.js +0 -103
  72. package/web/node_modules/.bun/base64id@2.0.0/node_modules/base64id/package.json +0 -13
  73. package/web/node_modules/.bun/cookie@0.7.2/node_modules/cookie/index.js +0 -335
  74. package/web/node_modules/.bun/cookie@0.7.2/node_modules/cookie/package.json +0 -44
  75. package/web/node_modules/.bun/cookie@1.1.1/node_modules/cookie/package.json +0 -47
  76. package/web/node_modules/.bun/cors@2.8.5/node_modules/cors/lib/index.js +0 -238
  77. package/web/node_modules/.bun/cors@2.8.5/node_modules/cors/package.json +0 -41
  78. package/web/node_modules/.bun/debug@4.3.7/node_modules/debug/package.json +0 -60
  79. package/web/node_modules/.bun/debug@4.3.7/node_modules/debug/src/browser.js +0 -271
  80. package/web/node_modules/.bun/debug@4.3.7/node_modules/debug/src/common.js +0 -274
  81. package/web/node_modules/.bun/debug@4.3.7/node_modules/debug/src/index.js +0 -10
  82. package/web/node_modules/.bun/debug@4.3.7/node_modules/debug/src/node.js +0 -263
  83. package/web/node_modules/.bun/engine.io-parser@5.2.3/node_modules/engine.io-parser/build/cjs/commons.js +0 -19
  84. package/web/node_modules/.bun/engine.io-parser@5.2.3/node_modules/engine.io-parser/build/cjs/decodePacket.js +0 -59
  85. package/web/node_modules/.bun/engine.io-parser@5.2.3/node_modules/engine.io-parser/build/cjs/encodePacket.js +0 -38
  86. package/web/node_modules/.bun/engine.io-parser@5.2.3/node_modules/engine.io-parser/build/cjs/index.js +0 -164
  87. package/web/node_modules/.bun/engine.io-parser@5.2.3/node_modules/engine.io-parser/build/cjs/package.json +0 -8
  88. package/web/node_modules/.bun/engine.io-parser@5.2.3/node_modules/engine.io-parser/package.json +0 -46
  89. package/web/node_modules/.bun/engine.io@6.6.4/node_modules/engine.io/build/engine.io.js +0 -54
  90. package/web/node_modules/.bun/engine.io@6.6.4/node_modules/engine.io/build/parser-v3/index.js +0 -424
  91. package/web/node_modules/.bun/engine.io@6.6.4/node_modules/engine.io/build/parser-v3/utf8.js +0 -187
  92. package/web/node_modules/.bun/engine.io@6.6.4/node_modules/engine.io/build/server.js +0 -786
  93. package/web/node_modules/.bun/engine.io@6.6.4/node_modules/engine.io/build/socket.js +0 -460
  94. package/web/node_modules/.bun/engine.io@6.6.4/node_modules/engine.io/build/transport.js +0 -117
  95. package/web/node_modules/.bun/engine.io@6.6.4/node_modules/engine.io/build/transports/index.js +0 -23
  96. package/web/node_modules/.bun/engine.io@6.6.4/node_modules/engine.io/build/transports/polling-jsonp.js +0 -41
  97. package/web/node_modules/.bun/engine.io@6.6.4/node_modules/engine.io/build/transports/polling.js +0 -332
  98. package/web/node_modules/.bun/engine.io@6.6.4/node_modules/engine.io/build/transports/websocket.js +0 -94
  99. package/web/node_modules/.bun/engine.io@6.6.4/node_modules/engine.io/build/transports/webtransport.js +0 -63
  100. package/web/node_modules/.bun/engine.io@6.6.4/node_modules/engine.io/build/transports-uws/index.js +0 -8
  101. package/web/node_modules/.bun/engine.io@6.6.4/node_modules/engine.io/build/transports-uws/polling.js +0 -364
  102. package/web/node_modules/.bun/engine.io@6.6.4/node_modules/engine.io/build/transports-uws/websocket.js +0 -73
  103. package/web/node_modules/.bun/engine.io@6.6.4/node_modules/engine.io/build/userver.js +0 -279
  104. package/web/node_modules/.bun/engine.io@6.6.4/node_modules/engine.io/package.json +0 -70
  105. package/web/node_modules/.bun/has-flag@4.0.0/node_modules/has-flag/index.js +0 -8
  106. package/web/node_modules/.bun/has-flag@4.0.0/node_modules/has-flag/package.json +0 -46
  107. package/web/node_modules/.bun/mime-db@1.52.0/node_modules/mime-db/db.json +0 -8519
  108. package/web/node_modules/.bun/mime-db@1.52.0/node_modules/mime-db/index.js +0 -12
  109. package/web/node_modules/.bun/mime-db@1.52.0/node_modules/mime-db/package.json +0 -60
  110. package/web/node_modules/.bun/mime-types@2.1.35/node_modules/mime-types/index.js +0 -188
  111. package/web/node_modules/.bun/mime-types@2.1.35/node_modules/mime-types/package.json +0 -44
  112. package/web/node_modules/.bun/ms@2.1.3/node_modules/ms/index.js +0 -162
  113. package/web/node_modules/.bun/ms@2.1.3/node_modules/ms/package.json +0 -38
  114. package/web/node_modules/.bun/negotiator@0.6.3/node_modules/negotiator/index.js +0 -82
  115. package/web/node_modules/.bun/negotiator@0.6.3/node_modules/negotiator/lib/charset.js +0 -169
  116. package/web/node_modules/.bun/negotiator@0.6.3/node_modules/negotiator/lib/encoding.js +0 -184
  117. package/web/node_modules/.bun/negotiator@0.6.3/node_modules/negotiator/lib/language.js +0 -179
  118. package/web/node_modules/.bun/negotiator@0.6.3/node_modules/negotiator/lib/mediaType.js +0 -294
  119. package/web/node_modules/.bun/negotiator@0.6.3/node_modules/negotiator/package.json +0 -42
  120. package/web/node_modules/.bun/object-assign@4.1.1/node_modules/object-assign/index.js +0 -90
  121. package/web/node_modules/.bun/object-assign@4.1.1/node_modules/object-assign/package.json +0 -42
  122. package/web/node_modules/.bun/socket.io-adapter@2.5.5/node_modules/socket.io-adapter/dist/cluster-adapter.js +0 -674
  123. package/web/node_modules/.bun/socket.io-adapter@2.5.5/node_modules/socket.io-adapter/dist/contrib/yeast.js +0 -55
  124. package/web/node_modules/.bun/socket.io-adapter@2.5.5/node_modules/socket.io-adapter/dist/in-memory-adapter.js +0 -394
  125. package/web/node_modules/.bun/socket.io-adapter@2.5.5/node_modules/socket.io-adapter/dist/index.js +0 -10
  126. package/web/node_modules/.bun/socket.io-adapter@2.5.5/node_modules/socket.io-adapter/package.json +0 -39
  127. package/web/node_modules/.bun/socket.io-parser@4.2.4/node_modules/socket.io-parser/build/cjs/binary.js +0 -88
  128. package/web/node_modules/.bun/socket.io-parser@4.2.4/node_modules/socket.io-parser/build/cjs/index.js +0 -321
  129. package/web/node_modules/.bun/socket.io-parser@4.2.4/node_modules/socket.io-parser/build/cjs/is-binary.js +0 -55
  130. package/web/node_modules/.bun/socket.io-parser@4.2.4/node_modules/socket.io-parser/build/cjs/package.json +0 -3
  131. package/web/node_modules/.bun/socket.io-parser@4.2.4/node_modules/socket.io-parser/package.json +0 -58
  132. package/web/node_modules/.bun/socket.io@4.8.1/node_modules/socket.io/client-dist/socket.io.esm.min.js +0 -7
  133. package/web/node_modules/.bun/socket.io@4.8.1/node_modules/socket.io/client-dist/socket.io.js +0 -4908
  134. package/web/node_modules/.bun/socket.io@4.8.1/node_modules/socket.io/client-dist/socket.io.min.js +0 -7
  135. package/web/node_modules/.bun/socket.io@4.8.1/node_modules/socket.io/client-dist/socket.io.msgpack.min.js +0 -7
  136. package/web/node_modules/.bun/socket.io@4.8.1/node_modules/socket.io/dist/broadcast-operator.js +0 -436
  137. package/web/node_modules/.bun/socket.io@4.8.1/node_modules/socket.io/dist/client.js +0 -268
  138. package/web/node_modules/.bun/socket.io@4.8.1/node_modules/socket.io/dist/index.js +0 -804
  139. package/web/node_modules/.bun/socket.io@4.8.1/node_modules/socket.io/dist/namespace.js +0 -581
  140. package/web/node_modules/.bun/socket.io@4.8.1/node_modules/socket.io/dist/parent-namespace.js +0 -88
  141. package/web/node_modules/.bun/socket.io@4.8.1/node_modules/socket.io/dist/socket-types.js +0 -11
  142. package/web/node_modules/.bun/socket.io@4.8.1/node_modules/socket.io/dist/socket.js +0 -977
  143. package/web/node_modules/.bun/socket.io@4.8.1/node_modules/socket.io/dist/typed-events.js +0 -81
  144. package/web/node_modules/.bun/socket.io@4.8.1/node_modules/socket.io/dist/uws.js +0 -136
  145. package/web/node_modules/.bun/socket.io@4.8.1/node_modules/socket.io/package.json +0 -85
  146. package/web/node_modules/.bun/socket.io@4.8.1/node_modules/socket.io/wrapper.mjs +0 -3
  147. package/web/node_modules/.bun/supports-color@7.2.0/node_modules/supports-color/index.js +0 -135
  148. package/web/node_modules/.bun/supports-color@7.2.0/node_modules/supports-color/package.json +0 -53
  149. package/web/node_modules/.bun/vary@1.1.2/node_modules/vary/index.js +0 -149
  150. package/web/node_modules/.bun/vary@1.1.2/node_modules/vary/package.json +0 -43
  151. package/web/node_modules/.bun/ws@8.17.1/node_modules/ws/index.js +0 -13
  152. package/web/node_modules/.bun/ws@8.17.1/node_modules/ws/lib/buffer-util.js +0 -131
  153. package/web/node_modules/.bun/ws@8.17.1/node_modules/ws/lib/constants.js +0 -12
  154. package/web/node_modules/.bun/ws@8.17.1/node_modules/ws/lib/event-target.js +0 -292
  155. package/web/node_modules/.bun/ws@8.17.1/node_modules/ws/lib/extension.js +0 -203
  156. package/web/node_modules/.bun/ws@8.17.1/node_modules/ws/lib/limiter.js +0 -55
  157. package/web/node_modules/.bun/ws@8.17.1/node_modules/ws/lib/permessage-deflate.js +0 -514
  158. package/web/node_modules/.bun/ws@8.17.1/node_modules/ws/lib/receiver.js +0 -704
  159. package/web/node_modules/.bun/ws@8.17.1/node_modules/ws/lib/sender.js +0 -497
  160. package/web/node_modules/.bun/ws@8.17.1/node_modules/ws/lib/stream.js +0 -159
  161. package/web/node_modules/.bun/ws@8.17.1/node_modules/ws/lib/subprotocol.js +0 -62
  162. package/web/node_modules/.bun/ws@8.17.1/node_modules/ws/lib/validation.js +0 -130
  163. package/web/node_modules/.bun/ws@8.17.1/node_modules/ws/lib/websocket-server.js +0 -540
  164. package/web/node_modules/.bun/ws@8.17.1/node_modules/ws/lib/websocket.js +0 -1338
  165. package/web/node_modules/.bun/ws@8.17.1/node_modules/ws/package.json +0 -69
  166. package/web/node_modules/.bun/ws@8.18.3/node_modules/ws/lib/buffer-util.js +0 -131
  167. package/web/node_modules/.bun/ws@8.18.3/node_modules/ws/lib/constants.js +0 -18
  168. package/web/node_modules/.bun/ws@8.18.3/node_modules/ws/lib/event-target.js +0 -292
  169. package/web/node_modules/.bun/ws@8.18.3/node_modules/ws/lib/extension.js +0 -203
  170. package/web/node_modules/.bun/ws@8.18.3/node_modules/ws/lib/limiter.js +0 -55
  171. package/web/node_modules/.bun/ws@8.18.3/node_modules/ws/lib/permessage-deflate.js +0 -528
  172. package/web/node_modules/.bun/ws@8.18.3/node_modules/ws/lib/receiver.js +0 -706
  173. package/web/node_modules/.bun/ws@8.18.3/node_modules/ws/lib/sender.js +0 -602
  174. package/web/node_modules/.bun/ws@8.18.3/node_modules/ws/lib/stream.js +0 -161
  175. package/web/node_modules/.bun/ws@8.18.3/node_modules/ws/lib/subprotocol.js +0 -62
  176. package/web/node_modules/.bun/ws@8.18.3/node_modules/ws/lib/validation.js +0 -152
  177. package/web/node_modules/.bun/ws@8.18.3/node_modules/ws/lib/websocket-server.js +0 -550
  178. package/web/node_modules/.bun/ws@8.18.3/node_modules/ws/lib/websocket.js +0 -1388
  179. package/web/node_modules/.bun/ws@8.18.3/node_modules/ws/package.json +0 -69
  180. package/web/node_modules/.bun/ws@8.18.3/node_modules/ws/wrapper.mjs +0 -8
  181. /package/web/.next/static/{A7pW-dtFIbPCSkvE8uenX → Im7EdK1Q3oOmTznohTOr5}/_clientMiddlewareManifest.json +0 -0
  182. /package/web/.next/static/{A7pW-dtFIbPCSkvE8uenX → Im7EdK1Q3oOmTznohTOr5}/_ssgManifest.js +0 -0
@@ -1,497 +0,0 @@
1
- /* eslint no-unused-vars: ["error", { "varsIgnorePattern": "^Duplex" }] */
2
-
3
- 'use strict';
4
-
5
- const { Duplex } = require('stream');
6
- const { randomFillSync } = require('crypto');
7
-
8
- const PerMessageDeflate = require('./permessage-deflate');
9
- const { EMPTY_BUFFER } = require('./constants');
10
- const { isValidStatusCode } = require('./validation');
11
- const { mask: applyMask, toBuffer } = require('./buffer-util');
12
-
13
- const kByteLength = Symbol('kByteLength');
14
- const maskBuffer = Buffer.alloc(4);
15
- const RANDOM_POOL_SIZE = 8 * 1024;
16
- let randomPool;
17
- let randomPoolPointer = RANDOM_POOL_SIZE;
18
-
19
- /**
20
- * HyBi Sender implementation.
21
- */
22
- class Sender {
23
- /**
24
- * Creates a Sender instance.
25
- *
26
- * @param {Duplex} socket The connection socket
27
- * @param {Object} [extensions] An object containing the negotiated extensions
28
- * @param {Function} [generateMask] The function used to generate the masking
29
- * key
30
- */
31
- constructor(socket, extensions, generateMask) {
32
- this._extensions = extensions || {};
33
-
34
- if (generateMask) {
35
- this._generateMask = generateMask;
36
- this._maskBuffer = Buffer.alloc(4);
37
- }
38
-
39
- this._socket = socket;
40
-
41
- this._firstFragment = true;
42
- this._compress = false;
43
-
44
- this._bufferedBytes = 0;
45
- this._deflating = false;
46
- this._queue = [];
47
- }
48
-
49
- /**
50
- * Frames a piece of data according to the HyBi WebSocket protocol.
51
- *
52
- * @param {(Buffer|String)} data The data to frame
53
- * @param {Object} options Options object
54
- * @param {Boolean} [options.fin=false] Specifies whether or not to set the
55
- * FIN bit
56
- * @param {Function} [options.generateMask] The function used to generate the
57
- * masking key
58
- * @param {Boolean} [options.mask=false] Specifies whether or not to mask
59
- * `data`
60
- * @param {Buffer} [options.maskBuffer] The buffer used to store the masking
61
- * key
62
- * @param {Number} options.opcode The opcode
63
- * @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
64
- * modified
65
- * @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
66
- * RSV1 bit
67
- * @return {(Buffer|String)[]} The framed data
68
- * @public
69
- */
70
- static frame(data, options) {
71
- let mask;
72
- let merge = false;
73
- let offset = 2;
74
- let skipMasking = false;
75
-
76
- if (options.mask) {
77
- mask = options.maskBuffer || maskBuffer;
78
-
79
- if (options.generateMask) {
80
- options.generateMask(mask);
81
- } else {
82
- if (randomPoolPointer === RANDOM_POOL_SIZE) {
83
- /* istanbul ignore else */
84
- if (randomPool === undefined) {
85
- //
86
- // This is lazily initialized because server-sent frames must not
87
- // be masked so it may never be used.
88
- //
89
- randomPool = Buffer.alloc(RANDOM_POOL_SIZE);
90
- }
91
-
92
- randomFillSync(randomPool, 0, RANDOM_POOL_SIZE);
93
- randomPoolPointer = 0;
94
- }
95
-
96
- mask[0] = randomPool[randomPoolPointer++];
97
- mask[1] = randomPool[randomPoolPointer++];
98
- mask[2] = randomPool[randomPoolPointer++];
99
- mask[3] = randomPool[randomPoolPointer++];
100
- }
101
-
102
- skipMasking = (mask[0] | mask[1] | mask[2] | mask[3]) === 0;
103
- offset = 6;
104
- }
105
-
106
- let dataLength;
107
-
108
- if (typeof data === 'string') {
109
- if (
110
- (!options.mask || skipMasking) &&
111
- options[kByteLength] !== undefined
112
- ) {
113
- dataLength = options[kByteLength];
114
- } else {
115
- data = Buffer.from(data);
116
- dataLength = data.length;
117
- }
118
- } else {
119
- dataLength = data.length;
120
- merge = options.mask && options.readOnly && !skipMasking;
121
- }
122
-
123
- let payloadLength = dataLength;
124
-
125
- if (dataLength >= 65536) {
126
- offset += 8;
127
- payloadLength = 127;
128
- } else if (dataLength > 125) {
129
- offset += 2;
130
- payloadLength = 126;
131
- }
132
-
133
- const target = Buffer.allocUnsafe(merge ? dataLength + offset : offset);
134
-
135
- target[0] = options.fin ? options.opcode | 0x80 : options.opcode;
136
- if (options.rsv1) target[0] |= 0x40;
137
-
138
- target[1] = payloadLength;
139
-
140
- if (payloadLength === 126) {
141
- target.writeUInt16BE(dataLength, 2);
142
- } else if (payloadLength === 127) {
143
- target[2] = target[3] = 0;
144
- target.writeUIntBE(dataLength, 4, 6);
145
- }
146
-
147
- if (!options.mask) return [target, data];
148
-
149
- target[1] |= 0x80;
150
- target[offset - 4] = mask[0];
151
- target[offset - 3] = mask[1];
152
- target[offset - 2] = mask[2];
153
- target[offset - 1] = mask[3];
154
-
155
- if (skipMasking) return [target, data];
156
-
157
- if (merge) {
158
- applyMask(data, mask, target, offset, dataLength);
159
- return [target];
160
- }
161
-
162
- applyMask(data, mask, data, 0, dataLength);
163
- return [target, data];
164
- }
165
-
166
- /**
167
- * Sends a close message to the other peer.
168
- *
169
- * @param {Number} [code] The status code component of the body
170
- * @param {(String|Buffer)} [data] The message component of the body
171
- * @param {Boolean} [mask=false] Specifies whether or not to mask the message
172
- * @param {Function} [cb] Callback
173
- * @public
174
- */
175
- close(code, data, mask, cb) {
176
- let buf;
177
-
178
- if (code === undefined) {
179
- buf = EMPTY_BUFFER;
180
- } else if (typeof code !== 'number' || !isValidStatusCode(code)) {
181
- throw new TypeError('First argument must be a valid error code number');
182
- } else if (data === undefined || !data.length) {
183
- buf = Buffer.allocUnsafe(2);
184
- buf.writeUInt16BE(code, 0);
185
- } else {
186
- const length = Buffer.byteLength(data);
187
-
188
- if (length > 123) {
189
- throw new RangeError('The message must not be greater than 123 bytes');
190
- }
191
-
192
- buf = Buffer.allocUnsafe(2 + length);
193
- buf.writeUInt16BE(code, 0);
194
-
195
- if (typeof data === 'string') {
196
- buf.write(data, 2);
197
- } else {
198
- buf.set(data, 2);
199
- }
200
- }
201
-
202
- const options = {
203
- [kByteLength]: buf.length,
204
- fin: true,
205
- generateMask: this._generateMask,
206
- mask,
207
- maskBuffer: this._maskBuffer,
208
- opcode: 0x08,
209
- readOnly: false,
210
- rsv1: false
211
- };
212
-
213
- if (this._deflating) {
214
- this.enqueue([this.dispatch, buf, false, options, cb]);
215
- } else {
216
- this.sendFrame(Sender.frame(buf, options), cb);
217
- }
218
- }
219
-
220
- /**
221
- * Sends a ping message to the other peer.
222
- *
223
- * @param {*} data The message to send
224
- * @param {Boolean} [mask=false] Specifies whether or not to mask `data`
225
- * @param {Function} [cb] Callback
226
- * @public
227
- */
228
- ping(data, mask, cb) {
229
- let byteLength;
230
- let readOnly;
231
-
232
- if (typeof data === 'string') {
233
- byteLength = Buffer.byteLength(data);
234
- readOnly = false;
235
- } else {
236
- data = toBuffer(data);
237
- byteLength = data.length;
238
- readOnly = toBuffer.readOnly;
239
- }
240
-
241
- if (byteLength > 125) {
242
- throw new RangeError('The data size must not be greater than 125 bytes');
243
- }
244
-
245
- const options = {
246
- [kByteLength]: byteLength,
247
- fin: true,
248
- generateMask: this._generateMask,
249
- mask,
250
- maskBuffer: this._maskBuffer,
251
- opcode: 0x09,
252
- readOnly,
253
- rsv1: false
254
- };
255
-
256
- if (this._deflating) {
257
- this.enqueue([this.dispatch, data, false, options, cb]);
258
- } else {
259
- this.sendFrame(Sender.frame(data, options), cb);
260
- }
261
- }
262
-
263
- /**
264
- * Sends a pong message to the other peer.
265
- *
266
- * @param {*} data The message to send
267
- * @param {Boolean} [mask=false] Specifies whether or not to mask `data`
268
- * @param {Function} [cb] Callback
269
- * @public
270
- */
271
- pong(data, mask, cb) {
272
- let byteLength;
273
- let readOnly;
274
-
275
- if (typeof data === 'string') {
276
- byteLength = Buffer.byteLength(data);
277
- readOnly = false;
278
- } else {
279
- data = toBuffer(data);
280
- byteLength = data.length;
281
- readOnly = toBuffer.readOnly;
282
- }
283
-
284
- if (byteLength > 125) {
285
- throw new RangeError('The data size must not be greater than 125 bytes');
286
- }
287
-
288
- const options = {
289
- [kByteLength]: byteLength,
290
- fin: true,
291
- generateMask: this._generateMask,
292
- mask,
293
- maskBuffer: this._maskBuffer,
294
- opcode: 0x0a,
295
- readOnly,
296
- rsv1: false
297
- };
298
-
299
- if (this._deflating) {
300
- this.enqueue([this.dispatch, data, false, options, cb]);
301
- } else {
302
- this.sendFrame(Sender.frame(data, options), cb);
303
- }
304
- }
305
-
306
- /**
307
- * Sends a data message to the other peer.
308
- *
309
- * @param {*} data The message to send
310
- * @param {Object} options Options object
311
- * @param {Boolean} [options.binary=false] Specifies whether `data` is binary
312
- * or text
313
- * @param {Boolean} [options.compress=false] Specifies whether or not to
314
- * compress `data`
315
- * @param {Boolean} [options.fin=false] Specifies whether the fragment is the
316
- * last one
317
- * @param {Boolean} [options.mask=false] Specifies whether or not to mask
318
- * `data`
319
- * @param {Function} [cb] Callback
320
- * @public
321
- */
322
- send(data, options, cb) {
323
- const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
324
- let opcode = options.binary ? 2 : 1;
325
- let rsv1 = options.compress;
326
-
327
- let byteLength;
328
- let readOnly;
329
-
330
- if (typeof data === 'string') {
331
- byteLength = Buffer.byteLength(data);
332
- readOnly = false;
333
- } else {
334
- data = toBuffer(data);
335
- byteLength = data.length;
336
- readOnly = toBuffer.readOnly;
337
- }
338
-
339
- if (this._firstFragment) {
340
- this._firstFragment = false;
341
- if (
342
- rsv1 &&
343
- perMessageDeflate &&
344
- perMessageDeflate.params[
345
- perMessageDeflate._isServer
346
- ? 'server_no_context_takeover'
347
- : 'client_no_context_takeover'
348
- ]
349
- ) {
350
- rsv1 = byteLength >= perMessageDeflate._threshold;
351
- }
352
- this._compress = rsv1;
353
- } else {
354
- rsv1 = false;
355
- opcode = 0;
356
- }
357
-
358
- if (options.fin) this._firstFragment = true;
359
-
360
- if (perMessageDeflate) {
361
- const opts = {
362
- [kByteLength]: byteLength,
363
- fin: options.fin,
364
- generateMask: this._generateMask,
365
- mask: options.mask,
366
- maskBuffer: this._maskBuffer,
367
- opcode,
368
- readOnly,
369
- rsv1
370
- };
371
-
372
- if (this._deflating) {
373
- this.enqueue([this.dispatch, data, this._compress, opts, cb]);
374
- } else {
375
- this.dispatch(data, this._compress, opts, cb);
376
- }
377
- } else {
378
- this.sendFrame(
379
- Sender.frame(data, {
380
- [kByteLength]: byteLength,
381
- fin: options.fin,
382
- generateMask: this._generateMask,
383
- mask: options.mask,
384
- maskBuffer: this._maskBuffer,
385
- opcode,
386
- readOnly,
387
- rsv1: false
388
- }),
389
- cb
390
- );
391
- }
392
- }
393
-
394
- /**
395
- * Dispatches a message.
396
- *
397
- * @param {(Buffer|String)} data The message to send
398
- * @param {Boolean} [compress=false] Specifies whether or not to compress
399
- * `data`
400
- * @param {Object} options Options object
401
- * @param {Boolean} [options.fin=false] Specifies whether or not to set the
402
- * FIN bit
403
- * @param {Function} [options.generateMask] The function used to generate the
404
- * masking key
405
- * @param {Boolean} [options.mask=false] Specifies whether or not to mask
406
- * `data`
407
- * @param {Buffer} [options.maskBuffer] The buffer used to store the masking
408
- * key
409
- * @param {Number} options.opcode The opcode
410
- * @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
411
- * modified
412
- * @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
413
- * RSV1 bit
414
- * @param {Function} [cb] Callback
415
- * @private
416
- */
417
- dispatch(data, compress, options, cb) {
418
- if (!compress) {
419
- this.sendFrame(Sender.frame(data, options), cb);
420
- return;
421
- }
422
-
423
- const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
424
-
425
- this._bufferedBytes += options[kByteLength];
426
- this._deflating = true;
427
- perMessageDeflate.compress(data, options.fin, (_, buf) => {
428
- if (this._socket.destroyed) {
429
- const err = new Error(
430
- 'The socket was closed while data was being compressed'
431
- );
432
-
433
- if (typeof cb === 'function') cb(err);
434
-
435
- for (let i = 0; i < this._queue.length; i++) {
436
- const params = this._queue[i];
437
- const callback = params[params.length - 1];
438
-
439
- if (typeof callback === 'function') callback(err);
440
- }
441
-
442
- return;
443
- }
444
-
445
- this._bufferedBytes -= options[kByteLength];
446
- this._deflating = false;
447
- options.readOnly = false;
448
- this.sendFrame(Sender.frame(buf, options), cb);
449
- this.dequeue();
450
- });
451
- }
452
-
453
- /**
454
- * Executes queued send operations.
455
- *
456
- * @private
457
- */
458
- dequeue() {
459
- while (!this._deflating && this._queue.length) {
460
- const params = this._queue.shift();
461
-
462
- this._bufferedBytes -= params[3][kByteLength];
463
- Reflect.apply(params[0], this, params.slice(1));
464
- }
465
- }
466
-
467
- /**
468
- * Enqueues a send operation.
469
- *
470
- * @param {Array} params Send operation parameters.
471
- * @private
472
- */
473
- enqueue(params) {
474
- this._bufferedBytes += params[3][kByteLength];
475
- this._queue.push(params);
476
- }
477
-
478
- /**
479
- * Sends a frame.
480
- *
481
- * @param {Buffer[]} list The frame to send
482
- * @param {Function} [cb] Callback
483
- * @private
484
- */
485
- sendFrame(list, cb) {
486
- if (list.length === 2) {
487
- this._socket.cork();
488
- this._socket.write(list[0]);
489
- this._socket.write(list[1], cb);
490
- this._socket.uncork();
491
- } else {
492
- this._socket.write(list[0], cb);
493
- }
494
- }
495
- }
496
-
497
- module.exports = Sender;
@@ -1,159 +0,0 @@
1
- 'use strict';
2
-
3
- const { Duplex } = require('stream');
4
-
5
- /**
6
- * Emits the `'close'` event on a stream.
7
- *
8
- * @param {Duplex} stream The stream.
9
- * @private
10
- */
11
- function emitClose(stream) {
12
- stream.emit('close');
13
- }
14
-
15
- /**
16
- * The listener of the `'end'` event.
17
- *
18
- * @private
19
- */
20
- function duplexOnEnd() {
21
- if (!this.destroyed && this._writableState.finished) {
22
- this.destroy();
23
- }
24
- }
25
-
26
- /**
27
- * The listener of the `'error'` event.
28
- *
29
- * @param {Error} err The error
30
- * @private
31
- */
32
- function duplexOnError(err) {
33
- this.removeListener('error', duplexOnError);
34
- this.destroy();
35
- if (this.listenerCount('error') === 0) {
36
- // Do not suppress the throwing behavior.
37
- this.emit('error', err);
38
- }
39
- }
40
-
41
- /**
42
- * Wraps a `WebSocket` in a duplex stream.
43
- *
44
- * @param {WebSocket} ws The `WebSocket` to wrap
45
- * @param {Object} [options] The options for the `Duplex` constructor
46
- * @return {Duplex} The duplex stream
47
- * @public
48
- */
49
- function createWebSocketStream(ws, options) {
50
- let terminateOnDestroy = true;
51
-
52
- const duplex = new Duplex({
53
- ...options,
54
- autoDestroy: false,
55
- emitClose: false,
56
- objectMode: false,
57
- writableObjectMode: false
58
- });
59
-
60
- ws.on('message', function message(msg, isBinary) {
61
- const data =
62
- !isBinary && duplex._readableState.objectMode ? msg.toString() : msg;
63
-
64
- if (!duplex.push(data)) ws.pause();
65
- });
66
-
67
- ws.once('error', function error(err) {
68
- if (duplex.destroyed) return;
69
-
70
- // Prevent `ws.terminate()` from being called by `duplex._destroy()`.
71
- //
72
- // - If the `'error'` event is emitted before the `'open'` event, then
73
- // `ws.terminate()` is a noop as no socket is assigned.
74
- // - Otherwise, the error is re-emitted by the listener of the `'error'`
75
- // event of the `Receiver` object. The listener already closes the
76
- // connection by calling `ws.close()`. This allows a close frame to be
77
- // sent to the other peer. If `ws.terminate()` is called right after this,
78
- // then the close frame might not be sent.
79
- terminateOnDestroy = false;
80
- duplex.destroy(err);
81
- });
82
-
83
- ws.once('close', function close() {
84
- if (duplex.destroyed) return;
85
-
86
- duplex.push(null);
87
- });
88
-
89
- duplex._destroy = function (err, callback) {
90
- if (ws.readyState === ws.CLOSED) {
91
- callback(err);
92
- process.nextTick(emitClose, duplex);
93
- return;
94
- }
95
-
96
- let called = false;
97
-
98
- ws.once('error', function error(err) {
99
- called = true;
100
- callback(err);
101
- });
102
-
103
- ws.once('close', function close() {
104
- if (!called) callback(err);
105
- process.nextTick(emitClose, duplex);
106
- });
107
-
108
- if (terminateOnDestroy) ws.terminate();
109
- };
110
-
111
- duplex._final = function (callback) {
112
- if (ws.readyState === ws.CONNECTING) {
113
- ws.once('open', function open() {
114
- duplex._final(callback);
115
- });
116
- return;
117
- }
118
-
119
- // If the value of the `_socket` property is `null` it means that `ws` is a
120
- // client websocket and the handshake failed. In fact, when this happens, a
121
- // socket is never assigned to the websocket. Wait for the `'error'` event
122
- // that will be emitted by the websocket.
123
- if (ws._socket === null) return;
124
-
125
- if (ws._socket._writableState.finished) {
126
- callback();
127
- if (duplex._readableState.endEmitted) duplex.destroy();
128
- } else {
129
- ws._socket.once('finish', function finish() {
130
- // `duplex` is not destroyed here because the `'end'` event will be
131
- // emitted on `duplex` after this `'finish'` event. The EOF signaling
132
- // `null` chunk is, in fact, pushed when the websocket emits `'close'`.
133
- callback();
134
- });
135
- ws.close();
136
- }
137
- };
138
-
139
- duplex._read = function () {
140
- if (ws.isPaused) ws.resume();
141
- };
142
-
143
- duplex._write = function (chunk, encoding, callback) {
144
- if (ws.readyState === ws.CONNECTING) {
145
- ws.once('open', function open() {
146
- duplex._write(chunk, encoding, callback);
147
- });
148
- return;
149
- }
150
-
151
- ws.send(chunk, callback);
152
- };
153
-
154
- duplex.on('end', duplexOnEnd);
155
- duplex.on('error', duplexOnError);
156
- return duplex;
157
- }
158
-
159
- module.exports = createWebSocketStream;
@@ -1,62 +0,0 @@
1
- 'use strict';
2
-
3
- const { tokenChars } = require('./validation');
4
-
5
- /**
6
- * Parses the `Sec-WebSocket-Protocol` header into a set of subprotocol names.
7
- *
8
- * @param {String} header The field value of the header
9
- * @return {Set} The subprotocol names
10
- * @public
11
- */
12
- function parse(header) {
13
- const protocols = new Set();
14
- let start = -1;
15
- let end = -1;
16
- let i = 0;
17
-
18
- for (i; i < header.length; i++) {
19
- const code = header.charCodeAt(i);
20
-
21
- if (end === -1 && tokenChars[code] === 1) {
22
- if (start === -1) start = i;
23
- } else if (
24
- i !== 0 &&
25
- (code === 0x20 /* ' ' */ || code === 0x09) /* '\t' */
26
- ) {
27
- if (end === -1 && start !== -1) end = i;
28
- } else if (code === 0x2c /* ',' */) {
29
- if (start === -1) {
30
- throw new SyntaxError(`Unexpected character at index ${i}`);
31
- }
32
-
33
- if (end === -1) end = i;
34
-
35
- const protocol = header.slice(start, end);
36
-
37
- if (protocols.has(protocol)) {
38
- throw new SyntaxError(`The "${protocol}" subprotocol is duplicated`);
39
- }
40
-
41
- protocols.add(protocol);
42
- start = end = -1;
43
- } else {
44
- throw new SyntaxError(`Unexpected character at index ${i}`);
45
- }
46
- }
47
-
48
- if (start === -1 || end !== -1) {
49
- throw new SyntaxError('Unexpected end of input');
50
- }
51
-
52
- const protocol = header.slice(start, i);
53
-
54
- if (protocols.has(protocol)) {
55
- throw new SyntaxError(`The "${protocol}" subprotocol is duplicated`);
56
- }
57
-
58
- protocols.add(protocol);
59
- return protocols;
60
- }
61
-
62
- module.exports = { parse };