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,977 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Socket = void 0;
7
- const socket_io_parser_1 = require("socket.io-parser");
8
- const debug_1 = __importDefault(require("debug"));
9
- const typed_events_1 = require("./typed-events");
10
- const base64id_1 = __importDefault(require("base64id"));
11
- const broadcast_operator_1 = require("./broadcast-operator");
12
- const socket_types_1 = require("./socket-types");
13
- const debug = (0, debug_1.default)("socket.io:socket");
14
- const RECOVERABLE_DISCONNECT_REASONS = new Set([
15
- "transport error",
16
- "transport close",
17
- "forced close",
18
- "ping timeout",
19
- "server shutting down",
20
- "forced server close",
21
- ]);
22
- function noop() { }
23
- /**
24
- * This is the main object for interacting with a client.
25
- *
26
- * A Socket belongs to a given {@link Namespace} and uses an underlying {@link Client} to communicate.
27
- *
28
- * Within each {@link Namespace}, you can also define arbitrary channels (called "rooms") that the {@link Socket} can
29
- * join and leave. That provides a convenient way to broadcast to a group of socket instances.
30
- *
31
- * @example
32
- * io.on("connection", (socket) => {
33
- * console.log(`socket ${socket.id} connected`);
34
- *
35
- * // send an event to the client
36
- * socket.emit("foo", "bar");
37
- *
38
- * socket.on("foobar", () => {
39
- * // an event was received from the client
40
- * });
41
- *
42
- * // join the room named "room1"
43
- * socket.join("room1");
44
- *
45
- * // broadcast to everyone in the room named "room1"
46
- * io.to("room1").emit("hello");
47
- *
48
- * // upon disconnection
49
- * socket.on("disconnect", (reason) => {
50
- * console.log(`socket ${socket.id} disconnected due to ${reason}`);
51
- * });
52
- * });
53
- */
54
- class Socket extends typed_events_1.StrictEventEmitter {
55
- /**
56
- * Interface to a `Client` for a given `Namespace`.
57
- *
58
- * @param {Namespace} nsp
59
- * @param {Client} client
60
- * @param {Object} auth
61
- * @package
62
- */
63
- constructor(nsp, client, auth, previousSession) {
64
- super();
65
- this.nsp = nsp;
66
- this.client = client;
67
- /**
68
- * Whether the connection state was recovered after a temporary disconnection. In that case, any missed packets will
69
- * be transmitted to the client, the data attribute and the rooms will be restored.
70
- */
71
- this.recovered = false;
72
- /**
73
- * Additional information that can be attached to the Socket instance and which will be used in the
74
- * {@link Server.fetchSockets()} method.
75
- */
76
- this.data = {};
77
- /**
78
- * Whether the socket is currently connected or not.
79
- *
80
- * @example
81
- * io.use((socket, next) => {
82
- * console.log(socket.connected); // false
83
- * next();
84
- * });
85
- *
86
- * io.on("connection", (socket) => {
87
- * console.log(socket.connected); // true
88
- * });
89
- */
90
- this.connected = false;
91
- this.acks = new Map();
92
- this.fns = [];
93
- this.flags = {};
94
- this.server = nsp.server;
95
- this.adapter = this.nsp.adapter;
96
- if (previousSession) {
97
- this.id = previousSession.sid;
98
- this.pid = previousSession.pid;
99
- previousSession.rooms.forEach((room) => this.join(room));
100
- this.data = previousSession.data;
101
- previousSession.missedPackets.forEach((packet) => {
102
- this.packet({
103
- type: socket_io_parser_1.PacketType.EVENT,
104
- data: packet,
105
- });
106
- });
107
- this.recovered = true;
108
- }
109
- else {
110
- if (client.conn.protocol === 3) {
111
- // @ts-ignore
112
- this.id = nsp.name !== "/" ? nsp.name + "#" + client.id : client.id;
113
- }
114
- else {
115
- this.id = base64id_1.default.generateId(); // don't reuse the Engine.IO id because it's sensitive information
116
- }
117
- if (this.server._opts.connectionStateRecovery) {
118
- this.pid = base64id_1.default.generateId();
119
- }
120
- }
121
- this.handshake = this.buildHandshake(auth);
122
- // prevents crash when the socket receives an "error" event without listener
123
- this.on("error", noop);
124
- }
125
- /**
126
- * Builds the `handshake` BC object
127
- *
128
- * @private
129
- */
130
- buildHandshake(auth) {
131
- var _a, _b, _c, _d;
132
- return {
133
- headers: ((_a = this.request) === null || _a === void 0 ? void 0 : _a.headers) || {},
134
- time: new Date() + "",
135
- address: this.conn.remoteAddress,
136
- xdomain: !!((_b = this.request) === null || _b === void 0 ? void 0 : _b.headers.origin),
137
- // @ts-ignore
138
- secure: !this.request || !!this.request.connection.encrypted,
139
- issued: +new Date(),
140
- url: (_c = this.request) === null || _c === void 0 ? void 0 : _c.url,
141
- // @ts-ignore
142
- query: ((_d = this.request) === null || _d === void 0 ? void 0 : _d._query) || {},
143
- auth,
144
- };
145
- }
146
- /**
147
- * Emits to this client.
148
- *
149
- * @example
150
- * io.on("connection", (socket) => {
151
- * socket.emit("hello", "world");
152
- *
153
- * // all serializable datastructures are supported (no need to call JSON.stringify)
154
- * socket.emit("hello", 1, "2", { 3: ["4"], 5: Buffer.from([6]) });
155
- *
156
- * // with an acknowledgement from the client
157
- * socket.emit("hello", "world", (val) => {
158
- * // ...
159
- * });
160
- * });
161
- *
162
- * @return Always returns `true`.
163
- */
164
- emit(ev, ...args) {
165
- if (socket_types_1.RESERVED_EVENTS.has(ev)) {
166
- throw new Error(`"${String(ev)}" is a reserved event name`);
167
- }
168
- const data = [ev, ...args];
169
- const packet = {
170
- type: socket_io_parser_1.PacketType.EVENT,
171
- data: data,
172
- };
173
- // access last argument to see if it's an ACK callback
174
- if (typeof data[data.length - 1] === "function") {
175
- const id = this.nsp._ids++;
176
- debug("emitting packet with ack id %d", id);
177
- this.registerAckCallback(id, data.pop());
178
- packet.id = id;
179
- }
180
- const flags = Object.assign({}, this.flags);
181
- this.flags = {};
182
- // @ts-ignore
183
- if (this.nsp.server.opts.connectionStateRecovery) {
184
- // this ensures the packet is stored and can be transmitted upon reconnection
185
- this.adapter.broadcast(packet, {
186
- rooms: new Set([this.id]),
187
- except: new Set(),
188
- flags,
189
- });
190
- }
191
- else {
192
- this.notifyOutgoingListeners(packet);
193
- this.packet(packet, flags);
194
- }
195
- return true;
196
- }
197
- /**
198
- * Emits an event and waits for an acknowledgement
199
- *
200
- * @example
201
- * io.on("connection", async (socket) => {
202
- * // without timeout
203
- * const response = await socket.emitWithAck("hello", "world");
204
- *
205
- * // with a specific timeout
206
- * try {
207
- * const response = await socket.timeout(1000).emitWithAck("hello", "world");
208
- * } catch (err) {
209
- * // the client did not acknowledge the event in the given delay
210
- * }
211
- * });
212
- *
213
- * @return a Promise that will be fulfilled when the client acknowledges the event
214
- */
215
- emitWithAck(ev, ...args) {
216
- // the timeout flag is optional
217
- const withErr = this.flags.timeout !== undefined;
218
- return new Promise((resolve, reject) => {
219
- args.push((arg1, arg2) => {
220
- if (withErr) {
221
- return arg1 ? reject(arg1) : resolve(arg2);
222
- }
223
- else {
224
- return resolve(arg1);
225
- }
226
- });
227
- this.emit(ev, ...args);
228
- });
229
- }
230
- /**
231
- * @private
232
- */
233
- registerAckCallback(id, ack) {
234
- const timeout = this.flags.timeout;
235
- if (timeout === undefined) {
236
- this.acks.set(id, ack);
237
- return;
238
- }
239
- const timer = setTimeout(() => {
240
- debug("event with ack id %d has timed out after %d ms", id, timeout);
241
- this.acks.delete(id);
242
- ack.call(this, new Error("operation has timed out"));
243
- }, timeout);
244
- this.acks.set(id, (...args) => {
245
- clearTimeout(timer);
246
- ack.apply(this, [null, ...args]);
247
- });
248
- }
249
- /**
250
- * Targets a room when broadcasting.
251
- *
252
- * @example
253
- * io.on("connection", (socket) => {
254
- * // the “foo” event will be broadcast to all connected clients in the “room-101” room, except this socket
255
- * socket.to("room-101").emit("foo", "bar");
256
- *
257
- * // the code above is equivalent to:
258
- * io.to("room-101").except(socket.id).emit("foo", "bar");
259
- *
260
- * // with an array of rooms (a client will be notified at most once)
261
- * socket.to(["room-101", "room-102"]).emit("foo", "bar");
262
- *
263
- * // with multiple chained calls
264
- * socket.to("room-101").to("room-102").emit("foo", "bar");
265
- * });
266
- *
267
- * @param room - a room, or an array of rooms
268
- * @return a new {@link BroadcastOperator} instance for chaining
269
- */
270
- to(room) {
271
- return this.newBroadcastOperator().to(room);
272
- }
273
- /**
274
- * Targets a room when broadcasting. Similar to `to()`, but might feel clearer in some cases:
275
- *
276
- * @example
277
- * io.on("connection", (socket) => {
278
- * // disconnect all clients in the "room-101" room, except this socket
279
- * socket.in("room-101").disconnectSockets();
280
- * });
281
- *
282
- * @param room - a room, or an array of rooms
283
- * @return a new {@link BroadcastOperator} instance for chaining
284
- */
285
- in(room) {
286
- return this.newBroadcastOperator().in(room);
287
- }
288
- /**
289
- * Excludes a room when broadcasting.
290
- *
291
- * @example
292
- * io.on("connection", (socket) => {
293
- * // the "foo" event will be broadcast to all connected clients, except the ones that are in the "room-101" room
294
- * // and this socket
295
- * socket.except("room-101").emit("foo", "bar");
296
- *
297
- * // with an array of rooms
298
- * socket.except(["room-101", "room-102"]).emit("foo", "bar");
299
- *
300
- * // with multiple chained calls
301
- * socket.except("room-101").except("room-102").emit("foo", "bar");
302
- * });
303
- *
304
- * @param room - a room, or an array of rooms
305
- * @return a new {@link BroadcastOperator} instance for chaining
306
- */
307
- except(room) {
308
- return this.newBroadcastOperator().except(room);
309
- }
310
- /**
311
- * Sends a `message` event.
312
- *
313
- * This method mimics the WebSocket.send() method.
314
- *
315
- * @see https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/send
316
- *
317
- * @example
318
- * io.on("connection", (socket) => {
319
- * socket.send("hello");
320
- *
321
- * // this is equivalent to
322
- * socket.emit("message", "hello");
323
- * });
324
- *
325
- * @return self
326
- */
327
- send(...args) {
328
- this.emit("message", ...args);
329
- return this;
330
- }
331
- /**
332
- * Sends a `message` event. Alias of {@link send}.
333
- *
334
- * @return self
335
- */
336
- write(...args) {
337
- this.emit("message", ...args);
338
- return this;
339
- }
340
- /**
341
- * Writes a packet.
342
- *
343
- * @param {Object} packet - packet object
344
- * @param {Object} opts - options
345
- * @private
346
- */
347
- packet(packet, opts = {}) {
348
- packet.nsp = this.nsp.name;
349
- opts.compress = false !== opts.compress;
350
- this.client._packet(packet, opts);
351
- }
352
- /**
353
- * Joins a room.
354
- *
355
- * @example
356
- * io.on("connection", (socket) => {
357
- * // join a single room
358
- * socket.join("room1");
359
- *
360
- * // join multiple rooms
361
- * socket.join(["room1", "room2"]);
362
- * });
363
- *
364
- * @param {String|Array} rooms - room or array of rooms
365
- * @return a Promise or nothing, depending on the adapter
366
- */
367
- join(rooms) {
368
- debug("join room %s", rooms);
369
- return this.adapter.addAll(this.id, new Set(Array.isArray(rooms) ? rooms : [rooms]));
370
- }
371
- /**
372
- * Leaves a room.
373
- *
374
- * @example
375
- * io.on("connection", (socket) => {
376
- * // leave a single room
377
- * socket.leave("room1");
378
- *
379
- * // leave multiple rooms
380
- * socket.leave("room1").leave("room2");
381
- * });
382
- *
383
- * @param {String} room
384
- * @return a Promise or nothing, depending on the adapter
385
- */
386
- leave(room) {
387
- debug("leave room %s", room);
388
- return this.adapter.del(this.id, room);
389
- }
390
- /**
391
- * Leave all rooms.
392
- *
393
- * @private
394
- */
395
- leaveAll() {
396
- this.adapter.delAll(this.id);
397
- }
398
- /**
399
- * Called by `Namespace` upon successful
400
- * middleware execution (ie: authorization).
401
- * Socket is added to namespace array before
402
- * call to join, so adapters can access it.
403
- *
404
- * @private
405
- */
406
- _onconnect() {
407
- debug("socket connected - writing packet");
408
- this.connected = true;
409
- this.join(this.id);
410
- if (this.conn.protocol === 3) {
411
- this.packet({ type: socket_io_parser_1.PacketType.CONNECT });
412
- }
413
- else {
414
- this.packet({
415
- type: socket_io_parser_1.PacketType.CONNECT,
416
- data: { sid: this.id, pid: this.pid },
417
- });
418
- }
419
- }
420
- /**
421
- * Called with each packet. Called by `Client`.
422
- *
423
- * @param {Object} packet
424
- * @private
425
- */
426
- _onpacket(packet) {
427
- debug("got packet %j", packet);
428
- switch (packet.type) {
429
- case socket_io_parser_1.PacketType.EVENT:
430
- this.onevent(packet);
431
- break;
432
- case socket_io_parser_1.PacketType.BINARY_EVENT:
433
- this.onevent(packet);
434
- break;
435
- case socket_io_parser_1.PacketType.ACK:
436
- this.onack(packet);
437
- break;
438
- case socket_io_parser_1.PacketType.BINARY_ACK:
439
- this.onack(packet);
440
- break;
441
- case socket_io_parser_1.PacketType.DISCONNECT:
442
- this.ondisconnect();
443
- break;
444
- }
445
- }
446
- /**
447
- * Called upon event packet.
448
- *
449
- * @param {Packet} packet - packet object
450
- * @private
451
- */
452
- onevent(packet) {
453
- const args = packet.data || [];
454
- debug("emitting event %j", args);
455
- if (null != packet.id) {
456
- debug("attaching ack callback to event");
457
- args.push(this.ack(packet.id));
458
- }
459
- if (this._anyListeners && this._anyListeners.length) {
460
- const listeners = this._anyListeners.slice();
461
- for (const listener of listeners) {
462
- listener.apply(this, args);
463
- }
464
- }
465
- this.dispatch(args);
466
- }
467
- /**
468
- * Produces an ack callback to emit with an event.
469
- *
470
- * @param {Number} id - packet id
471
- * @private
472
- */
473
- ack(id) {
474
- const self = this;
475
- let sent = false;
476
- return function () {
477
- // prevent double callbacks
478
- if (sent)
479
- return;
480
- const args = Array.prototype.slice.call(arguments);
481
- debug("sending ack %j", args);
482
- self.packet({
483
- id: id,
484
- type: socket_io_parser_1.PacketType.ACK,
485
- data: args,
486
- });
487
- sent = true;
488
- };
489
- }
490
- /**
491
- * Called upon ack packet.
492
- *
493
- * @private
494
- */
495
- onack(packet) {
496
- const ack = this.acks.get(packet.id);
497
- if ("function" == typeof ack) {
498
- debug("calling ack %s with %j", packet.id, packet.data);
499
- ack.apply(this, packet.data);
500
- this.acks.delete(packet.id);
501
- }
502
- else {
503
- debug("bad ack %s", packet.id);
504
- }
505
- }
506
- /**
507
- * Called upon client disconnect packet.
508
- *
509
- * @private
510
- */
511
- ondisconnect() {
512
- debug("got disconnect packet");
513
- this._onclose("client namespace disconnect");
514
- }
515
- /**
516
- * Handles a client error.
517
- *
518
- * @private
519
- */
520
- _onerror(err) {
521
- // FIXME the meaning of the "error" event is overloaded:
522
- // - it can be sent by the client (`socket.emit("error")`)
523
- // - it can be emitted when the connection encounters an error (an invalid packet for example)
524
- // - it can be emitted when a packet is rejected in a middleware (`socket.use()`)
525
- this.emitReserved("error", err);
526
- }
527
- /**
528
- * Called upon closing. Called by `Client`.
529
- *
530
- * @param {String} reason
531
- * @param description
532
- * @throw {Error} optional error object
533
- *
534
- * @private
535
- */
536
- _onclose(reason, description) {
537
- if (!this.connected)
538
- return this;
539
- debug("closing socket - reason %s", reason);
540
- this.emitReserved("disconnecting", reason, description);
541
- if (this.server._opts.connectionStateRecovery &&
542
- RECOVERABLE_DISCONNECT_REASONS.has(reason)) {
543
- debug("connection state recovery is enabled for sid %s", this.id);
544
- this.adapter.persistSession({
545
- sid: this.id,
546
- pid: this.pid,
547
- rooms: [...this.rooms],
548
- data: this.data,
549
- });
550
- }
551
- this._cleanup();
552
- this.client._remove(this);
553
- this.connected = false;
554
- this.emitReserved("disconnect", reason, description);
555
- return;
556
- }
557
- /**
558
- * Makes the socket leave all the rooms it was part of and prevents it from joining any other room
559
- *
560
- * @private
561
- */
562
- _cleanup() {
563
- this.leaveAll();
564
- this.nsp._remove(this);
565
- this.join = noop;
566
- }
567
- /**
568
- * Produces an `error` packet.
569
- *
570
- * @param {Object} err - error object
571
- *
572
- * @private
573
- */
574
- _error(err) {
575
- this.packet({ type: socket_io_parser_1.PacketType.CONNECT_ERROR, data: err });
576
- }
577
- /**
578
- * Disconnects this client.
579
- *
580
- * @example
581
- * io.on("connection", (socket) => {
582
- * // disconnect this socket (the connection might be kept alive for other namespaces)
583
- * socket.disconnect();
584
- *
585
- * // disconnect this socket and close the underlying connection
586
- * socket.disconnect(true);
587
- * })
588
- *
589
- * @param {Boolean} close - if `true`, closes the underlying connection
590
- * @return self
591
- */
592
- disconnect(close = false) {
593
- if (!this.connected)
594
- return this;
595
- if (close) {
596
- this.client._disconnect();
597
- }
598
- else {
599
- this.packet({ type: socket_io_parser_1.PacketType.DISCONNECT });
600
- this._onclose("server namespace disconnect");
601
- }
602
- return this;
603
- }
604
- /**
605
- * Sets the compress flag.
606
- *
607
- * @example
608
- * io.on("connection", (socket) => {
609
- * socket.compress(false).emit("hello");
610
- * });
611
- *
612
- * @param {Boolean} compress - if `true`, compresses the sending data
613
- * @return {Socket} self
614
- */
615
- compress(compress) {
616
- this.flags.compress = compress;
617
- return this;
618
- }
619
- /**
620
- * Sets a modifier for a subsequent event emission that the event data may be lost if the client is not ready to
621
- * receive messages (because of network slowness or other issues, or because they’re connected through long polling
622
- * and is in the middle of a request-response cycle).
623
- *
624
- * @example
625
- * io.on("connection", (socket) => {
626
- * socket.volatile.emit("hello"); // the client may or may not receive it
627
- * });
628
- *
629
- * @return {Socket} self
630
- */
631
- get volatile() {
632
- this.flags.volatile = true;
633
- return this;
634
- }
635
- /**
636
- * Sets a modifier for a subsequent event emission that the event data will only be broadcast to every sockets but the
637
- * sender.
638
- *
639
- * @example
640
- * io.on("connection", (socket) => {
641
- * // the “foo” event will be broadcast to all connected clients, except this socket
642
- * socket.broadcast.emit("foo", "bar");
643
- * });
644
- *
645
- * @return a new {@link BroadcastOperator} instance for chaining
646
- */
647
- get broadcast() {
648
- return this.newBroadcastOperator();
649
- }
650
- /**
651
- * Sets a modifier for a subsequent event emission that the event data will only be broadcast to the current node.
652
- *
653
- * @example
654
- * io.on("connection", (socket) => {
655
- * // the “foo” event will be broadcast to all connected clients on this node, except this socket
656
- * socket.local.emit("foo", "bar");
657
- * });
658
- *
659
- * @return a new {@link BroadcastOperator} instance for chaining
660
- */
661
- get local() {
662
- return this.newBroadcastOperator().local;
663
- }
664
- /**
665
- * Sets a modifier for a subsequent event emission that the callback will be called with an error when the
666
- * given number of milliseconds have elapsed without an acknowledgement from the client:
667
- *
668
- * @example
669
- * io.on("connection", (socket) => {
670
- * socket.timeout(5000).emit("my-event", (err) => {
671
- * if (err) {
672
- * // the client did not acknowledge the event in the given delay
673
- * }
674
- * });
675
- * });
676
- *
677
- * @returns self
678
- */
679
- timeout(timeout) {
680
- this.flags.timeout = timeout;
681
- return this;
682
- }
683
- /**
684
- * Dispatch incoming event to socket listeners.
685
- *
686
- * @param {Array} event - event that will get emitted
687
- * @private
688
- */
689
- dispatch(event) {
690
- debug("dispatching an event %j", event);
691
- this.run(event, (err) => {
692
- process.nextTick(() => {
693
- if (err) {
694
- return this._onerror(err);
695
- }
696
- if (this.connected) {
697
- super.emitUntyped.apply(this, event);
698
- }
699
- else {
700
- debug("ignore packet received after disconnection");
701
- }
702
- });
703
- });
704
- }
705
- /**
706
- * Sets up socket middleware.
707
- *
708
- * @example
709
- * io.on("connection", (socket) => {
710
- * socket.use(([event, ...args], next) => {
711
- * if (isUnauthorized(event)) {
712
- * return next(new Error("unauthorized event"));
713
- * }
714
- * // do not forget to call next
715
- * next();
716
- * });
717
- *
718
- * socket.on("error", (err) => {
719
- * if (err && err.message === "unauthorized event") {
720
- * socket.disconnect();
721
- * }
722
- * });
723
- * });
724
- *
725
- * @param {Function} fn - middleware function (event, next)
726
- * @return {Socket} self
727
- */
728
- use(fn) {
729
- this.fns.push(fn);
730
- return this;
731
- }
732
- /**
733
- * Executes the middleware for an incoming event.
734
- *
735
- * @param {Array} event - event that will get emitted
736
- * @param {Function} fn - last fn call in the middleware
737
- * @private
738
- */
739
- run(event, fn) {
740
- if (!this.fns.length)
741
- return fn();
742
- const fns = this.fns.slice(0);
743
- function run(i) {
744
- fns[i](event, (err) => {
745
- // upon error, short-circuit
746
- if (err)
747
- return fn(err);
748
- // if no middleware left, summon callback
749
- if (!fns[i + 1])
750
- return fn();
751
- // go on to next
752
- run(i + 1);
753
- });
754
- }
755
- run(0);
756
- }
757
- /**
758
- * Whether the socket is currently disconnected
759
- */
760
- get disconnected() {
761
- return !this.connected;
762
- }
763
- /**
764
- * A reference to the request that originated the underlying Engine.IO Socket.
765
- */
766
- get request() {
767
- return this.client.request;
768
- }
769
- /**
770
- * A reference to the underlying Client transport connection (Engine.IO Socket object).
771
- *
772
- * @example
773
- * io.on("connection", (socket) => {
774
- * console.log(socket.conn.transport.name); // prints "polling" or "websocket"
775
- *
776
- * socket.conn.once("upgrade", () => {
777
- * console.log(socket.conn.transport.name); // prints "websocket"
778
- * });
779
- * });
780
- */
781
- get conn() {
782
- return this.client.conn;
783
- }
784
- /**
785
- * Returns the rooms the socket is currently in.
786
- *
787
- * @example
788
- * io.on("connection", (socket) => {
789
- * console.log(socket.rooms); // Set { <socket.id> }
790
- *
791
- * socket.join("room1");
792
- *
793
- * console.log(socket.rooms); // Set { <socket.id>, "room1" }
794
- * });
795
- */
796
- get rooms() {
797
- return this.adapter.socketRooms(this.id) || new Set();
798
- }
799
- /**
800
- * Adds a listener that will be fired when any event is received. The event name is passed as the first argument to
801
- * the callback.
802
- *
803
- * @example
804
- * io.on("connection", (socket) => {
805
- * socket.onAny((event, ...args) => {
806
- * console.log(`got event ${event}`);
807
- * });
808
- * });
809
- *
810
- * @param listener
811
- */
812
- onAny(listener) {
813
- this._anyListeners = this._anyListeners || [];
814
- this._anyListeners.push(listener);
815
- return this;
816
- }
817
- /**
818
- * Adds a listener that will be fired when any event is received. The event name is passed as the first argument to
819
- * the callback. The listener is added to the beginning of the listeners array.
820
- *
821
- * @param listener
822
- */
823
- prependAny(listener) {
824
- this._anyListeners = this._anyListeners || [];
825
- this._anyListeners.unshift(listener);
826
- return this;
827
- }
828
- /**
829
- * Removes the listener that will be fired when any event is received.
830
- *
831
- * @example
832
- * io.on("connection", (socket) => {
833
- * const catchAllListener = (event, ...args) => {
834
- * console.log(`got event ${event}`);
835
- * }
836
- *
837
- * socket.onAny(catchAllListener);
838
- *
839
- * // remove a specific listener
840
- * socket.offAny(catchAllListener);
841
- *
842
- * // or remove all listeners
843
- * socket.offAny();
844
- * });
845
- *
846
- * @param listener
847
- */
848
- offAny(listener) {
849
- if (!this._anyListeners) {
850
- return this;
851
- }
852
- if (listener) {
853
- const listeners = this._anyListeners;
854
- for (let i = 0; i < listeners.length; i++) {
855
- if (listener === listeners[i]) {
856
- listeners.splice(i, 1);
857
- return this;
858
- }
859
- }
860
- }
861
- else {
862
- this._anyListeners = [];
863
- }
864
- return this;
865
- }
866
- /**
867
- * Returns an array of listeners that are listening for any event that is specified. This array can be manipulated,
868
- * e.g. to remove listeners.
869
- */
870
- listenersAny() {
871
- return this._anyListeners || [];
872
- }
873
- /**
874
- * Adds a listener that will be fired when any event is sent. The event name is passed as the first argument to
875
- * the callback.
876
- *
877
- * Note: acknowledgements sent to the client are not included.
878
- *
879
- * @example
880
- * io.on("connection", (socket) => {
881
- * socket.onAnyOutgoing((event, ...args) => {
882
- * console.log(`sent event ${event}`);
883
- * });
884
- * });
885
- *
886
- * @param listener
887
- */
888
- onAnyOutgoing(listener) {
889
- this._anyOutgoingListeners = this._anyOutgoingListeners || [];
890
- this._anyOutgoingListeners.push(listener);
891
- return this;
892
- }
893
- /**
894
- * Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the
895
- * callback. The listener is added to the beginning of the listeners array.
896
- *
897
- * @example
898
- * io.on("connection", (socket) => {
899
- * socket.prependAnyOutgoing((event, ...args) => {
900
- * console.log(`sent event ${event}`);
901
- * });
902
- * });
903
- *
904
- * @param listener
905
- */
906
- prependAnyOutgoing(listener) {
907
- this._anyOutgoingListeners = this._anyOutgoingListeners || [];
908
- this._anyOutgoingListeners.unshift(listener);
909
- return this;
910
- }
911
- /**
912
- * Removes the listener that will be fired when any event is sent.
913
- *
914
- * @example
915
- * io.on("connection", (socket) => {
916
- * const catchAllListener = (event, ...args) => {
917
- * console.log(`sent event ${event}`);
918
- * }
919
- *
920
- * socket.onAnyOutgoing(catchAllListener);
921
- *
922
- * // remove a specific listener
923
- * socket.offAnyOutgoing(catchAllListener);
924
- *
925
- * // or remove all listeners
926
- * socket.offAnyOutgoing();
927
- * });
928
- *
929
- * @param listener - the catch-all listener
930
- */
931
- offAnyOutgoing(listener) {
932
- if (!this._anyOutgoingListeners) {
933
- return this;
934
- }
935
- if (listener) {
936
- const listeners = this._anyOutgoingListeners;
937
- for (let i = 0; i < listeners.length; i++) {
938
- if (listener === listeners[i]) {
939
- listeners.splice(i, 1);
940
- return this;
941
- }
942
- }
943
- }
944
- else {
945
- this._anyOutgoingListeners = [];
946
- }
947
- return this;
948
- }
949
- /**
950
- * Returns an array of listeners that are listening for any event that is specified. This array can be manipulated,
951
- * e.g. to remove listeners.
952
- */
953
- listenersAnyOutgoing() {
954
- return this._anyOutgoingListeners || [];
955
- }
956
- /**
957
- * Notify the listeners for each packet sent (emit or broadcast)
958
- *
959
- * @param packet
960
- *
961
- * @private
962
- */
963
- notifyOutgoingListeners(packet) {
964
- if (this._anyOutgoingListeners && this._anyOutgoingListeners.length) {
965
- const listeners = this._anyOutgoingListeners.slice();
966
- for (const listener of listeners) {
967
- listener.apply(this, packet.data);
968
- }
969
- }
970
- }
971
- newBroadcastOperator() {
972
- const flags = Object.assign({}, this.flags);
973
- this.flags = {};
974
- return new broadcast_operator_1.BroadcastOperator(this.adapter, new Set(), new Set([this.id]), flags);
975
- }
976
- }
977
- exports.Socket = Socket;