lightclaw2 0.0.1
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.
- package/README.md +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/src/channel.d.ts +11 -0
- package/dist/src/channel.d.ts.map +1 -0
- package/dist/src/channel.js +255 -0
- package/dist/src/channel.js.map +1 -0
- package/dist/src/config.d.ts +29 -0
- package/dist/src/config.d.ts.map +1 -0
- package/dist/src/config.js +99 -0
- package/dist/src/config.js.map +1 -0
- package/dist/src/dedup.d.ts +7 -0
- package/dist/src/dedup.d.ts.map +1 -0
- package/dist/src/dedup.js +52 -0
- package/dist/src/dedup.js.map +1 -0
- package/dist/src/gateway.d.ts +16 -0
- package/dist/src/gateway.d.ts.map +1 -0
- package/dist/src/gateway.js +283 -0
- package/dist/src/gateway.js.map +1 -0
- package/dist/src/inbound.d.ts +18 -0
- package/dist/src/inbound.d.ts.map +1 -0
- package/dist/src/inbound.js +252 -0
- package/dist/src/inbound.js.map +1 -0
- package/dist/src/media.d.ts +12 -0
- package/dist/src/media.d.ts.map +1 -0
- package/dist/src/media.js +87 -0
- package/dist/src/media.js.map +1 -0
- package/dist/src/outbound.d.ts +28 -0
- package/dist/src/outbound.d.ts.map +1 -0
- package/dist/src/outbound.js +172 -0
- package/dist/src/outbound.js.map +1 -0
- package/dist/src/runtime.d.ts +4 -0
- package/dist/src/runtime.d.ts.map +1 -0
- package/dist/src/runtime.js +11 -0
- package/dist/src/runtime.js.map +1 -0
- package/dist/src/session-history.d.ts +88 -0
- package/dist/src/session-history.d.ts.map +1 -0
- package/dist/src/session-history.js +545 -0
- package/dist/src/session-history.js.map +1 -0
- package/dist/src/socket-handlers.d.ts +21 -0
- package/dist/src/socket-handlers.d.ts.map +1 -0
- package/dist/src/socket-handlers.js +120 -0
- package/dist/src/socket-handlers.js.map +1 -0
- package/dist/src/socket-registry.d.ts +53 -0
- package/dist/src/socket-registry.d.ts.map +1 -0
- package/dist/src/socket-registry.js +115 -0
- package/dist/src/socket-registry.js.map +1 -0
- package/dist/src/types.d.ts +100 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +10 -0
- package/dist/src/types.js.map +1 -0
- package/node_modules/@socket.io/component-emitter/LICENSE +24 -0
- package/node_modules/@socket.io/component-emitter/Readme.md +79 -0
- package/node_modules/@socket.io/component-emitter/lib/cjs/index.d.ts +179 -0
- package/node_modules/@socket.io/component-emitter/lib/cjs/index.js +176 -0
- package/node_modules/@socket.io/component-emitter/lib/cjs/package.json +4 -0
- package/node_modules/@socket.io/component-emitter/lib/esm/index.d.ts +179 -0
- package/node_modules/@socket.io/component-emitter/lib/esm/index.js +169 -0
- package/node_modules/@socket.io/component-emitter/lib/esm/package.json +4 -0
- package/node_modules/@socket.io/component-emitter/package.json +28 -0
- package/node_modules/debug/LICENSE +20 -0
- package/node_modules/debug/README.md +481 -0
- package/node_modules/debug/package.json +64 -0
- package/node_modules/debug/src/browser.js +272 -0
- package/node_modules/debug/src/common.js +292 -0
- package/node_modules/debug/src/index.js +10 -0
- package/node_modules/debug/src/node.js +263 -0
- package/node_modules/engine.io-client/LICENSE +22 -0
- package/node_modules/engine.io-client/README.md +331 -0
- package/node_modules/engine.io-client/build/cjs/browser-entrypoint.d.ts +3 -0
- package/node_modules/engine.io-client/build/cjs/browser-entrypoint.js +4 -0
- package/node_modules/engine.io-client/build/cjs/contrib/has-cors.d.ts +1 -0
- package/node_modules/engine.io-client/build/cjs/contrib/has-cors.js +14 -0
- package/node_modules/engine.io-client/build/cjs/contrib/parseqs.d.ts +15 -0
- package/node_modules/engine.io-client/build/cjs/contrib/parseqs.js +38 -0
- package/node_modules/engine.io-client/build/cjs/contrib/parseuri.d.ts +1 -0
- package/node_modules/engine.io-client/build/cjs/contrib/parseuri.js +67 -0
- package/node_modules/engine.io-client/build/cjs/globals.d.ts +4 -0
- package/node_modules/engine.io-client/build/cjs/globals.js +26 -0
- package/node_modules/engine.io-client/build/cjs/globals.node.d.ts +21 -0
- package/node_modules/engine.io-client/build/cjs/globals.node.js +97 -0
- package/node_modules/engine.io-client/build/cjs/index.d.ts +15 -0
- package/node_modules/engine.io-client/build/cjs/index.js +32 -0
- package/node_modules/engine.io-client/build/cjs/package.json +10 -0
- package/node_modules/engine.io-client/build/cjs/socket.d.ts +482 -0
- package/node_modules/engine.io-client/build/cjs/socket.js +765 -0
- package/node_modules/engine.io-client/build/cjs/transport.d.ts +106 -0
- package/node_modules/engine.io-client/build/cjs/transport.js +153 -0
- package/node_modules/engine.io-client/build/cjs/transports/index.d.ts +8 -0
- package/node_modules/engine.io-client/build/cjs/transports/index.js +11 -0
- package/node_modules/engine.io-client/build/cjs/transports/polling-fetch.d.ts +15 -0
- package/node_modules/engine.io-client/build/cjs/transports/polling-fetch.js +60 -0
- package/node_modules/engine.io-client/build/cjs/transports/polling-xhr.d.ts +108 -0
- package/node_modules/engine.io-client/build/cjs/transports/polling-xhr.js +285 -0
- package/node_modules/engine.io-client/build/cjs/transports/polling-xhr.node.d.ts +11 -0
- package/node_modules/engine.io-client/build/cjs/transports/polling-xhr.node.js +44 -0
- package/node_modules/engine.io-client/build/cjs/transports/polling.d.ts +52 -0
- package/node_modules/engine.io-client/build/cjs/transports/polling.js +165 -0
- package/node_modules/engine.io-client/build/cjs/transports/websocket.d.ts +36 -0
- package/node_modules/engine.io-client/build/cjs/transports/websocket.js +136 -0
- package/node_modules/engine.io-client/build/cjs/transports/websocket.node.d.ts +14 -0
- package/node_modules/engine.io-client/build/cjs/transports/websocket.node.js +68 -0
- package/node_modules/engine.io-client/build/cjs/transports/webtransport.d.ts +18 -0
- package/node_modules/engine.io-client/build/cjs/transports/webtransport.js +94 -0
- package/node_modules/engine.io-client/build/cjs/util.d.ts +7 -0
- package/node_modules/engine.io-client/build/cjs/util.js +65 -0
- package/node_modules/engine.io-client/build/esm/browser-entrypoint.d.ts +3 -0
- package/node_modules/engine.io-client/build/esm/browser-entrypoint.js +2 -0
- package/node_modules/engine.io-client/build/esm/contrib/has-cors.d.ts +1 -0
- package/node_modules/engine.io-client/build/esm/contrib/has-cors.js +11 -0
- package/node_modules/engine.io-client/build/esm/contrib/parseqs.d.ts +15 -0
- package/node_modules/engine.io-client/build/esm/contrib/parseqs.js +34 -0
- package/node_modules/engine.io-client/build/esm/contrib/parseuri.d.ts +1 -0
- package/node_modules/engine.io-client/build/esm/contrib/parseuri.js +64 -0
- package/node_modules/engine.io-client/build/esm/globals.d.ts +4 -0
- package/node_modules/engine.io-client/build/esm/globals.js +22 -0
- package/node_modules/engine.io-client/build/esm/globals.node.d.ts +21 -0
- package/node_modules/engine.io-client/build/esm/globals.node.js +91 -0
- package/node_modules/engine.io-client/build/esm/index.d.ts +15 -0
- package/node_modules/engine.io-client/build/esm/index.js +15 -0
- package/node_modules/engine.io-client/build/esm/package.json +10 -0
- package/node_modules/engine.io-client/build/esm/socket.d.ts +482 -0
- package/node_modules/engine.io-client/build/esm/socket.js +727 -0
- package/node_modules/engine.io-client/build/esm/transport.d.ts +106 -0
- package/node_modules/engine.io-client/build/esm/transport.js +142 -0
- package/node_modules/engine.io-client/build/esm/transports/index.d.ts +8 -0
- package/node_modules/engine.io-client/build/esm/transports/index.js +8 -0
- package/node_modules/engine.io-client/build/esm/transports/polling-fetch.d.ts +15 -0
- package/node_modules/engine.io-client/build/esm/transports/polling-fetch.js +56 -0
- package/node_modules/engine.io-client/build/esm/transports/polling-xhr.d.ts +108 -0
- package/node_modules/engine.io-client/build/esm/transports/polling-xhr.js +271 -0
- package/node_modules/engine.io-client/build/esm/transports/polling-xhr.node.d.ts +11 -0
- package/node_modules/engine.io-client/build/esm/transports/polling-xhr.node.js +17 -0
- package/node_modules/engine.io-client/build/esm/transports/polling.d.ts +52 -0
- package/node_modules/engine.io-client/build/esm/transports/polling.js +145 -0
- package/node_modules/engine.io-client/build/esm/transports/websocket.d.ts +36 -0
- package/node_modules/engine.io-client/build/esm/transports/websocket.js +125 -0
- package/node_modules/engine.io-client/build/esm/transports/websocket.node.d.ts +14 -0
- package/node_modules/engine.io-client/build/esm/transports/websocket.node.js +41 -0
- package/node_modules/engine.io-client/build/esm/transports/webtransport.d.ts +18 -0
- package/node_modules/engine.io-client/build/esm/transports/webtransport.js +80 -0
- package/node_modules/engine.io-client/build/esm/util.d.ts +7 -0
- package/node_modules/engine.io-client/build/esm/util.js +59 -0
- package/node_modules/engine.io-client/build/esm-debug/browser-entrypoint.d.ts +3 -0
- package/node_modules/engine.io-client/build/esm-debug/browser-entrypoint.js +2 -0
- package/node_modules/engine.io-client/build/esm-debug/contrib/has-cors.d.ts +1 -0
- package/node_modules/engine.io-client/build/esm-debug/contrib/has-cors.js +11 -0
- package/node_modules/engine.io-client/build/esm-debug/contrib/parseqs.d.ts +15 -0
- package/node_modules/engine.io-client/build/esm-debug/contrib/parseqs.js +34 -0
- package/node_modules/engine.io-client/build/esm-debug/contrib/parseuri.d.ts +1 -0
- package/node_modules/engine.io-client/build/esm-debug/contrib/parseuri.js +64 -0
- package/node_modules/engine.io-client/build/esm-debug/globals.d.ts +4 -0
- package/node_modules/engine.io-client/build/esm-debug/globals.js +22 -0
- package/node_modules/engine.io-client/build/esm-debug/globals.node.d.ts +21 -0
- package/node_modules/engine.io-client/build/esm-debug/globals.node.js +91 -0
- package/node_modules/engine.io-client/build/esm-debug/index.d.ts +15 -0
- package/node_modules/engine.io-client/build/esm-debug/index.js +15 -0
- package/node_modules/engine.io-client/build/esm-debug/package.json +10 -0
- package/node_modules/engine.io-client/build/esm-debug/socket.d.ts +482 -0
- package/node_modules/engine.io-client/build/esm-debug/socket.js +756 -0
- package/node_modules/engine.io-client/build/esm-debug/transport.d.ts +106 -0
- package/node_modules/engine.io-client/build/esm-debug/transport.js +145 -0
- package/node_modules/engine.io-client/build/esm-debug/transports/index.d.ts +8 -0
- package/node_modules/engine.io-client/build/esm-debug/transports/index.js +8 -0
- package/node_modules/engine.io-client/build/esm-debug/transports/polling-fetch.d.ts +15 -0
- package/node_modules/engine.io-client/build/esm-debug/transports/polling-fetch.js +56 -0
- package/node_modules/engine.io-client/build/esm-debug/transports/polling-xhr.d.ts +108 -0
- package/node_modules/engine.io-client/build/esm-debug/transports/polling-xhr.js +276 -0
- package/node_modules/engine.io-client/build/esm-debug/transports/polling-xhr.node.d.ts +11 -0
- package/node_modules/engine.io-client/build/esm-debug/transports/polling-xhr.node.js +17 -0
- package/node_modules/engine.io-client/build/esm-debug/transports/polling.d.ts +52 -0
- package/node_modules/engine.io-client/build/esm-debug/transports/polling.js +158 -0
- package/node_modules/engine.io-client/build/esm-debug/transports/websocket.d.ts +36 -0
- package/node_modules/engine.io-client/build/esm-debug/transports/websocket.js +128 -0
- package/node_modules/engine.io-client/build/esm-debug/transports/websocket.node.d.ts +14 -0
- package/node_modules/engine.io-client/build/esm-debug/transports/websocket.node.js +41 -0
- package/node_modules/engine.io-client/build/esm-debug/transports/webtransport.d.ts +18 -0
- package/node_modules/engine.io-client/build/esm-debug/transports/webtransport.js +87 -0
- package/node_modules/engine.io-client/build/esm-debug/util.d.ts +7 -0
- package/node_modules/engine.io-client/build/esm-debug/util.js +59 -0
- package/node_modules/engine.io-client/dist/engine.io.esm.min.js +7 -0
- package/node_modules/engine.io-client/dist/engine.io.esm.min.js.map +1 -0
- package/node_modules/engine.io-client/dist/engine.io.js +3064 -0
- package/node_modules/engine.io-client/dist/engine.io.js.map +1 -0
- package/node_modules/engine.io-client/dist/engine.io.min.js +7 -0
- package/node_modules/engine.io-client/dist/engine.io.min.js.map +1 -0
- package/node_modules/engine.io-client/node_modules/ws/LICENSE +20 -0
- package/node_modules/engine.io-client/node_modules/ws/README.md +548 -0
- package/node_modules/engine.io-client/node_modules/ws/browser.js +8 -0
- package/node_modules/engine.io-client/node_modules/ws/index.js +13 -0
- package/node_modules/engine.io-client/node_modules/ws/lib/buffer-util.js +131 -0
- package/node_modules/engine.io-client/node_modules/ws/lib/constants.js +18 -0
- package/node_modules/engine.io-client/node_modules/ws/lib/event-target.js +292 -0
- package/node_modules/engine.io-client/node_modules/ws/lib/extension.js +203 -0
- package/node_modules/engine.io-client/node_modules/ws/lib/limiter.js +55 -0
- package/node_modules/engine.io-client/node_modules/ws/lib/permessage-deflate.js +528 -0
- package/node_modules/engine.io-client/node_modules/ws/lib/receiver.js +706 -0
- package/node_modules/engine.io-client/node_modules/ws/lib/sender.js +602 -0
- package/node_modules/engine.io-client/node_modules/ws/lib/stream.js +161 -0
- package/node_modules/engine.io-client/node_modules/ws/lib/subprotocol.js +62 -0
- package/node_modules/engine.io-client/node_modules/ws/lib/validation.js +152 -0
- package/node_modules/engine.io-client/node_modules/ws/lib/websocket-server.js +550 -0
- package/node_modules/engine.io-client/node_modules/ws/lib/websocket.js +1388 -0
- package/node_modules/engine.io-client/node_modules/ws/package.json +69 -0
- package/node_modules/engine.io-client/node_modules/ws/wrapper.mjs +8 -0
- package/node_modules/engine.io-client/package.json +95 -0
- package/node_modules/engine.io-parser/LICENSE +22 -0
- package/node_modules/engine.io-parser/Readme.md +158 -0
- package/node_modules/engine.io-parser/build/cjs/commons.d.ts +14 -0
- package/node_modules/engine.io-parser/build/cjs/commons.js +19 -0
- package/node_modules/engine.io-parser/build/cjs/contrib/base64-arraybuffer.d.ts +2 -0
- package/node_modules/engine.io-parser/build/cjs/contrib/base64-arraybuffer.js +48 -0
- package/node_modules/engine.io-parser/build/cjs/decodePacket.browser.d.ts +2 -0
- package/node_modules/engine.io-parser/build/cjs/decodePacket.browser.js +66 -0
- package/node_modules/engine.io-parser/build/cjs/decodePacket.d.ts +2 -0
- package/node_modules/engine.io-parser/build/cjs/decodePacket.js +59 -0
- package/node_modules/engine.io-parser/build/cjs/encodePacket.browser.d.ts +4 -0
- package/node_modules/engine.io-parser/build/cjs/encodePacket.browser.js +72 -0
- package/node_modules/engine.io-parser/build/cjs/encodePacket.d.ts +3 -0
- package/node_modules/engine.io-parser/build/cjs/encodePacket.js +38 -0
- package/node_modules/engine.io-parser/build/cjs/index.d.ts +9 -0
- package/node_modules/engine.io-parser/build/cjs/index.js +164 -0
- package/node_modules/engine.io-parser/build/cjs/package.json +8 -0
- package/node_modules/engine.io-parser/build/esm/commons.d.ts +14 -0
- package/node_modules/engine.io-parser/build/esm/commons.js +14 -0
- package/node_modules/engine.io-parser/build/esm/contrib/base64-arraybuffer.d.ts +2 -0
- package/node_modules/engine.io-parser/build/esm/contrib/base64-arraybuffer.js +43 -0
- package/node_modules/engine.io-parser/build/esm/decodePacket.browser.d.ts +2 -0
- package/node_modules/engine.io-parser/build/esm/decodePacket.browser.js +62 -0
- package/node_modules/engine.io-parser/build/esm/decodePacket.d.ts +2 -0
- package/node_modules/engine.io-parser/build/esm/decodePacket.js +55 -0
- package/node_modules/engine.io-parser/build/esm/encodePacket.browser.d.ts +4 -0
- package/node_modules/engine.io-parser/build/esm/encodePacket.browser.js +68 -0
- package/node_modules/engine.io-parser/build/esm/encodePacket.d.ts +3 -0
- package/node_modules/engine.io-parser/build/esm/encodePacket.js +33 -0
- package/node_modules/engine.io-parser/build/esm/index.d.ts +9 -0
- package/node_modules/engine.io-parser/build/esm/index.js +156 -0
- package/node_modules/engine.io-parser/build/esm/package.json +8 -0
- package/node_modules/engine.io-parser/package.json +46 -0
- package/node_modules/ms/index.js +162 -0
- package/node_modules/ms/license.md +21 -0
- package/node_modules/ms/package.json +38 -0
- package/node_modules/ms/readme.md +59 -0
- package/node_modules/socket.io-client/LICENSE +21 -0
- package/node_modules/socket.io-client/README.md +29 -0
- package/node_modules/socket.io-client/build/cjs/browser-entrypoint.d.ts +2 -0
- package/node_modules/socket.io-client/build/cjs/browser-entrypoint.js +4 -0
- package/node_modules/socket.io-client/build/cjs/contrib/backo2.d.ts +12 -0
- package/node_modules/socket.io-client/build/cjs/contrib/backo2.js +69 -0
- package/node_modules/socket.io-client/build/cjs/index.d.ts +29 -0
- package/node_modules/socket.io-client/build/cjs/index.js +76 -0
- package/node_modules/socket.io-client/build/cjs/manager.d.ts +295 -0
- package/node_modules/socket.io-client/build/cjs/manager.js +416 -0
- package/node_modules/socket.io-client/build/cjs/on.d.ts +2 -0
- package/node_modules/socket.io-client/build/cjs/on.js +9 -0
- package/node_modules/socket.io-client/build/cjs/socket.d.ts +593 -0
- package/node_modules/socket.io-client/build/cjs/socket.js +909 -0
- package/node_modules/socket.io-client/build/cjs/url.d.ts +33 -0
- package/node_modules/socket.io-client/build/cjs/url.js +69 -0
- package/node_modules/socket.io-client/build/esm/browser-entrypoint.d.ts +2 -0
- package/node_modules/socket.io-client/build/esm/browser-entrypoint.js +2 -0
- package/node_modules/socket.io-client/build/esm/contrib/backo2.d.ts +12 -0
- package/node_modules/socket.io-client/build/esm/contrib/backo2.js +66 -0
- package/node_modules/socket.io-client/build/esm/index.d.ts +29 -0
- package/node_modules/socket.io-client/build/esm/index.js +58 -0
- package/node_modules/socket.io-client/build/esm/manager.d.ts +295 -0
- package/node_modules/socket.io-client/build/esm/manager.js +367 -0
- package/node_modules/socket.io-client/build/esm/on.d.ts +2 -0
- package/node_modules/socket.io-client/build/esm/on.js +6 -0
- package/node_modules/socket.io-client/build/esm/package.json +5 -0
- package/node_modules/socket.io-client/build/esm/socket.d.ts +593 -0
- package/node_modules/socket.io-client/build/esm/socket.js +880 -0
- package/node_modules/socket.io-client/build/esm/url.d.ts +33 -0
- package/node_modules/socket.io-client/build/esm/url.js +59 -0
- package/node_modules/socket.io-client/build/esm-debug/browser-entrypoint.d.ts +2 -0
- package/node_modules/socket.io-client/build/esm-debug/browser-entrypoint.js +2 -0
- package/node_modules/socket.io-client/build/esm-debug/contrib/backo2.d.ts +12 -0
- package/node_modules/socket.io-client/build/esm-debug/contrib/backo2.js +66 -0
- package/node_modules/socket.io-client/build/esm-debug/index.d.ts +29 -0
- package/node_modules/socket.io-client/build/esm-debug/index.js +62 -0
- package/node_modules/socket.io-client/build/esm-debug/manager.d.ts +295 -0
- package/node_modules/socket.io-client/build/esm-debug/manager.js +386 -0
- package/node_modules/socket.io-client/build/esm-debug/on.d.ts +2 -0
- package/node_modules/socket.io-client/build/esm-debug/on.js +6 -0
- package/node_modules/socket.io-client/build/esm-debug/package.json +5 -0
- package/node_modules/socket.io-client/build/esm-debug/socket.d.ts +593 -0
- package/node_modules/socket.io-client/build/esm-debug/socket.js +902 -0
- package/node_modules/socket.io-client/build/esm-debug/url.d.ts +33 -0
- package/node_modules/socket.io-client/build/esm-debug/url.js +63 -0
- package/node_modules/socket.io-client/dist/socket.io.esm.min.js +7 -0
- package/node_modules/socket.io-client/dist/socket.io.esm.min.js.map +1 -0
- package/node_modules/socket.io-client/dist/socket.io.js +4955 -0
- package/node_modules/socket.io-client/dist/socket.io.js.map +1 -0
- package/node_modules/socket.io-client/dist/socket.io.min.js +7 -0
- package/node_modules/socket.io-client/dist/socket.io.min.js.map +1 -0
- package/node_modules/socket.io-client/dist/socket.io.msgpack.min.js +7 -0
- package/node_modules/socket.io-client/dist/socket.io.msgpack.min.js.map +1 -0
- package/node_modules/socket.io-client/package.json +101 -0
- package/node_modules/socket.io-parser/LICENSE +20 -0
- package/node_modules/socket.io-parser/Readme.md +81 -0
- package/node_modules/socket.io-parser/build/cjs/binary.d.ts +20 -0
- package/node_modules/socket.io-parser/build/cjs/binary.js +87 -0
- package/node_modules/socket.io-parser/build/cjs/index.d.ts +91 -0
- package/node_modules/socket.io-parser/build/cjs/index.js +359 -0
- package/node_modules/socket.io-parser/build/cjs/is-binary.d.ts +7 -0
- package/node_modules/socket.io-parser/build/cjs/is-binary.js +54 -0
- package/node_modules/socket.io-parser/build/cjs/package.json +3 -0
- package/node_modules/socket.io-parser/build/esm/binary.d.ts +20 -0
- package/node_modules/socket.io-parser/build/esm/binary.js +83 -0
- package/node_modules/socket.io-parser/build/esm/index.d.ts +91 -0
- package/node_modules/socket.io-parser/build/esm/index.js +348 -0
- package/node_modules/socket.io-parser/build/esm/is-binary.d.ts +7 -0
- package/node_modules/socket.io-parser/build/esm/is-binary.js +50 -0
- package/node_modules/socket.io-parser/build/esm/package.json +3 -0
- package/node_modules/socket.io-parser/build/esm-debug/binary.d.ts +20 -0
- package/node_modules/socket.io-parser/build/esm-debug/binary.js +83 -0
- package/node_modules/socket.io-parser/build/esm-debug/index.d.ts +91 -0
- package/node_modules/socket.io-parser/build/esm-debug/index.js +353 -0
- package/node_modules/socket.io-parser/build/esm-debug/is-binary.d.ts +7 -0
- package/node_modules/socket.io-parser/build/esm-debug/is-binary.js +50 -0
- package/node_modules/socket.io-parser/build/esm-debug/package.json +3 -0
- package/node_modules/socket.io-parser/package.json +44 -0
- package/node_modules/xmlhttprequest-ssl/LICENSE +22 -0
- package/node_modules/xmlhttprequest-ssl/README.md +67 -0
- package/node_modules/xmlhttprequest-ssl/lib/XMLHttpRequest.js +689 -0
- package/node_modules/xmlhttprequest-ssl/package.json +40 -0
- package/openclaw.plugin.json +17 -0
- package/package.json +61 -0
- package/skills/lightclaw-cron/SKILL.md +381 -0
|
@@ -0,0 +1,880 @@
|
|
|
1
|
+
import { PacketType } from "socket.io-parser";
|
|
2
|
+
import { on } from "./on.js";
|
|
3
|
+
import { Emitter, } from "@socket.io/component-emitter";
|
|
4
|
+
/**
|
|
5
|
+
* Internal events.
|
|
6
|
+
* These events can't be emitted by the user.
|
|
7
|
+
*/
|
|
8
|
+
const RESERVED_EVENTS = Object.freeze({
|
|
9
|
+
connect: 1,
|
|
10
|
+
connect_error: 1,
|
|
11
|
+
disconnect: 1,
|
|
12
|
+
disconnecting: 1,
|
|
13
|
+
// EventEmitter reserved events: https://nodejs.org/api/events.html#events_event_newlistener
|
|
14
|
+
newListener: 1,
|
|
15
|
+
removeListener: 1,
|
|
16
|
+
});
|
|
17
|
+
/**
|
|
18
|
+
* A Socket is the fundamental class for interacting with the server.
|
|
19
|
+
*
|
|
20
|
+
* A Socket belongs to a certain Namespace (by default /) and uses an underlying {@link Manager} to communicate.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* const socket = io();
|
|
24
|
+
*
|
|
25
|
+
* socket.on("connect", () => {
|
|
26
|
+
* console.log("connected");
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* // send an event to the server
|
|
30
|
+
* socket.emit("foo", "bar");
|
|
31
|
+
*
|
|
32
|
+
* socket.on("foobar", () => {
|
|
33
|
+
* // an event was received from the server
|
|
34
|
+
* });
|
|
35
|
+
*
|
|
36
|
+
* // upon disconnection
|
|
37
|
+
* socket.on("disconnect", (reason) => {
|
|
38
|
+
* console.log(`disconnected due to ${reason}`);
|
|
39
|
+
* });
|
|
40
|
+
*/
|
|
41
|
+
export class Socket extends Emitter {
|
|
42
|
+
/**
|
|
43
|
+
* `Socket` constructor.
|
|
44
|
+
*/
|
|
45
|
+
constructor(io, nsp, opts) {
|
|
46
|
+
super();
|
|
47
|
+
/**
|
|
48
|
+
* Whether the socket is currently connected to the server.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* const socket = io();
|
|
52
|
+
*
|
|
53
|
+
* socket.on("connect", () => {
|
|
54
|
+
* console.log(socket.connected); // true
|
|
55
|
+
* });
|
|
56
|
+
*
|
|
57
|
+
* socket.on("disconnect", () => {
|
|
58
|
+
* console.log(socket.connected); // false
|
|
59
|
+
* });
|
|
60
|
+
*/
|
|
61
|
+
this.connected = false;
|
|
62
|
+
/**
|
|
63
|
+
* Whether the connection state was recovered after a temporary disconnection. In that case, any missed packets will
|
|
64
|
+
* be transmitted by the server.
|
|
65
|
+
*/
|
|
66
|
+
this.recovered = false;
|
|
67
|
+
/**
|
|
68
|
+
* Buffer for packets received before the CONNECT packet
|
|
69
|
+
*/
|
|
70
|
+
this.receiveBuffer = [];
|
|
71
|
+
/**
|
|
72
|
+
* Buffer for packets that will be sent once the socket is connected
|
|
73
|
+
*/
|
|
74
|
+
this.sendBuffer = [];
|
|
75
|
+
/**
|
|
76
|
+
* The queue of packets to be sent with retry in case of failure.
|
|
77
|
+
*
|
|
78
|
+
* Packets are sent one by one, each waiting for the server acknowledgement, in order to guarantee the delivery order.
|
|
79
|
+
* @private
|
|
80
|
+
*/
|
|
81
|
+
this._queue = [];
|
|
82
|
+
/**
|
|
83
|
+
* A sequence to generate the ID of the {@link QueuedPacket}.
|
|
84
|
+
* @private
|
|
85
|
+
*/
|
|
86
|
+
this._queueSeq = 0;
|
|
87
|
+
this.ids = 0;
|
|
88
|
+
/**
|
|
89
|
+
* A map containing acknowledgement handlers.
|
|
90
|
+
*
|
|
91
|
+
* The `withError` attribute is used to differentiate handlers that accept an error as first argument:
|
|
92
|
+
*
|
|
93
|
+
* - `socket.emit("test", (err, value) => { ... })` with `ackTimeout` option
|
|
94
|
+
* - `socket.timeout(5000).emit("test", (err, value) => { ... })`
|
|
95
|
+
* - `const value = await socket.emitWithAck("test")`
|
|
96
|
+
*
|
|
97
|
+
* From those that don't:
|
|
98
|
+
*
|
|
99
|
+
* - `socket.emit("test", (value) => { ... });`
|
|
100
|
+
*
|
|
101
|
+
* In the first case, the handlers will be called with an error when:
|
|
102
|
+
*
|
|
103
|
+
* - the timeout is reached
|
|
104
|
+
* - the socket gets disconnected
|
|
105
|
+
*
|
|
106
|
+
* In the second case, the handlers will be simply discarded upon disconnection, since the client will never receive
|
|
107
|
+
* an acknowledgement from the server.
|
|
108
|
+
*
|
|
109
|
+
* @private
|
|
110
|
+
*/
|
|
111
|
+
this.acks = {};
|
|
112
|
+
this.flags = {};
|
|
113
|
+
this.io = io;
|
|
114
|
+
this.nsp = nsp;
|
|
115
|
+
if (opts && opts.auth) {
|
|
116
|
+
this.auth = opts.auth;
|
|
117
|
+
}
|
|
118
|
+
this._opts = Object.assign({}, opts);
|
|
119
|
+
if (this.io._autoConnect)
|
|
120
|
+
this.open();
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Whether the socket is currently disconnected
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* const socket = io();
|
|
127
|
+
*
|
|
128
|
+
* socket.on("connect", () => {
|
|
129
|
+
* console.log(socket.disconnected); // false
|
|
130
|
+
* });
|
|
131
|
+
*
|
|
132
|
+
* socket.on("disconnect", () => {
|
|
133
|
+
* console.log(socket.disconnected); // true
|
|
134
|
+
* });
|
|
135
|
+
*/
|
|
136
|
+
get disconnected() {
|
|
137
|
+
return !this.connected;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Subscribe to open, close and packet events
|
|
141
|
+
*
|
|
142
|
+
* @private
|
|
143
|
+
*/
|
|
144
|
+
subEvents() {
|
|
145
|
+
if (this.subs)
|
|
146
|
+
return;
|
|
147
|
+
const io = this.io;
|
|
148
|
+
this.subs = [
|
|
149
|
+
on(io, "open", this.onopen.bind(this)),
|
|
150
|
+
on(io, "packet", this.onpacket.bind(this)),
|
|
151
|
+
on(io, "error", this.onerror.bind(this)),
|
|
152
|
+
on(io, "close", this.onclose.bind(this)),
|
|
153
|
+
];
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Whether the Socket will try to reconnect when its Manager connects or reconnects.
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* const socket = io();
|
|
160
|
+
*
|
|
161
|
+
* console.log(socket.active); // true
|
|
162
|
+
*
|
|
163
|
+
* socket.on("disconnect", (reason) => {
|
|
164
|
+
* if (reason === "io server disconnect") {
|
|
165
|
+
* // the disconnection was initiated by the server, you need to manually reconnect
|
|
166
|
+
* console.log(socket.active); // false
|
|
167
|
+
* }
|
|
168
|
+
* // else the socket will automatically try to reconnect
|
|
169
|
+
* console.log(socket.active); // true
|
|
170
|
+
* });
|
|
171
|
+
*/
|
|
172
|
+
get active() {
|
|
173
|
+
return !!this.subs;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* "Opens" the socket.
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* const socket = io({
|
|
180
|
+
* autoConnect: false
|
|
181
|
+
* });
|
|
182
|
+
*
|
|
183
|
+
* socket.connect();
|
|
184
|
+
*/
|
|
185
|
+
connect() {
|
|
186
|
+
if (this.connected)
|
|
187
|
+
return this;
|
|
188
|
+
this.subEvents();
|
|
189
|
+
if (!this.io["_reconnecting"])
|
|
190
|
+
this.io.open(); // ensure open
|
|
191
|
+
if ("open" === this.io._readyState)
|
|
192
|
+
this.onopen();
|
|
193
|
+
return this;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Alias for {@link connect()}.
|
|
197
|
+
*/
|
|
198
|
+
open() {
|
|
199
|
+
return this.connect();
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Sends a `message` event.
|
|
203
|
+
*
|
|
204
|
+
* This method mimics the WebSocket.send() method.
|
|
205
|
+
*
|
|
206
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/send
|
|
207
|
+
*
|
|
208
|
+
* @example
|
|
209
|
+
* socket.send("hello");
|
|
210
|
+
*
|
|
211
|
+
* // this is equivalent to
|
|
212
|
+
* socket.emit("message", "hello");
|
|
213
|
+
*
|
|
214
|
+
* @return self
|
|
215
|
+
*/
|
|
216
|
+
send(...args) {
|
|
217
|
+
args.unshift("message");
|
|
218
|
+
this.emit.apply(this, args);
|
|
219
|
+
return this;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Override `emit`.
|
|
223
|
+
* If the event is in `events`, it's emitted normally.
|
|
224
|
+
*
|
|
225
|
+
* @example
|
|
226
|
+
* socket.emit("hello", "world");
|
|
227
|
+
*
|
|
228
|
+
* // all serializable datastructures are supported (no need to call JSON.stringify)
|
|
229
|
+
* socket.emit("hello", 1, "2", { 3: ["4"], 5: Uint8Array.from([6]) });
|
|
230
|
+
*
|
|
231
|
+
* // with an acknowledgement from the server
|
|
232
|
+
* socket.emit("hello", "world", (val) => {
|
|
233
|
+
* // ...
|
|
234
|
+
* });
|
|
235
|
+
*
|
|
236
|
+
* @return self
|
|
237
|
+
*/
|
|
238
|
+
emit(ev, ...args) {
|
|
239
|
+
var _a, _b, _c;
|
|
240
|
+
if (RESERVED_EVENTS.hasOwnProperty(ev)) {
|
|
241
|
+
throw new Error('"' + ev.toString() + '" is a reserved event name');
|
|
242
|
+
}
|
|
243
|
+
args.unshift(ev);
|
|
244
|
+
if (this._opts.retries && !this.flags.fromQueue && !this.flags.volatile) {
|
|
245
|
+
this._addToQueue(args);
|
|
246
|
+
return this;
|
|
247
|
+
}
|
|
248
|
+
const packet = {
|
|
249
|
+
type: PacketType.EVENT,
|
|
250
|
+
data: args,
|
|
251
|
+
};
|
|
252
|
+
packet.options = {};
|
|
253
|
+
packet.options.compress = this.flags.compress !== false;
|
|
254
|
+
// event ack callback
|
|
255
|
+
if ("function" === typeof args[args.length - 1]) {
|
|
256
|
+
const id = this.ids++;
|
|
257
|
+
const ack = args.pop();
|
|
258
|
+
this._registerAckCallback(id, ack);
|
|
259
|
+
packet.id = id;
|
|
260
|
+
}
|
|
261
|
+
const isTransportWritable = (_b = (_a = this.io.engine) === null || _a === void 0 ? void 0 : _a.transport) === null || _b === void 0 ? void 0 : _b.writable;
|
|
262
|
+
const isConnected = this.connected && !((_c = this.io.engine) === null || _c === void 0 ? void 0 : _c._hasPingExpired());
|
|
263
|
+
const discardPacket = this.flags.volatile && !isTransportWritable;
|
|
264
|
+
if (discardPacket) {
|
|
265
|
+
}
|
|
266
|
+
else if (isConnected) {
|
|
267
|
+
this.notifyOutgoingListeners(packet);
|
|
268
|
+
this.packet(packet);
|
|
269
|
+
}
|
|
270
|
+
else {
|
|
271
|
+
this.sendBuffer.push(packet);
|
|
272
|
+
}
|
|
273
|
+
this.flags = {};
|
|
274
|
+
return this;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* @private
|
|
278
|
+
*/
|
|
279
|
+
_registerAckCallback(id, ack) {
|
|
280
|
+
var _a;
|
|
281
|
+
const timeout = (_a = this.flags.timeout) !== null && _a !== void 0 ? _a : this._opts.ackTimeout;
|
|
282
|
+
if (timeout === undefined) {
|
|
283
|
+
this.acks[id] = ack;
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
// @ts-ignore
|
|
287
|
+
const timer = this.io.setTimeoutFn(() => {
|
|
288
|
+
delete this.acks[id];
|
|
289
|
+
for (let i = 0; i < this.sendBuffer.length; i++) {
|
|
290
|
+
if (this.sendBuffer[i].id === id) {
|
|
291
|
+
this.sendBuffer.splice(i, 1);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
ack.call(this, new Error("operation has timed out"));
|
|
295
|
+
}, timeout);
|
|
296
|
+
const fn = (...args) => {
|
|
297
|
+
// @ts-ignore
|
|
298
|
+
this.io.clearTimeoutFn(timer);
|
|
299
|
+
ack.apply(this, args);
|
|
300
|
+
};
|
|
301
|
+
fn.withError = true;
|
|
302
|
+
this.acks[id] = fn;
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Emits an event and waits for an acknowledgement
|
|
306
|
+
*
|
|
307
|
+
* @example
|
|
308
|
+
* // without timeout
|
|
309
|
+
* const response = await socket.emitWithAck("hello", "world");
|
|
310
|
+
*
|
|
311
|
+
* // with a specific timeout
|
|
312
|
+
* try {
|
|
313
|
+
* const response = await socket.timeout(1000).emitWithAck("hello", "world");
|
|
314
|
+
* } catch (err) {
|
|
315
|
+
* // the server did not acknowledge the event in the given delay
|
|
316
|
+
* }
|
|
317
|
+
*
|
|
318
|
+
* @return a Promise that will be fulfilled when the server acknowledges the event
|
|
319
|
+
*/
|
|
320
|
+
emitWithAck(ev, ...args) {
|
|
321
|
+
return new Promise((resolve, reject) => {
|
|
322
|
+
const fn = (arg1, arg2) => {
|
|
323
|
+
return arg1 ? reject(arg1) : resolve(arg2);
|
|
324
|
+
};
|
|
325
|
+
fn.withError = true;
|
|
326
|
+
args.push(fn);
|
|
327
|
+
this.emit(ev, ...args);
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Add the packet to the queue.
|
|
332
|
+
* @param args
|
|
333
|
+
* @private
|
|
334
|
+
*/
|
|
335
|
+
_addToQueue(args) {
|
|
336
|
+
let ack;
|
|
337
|
+
if (typeof args[args.length - 1] === "function") {
|
|
338
|
+
ack = args.pop();
|
|
339
|
+
}
|
|
340
|
+
const packet = {
|
|
341
|
+
id: this._queueSeq++,
|
|
342
|
+
tryCount: 0,
|
|
343
|
+
pending: false,
|
|
344
|
+
args,
|
|
345
|
+
flags: Object.assign({ fromQueue: true }, this.flags),
|
|
346
|
+
};
|
|
347
|
+
args.push((err, ...responseArgs) => {
|
|
348
|
+
if (packet !== this._queue[0]) {
|
|
349
|
+
}
|
|
350
|
+
const hasError = err !== null;
|
|
351
|
+
if (hasError) {
|
|
352
|
+
if (packet.tryCount > this._opts.retries) {
|
|
353
|
+
this._queue.shift();
|
|
354
|
+
if (ack) {
|
|
355
|
+
ack(err);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
else {
|
|
360
|
+
this._queue.shift();
|
|
361
|
+
if (ack) {
|
|
362
|
+
ack(null, ...responseArgs);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
packet.pending = false;
|
|
366
|
+
return this._drainQueue();
|
|
367
|
+
});
|
|
368
|
+
this._queue.push(packet);
|
|
369
|
+
this._drainQueue();
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Send the first packet of the queue, and wait for an acknowledgement from the server.
|
|
373
|
+
* @param force - whether to resend a packet that has not been acknowledged yet
|
|
374
|
+
*
|
|
375
|
+
* @private
|
|
376
|
+
*/
|
|
377
|
+
_drainQueue(force = false) {
|
|
378
|
+
if (!this.connected || this._queue.length === 0) {
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
const packet = this._queue[0];
|
|
382
|
+
if (packet.pending && !force) {
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
packet.pending = true;
|
|
386
|
+
packet.tryCount++;
|
|
387
|
+
this.flags = packet.flags;
|
|
388
|
+
this.emit.apply(this, packet.args);
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Sends a packet.
|
|
392
|
+
*
|
|
393
|
+
* @param packet
|
|
394
|
+
* @private
|
|
395
|
+
*/
|
|
396
|
+
packet(packet) {
|
|
397
|
+
packet.nsp = this.nsp;
|
|
398
|
+
this.io._packet(packet);
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Called upon engine `open`.
|
|
402
|
+
*
|
|
403
|
+
* @private
|
|
404
|
+
*/
|
|
405
|
+
onopen() {
|
|
406
|
+
if (typeof this.auth == "function") {
|
|
407
|
+
this.auth((data) => {
|
|
408
|
+
this._sendConnectPacket(data);
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
else {
|
|
412
|
+
this._sendConnectPacket(this.auth);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
/**
|
|
416
|
+
* Sends a CONNECT packet to initiate the Socket.IO session.
|
|
417
|
+
*
|
|
418
|
+
* @param data
|
|
419
|
+
* @private
|
|
420
|
+
*/
|
|
421
|
+
_sendConnectPacket(data) {
|
|
422
|
+
this.packet({
|
|
423
|
+
type: PacketType.CONNECT,
|
|
424
|
+
data: this._pid
|
|
425
|
+
? Object.assign({ pid: this._pid, offset: this._lastOffset }, data)
|
|
426
|
+
: data,
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
430
|
+
* Called upon engine or manager `error`.
|
|
431
|
+
*
|
|
432
|
+
* @param err
|
|
433
|
+
* @private
|
|
434
|
+
*/
|
|
435
|
+
onerror(err) {
|
|
436
|
+
if (!this.connected) {
|
|
437
|
+
this.emitReserved("connect_error", err);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
/**
|
|
441
|
+
* Called upon engine `close`.
|
|
442
|
+
*
|
|
443
|
+
* @param reason
|
|
444
|
+
* @param description
|
|
445
|
+
* @private
|
|
446
|
+
*/
|
|
447
|
+
onclose(reason, description) {
|
|
448
|
+
this.connected = false;
|
|
449
|
+
delete this.id;
|
|
450
|
+
this.emitReserved("disconnect", reason, description);
|
|
451
|
+
this._clearAcks();
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* Clears the acknowledgement handlers upon disconnection, since the client will never receive an acknowledgement from
|
|
455
|
+
* the server.
|
|
456
|
+
*
|
|
457
|
+
* @private
|
|
458
|
+
*/
|
|
459
|
+
_clearAcks() {
|
|
460
|
+
Object.keys(this.acks).forEach((id) => {
|
|
461
|
+
const isBuffered = this.sendBuffer.some((packet) => String(packet.id) === id);
|
|
462
|
+
if (!isBuffered) {
|
|
463
|
+
// note: handlers that do not accept an error as first argument are ignored here
|
|
464
|
+
const ack = this.acks[id];
|
|
465
|
+
delete this.acks[id];
|
|
466
|
+
if (ack.withError) {
|
|
467
|
+
ack.call(this, new Error("socket has been disconnected"));
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
/**
|
|
473
|
+
* Called with socket packet.
|
|
474
|
+
*
|
|
475
|
+
* @param packet
|
|
476
|
+
* @private
|
|
477
|
+
*/
|
|
478
|
+
onpacket(packet) {
|
|
479
|
+
const sameNamespace = packet.nsp === this.nsp;
|
|
480
|
+
if (!sameNamespace)
|
|
481
|
+
return;
|
|
482
|
+
switch (packet.type) {
|
|
483
|
+
case PacketType.CONNECT:
|
|
484
|
+
if (packet.data && packet.data.sid) {
|
|
485
|
+
this.onconnect(packet.data.sid, packet.data.pid);
|
|
486
|
+
}
|
|
487
|
+
else {
|
|
488
|
+
this.emitReserved("connect_error", new Error("It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible (more information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/)"));
|
|
489
|
+
}
|
|
490
|
+
break;
|
|
491
|
+
case PacketType.EVENT:
|
|
492
|
+
case PacketType.BINARY_EVENT:
|
|
493
|
+
this.onevent(packet);
|
|
494
|
+
break;
|
|
495
|
+
case PacketType.ACK:
|
|
496
|
+
case PacketType.BINARY_ACK:
|
|
497
|
+
this.onack(packet);
|
|
498
|
+
break;
|
|
499
|
+
case PacketType.DISCONNECT:
|
|
500
|
+
this.ondisconnect();
|
|
501
|
+
break;
|
|
502
|
+
case PacketType.CONNECT_ERROR:
|
|
503
|
+
this.destroy();
|
|
504
|
+
const err = new Error(packet.data.message);
|
|
505
|
+
// @ts-ignore
|
|
506
|
+
err.data = packet.data.data;
|
|
507
|
+
this.emitReserved("connect_error", err);
|
|
508
|
+
break;
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
/**
|
|
512
|
+
* Called upon a server event.
|
|
513
|
+
*
|
|
514
|
+
* @param packet
|
|
515
|
+
* @private
|
|
516
|
+
*/
|
|
517
|
+
onevent(packet) {
|
|
518
|
+
const args = packet.data || [];
|
|
519
|
+
if (null != packet.id) {
|
|
520
|
+
args.push(this.ack(packet.id));
|
|
521
|
+
}
|
|
522
|
+
if (this.connected) {
|
|
523
|
+
this.emitEvent(args);
|
|
524
|
+
}
|
|
525
|
+
else {
|
|
526
|
+
this.receiveBuffer.push(Object.freeze(args));
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
emitEvent(args) {
|
|
530
|
+
if (this._anyListeners && this._anyListeners.length) {
|
|
531
|
+
const listeners = this._anyListeners.slice();
|
|
532
|
+
for (const listener of listeners) {
|
|
533
|
+
listener.apply(this, args);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
super.emit.apply(this, args);
|
|
537
|
+
if (this._pid && args.length && typeof args[args.length - 1] === "string") {
|
|
538
|
+
this._lastOffset = args[args.length - 1];
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* Produces an ack callback to emit with an event.
|
|
543
|
+
*
|
|
544
|
+
* @private
|
|
545
|
+
*/
|
|
546
|
+
ack(id) {
|
|
547
|
+
const self = this;
|
|
548
|
+
let sent = false;
|
|
549
|
+
return function (...args) {
|
|
550
|
+
// prevent double callbacks
|
|
551
|
+
if (sent)
|
|
552
|
+
return;
|
|
553
|
+
sent = true;
|
|
554
|
+
self.packet({
|
|
555
|
+
type: PacketType.ACK,
|
|
556
|
+
id: id,
|
|
557
|
+
data: args,
|
|
558
|
+
});
|
|
559
|
+
};
|
|
560
|
+
}
|
|
561
|
+
/**
|
|
562
|
+
* Called upon a server acknowledgement.
|
|
563
|
+
*
|
|
564
|
+
* @param packet
|
|
565
|
+
* @private
|
|
566
|
+
*/
|
|
567
|
+
onack(packet) {
|
|
568
|
+
const ack = this.acks[packet.id];
|
|
569
|
+
if (typeof ack !== "function") {
|
|
570
|
+
return;
|
|
571
|
+
}
|
|
572
|
+
delete this.acks[packet.id];
|
|
573
|
+
// @ts-ignore FIXME ack is incorrectly inferred as 'never'
|
|
574
|
+
if (ack.withError) {
|
|
575
|
+
packet.data.unshift(null);
|
|
576
|
+
}
|
|
577
|
+
// @ts-ignore
|
|
578
|
+
ack.apply(this, packet.data);
|
|
579
|
+
}
|
|
580
|
+
/**
|
|
581
|
+
* Called upon server connect.
|
|
582
|
+
*
|
|
583
|
+
* @private
|
|
584
|
+
*/
|
|
585
|
+
onconnect(id, pid) {
|
|
586
|
+
this.id = id;
|
|
587
|
+
this.recovered = pid && this._pid === pid;
|
|
588
|
+
this._pid = pid; // defined only if connection state recovery is enabled
|
|
589
|
+
this.connected = true;
|
|
590
|
+
this.emitBuffered();
|
|
591
|
+
this._drainQueue(true);
|
|
592
|
+
this.emitReserved("connect");
|
|
593
|
+
}
|
|
594
|
+
/**
|
|
595
|
+
* Emit buffered events (received and emitted).
|
|
596
|
+
*
|
|
597
|
+
* @private
|
|
598
|
+
*/
|
|
599
|
+
emitBuffered() {
|
|
600
|
+
this.receiveBuffer.forEach((args) => this.emitEvent(args));
|
|
601
|
+
this.receiveBuffer = [];
|
|
602
|
+
this.sendBuffer.forEach((packet) => {
|
|
603
|
+
this.notifyOutgoingListeners(packet);
|
|
604
|
+
this.packet(packet);
|
|
605
|
+
});
|
|
606
|
+
this.sendBuffer = [];
|
|
607
|
+
}
|
|
608
|
+
/**
|
|
609
|
+
* Called upon server disconnect.
|
|
610
|
+
*
|
|
611
|
+
* @private
|
|
612
|
+
*/
|
|
613
|
+
ondisconnect() {
|
|
614
|
+
this.destroy();
|
|
615
|
+
this.onclose("io server disconnect");
|
|
616
|
+
}
|
|
617
|
+
/**
|
|
618
|
+
* Called upon forced client/server side disconnections,
|
|
619
|
+
* this method ensures the manager stops tracking us and
|
|
620
|
+
* that reconnections don't get triggered for this.
|
|
621
|
+
*
|
|
622
|
+
* @private
|
|
623
|
+
*/
|
|
624
|
+
destroy() {
|
|
625
|
+
if (this.subs) {
|
|
626
|
+
// clean subscriptions to avoid reconnections
|
|
627
|
+
this.subs.forEach((subDestroy) => subDestroy());
|
|
628
|
+
this.subs = undefined;
|
|
629
|
+
}
|
|
630
|
+
this.io["_destroy"](this);
|
|
631
|
+
}
|
|
632
|
+
/**
|
|
633
|
+
* Disconnects the socket manually. In that case, the socket will not try to reconnect.
|
|
634
|
+
*
|
|
635
|
+
* If this is the last active Socket instance of the {@link Manager}, the low-level connection will be closed.
|
|
636
|
+
*
|
|
637
|
+
* @example
|
|
638
|
+
* const socket = io();
|
|
639
|
+
*
|
|
640
|
+
* socket.on("disconnect", (reason) => {
|
|
641
|
+
* // console.log(reason); prints "io client disconnect"
|
|
642
|
+
* });
|
|
643
|
+
*
|
|
644
|
+
* socket.disconnect();
|
|
645
|
+
*
|
|
646
|
+
* @return self
|
|
647
|
+
*/
|
|
648
|
+
disconnect() {
|
|
649
|
+
if (this.connected) {
|
|
650
|
+
this.packet({ type: PacketType.DISCONNECT });
|
|
651
|
+
}
|
|
652
|
+
// remove socket from pool
|
|
653
|
+
this.destroy();
|
|
654
|
+
if (this.connected) {
|
|
655
|
+
// fire events
|
|
656
|
+
this.onclose("io client disconnect");
|
|
657
|
+
}
|
|
658
|
+
return this;
|
|
659
|
+
}
|
|
660
|
+
/**
|
|
661
|
+
* Alias for {@link disconnect()}.
|
|
662
|
+
*
|
|
663
|
+
* @return self
|
|
664
|
+
*/
|
|
665
|
+
close() {
|
|
666
|
+
return this.disconnect();
|
|
667
|
+
}
|
|
668
|
+
/**
|
|
669
|
+
* Sets the compress flag.
|
|
670
|
+
*
|
|
671
|
+
* @example
|
|
672
|
+
* socket.compress(false).emit("hello");
|
|
673
|
+
*
|
|
674
|
+
* @param compress - if `true`, compresses the sending data
|
|
675
|
+
* @return self
|
|
676
|
+
*/
|
|
677
|
+
compress(compress) {
|
|
678
|
+
this.flags.compress = compress;
|
|
679
|
+
return this;
|
|
680
|
+
}
|
|
681
|
+
/**
|
|
682
|
+
* Sets a modifier for a subsequent event emission that the event message will be dropped when this socket is not
|
|
683
|
+
* ready to send messages.
|
|
684
|
+
*
|
|
685
|
+
* @example
|
|
686
|
+
* socket.volatile.emit("hello"); // the server may or may not receive it
|
|
687
|
+
*
|
|
688
|
+
* @returns self
|
|
689
|
+
*/
|
|
690
|
+
get volatile() {
|
|
691
|
+
this.flags.volatile = true;
|
|
692
|
+
return this;
|
|
693
|
+
}
|
|
694
|
+
/**
|
|
695
|
+
* Sets a modifier for a subsequent event emission that the callback will be called with an error when the
|
|
696
|
+
* given number of milliseconds have elapsed without an acknowledgement from the server:
|
|
697
|
+
*
|
|
698
|
+
* @example
|
|
699
|
+
* socket.timeout(5000).emit("my-event", (err) => {
|
|
700
|
+
* if (err) {
|
|
701
|
+
* // the server did not acknowledge the event in the given delay
|
|
702
|
+
* }
|
|
703
|
+
* });
|
|
704
|
+
*
|
|
705
|
+
* @returns self
|
|
706
|
+
*/
|
|
707
|
+
timeout(timeout) {
|
|
708
|
+
this.flags.timeout = timeout;
|
|
709
|
+
return this;
|
|
710
|
+
}
|
|
711
|
+
/**
|
|
712
|
+
* Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the
|
|
713
|
+
* callback.
|
|
714
|
+
*
|
|
715
|
+
* @example
|
|
716
|
+
* socket.onAny((event, ...args) => {
|
|
717
|
+
* console.log(`got ${event}`);
|
|
718
|
+
* });
|
|
719
|
+
*
|
|
720
|
+
* @param listener
|
|
721
|
+
*/
|
|
722
|
+
onAny(listener) {
|
|
723
|
+
this._anyListeners = this._anyListeners || [];
|
|
724
|
+
this._anyListeners.push(listener);
|
|
725
|
+
return this;
|
|
726
|
+
}
|
|
727
|
+
/**
|
|
728
|
+
* Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the
|
|
729
|
+
* callback. The listener is added to the beginning of the listeners array.
|
|
730
|
+
*
|
|
731
|
+
* @example
|
|
732
|
+
* socket.prependAny((event, ...args) => {
|
|
733
|
+
* console.log(`got event ${event}`);
|
|
734
|
+
* });
|
|
735
|
+
*
|
|
736
|
+
* @param listener
|
|
737
|
+
*/
|
|
738
|
+
prependAny(listener) {
|
|
739
|
+
this._anyListeners = this._anyListeners || [];
|
|
740
|
+
this._anyListeners.unshift(listener);
|
|
741
|
+
return this;
|
|
742
|
+
}
|
|
743
|
+
/**
|
|
744
|
+
* Removes the listener that will be fired when any event is emitted.
|
|
745
|
+
*
|
|
746
|
+
* @example
|
|
747
|
+
* const catchAllListener = (event, ...args) => {
|
|
748
|
+
* console.log(`got event ${event}`);
|
|
749
|
+
* }
|
|
750
|
+
*
|
|
751
|
+
* socket.onAny(catchAllListener);
|
|
752
|
+
*
|
|
753
|
+
* // remove a specific listener
|
|
754
|
+
* socket.offAny(catchAllListener);
|
|
755
|
+
*
|
|
756
|
+
* // or remove all listeners
|
|
757
|
+
* socket.offAny();
|
|
758
|
+
*
|
|
759
|
+
* @param listener
|
|
760
|
+
*/
|
|
761
|
+
offAny(listener) {
|
|
762
|
+
if (!this._anyListeners) {
|
|
763
|
+
return this;
|
|
764
|
+
}
|
|
765
|
+
if (listener) {
|
|
766
|
+
const listeners = this._anyListeners;
|
|
767
|
+
for (let i = 0; i < listeners.length; i++) {
|
|
768
|
+
if (listener === listeners[i]) {
|
|
769
|
+
listeners.splice(i, 1);
|
|
770
|
+
return this;
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
else {
|
|
775
|
+
this._anyListeners = [];
|
|
776
|
+
}
|
|
777
|
+
return this;
|
|
778
|
+
}
|
|
779
|
+
/**
|
|
780
|
+
* Returns an array of listeners that are listening for any event that is specified. This array can be manipulated,
|
|
781
|
+
* e.g. to remove listeners.
|
|
782
|
+
*/
|
|
783
|
+
listenersAny() {
|
|
784
|
+
return this._anyListeners || [];
|
|
785
|
+
}
|
|
786
|
+
/**
|
|
787
|
+
* Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the
|
|
788
|
+
* callback.
|
|
789
|
+
*
|
|
790
|
+
* Note: acknowledgements sent to the server are not included.
|
|
791
|
+
*
|
|
792
|
+
* @example
|
|
793
|
+
* socket.onAnyOutgoing((event, ...args) => {
|
|
794
|
+
* console.log(`sent event ${event}`);
|
|
795
|
+
* });
|
|
796
|
+
*
|
|
797
|
+
* @param listener
|
|
798
|
+
*/
|
|
799
|
+
onAnyOutgoing(listener) {
|
|
800
|
+
this._anyOutgoingListeners = this._anyOutgoingListeners || [];
|
|
801
|
+
this._anyOutgoingListeners.push(listener);
|
|
802
|
+
return this;
|
|
803
|
+
}
|
|
804
|
+
/**
|
|
805
|
+
* Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the
|
|
806
|
+
* callback. The listener is added to the beginning of the listeners array.
|
|
807
|
+
*
|
|
808
|
+
* Note: acknowledgements sent to the server are not included.
|
|
809
|
+
*
|
|
810
|
+
* @example
|
|
811
|
+
* socket.prependAnyOutgoing((event, ...args) => {
|
|
812
|
+
* console.log(`sent event ${event}`);
|
|
813
|
+
* });
|
|
814
|
+
*
|
|
815
|
+
* @param listener
|
|
816
|
+
*/
|
|
817
|
+
prependAnyOutgoing(listener) {
|
|
818
|
+
this._anyOutgoingListeners = this._anyOutgoingListeners || [];
|
|
819
|
+
this._anyOutgoingListeners.unshift(listener);
|
|
820
|
+
return this;
|
|
821
|
+
}
|
|
822
|
+
/**
|
|
823
|
+
* Removes the listener that will be fired when any event is emitted.
|
|
824
|
+
*
|
|
825
|
+
* @example
|
|
826
|
+
* const catchAllListener = (event, ...args) => {
|
|
827
|
+
* console.log(`sent event ${event}`);
|
|
828
|
+
* }
|
|
829
|
+
*
|
|
830
|
+
* socket.onAnyOutgoing(catchAllListener);
|
|
831
|
+
*
|
|
832
|
+
* // remove a specific listener
|
|
833
|
+
* socket.offAnyOutgoing(catchAllListener);
|
|
834
|
+
*
|
|
835
|
+
* // or remove all listeners
|
|
836
|
+
* socket.offAnyOutgoing();
|
|
837
|
+
*
|
|
838
|
+
* @param [listener] - the catch-all listener (optional)
|
|
839
|
+
*/
|
|
840
|
+
offAnyOutgoing(listener) {
|
|
841
|
+
if (!this._anyOutgoingListeners) {
|
|
842
|
+
return this;
|
|
843
|
+
}
|
|
844
|
+
if (listener) {
|
|
845
|
+
const listeners = this._anyOutgoingListeners;
|
|
846
|
+
for (let i = 0; i < listeners.length; i++) {
|
|
847
|
+
if (listener === listeners[i]) {
|
|
848
|
+
listeners.splice(i, 1);
|
|
849
|
+
return this;
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
else {
|
|
854
|
+
this._anyOutgoingListeners = [];
|
|
855
|
+
}
|
|
856
|
+
return this;
|
|
857
|
+
}
|
|
858
|
+
/**
|
|
859
|
+
* Returns an array of listeners that are listening for any event that is specified. This array can be manipulated,
|
|
860
|
+
* e.g. to remove listeners.
|
|
861
|
+
*/
|
|
862
|
+
listenersAnyOutgoing() {
|
|
863
|
+
return this._anyOutgoingListeners || [];
|
|
864
|
+
}
|
|
865
|
+
/**
|
|
866
|
+
* Notify the listeners for each packet sent
|
|
867
|
+
*
|
|
868
|
+
* @param packet
|
|
869
|
+
*
|
|
870
|
+
* @private
|
|
871
|
+
*/
|
|
872
|
+
notifyOutgoingListeners(packet) {
|
|
873
|
+
if (this._anyOutgoingListeners && this._anyOutgoingListeners.length) {
|
|
874
|
+
const listeners = this._anyOutgoingListeners.slice();
|
|
875
|
+
for (const listener of listeners) {
|
|
876
|
+
listener.apply(this, packet.data);
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
}
|