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,3064 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Engine.IO v6.6.4
|
|
3
|
+
* (c) 2014-2025 Guillermo Rauch
|
|
4
|
+
* Released under the MIT License.
|
|
5
|
+
*/
|
|
6
|
+
(function (global, factory) {
|
|
7
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
|
8
|
+
typeof define === 'function' && define.amd ? define(factory) :
|
|
9
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.eio = factory());
|
|
10
|
+
})(this, (function () { 'use strict';
|
|
11
|
+
|
|
12
|
+
function _arrayLikeToArray(r, a) {
|
|
13
|
+
(null == a || a > r.length) && (a = r.length);
|
|
14
|
+
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
15
|
+
return n;
|
|
16
|
+
}
|
|
17
|
+
function _arrayWithoutHoles(r) {
|
|
18
|
+
if (Array.isArray(r)) return _arrayLikeToArray(r);
|
|
19
|
+
}
|
|
20
|
+
function _construct(t, e, r) {
|
|
21
|
+
if (_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments);
|
|
22
|
+
var o = [null];
|
|
23
|
+
o.push.apply(o, e);
|
|
24
|
+
var p = new (t.bind.apply(t, o))();
|
|
25
|
+
return r && _setPrototypeOf(p, r.prototype), p;
|
|
26
|
+
}
|
|
27
|
+
function _defineProperties(e, r) {
|
|
28
|
+
for (var t = 0; t < r.length; t++) {
|
|
29
|
+
var o = r[t];
|
|
30
|
+
o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function _createClass(e, r, t) {
|
|
34
|
+
return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
|
|
35
|
+
writable: !1
|
|
36
|
+
}), e;
|
|
37
|
+
}
|
|
38
|
+
function _createForOfIteratorHelper(r, e) {
|
|
39
|
+
var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
40
|
+
if (!t) {
|
|
41
|
+
if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) {
|
|
42
|
+
t && (r = t);
|
|
43
|
+
var n = 0,
|
|
44
|
+
F = function () {};
|
|
45
|
+
return {
|
|
46
|
+
s: F,
|
|
47
|
+
n: function () {
|
|
48
|
+
return n >= r.length ? {
|
|
49
|
+
done: !0
|
|
50
|
+
} : {
|
|
51
|
+
done: !1,
|
|
52
|
+
value: r[n++]
|
|
53
|
+
};
|
|
54
|
+
},
|
|
55
|
+
e: function (r) {
|
|
56
|
+
throw r;
|
|
57
|
+
},
|
|
58
|
+
f: F
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
62
|
+
}
|
|
63
|
+
var o,
|
|
64
|
+
a = !0,
|
|
65
|
+
u = !1;
|
|
66
|
+
return {
|
|
67
|
+
s: function () {
|
|
68
|
+
t = t.call(r);
|
|
69
|
+
},
|
|
70
|
+
n: function () {
|
|
71
|
+
var r = t.next();
|
|
72
|
+
return a = r.done, r;
|
|
73
|
+
},
|
|
74
|
+
e: function (r) {
|
|
75
|
+
u = !0, o = r;
|
|
76
|
+
},
|
|
77
|
+
f: function () {
|
|
78
|
+
try {
|
|
79
|
+
a || null == t.return || t.return();
|
|
80
|
+
} finally {
|
|
81
|
+
if (u) throw o;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
function _extends() {
|
|
87
|
+
return _extends = Object.assign ? Object.assign.bind() : function (n) {
|
|
88
|
+
for (var e = 1; e < arguments.length; e++) {
|
|
89
|
+
var t = arguments[e];
|
|
90
|
+
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
|
91
|
+
}
|
|
92
|
+
return n;
|
|
93
|
+
}, _extends.apply(null, arguments);
|
|
94
|
+
}
|
|
95
|
+
function _getPrototypeOf(t) {
|
|
96
|
+
return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
|
|
97
|
+
return t.__proto__ || Object.getPrototypeOf(t);
|
|
98
|
+
}, _getPrototypeOf(t);
|
|
99
|
+
}
|
|
100
|
+
function _inheritsLoose(t, o) {
|
|
101
|
+
t.prototype = Object.create(o.prototype), t.prototype.constructor = t, _setPrototypeOf(t, o);
|
|
102
|
+
}
|
|
103
|
+
function _isNativeFunction(t) {
|
|
104
|
+
try {
|
|
105
|
+
return -1 !== Function.toString.call(t).indexOf("[native code]");
|
|
106
|
+
} catch (n) {
|
|
107
|
+
return "function" == typeof t;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function _isNativeReflectConstruct() {
|
|
111
|
+
try {
|
|
112
|
+
var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
|
|
113
|
+
} catch (t) {}
|
|
114
|
+
return (_isNativeReflectConstruct = function () {
|
|
115
|
+
return !!t;
|
|
116
|
+
})();
|
|
117
|
+
}
|
|
118
|
+
function _iterableToArray(r) {
|
|
119
|
+
if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
|
|
120
|
+
}
|
|
121
|
+
function _nonIterableSpread() {
|
|
122
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
123
|
+
}
|
|
124
|
+
function _setPrototypeOf(t, e) {
|
|
125
|
+
return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
|
|
126
|
+
return t.__proto__ = e, t;
|
|
127
|
+
}, _setPrototypeOf(t, e);
|
|
128
|
+
}
|
|
129
|
+
function _toConsumableArray(r) {
|
|
130
|
+
return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
|
|
131
|
+
}
|
|
132
|
+
function _toPrimitive(t, r) {
|
|
133
|
+
if ("object" != typeof t || !t) return t;
|
|
134
|
+
var e = t[Symbol.toPrimitive];
|
|
135
|
+
if (void 0 !== e) {
|
|
136
|
+
var i = e.call(t, r || "default");
|
|
137
|
+
if ("object" != typeof i) return i;
|
|
138
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
139
|
+
}
|
|
140
|
+
return ("string" === r ? String : Number)(t);
|
|
141
|
+
}
|
|
142
|
+
function _toPropertyKey(t) {
|
|
143
|
+
var i = _toPrimitive(t, "string");
|
|
144
|
+
return "symbol" == typeof i ? i : i + "";
|
|
145
|
+
}
|
|
146
|
+
function _typeof(o) {
|
|
147
|
+
"@babel/helpers - typeof";
|
|
148
|
+
|
|
149
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
|
|
150
|
+
return typeof o;
|
|
151
|
+
} : function (o) {
|
|
152
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
153
|
+
}, _typeof(o);
|
|
154
|
+
}
|
|
155
|
+
function _unsupportedIterableToArray(r, a) {
|
|
156
|
+
if (r) {
|
|
157
|
+
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
158
|
+
var t = {}.toString.call(r).slice(8, -1);
|
|
159
|
+
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
function _wrapNativeSuper(t) {
|
|
163
|
+
var r = "function" == typeof Map ? new Map() : void 0;
|
|
164
|
+
return _wrapNativeSuper = function (t) {
|
|
165
|
+
if (null === t || !_isNativeFunction(t)) return t;
|
|
166
|
+
if ("function" != typeof t) throw new TypeError("Super expression must either be null or a function");
|
|
167
|
+
if (void 0 !== r) {
|
|
168
|
+
if (r.has(t)) return r.get(t);
|
|
169
|
+
r.set(t, Wrapper);
|
|
170
|
+
}
|
|
171
|
+
function Wrapper() {
|
|
172
|
+
return _construct(t, arguments, _getPrototypeOf(this).constructor);
|
|
173
|
+
}
|
|
174
|
+
return Wrapper.prototype = Object.create(t.prototype, {
|
|
175
|
+
constructor: {
|
|
176
|
+
value: Wrapper,
|
|
177
|
+
enumerable: !1,
|
|
178
|
+
writable: !0,
|
|
179
|
+
configurable: !0
|
|
180
|
+
}
|
|
181
|
+
}), _setPrototypeOf(Wrapper, t);
|
|
182
|
+
}, _wrapNativeSuper(t);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
var PACKET_TYPES = Object.create(null); // no Map = no polyfill
|
|
186
|
+
PACKET_TYPES["open"] = "0";
|
|
187
|
+
PACKET_TYPES["close"] = "1";
|
|
188
|
+
PACKET_TYPES["ping"] = "2";
|
|
189
|
+
PACKET_TYPES["pong"] = "3";
|
|
190
|
+
PACKET_TYPES["message"] = "4";
|
|
191
|
+
PACKET_TYPES["upgrade"] = "5";
|
|
192
|
+
PACKET_TYPES["noop"] = "6";
|
|
193
|
+
var PACKET_TYPES_REVERSE = Object.create(null);
|
|
194
|
+
Object.keys(PACKET_TYPES).forEach(function (key) {
|
|
195
|
+
PACKET_TYPES_REVERSE[PACKET_TYPES[key]] = key;
|
|
196
|
+
});
|
|
197
|
+
var ERROR_PACKET = {
|
|
198
|
+
type: "error",
|
|
199
|
+
data: "parser error"
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
var withNativeBlob = typeof Blob === "function" || typeof Blob !== "undefined" && Object.prototype.toString.call(Blob) === "[object BlobConstructor]";
|
|
203
|
+
var withNativeArrayBuffer$1 = typeof ArrayBuffer === "function";
|
|
204
|
+
// ArrayBuffer.isView method is not defined in IE10
|
|
205
|
+
var isView = function isView(obj) {
|
|
206
|
+
return typeof ArrayBuffer.isView === "function" ? ArrayBuffer.isView(obj) : obj && obj.buffer instanceof ArrayBuffer;
|
|
207
|
+
};
|
|
208
|
+
var encodePacket = function encodePacket(_ref, supportsBinary, callback) {
|
|
209
|
+
var type = _ref.type,
|
|
210
|
+
data = _ref.data;
|
|
211
|
+
if (withNativeBlob && data instanceof Blob) {
|
|
212
|
+
if (supportsBinary) {
|
|
213
|
+
return callback(data);
|
|
214
|
+
} else {
|
|
215
|
+
return encodeBlobAsBase64(data, callback);
|
|
216
|
+
}
|
|
217
|
+
} else if (withNativeArrayBuffer$1 && (data instanceof ArrayBuffer || isView(data))) {
|
|
218
|
+
if (supportsBinary) {
|
|
219
|
+
return callback(data);
|
|
220
|
+
} else {
|
|
221
|
+
return encodeBlobAsBase64(new Blob([data]), callback);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
// plain string
|
|
225
|
+
return callback(PACKET_TYPES[type] + (data || ""));
|
|
226
|
+
};
|
|
227
|
+
var encodeBlobAsBase64 = function encodeBlobAsBase64(data, callback) {
|
|
228
|
+
var fileReader = new FileReader();
|
|
229
|
+
fileReader.onload = function () {
|
|
230
|
+
var content = fileReader.result.split(",")[1];
|
|
231
|
+
callback("b" + (content || ""));
|
|
232
|
+
};
|
|
233
|
+
return fileReader.readAsDataURL(data);
|
|
234
|
+
};
|
|
235
|
+
function toArray(data) {
|
|
236
|
+
if (data instanceof Uint8Array) {
|
|
237
|
+
return data;
|
|
238
|
+
} else if (data instanceof ArrayBuffer) {
|
|
239
|
+
return new Uint8Array(data);
|
|
240
|
+
} else {
|
|
241
|
+
return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
var TEXT_ENCODER;
|
|
245
|
+
function encodePacketToBinary(packet, callback) {
|
|
246
|
+
if (withNativeBlob && packet.data instanceof Blob) {
|
|
247
|
+
return packet.data.arrayBuffer().then(toArray).then(callback);
|
|
248
|
+
} else if (withNativeArrayBuffer$1 && (packet.data instanceof ArrayBuffer || isView(packet.data))) {
|
|
249
|
+
return callback(toArray(packet.data));
|
|
250
|
+
}
|
|
251
|
+
encodePacket(packet, false, function (encoded) {
|
|
252
|
+
if (!TEXT_ENCODER) {
|
|
253
|
+
TEXT_ENCODER = new TextEncoder();
|
|
254
|
+
}
|
|
255
|
+
callback(TEXT_ENCODER.encode(encoded));
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// imported from https://github.com/socketio/base64-arraybuffer
|
|
260
|
+
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
261
|
+
// Use a lookup table to find the index.
|
|
262
|
+
var lookup = typeof Uint8Array === 'undefined' ? [] : new Uint8Array(256);
|
|
263
|
+
for (var i = 0; i < chars.length; i++) {
|
|
264
|
+
lookup[chars.charCodeAt(i)] = i;
|
|
265
|
+
}
|
|
266
|
+
var decode$1 = function decode(base64) {
|
|
267
|
+
var bufferLength = base64.length * 0.75,
|
|
268
|
+
len = base64.length,
|
|
269
|
+
i,
|
|
270
|
+
p = 0,
|
|
271
|
+
encoded1,
|
|
272
|
+
encoded2,
|
|
273
|
+
encoded3,
|
|
274
|
+
encoded4;
|
|
275
|
+
if (base64[base64.length - 1] === '=') {
|
|
276
|
+
bufferLength--;
|
|
277
|
+
if (base64[base64.length - 2] === '=') {
|
|
278
|
+
bufferLength--;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
var arraybuffer = new ArrayBuffer(bufferLength),
|
|
282
|
+
bytes = new Uint8Array(arraybuffer);
|
|
283
|
+
for (i = 0; i < len; i += 4) {
|
|
284
|
+
encoded1 = lookup[base64.charCodeAt(i)];
|
|
285
|
+
encoded2 = lookup[base64.charCodeAt(i + 1)];
|
|
286
|
+
encoded3 = lookup[base64.charCodeAt(i + 2)];
|
|
287
|
+
encoded4 = lookup[base64.charCodeAt(i + 3)];
|
|
288
|
+
bytes[p++] = encoded1 << 2 | encoded2 >> 4;
|
|
289
|
+
bytes[p++] = (encoded2 & 15) << 4 | encoded3 >> 2;
|
|
290
|
+
bytes[p++] = (encoded3 & 3) << 6 | encoded4 & 63;
|
|
291
|
+
}
|
|
292
|
+
return arraybuffer;
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
var withNativeArrayBuffer = typeof ArrayBuffer === "function";
|
|
296
|
+
var decodePacket = function decodePacket(encodedPacket, binaryType) {
|
|
297
|
+
if (typeof encodedPacket !== "string") {
|
|
298
|
+
return {
|
|
299
|
+
type: "message",
|
|
300
|
+
data: mapBinary(encodedPacket, binaryType)
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
var type = encodedPacket.charAt(0);
|
|
304
|
+
if (type === "b") {
|
|
305
|
+
return {
|
|
306
|
+
type: "message",
|
|
307
|
+
data: decodeBase64Packet(encodedPacket.substring(1), binaryType)
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
var packetType = PACKET_TYPES_REVERSE[type];
|
|
311
|
+
if (!packetType) {
|
|
312
|
+
return ERROR_PACKET;
|
|
313
|
+
}
|
|
314
|
+
return encodedPacket.length > 1 ? {
|
|
315
|
+
type: PACKET_TYPES_REVERSE[type],
|
|
316
|
+
data: encodedPacket.substring(1)
|
|
317
|
+
} : {
|
|
318
|
+
type: PACKET_TYPES_REVERSE[type]
|
|
319
|
+
};
|
|
320
|
+
};
|
|
321
|
+
var decodeBase64Packet = function decodeBase64Packet(data, binaryType) {
|
|
322
|
+
if (withNativeArrayBuffer) {
|
|
323
|
+
var decoded = decode$1(data);
|
|
324
|
+
return mapBinary(decoded, binaryType);
|
|
325
|
+
} else {
|
|
326
|
+
return {
|
|
327
|
+
base64: true,
|
|
328
|
+
data: data
|
|
329
|
+
}; // fallback for old browsers
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
var mapBinary = function mapBinary(data, binaryType) {
|
|
333
|
+
switch (binaryType) {
|
|
334
|
+
case "blob":
|
|
335
|
+
if (data instanceof Blob) {
|
|
336
|
+
// from WebSocket + binaryType "blob"
|
|
337
|
+
return data;
|
|
338
|
+
} else {
|
|
339
|
+
// from HTTP long-polling or WebTransport
|
|
340
|
+
return new Blob([data]);
|
|
341
|
+
}
|
|
342
|
+
case "arraybuffer":
|
|
343
|
+
default:
|
|
344
|
+
if (data instanceof ArrayBuffer) {
|
|
345
|
+
// from HTTP long-polling (base64) or WebSocket + binaryType "arraybuffer"
|
|
346
|
+
return data;
|
|
347
|
+
} else {
|
|
348
|
+
// from WebTransport (Uint8Array)
|
|
349
|
+
return data.buffer;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
var SEPARATOR = String.fromCharCode(30); // see https://en.wikipedia.org/wiki/Delimiter#ASCII_delimited_text
|
|
355
|
+
var encodePayload = function encodePayload(packets, callback) {
|
|
356
|
+
// some packets may be added to the array while encoding, so the initial length must be saved
|
|
357
|
+
var length = packets.length;
|
|
358
|
+
var encodedPackets = new Array(length);
|
|
359
|
+
var count = 0;
|
|
360
|
+
packets.forEach(function (packet, i) {
|
|
361
|
+
// force base64 encoding for binary packets
|
|
362
|
+
encodePacket(packet, false, function (encodedPacket) {
|
|
363
|
+
encodedPackets[i] = encodedPacket;
|
|
364
|
+
if (++count === length) {
|
|
365
|
+
callback(encodedPackets.join(SEPARATOR));
|
|
366
|
+
}
|
|
367
|
+
});
|
|
368
|
+
});
|
|
369
|
+
};
|
|
370
|
+
var decodePayload = function decodePayload(encodedPayload, binaryType) {
|
|
371
|
+
var encodedPackets = encodedPayload.split(SEPARATOR);
|
|
372
|
+
var packets = [];
|
|
373
|
+
for (var i = 0; i < encodedPackets.length; i++) {
|
|
374
|
+
var decodedPacket = decodePacket(encodedPackets[i], binaryType);
|
|
375
|
+
packets.push(decodedPacket);
|
|
376
|
+
if (decodedPacket.type === "error") {
|
|
377
|
+
break;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
return packets;
|
|
381
|
+
};
|
|
382
|
+
function createPacketEncoderStream() {
|
|
383
|
+
return new TransformStream({
|
|
384
|
+
transform: function transform(packet, controller) {
|
|
385
|
+
encodePacketToBinary(packet, function (encodedPacket) {
|
|
386
|
+
var payloadLength = encodedPacket.length;
|
|
387
|
+
var header;
|
|
388
|
+
// inspired by the WebSocket format: https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_servers#decoding_payload_length
|
|
389
|
+
if (payloadLength < 126) {
|
|
390
|
+
header = new Uint8Array(1);
|
|
391
|
+
new DataView(header.buffer).setUint8(0, payloadLength);
|
|
392
|
+
} else if (payloadLength < 65536) {
|
|
393
|
+
header = new Uint8Array(3);
|
|
394
|
+
var view = new DataView(header.buffer);
|
|
395
|
+
view.setUint8(0, 126);
|
|
396
|
+
view.setUint16(1, payloadLength);
|
|
397
|
+
} else {
|
|
398
|
+
header = new Uint8Array(9);
|
|
399
|
+
var _view = new DataView(header.buffer);
|
|
400
|
+
_view.setUint8(0, 127);
|
|
401
|
+
_view.setBigUint64(1, BigInt(payloadLength));
|
|
402
|
+
}
|
|
403
|
+
// first bit indicates whether the payload is plain text (0) or binary (1)
|
|
404
|
+
if (packet.data && typeof packet.data !== "string") {
|
|
405
|
+
header[0] |= 0x80;
|
|
406
|
+
}
|
|
407
|
+
controller.enqueue(header);
|
|
408
|
+
controller.enqueue(encodedPacket);
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
var TEXT_DECODER;
|
|
414
|
+
function totalLength(chunks) {
|
|
415
|
+
return chunks.reduce(function (acc, chunk) {
|
|
416
|
+
return acc + chunk.length;
|
|
417
|
+
}, 0);
|
|
418
|
+
}
|
|
419
|
+
function concatChunks(chunks, size) {
|
|
420
|
+
if (chunks[0].length === size) {
|
|
421
|
+
return chunks.shift();
|
|
422
|
+
}
|
|
423
|
+
var buffer = new Uint8Array(size);
|
|
424
|
+
var j = 0;
|
|
425
|
+
for (var i = 0; i < size; i++) {
|
|
426
|
+
buffer[i] = chunks[0][j++];
|
|
427
|
+
if (j === chunks[0].length) {
|
|
428
|
+
chunks.shift();
|
|
429
|
+
j = 0;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
if (chunks.length && j < chunks[0].length) {
|
|
433
|
+
chunks[0] = chunks[0].slice(j);
|
|
434
|
+
}
|
|
435
|
+
return buffer;
|
|
436
|
+
}
|
|
437
|
+
function createPacketDecoderStream(maxPayload, binaryType) {
|
|
438
|
+
if (!TEXT_DECODER) {
|
|
439
|
+
TEXT_DECODER = new TextDecoder();
|
|
440
|
+
}
|
|
441
|
+
var chunks = [];
|
|
442
|
+
var state = 0 /* State.READ_HEADER */;
|
|
443
|
+
var expectedLength = -1;
|
|
444
|
+
var isBinary = false;
|
|
445
|
+
return new TransformStream({
|
|
446
|
+
transform: function transform(chunk, controller) {
|
|
447
|
+
chunks.push(chunk);
|
|
448
|
+
while (true) {
|
|
449
|
+
if (state === 0 /* State.READ_HEADER */) {
|
|
450
|
+
if (totalLength(chunks) < 1) {
|
|
451
|
+
break;
|
|
452
|
+
}
|
|
453
|
+
var header = concatChunks(chunks, 1);
|
|
454
|
+
isBinary = (header[0] & 0x80) === 0x80;
|
|
455
|
+
expectedLength = header[0] & 0x7f;
|
|
456
|
+
if (expectedLength < 126) {
|
|
457
|
+
state = 3 /* State.READ_PAYLOAD */;
|
|
458
|
+
} else if (expectedLength === 126) {
|
|
459
|
+
state = 1 /* State.READ_EXTENDED_LENGTH_16 */;
|
|
460
|
+
} else {
|
|
461
|
+
state = 2 /* State.READ_EXTENDED_LENGTH_64 */;
|
|
462
|
+
}
|
|
463
|
+
} else if (state === 1 /* State.READ_EXTENDED_LENGTH_16 */) {
|
|
464
|
+
if (totalLength(chunks) < 2) {
|
|
465
|
+
break;
|
|
466
|
+
}
|
|
467
|
+
var headerArray = concatChunks(chunks, 2);
|
|
468
|
+
expectedLength = new DataView(headerArray.buffer, headerArray.byteOffset, headerArray.length).getUint16(0);
|
|
469
|
+
state = 3 /* State.READ_PAYLOAD */;
|
|
470
|
+
} else if (state === 2 /* State.READ_EXTENDED_LENGTH_64 */) {
|
|
471
|
+
if (totalLength(chunks) < 8) {
|
|
472
|
+
break;
|
|
473
|
+
}
|
|
474
|
+
var _headerArray = concatChunks(chunks, 8);
|
|
475
|
+
var view = new DataView(_headerArray.buffer, _headerArray.byteOffset, _headerArray.length);
|
|
476
|
+
var n = view.getUint32(0);
|
|
477
|
+
if (n > Math.pow(2, 53 - 32) - 1) {
|
|
478
|
+
// the maximum safe integer in JavaScript is 2^53 - 1
|
|
479
|
+
controller.enqueue(ERROR_PACKET);
|
|
480
|
+
break;
|
|
481
|
+
}
|
|
482
|
+
expectedLength = n * Math.pow(2, 32) + view.getUint32(4);
|
|
483
|
+
state = 3 /* State.READ_PAYLOAD */;
|
|
484
|
+
} else {
|
|
485
|
+
if (totalLength(chunks) < expectedLength) {
|
|
486
|
+
break;
|
|
487
|
+
}
|
|
488
|
+
var data = concatChunks(chunks, expectedLength);
|
|
489
|
+
controller.enqueue(decodePacket(isBinary ? data : TEXT_DECODER.decode(data), binaryType));
|
|
490
|
+
state = 0 /* State.READ_HEADER */;
|
|
491
|
+
}
|
|
492
|
+
if (expectedLength === 0 || expectedLength > maxPayload) {
|
|
493
|
+
controller.enqueue(ERROR_PACKET);
|
|
494
|
+
break;
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
});
|
|
499
|
+
}
|
|
500
|
+
var protocol = 4;
|
|
501
|
+
|
|
502
|
+
/**
|
|
503
|
+
* Initialize a new `Emitter`.
|
|
504
|
+
*
|
|
505
|
+
* @api public
|
|
506
|
+
*/
|
|
507
|
+
|
|
508
|
+
function Emitter(obj) {
|
|
509
|
+
if (obj) return mixin(obj);
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
/**
|
|
513
|
+
* Mixin the emitter properties.
|
|
514
|
+
*
|
|
515
|
+
* @param {Object} obj
|
|
516
|
+
* @return {Object}
|
|
517
|
+
* @api private
|
|
518
|
+
*/
|
|
519
|
+
|
|
520
|
+
function mixin(obj) {
|
|
521
|
+
for (var key in Emitter.prototype) {
|
|
522
|
+
obj[key] = Emitter.prototype[key];
|
|
523
|
+
}
|
|
524
|
+
return obj;
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
/**
|
|
528
|
+
* Listen on the given `event` with `fn`.
|
|
529
|
+
*
|
|
530
|
+
* @param {String} event
|
|
531
|
+
* @param {Function} fn
|
|
532
|
+
* @return {Emitter}
|
|
533
|
+
* @api public
|
|
534
|
+
*/
|
|
535
|
+
|
|
536
|
+
Emitter.prototype.on = Emitter.prototype.addEventListener = function (event, fn) {
|
|
537
|
+
this._callbacks = this._callbacks || {};
|
|
538
|
+
(this._callbacks['$' + event] = this._callbacks['$' + event] || []).push(fn);
|
|
539
|
+
return this;
|
|
540
|
+
};
|
|
541
|
+
|
|
542
|
+
/**
|
|
543
|
+
* Adds an `event` listener that will be invoked a single
|
|
544
|
+
* time then automatically removed.
|
|
545
|
+
*
|
|
546
|
+
* @param {String} event
|
|
547
|
+
* @param {Function} fn
|
|
548
|
+
* @return {Emitter}
|
|
549
|
+
* @api public
|
|
550
|
+
*/
|
|
551
|
+
|
|
552
|
+
Emitter.prototype.once = function (event, fn) {
|
|
553
|
+
function on() {
|
|
554
|
+
this.off(event, on);
|
|
555
|
+
fn.apply(this, arguments);
|
|
556
|
+
}
|
|
557
|
+
on.fn = fn;
|
|
558
|
+
this.on(event, on);
|
|
559
|
+
return this;
|
|
560
|
+
};
|
|
561
|
+
|
|
562
|
+
/**
|
|
563
|
+
* Remove the given callback for `event` or all
|
|
564
|
+
* registered callbacks.
|
|
565
|
+
*
|
|
566
|
+
* @param {String} event
|
|
567
|
+
* @param {Function} fn
|
|
568
|
+
* @return {Emitter}
|
|
569
|
+
* @api public
|
|
570
|
+
*/
|
|
571
|
+
|
|
572
|
+
Emitter.prototype.off = Emitter.prototype.removeListener = Emitter.prototype.removeAllListeners = Emitter.prototype.removeEventListener = function (event, fn) {
|
|
573
|
+
this._callbacks = this._callbacks || {};
|
|
574
|
+
|
|
575
|
+
// all
|
|
576
|
+
if (0 == arguments.length) {
|
|
577
|
+
this._callbacks = {};
|
|
578
|
+
return this;
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
// specific event
|
|
582
|
+
var callbacks = this._callbacks['$' + event];
|
|
583
|
+
if (!callbacks) return this;
|
|
584
|
+
|
|
585
|
+
// remove all handlers
|
|
586
|
+
if (1 == arguments.length) {
|
|
587
|
+
delete this._callbacks['$' + event];
|
|
588
|
+
return this;
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
// remove specific handler
|
|
592
|
+
var cb;
|
|
593
|
+
for (var i = 0; i < callbacks.length; i++) {
|
|
594
|
+
cb = callbacks[i];
|
|
595
|
+
if (cb === fn || cb.fn === fn) {
|
|
596
|
+
callbacks.splice(i, 1);
|
|
597
|
+
break;
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
// Remove event specific arrays for event types that no
|
|
602
|
+
// one is subscribed for to avoid memory leak.
|
|
603
|
+
if (callbacks.length === 0) {
|
|
604
|
+
delete this._callbacks['$' + event];
|
|
605
|
+
}
|
|
606
|
+
return this;
|
|
607
|
+
};
|
|
608
|
+
|
|
609
|
+
/**
|
|
610
|
+
* Emit `event` with the given args.
|
|
611
|
+
*
|
|
612
|
+
* @param {String} event
|
|
613
|
+
* @param {Mixed} ...
|
|
614
|
+
* @return {Emitter}
|
|
615
|
+
*/
|
|
616
|
+
|
|
617
|
+
Emitter.prototype.emit = function (event) {
|
|
618
|
+
this._callbacks = this._callbacks || {};
|
|
619
|
+
var args = new Array(arguments.length - 1),
|
|
620
|
+
callbacks = this._callbacks['$' + event];
|
|
621
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
622
|
+
args[i - 1] = arguments[i];
|
|
623
|
+
}
|
|
624
|
+
if (callbacks) {
|
|
625
|
+
callbacks = callbacks.slice(0);
|
|
626
|
+
for (var i = 0, len = callbacks.length; i < len; ++i) {
|
|
627
|
+
callbacks[i].apply(this, args);
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
return this;
|
|
631
|
+
};
|
|
632
|
+
|
|
633
|
+
// alias used for reserved events (protected method)
|
|
634
|
+
Emitter.prototype.emitReserved = Emitter.prototype.emit;
|
|
635
|
+
|
|
636
|
+
/**
|
|
637
|
+
* Return array of callbacks for `event`.
|
|
638
|
+
*
|
|
639
|
+
* @param {String} event
|
|
640
|
+
* @return {Array}
|
|
641
|
+
* @api public
|
|
642
|
+
*/
|
|
643
|
+
|
|
644
|
+
Emitter.prototype.listeners = function (event) {
|
|
645
|
+
this._callbacks = this._callbacks || {};
|
|
646
|
+
return this._callbacks['$' + event] || [];
|
|
647
|
+
};
|
|
648
|
+
|
|
649
|
+
/**
|
|
650
|
+
* Check if this emitter has `event` handlers.
|
|
651
|
+
*
|
|
652
|
+
* @param {String} event
|
|
653
|
+
* @return {Boolean}
|
|
654
|
+
* @api public
|
|
655
|
+
*/
|
|
656
|
+
|
|
657
|
+
Emitter.prototype.hasListeners = function (event) {
|
|
658
|
+
return !!this.listeners(event).length;
|
|
659
|
+
};
|
|
660
|
+
|
|
661
|
+
var nextTick = function () {
|
|
662
|
+
var isPromiseAvailable = typeof Promise === "function" && typeof Promise.resolve === "function";
|
|
663
|
+
if (isPromiseAvailable) {
|
|
664
|
+
return function (cb) {
|
|
665
|
+
return Promise.resolve().then(cb);
|
|
666
|
+
};
|
|
667
|
+
} else {
|
|
668
|
+
return function (cb, setTimeoutFn) {
|
|
669
|
+
return setTimeoutFn(cb, 0);
|
|
670
|
+
};
|
|
671
|
+
}
|
|
672
|
+
}();
|
|
673
|
+
var globalThisShim = function () {
|
|
674
|
+
if (typeof self !== "undefined") {
|
|
675
|
+
return self;
|
|
676
|
+
} else if (typeof window !== "undefined") {
|
|
677
|
+
return window;
|
|
678
|
+
} else {
|
|
679
|
+
return Function("return this")();
|
|
680
|
+
}
|
|
681
|
+
}();
|
|
682
|
+
var defaultBinaryType = "arraybuffer";
|
|
683
|
+
function createCookieJar() {}
|
|
684
|
+
|
|
685
|
+
function pick(obj) {
|
|
686
|
+
for (var _len = arguments.length, attr = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
687
|
+
attr[_key - 1] = arguments[_key];
|
|
688
|
+
}
|
|
689
|
+
return attr.reduce(function (acc, k) {
|
|
690
|
+
if (obj.hasOwnProperty(k)) {
|
|
691
|
+
acc[k] = obj[k];
|
|
692
|
+
}
|
|
693
|
+
return acc;
|
|
694
|
+
}, {});
|
|
695
|
+
}
|
|
696
|
+
// Keep a reference to the real timeout functions so they can be used when overridden
|
|
697
|
+
var NATIVE_SET_TIMEOUT = globalThisShim.setTimeout;
|
|
698
|
+
var NATIVE_CLEAR_TIMEOUT = globalThisShim.clearTimeout;
|
|
699
|
+
function installTimerFunctions(obj, opts) {
|
|
700
|
+
if (opts.useNativeTimers) {
|
|
701
|
+
obj.setTimeoutFn = NATIVE_SET_TIMEOUT.bind(globalThisShim);
|
|
702
|
+
obj.clearTimeoutFn = NATIVE_CLEAR_TIMEOUT.bind(globalThisShim);
|
|
703
|
+
} else {
|
|
704
|
+
obj.setTimeoutFn = globalThisShim.setTimeout.bind(globalThisShim);
|
|
705
|
+
obj.clearTimeoutFn = globalThisShim.clearTimeout.bind(globalThisShim);
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
// base64 encoded buffers are about 33% bigger (https://en.wikipedia.org/wiki/Base64)
|
|
709
|
+
var BASE64_OVERHEAD = 1.33;
|
|
710
|
+
// we could also have used `new Blob([obj]).size`, but it isn't supported in IE9
|
|
711
|
+
function byteLength(obj) {
|
|
712
|
+
if (typeof obj === "string") {
|
|
713
|
+
return utf8Length(obj);
|
|
714
|
+
}
|
|
715
|
+
// arraybuffer or blob
|
|
716
|
+
return Math.ceil((obj.byteLength || obj.size) * BASE64_OVERHEAD);
|
|
717
|
+
}
|
|
718
|
+
function utf8Length(str) {
|
|
719
|
+
var c = 0,
|
|
720
|
+
length = 0;
|
|
721
|
+
for (var i = 0, l = str.length; i < l; i++) {
|
|
722
|
+
c = str.charCodeAt(i);
|
|
723
|
+
if (c < 0x80) {
|
|
724
|
+
length += 1;
|
|
725
|
+
} else if (c < 0x800) {
|
|
726
|
+
length += 2;
|
|
727
|
+
} else if (c < 0xd800 || c >= 0xe000) {
|
|
728
|
+
length += 3;
|
|
729
|
+
} else {
|
|
730
|
+
i++;
|
|
731
|
+
length += 4;
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
return length;
|
|
735
|
+
}
|
|
736
|
+
/**
|
|
737
|
+
* Generates a random 8-characters string.
|
|
738
|
+
*/
|
|
739
|
+
function randomString() {
|
|
740
|
+
return Date.now().toString(36).substring(3) + Math.random().toString(36).substring(2, 5);
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
// imported from https://github.com/galkn/querystring
|
|
744
|
+
/**
|
|
745
|
+
* Compiles a querystring
|
|
746
|
+
* Returns string representation of the object
|
|
747
|
+
*
|
|
748
|
+
* @param {Object}
|
|
749
|
+
* @api private
|
|
750
|
+
*/
|
|
751
|
+
function encode(obj) {
|
|
752
|
+
var str = '';
|
|
753
|
+
for (var i in obj) {
|
|
754
|
+
if (obj.hasOwnProperty(i)) {
|
|
755
|
+
if (str.length) str += '&';
|
|
756
|
+
str += encodeURIComponent(i) + '=' + encodeURIComponent(obj[i]);
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
return str;
|
|
760
|
+
}
|
|
761
|
+
/**
|
|
762
|
+
* Parses a simple querystring into an object
|
|
763
|
+
*
|
|
764
|
+
* @param {String} qs
|
|
765
|
+
* @api private
|
|
766
|
+
*/
|
|
767
|
+
function decode(qs) {
|
|
768
|
+
var qry = {};
|
|
769
|
+
var pairs = qs.split('&');
|
|
770
|
+
for (var i = 0, l = pairs.length; i < l; i++) {
|
|
771
|
+
var pair = pairs[i].split('=');
|
|
772
|
+
qry[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
|
|
773
|
+
}
|
|
774
|
+
return qry;
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
function getDefaultExportFromCjs (x) {
|
|
778
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
var browser = {exports: {}};
|
|
782
|
+
|
|
783
|
+
var ms;
|
|
784
|
+
var hasRequiredMs;
|
|
785
|
+
function requireMs() {
|
|
786
|
+
if (hasRequiredMs) return ms;
|
|
787
|
+
hasRequiredMs = 1;
|
|
788
|
+
var s = 1000;
|
|
789
|
+
var m = s * 60;
|
|
790
|
+
var h = m * 60;
|
|
791
|
+
var d = h * 24;
|
|
792
|
+
var w = d * 7;
|
|
793
|
+
var y = d * 365.25;
|
|
794
|
+
|
|
795
|
+
/**
|
|
796
|
+
* Parse or format the given `val`.
|
|
797
|
+
*
|
|
798
|
+
* Options:
|
|
799
|
+
*
|
|
800
|
+
* - `long` verbose formatting [false]
|
|
801
|
+
*
|
|
802
|
+
* @param {String|Number} val
|
|
803
|
+
* @param {Object} [options]
|
|
804
|
+
* @throws {Error} throw an error if val is not a non-empty string or a number
|
|
805
|
+
* @return {String|Number}
|
|
806
|
+
* @api public
|
|
807
|
+
*/
|
|
808
|
+
|
|
809
|
+
ms = function ms(val, options) {
|
|
810
|
+
options = options || {};
|
|
811
|
+
var type = _typeof(val);
|
|
812
|
+
if (type === 'string' && val.length > 0) {
|
|
813
|
+
return parse(val);
|
|
814
|
+
} else if (type === 'number' && isFinite(val)) {
|
|
815
|
+
return options["long"] ? fmtLong(val) : fmtShort(val);
|
|
816
|
+
}
|
|
817
|
+
throw new Error('val is not a non-empty string or a valid number. val=' + JSON.stringify(val));
|
|
818
|
+
};
|
|
819
|
+
|
|
820
|
+
/**
|
|
821
|
+
* Parse the given `str` and return milliseconds.
|
|
822
|
+
*
|
|
823
|
+
* @param {String} str
|
|
824
|
+
* @return {Number}
|
|
825
|
+
* @api private
|
|
826
|
+
*/
|
|
827
|
+
|
|
828
|
+
function parse(str) {
|
|
829
|
+
str = String(str);
|
|
830
|
+
if (str.length > 100) {
|
|
831
|
+
return;
|
|
832
|
+
}
|
|
833
|
+
var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(str);
|
|
834
|
+
if (!match) {
|
|
835
|
+
return;
|
|
836
|
+
}
|
|
837
|
+
var n = parseFloat(match[1]);
|
|
838
|
+
var type = (match[2] || 'ms').toLowerCase();
|
|
839
|
+
switch (type) {
|
|
840
|
+
case 'years':
|
|
841
|
+
case 'year':
|
|
842
|
+
case 'yrs':
|
|
843
|
+
case 'yr':
|
|
844
|
+
case 'y':
|
|
845
|
+
return n * y;
|
|
846
|
+
case 'weeks':
|
|
847
|
+
case 'week':
|
|
848
|
+
case 'w':
|
|
849
|
+
return n * w;
|
|
850
|
+
case 'days':
|
|
851
|
+
case 'day':
|
|
852
|
+
case 'd':
|
|
853
|
+
return n * d;
|
|
854
|
+
case 'hours':
|
|
855
|
+
case 'hour':
|
|
856
|
+
case 'hrs':
|
|
857
|
+
case 'hr':
|
|
858
|
+
case 'h':
|
|
859
|
+
return n * h;
|
|
860
|
+
case 'minutes':
|
|
861
|
+
case 'minute':
|
|
862
|
+
case 'mins':
|
|
863
|
+
case 'min':
|
|
864
|
+
case 'm':
|
|
865
|
+
return n * m;
|
|
866
|
+
case 'seconds':
|
|
867
|
+
case 'second':
|
|
868
|
+
case 'secs':
|
|
869
|
+
case 'sec':
|
|
870
|
+
case 's':
|
|
871
|
+
return n * s;
|
|
872
|
+
case 'milliseconds':
|
|
873
|
+
case 'millisecond':
|
|
874
|
+
case 'msecs':
|
|
875
|
+
case 'msec':
|
|
876
|
+
case 'ms':
|
|
877
|
+
return n;
|
|
878
|
+
default:
|
|
879
|
+
return undefined;
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
/**
|
|
884
|
+
* Short format for `ms`.
|
|
885
|
+
*
|
|
886
|
+
* @param {Number} ms
|
|
887
|
+
* @return {String}
|
|
888
|
+
* @api private
|
|
889
|
+
*/
|
|
890
|
+
|
|
891
|
+
function fmtShort(ms) {
|
|
892
|
+
var msAbs = Math.abs(ms);
|
|
893
|
+
if (msAbs >= d) {
|
|
894
|
+
return Math.round(ms / d) + 'd';
|
|
895
|
+
}
|
|
896
|
+
if (msAbs >= h) {
|
|
897
|
+
return Math.round(ms / h) + 'h';
|
|
898
|
+
}
|
|
899
|
+
if (msAbs >= m) {
|
|
900
|
+
return Math.round(ms / m) + 'm';
|
|
901
|
+
}
|
|
902
|
+
if (msAbs >= s) {
|
|
903
|
+
return Math.round(ms / s) + 's';
|
|
904
|
+
}
|
|
905
|
+
return ms + 'ms';
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
/**
|
|
909
|
+
* Long format for `ms`.
|
|
910
|
+
*
|
|
911
|
+
* @param {Number} ms
|
|
912
|
+
* @return {String}
|
|
913
|
+
* @api private
|
|
914
|
+
*/
|
|
915
|
+
|
|
916
|
+
function fmtLong(ms) {
|
|
917
|
+
var msAbs = Math.abs(ms);
|
|
918
|
+
if (msAbs >= d) {
|
|
919
|
+
return plural(ms, msAbs, d, 'day');
|
|
920
|
+
}
|
|
921
|
+
if (msAbs >= h) {
|
|
922
|
+
return plural(ms, msAbs, h, 'hour');
|
|
923
|
+
}
|
|
924
|
+
if (msAbs >= m) {
|
|
925
|
+
return plural(ms, msAbs, m, 'minute');
|
|
926
|
+
}
|
|
927
|
+
if (msAbs >= s) {
|
|
928
|
+
return plural(ms, msAbs, s, 'second');
|
|
929
|
+
}
|
|
930
|
+
return ms + ' ms';
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
/**
|
|
934
|
+
* Pluralization helper.
|
|
935
|
+
*/
|
|
936
|
+
|
|
937
|
+
function plural(ms, msAbs, n, name) {
|
|
938
|
+
var isPlural = msAbs >= n * 1.5;
|
|
939
|
+
return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : '');
|
|
940
|
+
}
|
|
941
|
+
return ms;
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
/**
|
|
945
|
+
* This is the common logic for both the Node.js and web browser
|
|
946
|
+
* implementations of `debug()`.
|
|
947
|
+
*/
|
|
948
|
+
|
|
949
|
+
function setup(env) {
|
|
950
|
+
createDebug.debug = createDebug;
|
|
951
|
+
createDebug["default"] = createDebug;
|
|
952
|
+
createDebug.coerce = coerce;
|
|
953
|
+
createDebug.disable = disable;
|
|
954
|
+
createDebug.enable = enable;
|
|
955
|
+
createDebug.enabled = enabled;
|
|
956
|
+
createDebug.humanize = requireMs();
|
|
957
|
+
createDebug.destroy = destroy;
|
|
958
|
+
Object.keys(env).forEach(function (key) {
|
|
959
|
+
createDebug[key] = env[key];
|
|
960
|
+
});
|
|
961
|
+
|
|
962
|
+
/**
|
|
963
|
+
* The currently active debug mode names, and names to skip.
|
|
964
|
+
*/
|
|
965
|
+
|
|
966
|
+
createDebug.names = [];
|
|
967
|
+
createDebug.skips = [];
|
|
968
|
+
|
|
969
|
+
/**
|
|
970
|
+
* Map of special "%n" handling functions, for the debug "format" argument.
|
|
971
|
+
*
|
|
972
|
+
* Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
|
|
973
|
+
*/
|
|
974
|
+
createDebug.formatters = {};
|
|
975
|
+
|
|
976
|
+
/**
|
|
977
|
+
* Selects a color for a debug namespace
|
|
978
|
+
* @param {String} namespace The namespace string for the debug instance to be colored
|
|
979
|
+
* @return {Number|String} An ANSI color code for the given namespace
|
|
980
|
+
* @api private
|
|
981
|
+
*/
|
|
982
|
+
function selectColor(namespace) {
|
|
983
|
+
var hash = 0;
|
|
984
|
+
for (var i = 0; i < namespace.length; i++) {
|
|
985
|
+
hash = (hash << 5) - hash + namespace.charCodeAt(i);
|
|
986
|
+
hash |= 0; // Convert to 32bit integer
|
|
987
|
+
}
|
|
988
|
+
return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
|
|
989
|
+
}
|
|
990
|
+
createDebug.selectColor = selectColor;
|
|
991
|
+
|
|
992
|
+
/**
|
|
993
|
+
* Create a debugger with the given `namespace`.
|
|
994
|
+
*
|
|
995
|
+
* @param {String} namespace
|
|
996
|
+
* @return {Function}
|
|
997
|
+
* @api public
|
|
998
|
+
*/
|
|
999
|
+
function createDebug(namespace) {
|
|
1000
|
+
var prevTime;
|
|
1001
|
+
var enableOverride = null;
|
|
1002
|
+
var namespacesCache;
|
|
1003
|
+
var enabledCache;
|
|
1004
|
+
function debug() {
|
|
1005
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1006
|
+
args[_key] = arguments[_key];
|
|
1007
|
+
}
|
|
1008
|
+
// Disabled?
|
|
1009
|
+
if (!debug.enabled) {
|
|
1010
|
+
return;
|
|
1011
|
+
}
|
|
1012
|
+
var self = debug;
|
|
1013
|
+
|
|
1014
|
+
// Set `diff` timestamp
|
|
1015
|
+
var curr = Number(new Date());
|
|
1016
|
+
var ms = curr - (prevTime || curr);
|
|
1017
|
+
self.diff = ms;
|
|
1018
|
+
self.prev = prevTime;
|
|
1019
|
+
self.curr = curr;
|
|
1020
|
+
prevTime = curr;
|
|
1021
|
+
args[0] = createDebug.coerce(args[0]);
|
|
1022
|
+
if (typeof args[0] !== 'string') {
|
|
1023
|
+
// Anything else let's inspect with %O
|
|
1024
|
+
args.unshift('%O');
|
|
1025
|
+
}
|
|
1026
|
+
|
|
1027
|
+
// Apply any `formatters` transformations
|
|
1028
|
+
var index = 0;
|
|
1029
|
+
args[0] = args[0].replace(/%([a-zA-Z%])/g, function (match, format) {
|
|
1030
|
+
// If we encounter an escaped % then don't increase the array index
|
|
1031
|
+
if (match === '%%') {
|
|
1032
|
+
return '%';
|
|
1033
|
+
}
|
|
1034
|
+
index++;
|
|
1035
|
+
var formatter = createDebug.formatters[format];
|
|
1036
|
+
if (typeof formatter === 'function') {
|
|
1037
|
+
var val = args[index];
|
|
1038
|
+
match = formatter.call(self, val);
|
|
1039
|
+
|
|
1040
|
+
// Now we need to remove `args[index]` since it's inlined in the `format`
|
|
1041
|
+
args.splice(index, 1);
|
|
1042
|
+
index--;
|
|
1043
|
+
}
|
|
1044
|
+
return match;
|
|
1045
|
+
});
|
|
1046
|
+
|
|
1047
|
+
// Apply env-specific formatting (colors, etc.)
|
|
1048
|
+
createDebug.formatArgs.call(self, args);
|
|
1049
|
+
var logFn = self.log || createDebug.log;
|
|
1050
|
+
logFn.apply(self, args);
|
|
1051
|
+
}
|
|
1052
|
+
debug.namespace = namespace;
|
|
1053
|
+
debug.useColors = createDebug.useColors();
|
|
1054
|
+
debug.color = createDebug.selectColor(namespace);
|
|
1055
|
+
debug.extend = extend;
|
|
1056
|
+
debug.destroy = createDebug.destroy; // XXX Temporary. Will be removed in the next major release.
|
|
1057
|
+
|
|
1058
|
+
Object.defineProperty(debug, 'enabled', {
|
|
1059
|
+
enumerable: true,
|
|
1060
|
+
configurable: false,
|
|
1061
|
+
get: function get() {
|
|
1062
|
+
if (enableOverride !== null) {
|
|
1063
|
+
return enableOverride;
|
|
1064
|
+
}
|
|
1065
|
+
if (namespacesCache !== createDebug.namespaces) {
|
|
1066
|
+
namespacesCache = createDebug.namespaces;
|
|
1067
|
+
enabledCache = createDebug.enabled(namespace);
|
|
1068
|
+
}
|
|
1069
|
+
return enabledCache;
|
|
1070
|
+
},
|
|
1071
|
+
set: function set(v) {
|
|
1072
|
+
enableOverride = v;
|
|
1073
|
+
}
|
|
1074
|
+
});
|
|
1075
|
+
|
|
1076
|
+
// Env-specific initialization logic for debug instances
|
|
1077
|
+
if (typeof createDebug.init === 'function') {
|
|
1078
|
+
createDebug.init(debug);
|
|
1079
|
+
}
|
|
1080
|
+
return debug;
|
|
1081
|
+
}
|
|
1082
|
+
function extend(namespace, delimiter) {
|
|
1083
|
+
var newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
|
|
1084
|
+
newDebug.log = this.log;
|
|
1085
|
+
return newDebug;
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
/**
|
|
1089
|
+
* Enables a debug mode by namespaces. This can include modes
|
|
1090
|
+
* separated by a colon and wildcards.
|
|
1091
|
+
*
|
|
1092
|
+
* @param {String} namespaces
|
|
1093
|
+
* @api public
|
|
1094
|
+
*/
|
|
1095
|
+
function enable(namespaces) {
|
|
1096
|
+
createDebug.save(namespaces);
|
|
1097
|
+
createDebug.namespaces = namespaces;
|
|
1098
|
+
createDebug.names = [];
|
|
1099
|
+
createDebug.skips = [];
|
|
1100
|
+
var split = (typeof namespaces === 'string' ? namespaces : '').trim().replace(/\s+/g, ',').split(',').filter(Boolean);
|
|
1101
|
+
var _iterator = _createForOfIteratorHelper(split),
|
|
1102
|
+
_step;
|
|
1103
|
+
try {
|
|
1104
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
1105
|
+
var ns = _step.value;
|
|
1106
|
+
if (ns[0] === '-') {
|
|
1107
|
+
createDebug.skips.push(ns.slice(1));
|
|
1108
|
+
} else {
|
|
1109
|
+
createDebug.names.push(ns);
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
} catch (err) {
|
|
1113
|
+
_iterator.e(err);
|
|
1114
|
+
} finally {
|
|
1115
|
+
_iterator.f();
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
/**
|
|
1120
|
+
* Checks if the given string matches a namespace template, honoring
|
|
1121
|
+
* asterisks as wildcards.
|
|
1122
|
+
*
|
|
1123
|
+
* @param {String} search
|
|
1124
|
+
* @param {String} template
|
|
1125
|
+
* @return {Boolean}
|
|
1126
|
+
*/
|
|
1127
|
+
function matchesTemplate(search, template) {
|
|
1128
|
+
var searchIndex = 0;
|
|
1129
|
+
var templateIndex = 0;
|
|
1130
|
+
var starIndex = -1;
|
|
1131
|
+
var matchIndex = 0;
|
|
1132
|
+
while (searchIndex < search.length) {
|
|
1133
|
+
if (templateIndex < template.length && (template[templateIndex] === search[searchIndex] || template[templateIndex] === '*')) {
|
|
1134
|
+
// Match character or proceed with wildcard
|
|
1135
|
+
if (template[templateIndex] === '*') {
|
|
1136
|
+
starIndex = templateIndex;
|
|
1137
|
+
matchIndex = searchIndex;
|
|
1138
|
+
templateIndex++; // Skip the '*'
|
|
1139
|
+
} else {
|
|
1140
|
+
searchIndex++;
|
|
1141
|
+
templateIndex++;
|
|
1142
|
+
}
|
|
1143
|
+
} else if (starIndex !== -1) {
|
|
1144
|
+
// eslint-disable-line no-negated-condition
|
|
1145
|
+
// Backtrack to the last '*' and try to match more characters
|
|
1146
|
+
templateIndex = starIndex + 1;
|
|
1147
|
+
matchIndex++;
|
|
1148
|
+
searchIndex = matchIndex;
|
|
1149
|
+
} else {
|
|
1150
|
+
return false; // No match
|
|
1151
|
+
}
|
|
1152
|
+
}
|
|
1153
|
+
|
|
1154
|
+
// Handle trailing '*' in template
|
|
1155
|
+
while (templateIndex < template.length && template[templateIndex] === '*') {
|
|
1156
|
+
templateIndex++;
|
|
1157
|
+
}
|
|
1158
|
+
return templateIndex === template.length;
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1161
|
+
/**
|
|
1162
|
+
* Disable debug output.
|
|
1163
|
+
*
|
|
1164
|
+
* @return {String} namespaces
|
|
1165
|
+
* @api public
|
|
1166
|
+
*/
|
|
1167
|
+
function disable() {
|
|
1168
|
+
var namespaces = [].concat(_toConsumableArray(createDebug.names), _toConsumableArray(createDebug.skips.map(function (namespace) {
|
|
1169
|
+
return '-' + namespace;
|
|
1170
|
+
}))).join(',');
|
|
1171
|
+
createDebug.enable('');
|
|
1172
|
+
return namespaces;
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
/**
|
|
1176
|
+
* Returns true if the given mode name is enabled, false otherwise.
|
|
1177
|
+
*
|
|
1178
|
+
* @param {String} name
|
|
1179
|
+
* @return {Boolean}
|
|
1180
|
+
* @api public
|
|
1181
|
+
*/
|
|
1182
|
+
function enabled(name) {
|
|
1183
|
+
var _iterator2 = _createForOfIteratorHelper(createDebug.skips),
|
|
1184
|
+
_step2;
|
|
1185
|
+
try {
|
|
1186
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
1187
|
+
var skip = _step2.value;
|
|
1188
|
+
if (matchesTemplate(name, skip)) {
|
|
1189
|
+
return false;
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1192
|
+
} catch (err) {
|
|
1193
|
+
_iterator2.e(err);
|
|
1194
|
+
} finally {
|
|
1195
|
+
_iterator2.f();
|
|
1196
|
+
}
|
|
1197
|
+
var _iterator3 = _createForOfIteratorHelper(createDebug.names),
|
|
1198
|
+
_step3;
|
|
1199
|
+
try {
|
|
1200
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
1201
|
+
var ns = _step3.value;
|
|
1202
|
+
if (matchesTemplate(name, ns)) {
|
|
1203
|
+
return true;
|
|
1204
|
+
}
|
|
1205
|
+
}
|
|
1206
|
+
} catch (err) {
|
|
1207
|
+
_iterator3.e(err);
|
|
1208
|
+
} finally {
|
|
1209
|
+
_iterator3.f();
|
|
1210
|
+
}
|
|
1211
|
+
return false;
|
|
1212
|
+
}
|
|
1213
|
+
|
|
1214
|
+
/**
|
|
1215
|
+
* Coerce `val`.
|
|
1216
|
+
*
|
|
1217
|
+
* @param {Mixed} val
|
|
1218
|
+
* @return {Mixed}
|
|
1219
|
+
* @api private
|
|
1220
|
+
*/
|
|
1221
|
+
function coerce(val) {
|
|
1222
|
+
if (val instanceof Error) {
|
|
1223
|
+
return val.stack || val.message;
|
|
1224
|
+
}
|
|
1225
|
+
return val;
|
|
1226
|
+
}
|
|
1227
|
+
|
|
1228
|
+
/**
|
|
1229
|
+
* XXX DO NOT USE. This is a temporary stub function.
|
|
1230
|
+
* XXX It WILL be removed in the next major release.
|
|
1231
|
+
*/
|
|
1232
|
+
function destroy() {
|
|
1233
|
+
console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
|
|
1234
|
+
}
|
|
1235
|
+
createDebug.enable(createDebug.load());
|
|
1236
|
+
return createDebug;
|
|
1237
|
+
}
|
|
1238
|
+
var common = setup;
|
|
1239
|
+
|
|
1240
|
+
/* eslint-env browser */
|
|
1241
|
+
browser.exports;
|
|
1242
|
+
(function (module, exports) {
|
|
1243
|
+
/**
|
|
1244
|
+
* This is the web browser implementation of `debug()`.
|
|
1245
|
+
*/
|
|
1246
|
+
|
|
1247
|
+
exports.formatArgs = formatArgs;
|
|
1248
|
+
exports.save = save;
|
|
1249
|
+
exports.load = load;
|
|
1250
|
+
exports.useColors = useColors;
|
|
1251
|
+
exports.storage = localstorage();
|
|
1252
|
+
exports.destroy = function () {
|
|
1253
|
+
var warned = false;
|
|
1254
|
+
return function () {
|
|
1255
|
+
if (!warned) {
|
|
1256
|
+
warned = true;
|
|
1257
|
+
console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
|
|
1258
|
+
}
|
|
1259
|
+
};
|
|
1260
|
+
}();
|
|
1261
|
+
|
|
1262
|
+
/**
|
|
1263
|
+
* Colors.
|
|
1264
|
+
*/
|
|
1265
|
+
|
|
1266
|
+
exports.colors = ['#0000CC', '#0000FF', '#0033CC', '#0033FF', '#0066CC', '#0066FF', '#0099CC', '#0099FF', '#00CC00', '#00CC33', '#00CC66', '#00CC99', '#00CCCC', '#00CCFF', '#3300CC', '#3300FF', '#3333CC', '#3333FF', '#3366CC', '#3366FF', '#3399CC', '#3399FF', '#33CC00', '#33CC33', '#33CC66', '#33CC99', '#33CCCC', '#33CCFF', '#6600CC', '#6600FF', '#6633CC', '#6633FF', '#66CC00', '#66CC33', '#9900CC', '#9900FF', '#9933CC', '#9933FF', '#99CC00', '#99CC33', '#CC0000', '#CC0033', '#CC0066', '#CC0099', '#CC00CC', '#CC00FF', '#CC3300', '#CC3333', '#CC3366', '#CC3399', '#CC33CC', '#CC33FF', '#CC6600', '#CC6633', '#CC9900', '#CC9933', '#CCCC00', '#CCCC33', '#FF0000', '#FF0033', '#FF0066', '#FF0099', '#FF00CC', '#FF00FF', '#FF3300', '#FF3333', '#FF3366', '#FF3399', '#FF33CC', '#FF33FF', '#FF6600', '#FF6633', '#FF9900', '#FF9933', '#FFCC00', '#FFCC33'];
|
|
1267
|
+
|
|
1268
|
+
/**
|
|
1269
|
+
* Currently only WebKit-based Web Inspectors, Firefox >= v31,
|
|
1270
|
+
* and the Firebug extension (any Firefox version) are known
|
|
1271
|
+
* to support "%c" CSS customizations.
|
|
1272
|
+
*
|
|
1273
|
+
* TODO: add a `localStorage` variable to explicitly enable/disable colors
|
|
1274
|
+
*/
|
|
1275
|
+
|
|
1276
|
+
// eslint-disable-next-line complexity
|
|
1277
|
+
function useColors() {
|
|
1278
|
+
// NB: In an Electron preload script, document will be defined but not fully
|
|
1279
|
+
// initialized. Since we know we're in Chrome, we'll just detect this case
|
|
1280
|
+
// explicitly
|
|
1281
|
+
if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) {
|
|
1282
|
+
return true;
|
|
1283
|
+
}
|
|
1284
|
+
|
|
1285
|
+
// Internet Explorer and Edge do not support colors.
|
|
1286
|
+
if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
|
|
1287
|
+
return false;
|
|
1288
|
+
}
|
|
1289
|
+
var m;
|
|
1290
|
+
|
|
1291
|
+
// Is webkit? http://stackoverflow.com/a/16459606/376773
|
|
1292
|
+
// document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
|
|
1293
|
+
// eslint-disable-next-line no-return-assign
|
|
1294
|
+
return typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance ||
|
|
1295
|
+
// Is firebug? http://stackoverflow.com/a/398120/376773
|
|
1296
|
+
typeof window !== 'undefined' && window.console && (window.console.firebug || window.console.exception && window.console.table) ||
|
|
1297
|
+
// Is firefox >= v31?
|
|
1298
|
+
// https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
|
|
1299
|
+
typeof navigator !== 'undefined' && navigator.userAgent && (m = navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)) && parseInt(m[1], 10) >= 31 ||
|
|
1300
|
+
// Double check webkit in userAgent just in case we are in a worker
|
|
1301
|
+
typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/);
|
|
1302
|
+
}
|
|
1303
|
+
|
|
1304
|
+
/**
|
|
1305
|
+
* Colorize log arguments if enabled.
|
|
1306
|
+
*
|
|
1307
|
+
* @api public
|
|
1308
|
+
*/
|
|
1309
|
+
|
|
1310
|
+
function formatArgs(args) {
|
|
1311
|
+
args[0] = (this.useColors ? '%c' : '') + this.namespace + (this.useColors ? ' %c' : ' ') + args[0] + (this.useColors ? '%c ' : ' ') + '+' + module.exports.humanize(this.diff);
|
|
1312
|
+
if (!this.useColors) {
|
|
1313
|
+
return;
|
|
1314
|
+
}
|
|
1315
|
+
var c = 'color: ' + this.color;
|
|
1316
|
+
args.splice(1, 0, c, 'color: inherit');
|
|
1317
|
+
|
|
1318
|
+
// The final "%c" is somewhat tricky, because there could be other
|
|
1319
|
+
// arguments passed either before or after the %c, so we need to
|
|
1320
|
+
// figure out the correct index to insert the CSS into
|
|
1321
|
+
var index = 0;
|
|
1322
|
+
var lastC = 0;
|
|
1323
|
+
args[0].replace(/%[a-zA-Z%]/g, function (match) {
|
|
1324
|
+
if (match === '%%') {
|
|
1325
|
+
return;
|
|
1326
|
+
}
|
|
1327
|
+
index++;
|
|
1328
|
+
if (match === '%c') {
|
|
1329
|
+
// We only are interested in the *last* %c
|
|
1330
|
+
// (the user may have provided their own)
|
|
1331
|
+
lastC = index;
|
|
1332
|
+
}
|
|
1333
|
+
});
|
|
1334
|
+
args.splice(lastC, 0, c);
|
|
1335
|
+
}
|
|
1336
|
+
|
|
1337
|
+
/**
|
|
1338
|
+
* Invokes `console.debug()` when available.
|
|
1339
|
+
* No-op when `console.debug` is not a "function".
|
|
1340
|
+
* If `console.debug` is not available, falls back
|
|
1341
|
+
* to `console.log`.
|
|
1342
|
+
*
|
|
1343
|
+
* @api public
|
|
1344
|
+
*/
|
|
1345
|
+
exports.log = console.debug || console.log || function () {};
|
|
1346
|
+
|
|
1347
|
+
/**
|
|
1348
|
+
* Save `namespaces`.
|
|
1349
|
+
*
|
|
1350
|
+
* @param {String} namespaces
|
|
1351
|
+
* @api private
|
|
1352
|
+
*/
|
|
1353
|
+
function save(namespaces) {
|
|
1354
|
+
try {
|
|
1355
|
+
if (namespaces) {
|
|
1356
|
+
exports.storage.setItem('debug', namespaces);
|
|
1357
|
+
} else {
|
|
1358
|
+
exports.storage.removeItem('debug');
|
|
1359
|
+
}
|
|
1360
|
+
} catch (error) {
|
|
1361
|
+
// Swallow
|
|
1362
|
+
// XXX (@Qix-) should we be logging these?
|
|
1363
|
+
}
|
|
1364
|
+
}
|
|
1365
|
+
|
|
1366
|
+
/**
|
|
1367
|
+
* Load `namespaces`.
|
|
1368
|
+
*
|
|
1369
|
+
* @return {String} returns the previously persisted debug modes
|
|
1370
|
+
* @api private
|
|
1371
|
+
*/
|
|
1372
|
+
function load() {
|
|
1373
|
+
var r;
|
|
1374
|
+
try {
|
|
1375
|
+
r = exports.storage.getItem('debug') || exports.storage.getItem('DEBUG');
|
|
1376
|
+
} catch (error) {
|
|
1377
|
+
// Swallow
|
|
1378
|
+
// XXX (@Qix-) should we be logging these?
|
|
1379
|
+
}
|
|
1380
|
+
|
|
1381
|
+
// If debug isn't set in LS, and we're in Electron, try to load $DEBUG
|
|
1382
|
+
if (!r && typeof process !== 'undefined' && 'env' in process) {
|
|
1383
|
+
r = process.env.DEBUG;
|
|
1384
|
+
}
|
|
1385
|
+
return r;
|
|
1386
|
+
}
|
|
1387
|
+
|
|
1388
|
+
/**
|
|
1389
|
+
* Localstorage attempts to return the localstorage.
|
|
1390
|
+
*
|
|
1391
|
+
* This is necessary because safari throws
|
|
1392
|
+
* when a user disables cookies/localstorage
|
|
1393
|
+
* and you attempt to access it.
|
|
1394
|
+
*
|
|
1395
|
+
* @return {LocalStorage}
|
|
1396
|
+
* @api private
|
|
1397
|
+
*/
|
|
1398
|
+
|
|
1399
|
+
function localstorage() {
|
|
1400
|
+
try {
|
|
1401
|
+
// TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context
|
|
1402
|
+
// The Browser also has localStorage in the global context.
|
|
1403
|
+
return localStorage;
|
|
1404
|
+
} catch (error) {
|
|
1405
|
+
// Swallow
|
|
1406
|
+
// XXX (@Qix-) should we be logging these?
|
|
1407
|
+
}
|
|
1408
|
+
}
|
|
1409
|
+
module.exports = common(exports);
|
|
1410
|
+
var formatters = module.exports.formatters;
|
|
1411
|
+
|
|
1412
|
+
/**
|
|
1413
|
+
* Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
|
|
1414
|
+
*/
|
|
1415
|
+
|
|
1416
|
+
formatters.j = function (v) {
|
|
1417
|
+
try {
|
|
1418
|
+
return JSON.stringify(v);
|
|
1419
|
+
} catch (error) {
|
|
1420
|
+
return '[UnexpectedJSONParseError]: ' + error.message;
|
|
1421
|
+
}
|
|
1422
|
+
};
|
|
1423
|
+
})(browser, browser.exports);
|
|
1424
|
+
var browserExports = browser.exports;
|
|
1425
|
+
var debugModule = /*@__PURE__*/getDefaultExportFromCjs(browserExports);
|
|
1426
|
+
|
|
1427
|
+
var debug$5 = debugModule("engine.io-client:transport"); // debug()
|
|
1428
|
+
var TransportError = /*#__PURE__*/function (_Error) {
|
|
1429
|
+
function TransportError(reason, description, context) {
|
|
1430
|
+
var _this;
|
|
1431
|
+
_this = _Error.call(this, reason) || this;
|
|
1432
|
+
_this.description = description;
|
|
1433
|
+
_this.context = context;
|
|
1434
|
+
_this.type = "TransportError";
|
|
1435
|
+
return _this;
|
|
1436
|
+
}
|
|
1437
|
+
_inheritsLoose(TransportError, _Error);
|
|
1438
|
+
return TransportError;
|
|
1439
|
+
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
1440
|
+
var Transport = /*#__PURE__*/function (_Emitter) {
|
|
1441
|
+
/**
|
|
1442
|
+
* Transport abstract constructor.
|
|
1443
|
+
*
|
|
1444
|
+
* @param {Object} opts - options
|
|
1445
|
+
* @protected
|
|
1446
|
+
*/
|
|
1447
|
+
function Transport(opts) {
|
|
1448
|
+
var _this2;
|
|
1449
|
+
_this2 = _Emitter.call(this) || this;
|
|
1450
|
+
_this2.writable = false;
|
|
1451
|
+
installTimerFunctions(_this2, opts);
|
|
1452
|
+
_this2.opts = opts;
|
|
1453
|
+
_this2.query = opts.query;
|
|
1454
|
+
_this2.socket = opts.socket;
|
|
1455
|
+
_this2.supportsBinary = !opts.forceBase64;
|
|
1456
|
+
return _this2;
|
|
1457
|
+
}
|
|
1458
|
+
/**
|
|
1459
|
+
* Emits an error.
|
|
1460
|
+
*
|
|
1461
|
+
* @param {String} reason
|
|
1462
|
+
* @param description
|
|
1463
|
+
* @param context - the error context
|
|
1464
|
+
* @return {Transport} for chaining
|
|
1465
|
+
* @protected
|
|
1466
|
+
*/
|
|
1467
|
+
_inheritsLoose(Transport, _Emitter);
|
|
1468
|
+
var _proto = Transport.prototype;
|
|
1469
|
+
_proto.onError = function onError(reason, description, context) {
|
|
1470
|
+
_Emitter.prototype.emitReserved.call(this, "error", new TransportError(reason, description, context));
|
|
1471
|
+
return this;
|
|
1472
|
+
}
|
|
1473
|
+
/**
|
|
1474
|
+
* Opens the transport.
|
|
1475
|
+
*/;
|
|
1476
|
+
_proto.open = function open() {
|
|
1477
|
+
this.readyState = "opening";
|
|
1478
|
+
this.doOpen();
|
|
1479
|
+
return this;
|
|
1480
|
+
}
|
|
1481
|
+
/**
|
|
1482
|
+
* Closes the transport.
|
|
1483
|
+
*/;
|
|
1484
|
+
_proto.close = function close() {
|
|
1485
|
+
if (this.readyState === "opening" || this.readyState === "open") {
|
|
1486
|
+
this.doClose();
|
|
1487
|
+
this.onClose();
|
|
1488
|
+
}
|
|
1489
|
+
return this;
|
|
1490
|
+
}
|
|
1491
|
+
/**
|
|
1492
|
+
* Sends multiple packets.
|
|
1493
|
+
*
|
|
1494
|
+
* @param {Array} packets
|
|
1495
|
+
*/;
|
|
1496
|
+
_proto.send = function send(packets) {
|
|
1497
|
+
if (this.readyState === "open") {
|
|
1498
|
+
this.write(packets);
|
|
1499
|
+
} else {
|
|
1500
|
+
// this might happen if the transport was silently closed in the beforeunload event handler
|
|
1501
|
+
debug$5("transport is not open, discarding packets");
|
|
1502
|
+
}
|
|
1503
|
+
}
|
|
1504
|
+
/**
|
|
1505
|
+
* Called upon open
|
|
1506
|
+
*
|
|
1507
|
+
* @protected
|
|
1508
|
+
*/;
|
|
1509
|
+
_proto.onOpen = function onOpen() {
|
|
1510
|
+
this.readyState = "open";
|
|
1511
|
+
this.writable = true;
|
|
1512
|
+
_Emitter.prototype.emitReserved.call(this, "open");
|
|
1513
|
+
}
|
|
1514
|
+
/**
|
|
1515
|
+
* Called with data.
|
|
1516
|
+
*
|
|
1517
|
+
* @param {String} data
|
|
1518
|
+
* @protected
|
|
1519
|
+
*/;
|
|
1520
|
+
_proto.onData = function onData(data) {
|
|
1521
|
+
var packet = decodePacket(data, this.socket.binaryType);
|
|
1522
|
+
this.onPacket(packet);
|
|
1523
|
+
}
|
|
1524
|
+
/**
|
|
1525
|
+
* Called with a decoded packet.
|
|
1526
|
+
*
|
|
1527
|
+
* @protected
|
|
1528
|
+
*/;
|
|
1529
|
+
_proto.onPacket = function onPacket(packet) {
|
|
1530
|
+
_Emitter.prototype.emitReserved.call(this, "packet", packet);
|
|
1531
|
+
}
|
|
1532
|
+
/**
|
|
1533
|
+
* Called upon close.
|
|
1534
|
+
*
|
|
1535
|
+
* @protected
|
|
1536
|
+
*/;
|
|
1537
|
+
_proto.onClose = function onClose(details) {
|
|
1538
|
+
this.readyState = "closed";
|
|
1539
|
+
_Emitter.prototype.emitReserved.call(this, "close", details);
|
|
1540
|
+
}
|
|
1541
|
+
/**
|
|
1542
|
+
* Pauses the transport, in order not to lose packets during an upgrade.
|
|
1543
|
+
*
|
|
1544
|
+
* @param onPause
|
|
1545
|
+
*/;
|
|
1546
|
+
_proto.pause = function pause(onPause) {};
|
|
1547
|
+
_proto.createUri = function createUri(schema) {
|
|
1548
|
+
var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1549
|
+
return schema + "://" + this._hostname() + this._port() + this.opts.path + this._query(query);
|
|
1550
|
+
};
|
|
1551
|
+
_proto._hostname = function _hostname() {
|
|
1552
|
+
var hostname = this.opts.hostname;
|
|
1553
|
+
return hostname.indexOf(":") === -1 ? hostname : "[" + hostname + "]";
|
|
1554
|
+
};
|
|
1555
|
+
_proto._port = function _port() {
|
|
1556
|
+
if (this.opts.port && (this.opts.secure && Number(this.opts.port) !== 443 || !this.opts.secure && Number(this.opts.port) !== 80)) {
|
|
1557
|
+
return ":" + this.opts.port;
|
|
1558
|
+
} else {
|
|
1559
|
+
return "";
|
|
1560
|
+
}
|
|
1561
|
+
};
|
|
1562
|
+
_proto._query = function _query(query) {
|
|
1563
|
+
var encodedQuery = encode(query);
|
|
1564
|
+
return encodedQuery.length ? "?" + encodedQuery : "";
|
|
1565
|
+
};
|
|
1566
|
+
return Transport;
|
|
1567
|
+
}(Emitter);
|
|
1568
|
+
|
|
1569
|
+
var debug$4 = debugModule("engine.io-client:polling"); // debug()
|
|
1570
|
+
var Polling = /*#__PURE__*/function (_Transport) {
|
|
1571
|
+
function Polling() {
|
|
1572
|
+
var _this;
|
|
1573
|
+
_this = _Transport.apply(this, arguments) || this;
|
|
1574
|
+
_this._polling = false;
|
|
1575
|
+
return _this;
|
|
1576
|
+
}
|
|
1577
|
+
_inheritsLoose(Polling, _Transport);
|
|
1578
|
+
var _proto = Polling.prototype;
|
|
1579
|
+
/**
|
|
1580
|
+
* Opens the socket (triggers polling). We write a PING message to determine
|
|
1581
|
+
* when the transport is open.
|
|
1582
|
+
*
|
|
1583
|
+
* @protected
|
|
1584
|
+
*/
|
|
1585
|
+
_proto.doOpen = function doOpen() {
|
|
1586
|
+
this._poll();
|
|
1587
|
+
}
|
|
1588
|
+
/**
|
|
1589
|
+
* Pauses polling.
|
|
1590
|
+
*
|
|
1591
|
+
* @param {Function} onPause - callback upon buffers are flushed and transport is paused
|
|
1592
|
+
* @package
|
|
1593
|
+
*/;
|
|
1594
|
+
_proto.pause = function pause(onPause) {
|
|
1595
|
+
var _this2 = this;
|
|
1596
|
+
this.readyState = "pausing";
|
|
1597
|
+
var pause = function pause() {
|
|
1598
|
+
debug$4("paused");
|
|
1599
|
+
_this2.readyState = "paused";
|
|
1600
|
+
onPause();
|
|
1601
|
+
};
|
|
1602
|
+
if (this._polling || !this.writable) {
|
|
1603
|
+
var total = 0;
|
|
1604
|
+
if (this._polling) {
|
|
1605
|
+
debug$4("we are currently polling - waiting to pause");
|
|
1606
|
+
total++;
|
|
1607
|
+
this.once("pollComplete", function () {
|
|
1608
|
+
debug$4("pre-pause polling complete");
|
|
1609
|
+
--total || pause();
|
|
1610
|
+
});
|
|
1611
|
+
}
|
|
1612
|
+
if (!this.writable) {
|
|
1613
|
+
debug$4("we are currently writing - waiting to pause");
|
|
1614
|
+
total++;
|
|
1615
|
+
this.once("drain", function () {
|
|
1616
|
+
debug$4("pre-pause writing complete");
|
|
1617
|
+
--total || pause();
|
|
1618
|
+
});
|
|
1619
|
+
}
|
|
1620
|
+
} else {
|
|
1621
|
+
pause();
|
|
1622
|
+
}
|
|
1623
|
+
}
|
|
1624
|
+
/**
|
|
1625
|
+
* Starts polling cycle.
|
|
1626
|
+
*
|
|
1627
|
+
* @private
|
|
1628
|
+
*/;
|
|
1629
|
+
_proto._poll = function _poll() {
|
|
1630
|
+
debug$4("polling");
|
|
1631
|
+
this._polling = true;
|
|
1632
|
+
this.doPoll();
|
|
1633
|
+
this.emitReserved("poll");
|
|
1634
|
+
}
|
|
1635
|
+
/**
|
|
1636
|
+
* Overloads onData to detect payloads.
|
|
1637
|
+
*
|
|
1638
|
+
* @protected
|
|
1639
|
+
*/;
|
|
1640
|
+
_proto.onData = function onData(data) {
|
|
1641
|
+
var _this3 = this;
|
|
1642
|
+
debug$4("polling got data %s", data);
|
|
1643
|
+
var callback = function callback(packet) {
|
|
1644
|
+
// if its the first message we consider the transport open
|
|
1645
|
+
if ("opening" === _this3.readyState && packet.type === "open") {
|
|
1646
|
+
_this3.onOpen();
|
|
1647
|
+
}
|
|
1648
|
+
// if its a close packet, we close the ongoing requests
|
|
1649
|
+
if ("close" === packet.type) {
|
|
1650
|
+
_this3.onClose({
|
|
1651
|
+
description: "transport closed by the server"
|
|
1652
|
+
});
|
|
1653
|
+
return false;
|
|
1654
|
+
}
|
|
1655
|
+
// otherwise bypass onData and handle the message
|
|
1656
|
+
_this3.onPacket(packet);
|
|
1657
|
+
};
|
|
1658
|
+
// decode payload
|
|
1659
|
+
decodePayload(data, this.socket.binaryType).forEach(callback);
|
|
1660
|
+
// if an event did not trigger closing
|
|
1661
|
+
if ("closed" !== this.readyState) {
|
|
1662
|
+
// if we got data we're not polling
|
|
1663
|
+
this._polling = false;
|
|
1664
|
+
this.emitReserved("pollComplete");
|
|
1665
|
+
if ("open" === this.readyState) {
|
|
1666
|
+
this._poll();
|
|
1667
|
+
} else {
|
|
1668
|
+
debug$4('ignoring poll - transport state "%s"', this.readyState);
|
|
1669
|
+
}
|
|
1670
|
+
}
|
|
1671
|
+
}
|
|
1672
|
+
/**
|
|
1673
|
+
* For polling, send a close packet.
|
|
1674
|
+
*
|
|
1675
|
+
* @protected
|
|
1676
|
+
*/;
|
|
1677
|
+
_proto.doClose = function doClose() {
|
|
1678
|
+
var _this4 = this;
|
|
1679
|
+
var close = function close() {
|
|
1680
|
+
debug$4("writing close packet");
|
|
1681
|
+
_this4.write([{
|
|
1682
|
+
type: "close"
|
|
1683
|
+
}]);
|
|
1684
|
+
};
|
|
1685
|
+
if ("open" === this.readyState) {
|
|
1686
|
+
debug$4("transport open - closing");
|
|
1687
|
+
close();
|
|
1688
|
+
} else {
|
|
1689
|
+
// in case we're trying to close while
|
|
1690
|
+
// handshaking is in progress (GH-164)
|
|
1691
|
+
debug$4("transport not open - deferring close");
|
|
1692
|
+
this.once("open", close);
|
|
1693
|
+
}
|
|
1694
|
+
}
|
|
1695
|
+
/**
|
|
1696
|
+
* Writes a packets payload.
|
|
1697
|
+
*
|
|
1698
|
+
* @param {Array} packets - data packets
|
|
1699
|
+
* @protected
|
|
1700
|
+
*/;
|
|
1701
|
+
_proto.write = function write(packets) {
|
|
1702
|
+
var _this5 = this;
|
|
1703
|
+
this.writable = false;
|
|
1704
|
+
encodePayload(packets, function (data) {
|
|
1705
|
+
_this5.doWrite(data, function () {
|
|
1706
|
+
_this5.writable = true;
|
|
1707
|
+
_this5.emitReserved("drain");
|
|
1708
|
+
});
|
|
1709
|
+
});
|
|
1710
|
+
}
|
|
1711
|
+
/**
|
|
1712
|
+
* Generates uri for connection.
|
|
1713
|
+
*
|
|
1714
|
+
* @private
|
|
1715
|
+
*/;
|
|
1716
|
+
_proto.uri = function uri() {
|
|
1717
|
+
var schema = this.opts.secure ? "https" : "http";
|
|
1718
|
+
var query = this.query || {};
|
|
1719
|
+
// cache busting is forced
|
|
1720
|
+
if (false !== this.opts.timestampRequests) {
|
|
1721
|
+
query[this.opts.timestampParam] = randomString();
|
|
1722
|
+
}
|
|
1723
|
+
if (!this.supportsBinary && !query.sid) {
|
|
1724
|
+
query.b64 = 1;
|
|
1725
|
+
}
|
|
1726
|
+
return this.createUri(schema, query);
|
|
1727
|
+
};
|
|
1728
|
+
return _createClass(Polling, [{
|
|
1729
|
+
key: "name",
|
|
1730
|
+
get: function get() {
|
|
1731
|
+
return "polling";
|
|
1732
|
+
}
|
|
1733
|
+
}]);
|
|
1734
|
+
}(Transport);
|
|
1735
|
+
|
|
1736
|
+
// imported from https://github.com/component/has-cors
|
|
1737
|
+
var value = false;
|
|
1738
|
+
try {
|
|
1739
|
+
value = typeof XMLHttpRequest !== 'undefined' && 'withCredentials' in new XMLHttpRequest();
|
|
1740
|
+
} catch (err) {
|
|
1741
|
+
// if XMLHttp support is disabled in IE then it will throw
|
|
1742
|
+
// when trying to create
|
|
1743
|
+
}
|
|
1744
|
+
var hasCORS = value;
|
|
1745
|
+
|
|
1746
|
+
var debug$3 = debugModule("engine.io-client:polling"); // debug()
|
|
1747
|
+
function empty() {}
|
|
1748
|
+
var BaseXHR = /*#__PURE__*/function (_Polling) {
|
|
1749
|
+
/**
|
|
1750
|
+
* XHR Polling constructor.
|
|
1751
|
+
*
|
|
1752
|
+
* @param {Object} opts
|
|
1753
|
+
* @package
|
|
1754
|
+
*/
|
|
1755
|
+
function BaseXHR(opts) {
|
|
1756
|
+
var _this;
|
|
1757
|
+
_this = _Polling.call(this, opts) || this;
|
|
1758
|
+
if (typeof location !== "undefined") {
|
|
1759
|
+
var isSSL = "https:" === location.protocol;
|
|
1760
|
+
var port = location.port;
|
|
1761
|
+
// some user agents have empty `location.port`
|
|
1762
|
+
if (!port) {
|
|
1763
|
+
port = isSSL ? "443" : "80";
|
|
1764
|
+
}
|
|
1765
|
+
_this.xd = typeof location !== "undefined" && opts.hostname !== location.hostname || port !== opts.port;
|
|
1766
|
+
}
|
|
1767
|
+
return _this;
|
|
1768
|
+
}
|
|
1769
|
+
/**
|
|
1770
|
+
* Sends data.
|
|
1771
|
+
*
|
|
1772
|
+
* @param {String} data to send.
|
|
1773
|
+
* @param {Function} called upon flush.
|
|
1774
|
+
* @private
|
|
1775
|
+
*/
|
|
1776
|
+
_inheritsLoose(BaseXHR, _Polling);
|
|
1777
|
+
var _proto = BaseXHR.prototype;
|
|
1778
|
+
_proto.doWrite = function doWrite(data, fn) {
|
|
1779
|
+
var _this2 = this;
|
|
1780
|
+
var req = this.request({
|
|
1781
|
+
method: "POST",
|
|
1782
|
+
data: data
|
|
1783
|
+
});
|
|
1784
|
+
req.on("success", fn);
|
|
1785
|
+
req.on("error", function (xhrStatus, context) {
|
|
1786
|
+
_this2.onError("xhr post error", xhrStatus, context);
|
|
1787
|
+
});
|
|
1788
|
+
}
|
|
1789
|
+
/**
|
|
1790
|
+
* Starts a poll cycle.
|
|
1791
|
+
*
|
|
1792
|
+
* @private
|
|
1793
|
+
*/;
|
|
1794
|
+
_proto.doPoll = function doPoll() {
|
|
1795
|
+
var _this3 = this;
|
|
1796
|
+
debug$3("xhr poll");
|
|
1797
|
+
var req = this.request();
|
|
1798
|
+
req.on("data", this.onData.bind(this));
|
|
1799
|
+
req.on("error", function (xhrStatus, context) {
|
|
1800
|
+
_this3.onError("xhr poll error", xhrStatus, context);
|
|
1801
|
+
});
|
|
1802
|
+
this.pollXhr = req;
|
|
1803
|
+
};
|
|
1804
|
+
return BaseXHR;
|
|
1805
|
+
}(Polling);
|
|
1806
|
+
var Request = /*#__PURE__*/function (_Emitter) {
|
|
1807
|
+
/**
|
|
1808
|
+
* Request constructor
|
|
1809
|
+
*
|
|
1810
|
+
* @param {Object} options
|
|
1811
|
+
* @package
|
|
1812
|
+
*/
|
|
1813
|
+
function Request(createRequest, uri, opts) {
|
|
1814
|
+
var _this4;
|
|
1815
|
+
_this4 = _Emitter.call(this) || this;
|
|
1816
|
+
_this4.createRequest = createRequest;
|
|
1817
|
+
installTimerFunctions(_this4, opts);
|
|
1818
|
+
_this4._opts = opts;
|
|
1819
|
+
_this4._method = opts.method || "GET";
|
|
1820
|
+
_this4._uri = uri;
|
|
1821
|
+
_this4._data = undefined !== opts.data ? opts.data : null;
|
|
1822
|
+
_this4._create();
|
|
1823
|
+
return _this4;
|
|
1824
|
+
}
|
|
1825
|
+
/**
|
|
1826
|
+
* Creates the XHR object and sends the request.
|
|
1827
|
+
*
|
|
1828
|
+
* @private
|
|
1829
|
+
*/
|
|
1830
|
+
_inheritsLoose(Request, _Emitter);
|
|
1831
|
+
var _proto2 = Request.prototype;
|
|
1832
|
+
_proto2._create = function _create() {
|
|
1833
|
+
var _this5 = this;
|
|
1834
|
+
var _a;
|
|
1835
|
+
var opts = pick(this._opts, "agent", "pfx", "key", "passphrase", "cert", "ca", "ciphers", "rejectUnauthorized", "autoUnref");
|
|
1836
|
+
opts.xdomain = !!this._opts.xd;
|
|
1837
|
+
var xhr = this._xhr = this.createRequest(opts);
|
|
1838
|
+
try {
|
|
1839
|
+
debug$3("xhr open %s: %s", this._method, this._uri);
|
|
1840
|
+
xhr.open(this._method, this._uri, true);
|
|
1841
|
+
try {
|
|
1842
|
+
if (this._opts.extraHeaders) {
|
|
1843
|
+
// @ts-ignore
|
|
1844
|
+
xhr.setDisableHeaderCheck && xhr.setDisableHeaderCheck(true);
|
|
1845
|
+
for (var i in this._opts.extraHeaders) {
|
|
1846
|
+
if (this._opts.extraHeaders.hasOwnProperty(i)) {
|
|
1847
|
+
xhr.setRequestHeader(i, this._opts.extraHeaders[i]);
|
|
1848
|
+
}
|
|
1849
|
+
}
|
|
1850
|
+
}
|
|
1851
|
+
} catch (e) {}
|
|
1852
|
+
if ("POST" === this._method) {
|
|
1853
|
+
try {
|
|
1854
|
+
xhr.setRequestHeader("Content-type", "text/plain;charset=UTF-8");
|
|
1855
|
+
} catch (e) {}
|
|
1856
|
+
}
|
|
1857
|
+
try {
|
|
1858
|
+
xhr.setRequestHeader("Accept", "*/*");
|
|
1859
|
+
} catch (e) {}
|
|
1860
|
+
(_a = this._opts.cookieJar) === null || _a === void 0 ? void 0 : _a.addCookies(xhr);
|
|
1861
|
+
// ie6 check
|
|
1862
|
+
if ("withCredentials" in xhr) {
|
|
1863
|
+
xhr.withCredentials = this._opts.withCredentials;
|
|
1864
|
+
}
|
|
1865
|
+
if (this._opts.requestTimeout) {
|
|
1866
|
+
xhr.timeout = this._opts.requestTimeout;
|
|
1867
|
+
}
|
|
1868
|
+
xhr.onreadystatechange = function () {
|
|
1869
|
+
var _a;
|
|
1870
|
+
if (xhr.readyState === 3) {
|
|
1871
|
+
(_a = _this5._opts.cookieJar) === null || _a === void 0 ? void 0 : _a.parseCookies(
|
|
1872
|
+
// @ts-ignore
|
|
1873
|
+
xhr.getResponseHeader("set-cookie"));
|
|
1874
|
+
}
|
|
1875
|
+
if (4 !== xhr.readyState) return;
|
|
1876
|
+
if (200 === xhr.status || 1223 === xhr.status) {
|
|
1877
|
+
_this5._onLoad();
|
|
1878
|
+
} else {
|
|
1879
|
+
// make sure the `error` event handler that's user-set
|
|
1880
|
+
// does not throw in the same tick and gets caught here
|
|
1881
|
+
_this5.setTimeoutFn(function () {
|
|
1882
|
+
_this5._onError(typeof xhr.status === "number" ? xhr.status : 0);
|
|
1883
|
+
}, 0);
|
|
1884
|
+
}
|
|
1885
|
+
};
|
|
1886
|
+
debug$3("xhr data %s", this._data);
|
|
1887
|
+
xhr.send(this._data);
|
|
1888
|
+
} catch (e) {
|
|
1889
|
+
// Need to defer since .create() is called directly from the constructor
|
|
1890
|
+
// and thus the 'error' event can only be only bound *after* this exception
|
|
1891
|
+
// occurs. Therefore, also, we cannot throw here at all.
|
|
1892
|
+
this.setTimeoutFn(function () {
|
|
1893
|
+
_this5._onError(e);
|
|
1894
|
+
}, 0);
|
|
1895
|
+
return;
|
|
1896
|
+
}
|
|
1897
|
+
if (typeof document !== "undefined") {
|
|
1898
|
+
this._index = Request.requestsCount++;
|
|
1899
|
+
Request.requests[this._index] = this;
|
|
1900
|
+
}
|
|
1901
|
+
}
|
|
1902
|
+
/**
|
|
1903
|
+
* Called upon error.
|
|
1904
|
+
*
|
|
1905
|
+
* @private
|
|
1906
|
+
*/;
|
|
1907
|
+
_proto2._onError = function _onError(err) {
|
|
1908
|
+
this.emitReserved("error", err, this._xhr);
|
|
1909
|
+
this._cleanup(true);
|
|
1910
|
+
}
|
|
1911
|
+
/**
|
|
1912
|
+
* Cleans up house.
|
|
1913
|
+
*
|
|
1914
|
+
* @private
|
|
1915
|
+
*/;
|
|
1916
|
+
_proto2._cleanup = function _cleanup(fromError) {
|
|
1917
|
+
if ("undefined" === typeof this._xhr || null === this._xhr) {
|
|
1918
|
+
return;
|
|
1919
|
+
}
|
|
1920
|
+
this._xhr.onreadystatechange = empty;
|
|
1921
|
+
if (fromError) {
|
|
1922
|
+
try {
|
|
1923
|
+
this._xhr.abort();
|
|
1924
|
+
} catch (e) {}
|
|
1925
|
+
}
|
|
1926
|
+
if (typeof document !== "undefined") {
|
|
1927
|
+
delete Request.requests[this._index];
|
|
1928
|
+
}
|
|
1929
|
+
this._xhr = null;
|
|
1930
|
+
}
|
|
1931
|
+
/**
|
|
1932
|
+
* Called upon load.
|
|
1933
|
+
*
|
|
1934
|
+
* @private
|
|
1935
|
+
*/;
|
|
1936
|
+
_proto2._onLoad = function _onLoad() {
|
|
1937
|
+
var data = this._xhr.responseText;
|
|
1938
|
+
if (data !== null) {
|
|
1939
|
+
this.emitReserved("data", data);
|
|
1940
|
+
this.emitReserved("success");
|
|
1941
|
+
this._cleanup();
|
|
1942
|
+
}
|
|
1943
|
+
}
|
|
1944
|
+
/**
|
|
1945
|
+
* Aborts the request.
|
|
1946
|
+
*
|
|
1947
|
+
* @package
|
|
1948
|
+
*/;
|
|
1949
|
+
_proto2.abort = function abort() {
|
|
1950
|
+
this._cleanup();
|
|
1951
|
+
};
|
|
1952
|
+
return Request;
|
|
1953
|
+
}(Emitter);
|
|
1954
|
+
Request.requestsCount = 0;
|
|
1955
|
+
Request.requests = {};
|
|
1956
|
+
/**
|
|
1957
|
+
* Aborts pending requests when unloading the window. This is needed to prevent
|
|
1958
|
+
* memory leaks (e.g. when using IE) and to ensure that no spurious error is
|
|
1959
|
+
* emitted.
|
|
1960
|
+
*/
|
|
1961
|
+
if (typeof document !== "undefined") {
|
|
1962
|
+
// @ts-ignore
|
|
1963
|
+
if (typeof attachEvent === "function") {
|
|
1964
|
+
// @ts-ignore
|
|
1965
|
+
attachEvent("onunload", unloadHandler);
|
|
1966
|
+
} else if (typeof addEventListener === "function") {
|
|
1967
|
+
var terminationEvent = "onpagehide" in globalThisShim ? "pagehide" : "unload";
|
|
1968
|
+
addEventListener(terminationEvent, unloadHandler, false);
|
|
1969
|
+
}
|
|
1970
|
+
}
|
|
1971
|
+
function unloadHandler() {
|
|
1972
|
+
for (var i in Request.requests) {
|
|
1973
|
+
if (Request.requests.hasOwnProperty(i)) {
|
|
1974
|
+
Request.requests[i].abort();
|
|
1975
|
+
}
|
|
1976
|
+
}
|
|
1977
|
+
}
|
|
1978
|
+
var hasXHR2 = function () {
|
|
1979
|
+
var xhr = newRequest({
|
|
1980
|
+
xdomain: false
|
|
1981
|
+
});
|
|
1982
|
+
return xhr && xhr.responseType !== null;
|
|
1983
|
+
}();
|
|
1984
|
+
/**
|
|
1985
|
+
* HTTP long-polling based on the built-in `XMLHttpRequest` object.
|
|
1986
|
+
*
|
|
1987
|
+
* Usage: browser
|
|
1988
|
+
*
|
|
1989
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest
|
|
1990
|
+
*/
|
|
1991
|
+
var XHR = /*#__PURE__*/function (_BaseXHR) {
|
|
1992
|
+
function XHR(opts) {
|
|
1993
|
+
var _this6;
|
|
1994
|
+
_this6 = _BaseXHR.call(this, opts) || this;
|
|
1995
|
+
var forceBase64 = opts && opts.forceBase64;
|
|
1996
|
+
_this6.supportsBinary = hasXHR2 && !forceBase64;
|
|
1997
|
+
return _this6;
|
|
1998
|
+
}
|
|
1999
|
+
_inheritsLoose(XHR, _BaseXHR);
|
|
2000
|
+
var _proto3 = XHR.prototype;
|
|
2001
|
+
_proto3.request = function request() {
|
|
2002
|
+
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
2003
|
+
_extends(opts, {
|
|
2004
|
+
xd: this.xd
|
|
2005
|
+
}, this.opts);
|
|
2006
|
+
return new Request(newRequest, this.uri(), opts);
|
|
2007
|
+
};
|
|
2008
|
+
return XHR;
|
|
2009
|
+
}(BaseXHR);
|
|
2010
|
+
function newRequest(opts) {
|
|
2011
|
+
var xdomain = opts.xdomain;
|
|
2012
|
+
// XMLHttpRequest can be disabled on IE
|
|
2013
|
+
try {
|
|
2014
|
+
if ("undefined" !== typeof XMLHttpRequest && (!xdomain || hasCORS)) {
|
|
2015
|
+
return new XMLHttpRequest();
|
|
2016
|
+
}
|
|
2017
|
+
} catch (e) {}
|
|
2018
|
+
if (!xdomain) {
|
|
2019
|
+
try {
|
|
2020
|
+
return new globalThisShim[["Active"].concat("Object").join("X")]("Microsoft.XMLHTTP");
|
|
2021
|
+
} catch (e) {}
|
|
2022
|
+
}
|
|
2023
|
+
}
|
|
2024
|
+
|
|
2025
|
+
var debug$2 = debugModule("engine.io-client:websocket"); // debug()
|
|
2026
|
+
// detect ReactNative environment
|
|
2027
|
+
var isReactNative = typeof navigator !== "undefined" && typeof navigator.product === "string" && navigator.product.toLowerCase() === "reactnative";
|
|
2028
|
+
var BaseWS = /*#__PURE__*/function (_Transport) {
|
|
2029
|
+
function BaseWS() {
|
|
2030
|
+
return _Transport.apply(this, arguments) || this;
|
|
2031
|
+
}
|
|
2032
|
+
_inheritsLoose(BaseWS, _Transport);
|
|
2033
|
+
var _proto = BaseWS.prototype;
|
|
2034
|
+
_proto.doOpen = function doOpen() {
|
|
2035
|
+
var uri = this.uri();
|
|
2036
|
+
var protocols = this.opts.protocols;
|
|
2037
|
+
// React Native only supports the 'headers' option, and will print a warning if anything else is passed
|
|
2038
|
+
var opts = isReactNative ? {} : pick(this.opts, "agent", "perMessageDeflate", "pfx", "key", "passphrase", "cert", "ca", "ciphers", "rejectUnauthorized", "localAddress", "protocolVersion", "origin", "maxPayload", "family", "checkServerIdentity");
|
|
2039
|
+
if (this.opts.extraHeaders) {
|
|
2040
|
+
opts.headers = this.opts.extraHeaders;
|
|
2041
|
+
}
|
|
2042
|
+
try {
|
|
2043
|
+
this.ws = this.createSocket(uri, protocols, opts);
|
|
2044
|
+
} catch (err) {
|
|
2045
|
+
return this.emitReserved("error", err);
|
|
2046
|
+
}
|
|
2047
|
+
this.ws.binaryType = this.socket.binaryType;
|
|
2048
|
+
this.addEventListeners();
|
|
2049
|
+
}
|
|
2050
|
+
/**
|
|
2051
|
+
* Adds event listeners to the socket
|
|
2052
|
+
*
|
|
2053
|
+
* @private
|
|
2054
|
+
*/;
|
|
2055
|
+
_proto.addEventListeners = function addEventListeners() {
|
|
2056
|
+
var _this = this;
|
|
2057
|
+
this.ws.onopen = function () {
|
|
2058
|
+
if (_this.opts.autoUnref) {
|
|
2059
|
+
_this.ws._socket.unref();
|
|
2060
|
+
}
|
|
2061
|
+
_this.onOpen();
|
|
2062
|
+
};
|
|
2063
|
+
this.ws.onclose = function (closeEvent) {
|
|
2064
|
+
return _this.onClose({
|
|
2065
|
+
description: "websocket connection closed",
|
|
2066
|
+
context: closeEvent
|
|
2067
|
+
});
|
|
2068
|
+
};
|
|
2069
|
+
this.ws.onmessage = function (ev) {
|
|
2070
|
+
return _this.onData(ev.data);
|
|
2071
|
+
};
|
|
2072
|
+
this.ws.onerror = function (e) {
|
|
2073
|
+
return _this.onError("websocket error", e);
|
|
2074
|
+
};
|
|
2075
|
+
};
|
|
2076
|
+
_proto.write = function write(packets) {
|
|
2077
|
+
var _this2 = this;
|
|
2078
|
+
this.writable = false;
|
|
2079
|
+
// encodePacket efficient as it uses WS framing
|
|
2080
|
+
// no need for encodePayload
|
|
2081
|
+
var _loop = function _loop() {
|
|
2082
|
+
var packet = packets[i];
|
|
2083
|
+
var lastPacket = i === packets.length - 1;
|
|
2084
|
+
encodePacket(packet, _this2.supportsBinary, function (data) {
|
|
2085
|
+
// Sometimes the websocket has already been closed but the browser didn't
|
|
2086
|
+
// have a chance of informing us about it yet, in that case send will
|
|
2087
|
+
// throw an error
|
|
2088
|
+
try {
|
|
2089
|
+
_this2.doWrite(packet, data);
|
|
2090
|
+
} catch (e) {
|
|
2091
|
+
debug$2("websocket closed before onclose event");
|
|
2092
|
+
}
|
|
2093
|
+
if (lastPacket) {
|
|
2094
|
+
// fake drain
|
|
2095
|
+
// defer to next tick to allow Socket to clear writeBuffer
|
|
2096
|
+
nextTick(function () {
|
|
2097
|
+
_this2.writable = true;
|
|
2098
|
+
_this2.emitReserved("drain");
|
|
2099
|
+
}, _this2.setTimeoutFn);
|
|
2100
|
+
}
|
|
2101
|
+
});
|
|
2102
|
+
};
|
|
2103
|
+
for (var i = 0; i < packets.length; i++) {
|
|
2104
|
+
_loop();
|
|
2105
|
+
}
|
|
2106
|
+
};
|
|
2107
|
+
_proto.doClose = function doClose() {
|
|
2108
|
+
if (typeof this.ws !== "undefined") {
|
|
2109
|
+
this.ws.onerror = function () {};
|
|
2110
|
+
this.ws.close();
|
|
2111
|
+
this.ws = null;
|
|
2112
|
+
}
|
|
2113
|
+
}
|
|
2114
|
+
/**
|
|
2115
|
+
* Generates uri for connection.
|
|
2116
|
+
*
|
|
2117
|
+
* @private
|
|
2118
|
+
*/;
|
|
2119
|
+
_proto.uri = function uri() {
|
|
2120
|
+
var schema = this.opts.secure ? "wss" : "ws";
|
|
2121
|
+
var query = this.query || {};
|
|
2122
|
+
// append timestamp to URI
|
|
2123
|
+
if (this.opts.timestampRequests) {
|
|
2124
|
+
query[this.opts.timestampParam] = randomString();
|
|
2125
|
+
}
|
|
2126
|
+
// communicate binary support capabilities
|
|
2127
|
+
if (!this.supportsBinary) {
|
|
2128
|
+
query.b64 = 1;
|
|
2129
|
+
}
|
|
2130
|
+
return this.createUri(schema, query);
|
|
2131
|
+
};
|
|
2132
|
+
return _createClass(BaseWS, [{
|
|
2133
|
+
key: "name",
|
|
2134
|
+
get: function get() {
|
|
2135
|
+
return "websocket";
|
|
2136
|
+
}
|
|
2137
|
+
}]);
|
|
2138
|
+
}(Transport);
|
|
2139
|
+
var WebSocketCtor = globalThisShim.WebSocket || globalThisShim.MozWebSocket;
|
|
2140
|
+
/**
|
|
2141
|
+
* WebSocket transport based on the built-in `WebSocket` object.
|
|
2142
|
+
*
|
|
2143
|
+
* Usage: browser, Node.js (since v21), Deno, Bun
|
|
2144
|
+
*
|
|
2145
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebSocket
|
|
2146
|
+
* @see https://caniuse.com/mdn-api_websocket
|
|
2147
|
+
* @see https://nodejs.org/api/globals.html#websocket
|
|
2148
|
+
*/
|
|
2149
|
+
var WS = /*#__PURE__*/function (_BaseWS) {
|
|
2150
|
+
function WS() {
|
|
2151
|
+
return _BaseWS.apply(this, arguments) || this;
|
|
2152
|
+
}
|
|
2153
|
+
_inheritsLoose(WS, _BaseWS);
|
|
2154
|
+
var _proto2 = WS.prototype;
|
|
2155
|
+
_proto2.createSocket = function createSocket(uri, protocols, opts) {
|
|
2156
|
+
return !isReactNative ? protocols ? new WebSocketCtor(uri, protocols) : new WebSocketCtor(uri) : new WebSocketCtor(uri, protocols, opts);
|
|
2157
|
+
};
|
|
2158
|
+
_proto2.doWrite = function doWrite(_packet, data) {
|
|
2159
|
+
this.ws.send(data);
|
|
2160
|
+
};
|
|
2161
|
+
return WS;
|
|
2162
|
+
}(BaseWS);
|
|
2163
|
+
|
|
2164
|
+
var debug$1 = debugModule("engine.io-client:webtransport"); // debug()
|
|
2165
|
+
/**
|
|
2166
|
+
* WebTransport transport based on the built-in `WebTransport` object.
|
|
2167
|
+
*
|
|
2168
|
+
* Usage: browser, Node.js (with the `@fails-components/webtransport` package)
|
|
2169
|
+
*
|
|
2170
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebTransport
|
|
2171
|
+
* @see https://caniuse.com/webtransport
|
|
2172
|
+
*/
|
|
2173
|
+
var WT = /*#__PURE__*/function (_Transport) {
|
|
2174
|
+
function WT() {
|
|
2175
|
+
return _Transport.apply(this, arguments) || this;
|
|
2176
|
+
}
|
|
2177
|
+
_inheritsLoose(WT, _Transport);
|
|
2178
|
+
var _proto = WT.prototype;
|
|
2179
|
+
_proto.doOpen = function doOpen() {
|
|
2180
|
+
var _this = this;
|
|
2181
|
+
try {
|
|
2182
|
+
// @ts-ignore
|
|
2183
|
+
this._transport = new WebTransport(this.createUri("https"), this.opts.transportOptions[this.name]);
|
|
2184
|
+
} catch (err) {
|
|
2185
|
+
return this.emitReserved("error", err);
|
|
2186
|
+
}
|
|
2187
|
+
this._transport.closed.then(function () {
|
|
2188
|
+
debug$1("transport closed gracefully");
|
|
2189
|
+
_this.onClose();
|
|
2190
|
+
})["catch"](function (err) {
|
|
2191
|
+
debug$1("transport closed due to %s", err);
|
|
2192
|
+
_this.onError("webtransport error", err);
|
|
2193
|
+
});
|
|
2194
|
+
// note: we could have used async/await, but that would require some additional polyfills
|
|
2195
|
+
this._transport.ready.then(function () {
|
|
2196
|
+
_this._transport.createBidirectionalStream().then(function (stream) {
|
|
2197
|
+
var decoderStream = createPacketDecoderStream(Number.MAX_SAFE_INTEGER, _this.socket.binaryType);
|
|
2198
|
+
var reader = stream.readable.pipeThrough(decoderStream).getReader();
|
|
2199
|
+
var encoderStream = createPacketEncoderStream();
|
|
2200
|
+
encoderStream.readable.pipeTo(stream.writable);
|
|
2201
|
+
_this._writer = encoderStream.writable.getWriter();
|
|
2202
|
+
var read = function read() {
|
|
2203
|
+
reader.read().then(function (_ref) {
|
|
2204
|
+
var done = _ref.done,
|
|
2205
|
+
value = _ref.value;
|
|
2206
|
+
if (done) {
|
|
2207
|
+
debug$1("session is closed");
|
|
2208
|
+
return;
|
|
2209
|
+
}
|
|
2210
|
+
debug$1("received chunk: %o", value);
|
|
2211
|
+
_this.onPacket(value);
|
|
2212
|
+
read();
|
|
2213
|
+
})["catch"](function (err) {
|
|
2214
|
+
debug$1("an error occurred while reading: %s", err);
|
|
2215
|
+
});
|
|
2216
|
+
};
|
|
2217
|
+
read();
|
|
2218
|
+
var packet = {
|
|
2219
|
+
type: "open"
|
|
2220
|
+
};
|
|
2221
|
+
if (_this.query.sid) {
|
|
2222
|
+
packet.data = "{\"sid\":\"".concat(_this.query.sid, "\"}");
|
|
2223
|
+
}
|
|
2224
|
+
_this._writer.write(packet).then(function () {
|
|
2225
|
+
return _this.onOpen();
|
|
2226
|
+
});
|
|
2227
|
+
});
|
|
2228
|
+
});
|
|
2229
|
+
};
|
|
2230
|
+
_proto.write = function write(packets) {
|
|
2231
|
+
var _this2 = this;
|
|
2232
|
+
this.writable = false;
|
|
2233
|
+
var _loop = function _loop() {
|
|
2234
|
+
var packet = packets[i];
|
|
2235
|
+
var lastPacket = i === packets.length - 1;
|
|
2236
|
+
_this2._writer.write(packet).then(function () {
|
|
2237
|
+
if (lastPacket) {
|
|
2238
|
+
nextTick(function () {
|
|
2239
|
+
_this2.writable = true;
|
|
2240
|
+
_this2.emitReserved("drain");
|
|
2241
|
+
}, _this2.setTimeoutFn);
|
|
2242
|
+
}
|
|
2243
|
+
});
|
|
2244
|
+
};
|
|
2245
|
+
for (var i = 0; i < packets.length; i++) {
|
|
2246
|
+
_loop();
|
|
2247
|
+
}
|
|
2248
|
+
};
|
|
2249
|
+
_proto.doClose = function doClose() {
|
|
2250
|
+
var _a;
|
|
2251
|
+
(_a = this._transport) === null || _a === void 0 ? void 0 : _a.close();
|
|
2252
|
+
};
|
|
2253
|
+
return _createClass(WT, [{
|
|
2254
|
+
key: "name",
|
|
2255
|
+
get: function get() {
|
|
2256
|
+
return "webtransport";
|
|
2257
|
+
}
|
|
2258
|
+
}]);
|
|
2259
|
+
}(Transport);
|
|
2260
|
+
|
|
2261
|
+
var transports = {
|
|
2262
|
+
websocket: WS,
|
|
2263
|
+
webtransport: WT,
|
|
2264
|
+
polling: XHR
|
|
2265
|
+
};
|
|
2266
|
+
|
|
2267
|
+
// imported from https://github.com/galkn/parseuri
|
|
2268
|
+
/**
|
|
2269
|
+
* Parses a URI
|
|
2270
|
+
*
|
|
2271
|
+
* Note: we could also have used the built-in URL object, but it isn't supported on all platforms.
|
|
2272
|
+
*
|
|
2273
|
+
* See:
|
|
2274
|
+
* - https://developer.mozilla.org/en-US/docs/Web/API/URL
|
|
2275
|
+
* - https://caniuse.com/url
|
|
2276
|
+
* - https://www.rfc-editor.org/rfc/rfc3986#appendix-B
|
|
2277
|
+
*
|
|
2278
|
+
* History of the parse() method:
|
|
2279
|
+
* - first commit: https://github.com/socketio/socket.io-client/commit/4ee1d5d94b3906a9c052b459f1a818b15f38f91c
|
|
2280
|
+
* - export into its own module: https://github.com/socketio/engine.io-client/commit/de2c561e4564efeb78f1bdb1ba39ef81b2822cb3
|
|
2281
|
+
* - reimport: https://github.com/socketio/engine.io-client/commit/df32277c3f6d622eec5ed09f493cae3f3391d242
|
|
2282
|
+
*
|
|
2283
|
+
* @author Steven Levithan <stevenlevithan.com> (MIT license)
|
|
2284
|
+
* @api private
|
|
2285
|
+
*/
|
|
2286
|
+
var re = /^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/;
|
|
2287
|
+
var parts = ['source', 'protocol', 'authority', 'userInfo', 'user', 'password', 'host', 'port', 'relative', 'path', 'directory', 'file', 'query', 'anchor'];
|
|
2288
|
+
function parse(str) {
|
|
2289
|
+
if (str.length > 8000) {
|
|
2290
|
+
throw "URI too long";
|
|
2291
|
+
}
|
|
2292
|
+
var src = str,
|
|
2293
|
+
b = str.indexOf('['),
|
|
2294
|
+
e = str.indexOf(']');
|
|
2295
|
+
if (b != -1 && e != -1) {
|
|
2296
|
+
str = str.substring(0, b) + str.substring(b, e).replace(/:/g, ';') + str.substring(e, str.length);
|
|
2297
|
+
}
|
|
2298
|
+
var m = re.exec(str || ''),
|
|
2299
|
+
uri = {},
|
|
2300
|
+
i = 14;
|
|
2301
|
+
while (i--) {
|
|
2302
|
+
uri[parts[i]] = m[i] || '';
|
|
2303
|
+
}
|
|
2304
|
+
if (b != -1 && e != -1) {
|
|
2305
|
+
uri.source = src;
|
|
2306
|
+
uri.host = uri.host.substring(1, uri.host.length - 1).replace(/;/g, ':');
|
|
2307
|
+
uri.authority = uri.authority.replace('[', '').replace(']', '').replace(/;/g, ':');
|
|
2308
|
+
uri.ipv6uri = true;
|
|
2309
|
+
}
|
|
2310
|
+
uri.pathNames = pathNames(uri, uri['path']);
|
|
2311
|
+
uri.queryKey = queryKey(uri, uri['query']);
|
|
2312
|
+
return uri;
|
|
2313
|
+
}
|
|
2314
|
+
function pathNames(obj, path) {
|
|
2315
|
+
var regx = /\/{2,9}/g,
|
|
2316
|
+
names = path.replace(regx, "/").split("/");
|
|
2317
|
+
if (path.slice(0, 1) == '/' || path.length === 0) {
|
|
2318
|
+
names.splice(0, 1);
|
|
2319
|
+
}
|
|
2320
|
+
if (path.slice(-1) == '/') {
|
|
2321
|
+
names.splice(names.length - 1, 1);
|
|
2322
|
+
}
|
|
2323
|
+
return names;
|
|
2324
|
+
}
|
|
2325
|
+
function queryKey(uri, query) {
|
|
2326
|
+
var data = {};
|
|
2327
|
+
query.replace(/(?:^|&)([^&=]*)=?([^&]*)/g, function ($0, $1, $2) {
|
|
2328
|
+
if ($1) {
|
|
2329
|
+
data[$1] = $2;
|
|
2330
|
+
}
|
|
2331
|
+
});
|
|
2332
|
+
return data;
|
|
2333
|
+
}
|
|
2334
|
+
|
|
2335
|
+
var debug = debugModule("engine.io-client:socket"); // debug()
|
|
2336
|
+
var withEventListeners = typeof addEventListener === "function" && typeof removeEventListener === "function";
|
|
2337
|
+
var OFFLINE_EVENT_LISTENERS = [];
|
|
2338
|
+
if (withEventListeners) {
|
|
2339
|
+
// within a ServiceWorker, any event handler for the 'offline' event must be added on the initial evaluation of the
|
|
2340
|
+
// script, so we create one single event listener here which will forward the event to the socket instances
|
|
2341
|
+
addEventListener("offline", function () {
|
|
2342
|
+
debug("closing %d connection(s) because the network was lost", OFFLINE_EVENT_LISTENERS.length);
|
|
2343
|
+
OFFLINE_EVENT_LISTENERS.forEach(function (listener) {
|
|
2344
|
+
return listener();
|
|
2345
|
+
});
|
|
2346
|
+
}, false);
|
|
2347
|
+
}
|
|
2348
|
+
/**
|
|
2349
|
+
* This class provides a WebSocket-like interface to connect to an Engine.IO server. The connection will be established
|
|
2350
|
+
* with one of the available low-level transports, like HTTP long-polling, WebSocket or WebTransport.
|
|
2351
|
+
*
|
|
2352
|
+
* This class comes without upgrade mechanism, which means that it will keep the first low-level transport that
|
|
2353
|
+
* successfully establishes the connection.
|
|
2354
|
+
*
|
|
2355
|
+
* In order to allow tree-shaking, there are no transports included, that's why the `transports` option is mandatory.
|
|
2356
|
+
*
|
|
2357
|
+
* @example
|
|
2358
|
+
* import { SocketWithoutUpgrade, WebSocket } from "engine.io-client";
|
|
2359
|
+
*
|
|
2360
|
+
* const socket = new SocketWithoutUpgrade({
|
|
2361
|
+
* transports: [WebSocket]
|
|
2362
|
+
* });
|
|
2363
|
+
*
|
|
2364
|
+
* socket.on("open", () => {
|
|
2365
|
+
* socket.send("hello");
|
|
2366
|
+
* });
|
|
2367
|
+
*
|
|
2368
|
+
* @see SocketWithUpgrade
|
|
2369
|
+
* @see Socket
|
|
2370
|
+
*/
|
|
2371
|
+
var SocketWithoutUpgrade = /*#__PURE__*/function (_Emitter) {
|
|
2372
|
+
/**
|
|
2373
|
+
* Socket constructor.
|
|
2374
|
+
*
|
|
2375
|
+
* @param {String|Object} uri - uri or options
|
|
2376
|
+
* @param {Object} opts - options
|
|
2377
|
+
*/
|
|
2378
|
+
function SocketWithoutUpgrade(uri, opts) {
|
|
2379
|
+
var _this;
|
|
2380
|
+
_this = _Emitter.call(this) || this;
|
|
2381
|
+
_this.binaryType = defaultBinaryType;
|
|
2382
|
+
_this.writeBuffer = [];
|
|
2383
|
+
_this._prevBufferLen = 0;
|
|
2384
|
+
_this._pingInterval = -1;
|
|
2385
|
+
_this._pingTimeout = -1;
|
|
2386
|
+
_this._maxPayload = -1;
|
|
2387
|
+
/**
|
|
2388
|
+
* The expiration timestamp of the {@link _pingTimeoutTimer} object is tracked, in case the timer is throttled and the
|
|
2389
|
+
* callback is not fired on time. This can happen for example when a laptop is suspended or when a phone is locked.
|
|
2390
|
+
*/
|
|
2391
|
+
_this._pingTimeoutTime = Infinity;
|
|
2392
|
+
if (uri && "object" === _typeof(uri)) {
|
|
2393
|
+
opts = uri;
|
|
2394
|
+
uri = null;
|
|
2395
|
+
}
|
|
2396
|
+
if (uri) {
|
|
2397
|
+
var parsedUri = parse(uri);
|
|
2398
|
+
opts.hostname = parsedUri.host;
|
|
2399
|
+
opts.secure = parsedUri.protocol === "https" || parsedUri.protocol === "wss";
|
|
2400
|
+
opts.port = parsedUri.port;
|
|
2401
|
+
if (parsedUri.query) opts.query = parsedUri.query;
|
|
2402
|
+
} else if (opts.host) {
|
|
2403
|
+
opts.hostname = parse(opts.host).host;
|
|
2404
|
+
}
|
|
2405
|
+
installTimerFunctions(_this, opts);
|
|
2406
|
+
_this.secure = null != opts.secure ? opts.secure : typeof location !== "undefined" && "https:" === location.protocol;
|
|
2407
|
+
if (opts.hostname && !opts.port) {
|
|
2408
|
+
// if no port is specified manually, use the protocol default
|
|
2409
|
+
opts.port = _this.secure ? "443" : "80";
|
|
2410
|
+
}
|
|
2411
|
+
_this.hostname = opts.hostname || (typeof location !== "undefined" ? location.hostname : "localhost");
|
|
2412
|
+
_this.port = opts.port || (typeof location !== "undefined" && location.port ? location.port : _this.secure ? "443" : "80");
|
|
2413
|
+
_this.transports = [];
|
|
2414
|
+
_this._transportsByName = {};
|
|
2415
|
+
opts.transports.forEach(function (t) {
|
|
2416
|
+
var transportName = t.prototype.name;
|
|
2417
|
+
_this.transports.push(transportName);
|
|
2418
|
+
_this._transportsByName[transportName] = t;
|
|
2419
|
+
});
|
|
2420
|
+
_this.opts = _extends({
|
|
2421
|
+
path: "/engine.io",
|
|
2422
|
+
agent: false,
|
|
2423
|
+
withCredentials: false,
|
|
2424
|
+
upgrade: true,
|
|
2425
|
+
timestampParam: "t",
|
|
2426
|
+
rememberUpgrade: false,
|
|
2427
|
+
addTrailingSlash: true,
|
|
2428
|
+
rejectUnauthorized: true,
|
|
2429
|
+
perMessageDeflate: {
|
|
2430
|
+
threshold: 1024
|
|
2431
|
+
},
|
|
2432
|
+
transportOptions: {},
|
|
2433
|
+
closeOnBeforeunload: false
|
|
2434
|
+
}, opts);
|
|
2435
|
+
_this.opts.path = _this.opts.path.replace(/\/$/, "") + (_this.opts.addTrailingSlash ? "/" : "");
|
|
2436
|
+
if (typeof _this.opts.query === "string") {
|
|
2437
|
+
_this.opts.query = decode(_this.opts.query);
|
|
2438
|
+
}
|
|
2439
|
+
if (withEventListeners) {
|
|
2440
|
+
if (_this.opts.closeOnBeforeunload) {
|
|
2441
|
+
// Firefox closes the connection when the "beforeunload" event is emitted but not Chrome. This event listener
|
|
2442
|
+
// ensures every browser behaves the same (no "disconnect" event at the Socket.IO level when the page is
|
|
2443
|
+
// closed/reloaded)
|
|
2444
|
+
_this._beforeunloadEventListener = function () {
|
|
2445
|
+
if (_this.transport) {
|
|
2446
|
+
// silently close the transport
|
|
2447
|
+
_this.transport.removeAllListeners();
|
|
2448
|
+
_this.transport.close();
|
|
2449
|
+
}
|
|
2450
|
+
};
|
|
2451
|
+
addEventListener("beforeunload", _this._beforeunloadEventListener, false);
|
|
2452
|
+
}
|
|
2453
|
+
if (_this.hostname !== "localhost") {
|
|
2454
|
+
debug("adding listener for the 'offline' event");
|
|
2455
|
+
_this._offlineEventListener = function () {
|
|
2456
|
+
_this._onClose("transport close", {
|
|
2457
|
+
description: "network connection lost"
|
|
2458
|
+
});
|
|
2459
|
+
};
|
|
2460
|
+
OFFLINE_EVENT_LISTENERS.push(_this._offlineEventListener);
|
|
2461
|
+
}
|
|
2462
|
+
}
|
|
2463
|
+
if (_this.opts.withCredentials) {
|
|
2464
|
+
_this._cookieJar = createCookieJar();
|
|
2465
|
+
}
|
|
2466
|
+
_this._open();
|
|
2467
|
+
return _this;
|
|
2468
|
+
}
|
|
2469
|
+
/**
|
|
2470
|
+
* Creates transport of the given type.
|
|
2471
|
+
*
|
|
2472
|
+
* @param {String} name - transport name
|
|
2473
|
+
* @return {Transport}
|
|
2474
|
+
* @private
|
|
2475
|
+
*/
|
|
2476
|
+
_inheritsLoose(SocketWithoutUpgrade, _Emitter);
|
|
2477
|
+
var _proto = SocketWithoutUpgrade.prototype;
|
|
2478
|
+
_proto.createTransport = function createTransport(name) {
|
|
2479
|
+
debug('creating transport "%s"', name);
|
|
2480
|
+
var query = _extends({}, this.opts.query);
|
|
2481
|
+
// append engine.io protocol identifier
|
|
2482
|
+
query.EIO = protocol;
|
|
2483
|
+
// transport name
|
|
2484
|
+
query.transport = name;
|
|
2485
|
+
// session id if we already have one
|
|
2486
|
+
if (this.id) query.sid = this.id;
|
|
2487
|
+
var opts = _extends({}, this.opts, {
|
|
2488
|
+
query: query,
|
|
2489
|
+
socket: this,
|
|
2490
|
+
hostname: this.hostname,
|
|
2491
|
+
secure: this.secure,
|
|
2492
|
+
port: this.port
|
|
2493
|
+
}, this.opts.transportOptions[name]);
|
|
2494
|
+
debug("options: %j", opts);
|
|
2495
|
+
return new this._transportsByName[name](opts);
|
|
2496
|
+
}
|
|
2497
|
+
/**
|
|
2498
|
+
* Initializes transport to use and starts probe.
|
|
2499
|
+
*
|
|
2500
|
+
* @private
|
|
2501
|
+
*/;
|
|
2502
|
+
_proto._open = function _open() {
|
|
2503
|
+
var _this2 = this;
|
|
2504
|
+
if (this.transports.length === 0) {
|
|
2505
|
+
// Emit error on next tick so it can be listened to
|
|
2506
|
+
this.setTimeoutFn(function () {
|
|
2507
|
+
_this2.emitReserved("error", "No transports available");
|
|
2508
|
+
}, 0);
|
|
2509
|
+
return;
|
|
2510
|
+
}
|
|
2511
|
+
var transportName = this.opts.rememberUpgrade && SocketWithoutUpgrade.priorWebsocketSuccess && this.transports.indexOf("websocket") !== -1 ? "websocket" : this.transports[0];
|
|
2512
|
+
this.readyState = "opening";
|
|
2513
|
+
var transport = this.createTransport(transportName);
|
|
2514
|
+
transport.open();
|
|
2515
|
+
this.setTransport(transport);
|
|
2516
|
+
}
|
|
2517
|
+
/**
|
|
2518
|
+
* Sets the current transport. Disables the existing one (if any).
|
|
2519
|
+
*
|
|
2520
|
+
* @private
|
|
2521
|
+
*/;
|
|
2522
|
+
_proto.setTransport = function setTransport(transport) {
|
|
2523
|
+
var _this3 = this;
|
|
2524
|
+
debug("setting transport %s", transport.name);
|
|
2525
|
+
if (this.transport) {
|
|
2526
|
+
debug("clearing existing transport %s", this.transport.name);
|
|
2527
|
+
this.transport.removeAllListeners();
|
|
2528
|
+
}
|
|
2529
|
+
// set up transport
|
|
2530
|
+
this.transport = transport;
|
|
2531
|
+
// set up transport listeners
|
|
2532
|
+
transport.on("drain", this._onDrain.bind(this)).on("packet", this._onPacket.bind(this)).on("error", this._onError.bind(this)).on("close", function (reason) {
|
|
2533
|
+
return _this3._onClose("transport close", reason);
|
|
2534
|
+
});
|
|
2535
|
+
}
|
|
2536
|
+
/**
|
|
2537
|
+
* Called when connection is deemed open.
|
|
2538
|
+
*
|
|
2539
|
+
* @private
|
|
2540
|
+
*/;
|
|
2541
|
+
_proto.onOpen = function onOpen() {
|
|
2542
|
+
debug("socket open");
|
|
2543
|
+
this.readyState = "open";
|
|
2544
|
+
SocketWithoutUpgrade.priorWebsocketSuccess = "websocket" === this.transport.name;
|
|
2545
|
+
this.emitReserved("open");
|
|
2546
|
+
this.flush();
|
|
2547
|
+
}
|
|
2548
|
+
/**
|
|
2549
|
+
* Handles a packet.
|
|
2550
|
+
*
|
|
2551
|
+
* @private
|
|
2552
|
+
*/;
|
|
2553
|
+
_proto._onPacket = function _onPacket(packet) {
|
|
2554
|
+
if ("opening" === this.readyState || "open" === this.readyState || "closing" === this.readyState) {
|
|
2555
|
+
debug('socket receive: type "%s", data "%s"', packet.type, packet.data);
|
|
2556
|
+
this.emitReserved("packet", packet);
|
|
2557
|
+
// Socket is live - any packet counts
|
|
2558
|
+
this.emitReserved("heartbeat");
|
|
2559
|
+
switch (packet.type) {
|
|
2560
|
+
case "open":
|
|
2561
|
+
this.onHandshake(JSON.parse(packet.data));
|
|
2562
|
+
break;
|
|
2563
|
+
case "ping":
|
|
2564
|
+
this._sendPacket("pong");
|
|
2565
|
+
this.emitReserved("ping");
|
|
2566
|
+
this.emitReserved("pong");
|
|
2567
|
+
this._resetPingTimeout();
|
|
2568
|
+
break;
|
|
2569
|
+
case "error":
|
|
2570
|
+
var err = new Error("server error");
|
|
2571
|
+
// @ts-ignore
|
|
2572
|
+
err.code = packet.data;
|
|
2573
|
+
this._onError(err);
|
|
2574
|
+
break;
|
|
2575
|
+
case "message":
|
|
2576
|
+
this.emitReserved("data", packet.data);
|
|
2577
|
+
this.emitReserved("message", packet.data);
|
|
2578
|
+
break;
|
|
2579
|
+
}
|
|
2580
|
+
} else {
|
|
2581
|
+
debug('packet received with socket readyState "%s"', this.readyState);
|
|
2582
|
+
}
|
|
2583
|
+
}
|
|
2584
|
+
/**
|
|
2585
|
+
* Called upon handshake completion.
|
|
2586
|
+
*
|
|
2587
|
+
* @param {Object} data - handshake obj
|
|
2588
|
+
* @private
|
|
2589
|
+
*/;
|
|
2590
|
+
_proto.onHandshake = function onHandshake(data) {
|
|
2591
|
+
this.emitReserved("handshake", data);
|
|
2592
|
+
this.id = data.sid;
|
|
2593
|
+
this.transport.query.sid = data.sid;
|
|
2594
|
+
this._pingInterval = data.pingInterval;
|
|
2595
|
+
this._pingTimeout = data.pingTimeout;
|
|
2596
|
+
this._maxPayload = data.maxPayload;
|
|
2597
|
+
this.onOpen();
|
|
2598
|
+
// In case open handler closes socket
|
|
2599
|
+
if ("closed" === this.readyState) return;
|
|
2600
|
+
this._resetPingTimeout();
|
|
2601
|
+
}
|
|
2602
|
+
/**
|
|
2603
|
+
* Sets and resets ping timeout timer based on server pings.
|
|
2604
|
+
*
|
|
2605
|
+
* @private
|
|
2606
|
+
*/;
|
|
2607
|
+
_proto._resetPingTimeout = function _resetPingTimeout() {
|
|
2608
|
+
var _this4 = this;
|
|
2609
|
+
this.clearTimeoutFn(this._pingTimeoutTimer);
|
|
2610
|
+
var delay = this._pingInterval + this._pingTimeout;
|
|
2611
|
+
this._pingTimeoutTime = Date.now() + delay;
|
|
2612
|
+
this._pingTimeoutTimer = this.setTimeoutFn(function () {
|
|
2613
|
+
_this4._onClose("ping timeout");
|
|
2614
|
+
}, delay);
|
|
2615
|
+
if (this.opts.autoUnref) {
|
|
2616
|
+
this._pingTimeoutTimer.unref();
|
|
2617
|
+
}
|
|
2618
|
+
}
|
|
2619
|
+
/**
|
|
2620
|
+
* Called on `drain` event
|
|
2621
|
+
*
|
|
2622
|
+
* @private
|
|
2623
|
+
*/;
|
|
2624
|
+
_proto._onDrain = function _onDrain() {
|
|
2625
|
+
this.writeBuffer.splice(0, this._prevBufferLen);
|
|
2626
|
+
// setting prevBufferLen = 0 is very important
|
|
2627
|
+
// for example, when upgrading, upgrade packet is sent over,
|
|
2628
|
+
// and a nonzero prevBufferLen could cause problems on `drain`
|
|
2629
|
+
this._prevBufferLen = 0;
|
|
2630
|
+
if (0 === this.writeBuffer.length) {
|
|
2631
|
+
this.emitReserved("drain");
|
|
2632
|
+
} else {
|
|
2633
|
+
this.flush();
|
|
2634
|
+
}
|
|
2635
|
+
}
|
|
2636
|
+
/**
|
|
2637
|
+
* Flush write buffers.
|
|
2638
|
+
*
|
|
2639
|
+
* @private
|
|
2640
|
+
*/;
|
|
2641
|
+
_proto.flush = function flush() {
|
|
2642
|
+
if ("closed" !== this.readyState && this.transport.writable && !this.upgrading && this.writeBuffer.length) {
|
|
2643
|
+
var packets = this._getWritablePackets();
|
|
2644
|
+
debug("flushing %d packets in socket", packets.length);
|
|
2645
|
+
this.transport.send(packets);
|
|
2646
|
+
// keep track of current length of writeBuffer
|
|
2647
|
+
// splice writeBuffer and callbackBuffer on `drain`
|
|
2648
|
+
this._prevBufferLen = packets.length;
|
|
2649
|
+
this.emitReserved("flush");
|
|
2650
|
+
}
|
|
2651
|
+
}
|
|
2652
|
+
/**
|
|
2653
|
+
* Ensure the encoded size of the writeBuffer is below the maxPayload value sent by the server (only for HTTP
|
|
2654
|
+
* long-polling)
|
|
2655
|
+
*
|
|
2656
|
+
* @private
|
|
2657
|
+
*/;
|
|
2658
|
+
_proto._getWritablePackets = function _getWritablePackets() {
|
|
2659
|
+
var shouldCheckPayloadSize = this._maxPayload && this.transport.name === "polling" && this.writeBuffer.length > 1;
|
|
2660
|
+
if (!shouldCheckPayloadSize) {
|
|
2661
|
+
return this.writeBuffer;
|
|
2662
|
+
}
|
|
2663
|
+
var payloadSize = 1; // first packet type
|
|
2664
|
+
for (var i = 0; i < this.writeBuffer.length; i++) {
|
|
2665
|
+
var data = this.writeBuffer[i].data;
|
|
2666
|
+
if (data) {
|
|
2667
|
+
payloadSize += byteLength(data);
|
|
2668
|
+
}
|
|
2669
|
+
if (i > 0 && payloadSize > this._maxPayload) {
|
|
2670
|
+
debug("only send %d out of %d packets", i, this.writeBuffer.length);
|
|
2671
|
+
return this.writeBuffer.slice(0, i);
|
|
2672
|
+
}
|
|
2673
|
+
payloadSize += 2; // separator + packet type
|
|
2674
|
+
}
|
|
2675
|
+
debug("payload size is %d (max: %d)", payloadSize, this._maxPayload);
|
|
2676
|
+
return this.writeBuffer;
|
|
2677
|
+
}
|
|
2678
|
+
/**
|
|
2679
|
+
* Checks whether the heartbeat timer has expired but the socket has not yet been notified.
|
|
2680
|
+
*
|
|
2681
|
+
* Note: this method is private for now because it does not really fit the WebSocket API, but if we put it in the
|
|
2682
|
+
* `write()` method then the message would not be buffered by the Socket.IO client.
|
|
2683
|
+
*
|
|
2684
|
+
* @return {boolean}
|
|
2685
|
+
* @private
|
|
2686
|
+
*/
|
|
2687
|
+
/* private */;
|
|
2688
|
+
_proto._hasPingExpired = function _hasPingExpired() {
|
|
2689
|
+
var _this5 = this;
|
|
2690
|
+
if (!this._pingTimeoutTime) return true;
|
|
2691
|
+
var hasExpired = Date.now() > this._pingTimeoutTime;
|
|
2692
|
+
if (hasExpired) {
|
|
2693
|
+
debug("throttled timer detected, scheduling connection close");
|
|
2694
|
+
this._pingTimeoutTime = 0;
|
|
2695
|
+
nextTick(function () {
|
|
2696
|
+
_this5._onClose("ping timeout");
|
|
2697
|
+
}, this.setTimeoutFn);
|
|
2698
|
+
}
|
|
2699
|
+
return hasExpired;
|
|
2700
|
+
}
|
|
2701
|
+
/**
|
|
2702
|
+
* Sends a message.
|
|
2703
|
+
*
|
|
2704
|
+
* @param {String} msg - message.
|
|
2705
|
+
* @param {Object} options.
|
|
2706
|
+
* @param {Function} fn - callback function.
|
|
2707
|
+
* @return {Socket} for chaining.
|
|
2708
|
+
*/;
|
|
2709
|
+
_proto.write = function write(msg, options, fn) {
|
|
2710
|
+
this._sendPacket("message", msg, options, fn);
|
|
2711
|
+
return this;
|
|
2712
|
+
}
|
|
2713
|
+
/**
|
|
2714
|
+
* Sends a message. Alias of {@link Socket#write}.
|
|
2715
|
+
*
|
|
2716
|
+
* @param {String} msg - message.
|
|
2717
|
+
* @param {Object} options.
|
|
2718
|
+
* @param {Function} fn - callback function.
|
|
2719
|
+
* @return {Socket} for chaining.
|
|
2720
|
+
*/;
|
|
2721
|
+
_proto.send = function send(msg, options, fn) {
|
|
2722
|
+
this._sendPacket("message", msg, options, fn);
|
|
2723
|
+
return this;
|
|
2724
|
+
}
|
|
2725
|
+
/**
|
|
2726
|
+
* Sends a packet.
|
|
2727
|
+
*
|
|
2728
|
+
* @param {String} type: packet type.
|
|
2729
|
+
* @param {String} data.
|
|
2730
|
+
* @param {Object} options.
|
|
2731
|
+
* @param {Function} fn - callback function.
|
|
2732
|
+
* @private
|
|
2733
|
+
*/;
|
|
2734
|
+
_proto._sendPacket = function _sendPacket(type, data, options, fn) {
|
|
2735
|
+
if ("function" === typeof data) {
|
|
2736
|
+
fn = data;
|
|
2737
|
+
data = undefined;
|
|
2738
|
+
}
|
|
2739
|
+
if ("function" === typeof options) {
|
|
2740
|
+
fn = options;
|
|
2741
|
+
options = null;
|
|
2742
|
+
}
|
|
2743
|
+
if ("closing" === this.readyState || "closed" === this.readyState) {
|
|
2744
|
+
return;
|
|
2745
|
+
}
|
|
2746
|
+
options = options || {};
|
|
2747
|
+
options.compress = false !== options.compress;
|
|
2748
|
+
var packet = {
|
|
2749
|
+
type: type,
|
|
2750
|
+
data: data,
|
|
2751
|
+
options: options
|
|
2752
|
+
};
|
|
2753
|
+
this.emitReserved("packetCreate", packet);
|
|
2754
|
+
this.writeBuffer.push(packet);
|
|
2755
|
+
if (fn) this.once("flush", fn);
|
|
2756
|
+
this.flush();
|
|
2757
|
+
}
|
|
2758
|
+
/**
|
|
2759
|
+
* Closes the connection.
|
|
2760
|
+
*/;
|
|
2761
|
+
_proto.close = function close() {
|
|
2762
|
+
var _this6 = this;
|
|
2763
|
+
var close = function close() {
|
|
2764
|
+
_this6._onClose("forced close");
|
|
2765
|
+
debug("socket closing - telling transport to close");
|
|
2766
|
+
_this6.transport.close();
|
|
2767
|
+
};
|
|
2768
|
+
var cleanupAndClose = function cleanupAndClose() {
|
|
2769
|
+
_this6.off("upgrade", cleanupAndClose);
|
|
2770
|
+
_this6.off("upgradeError", cleanupAndClose);
|
|
2771
|
+
close();
|
|
2772
|
+
};
|
|
2773
|
+
var waitForUpgrade = function waitForUpgrade() {
|
|
2774
|
+
// wait for upgrade to finish since we can't send packets while pausing a transport
|
|
2775
|
+
_this6.once("upgrade", cleanupAndClose);
|
|
2776
|
+
_this6.once("upgradeError", cleanupAndClose);
|
|
2777
|
+
};
|
|
2778
|
+
if ("opening" === this.readyState || "open" === this.readyState) {
|
|
2779
|
+
this.readyState = "closing";
|
|
2780
|
+
if (this.writeBuffer.length) {
|
|
2781
|
+
this.once("drain", function () {
|
|
2782
|
+
if (_this6.upgrading) {
|
|
2783
|
+
waitForUpgrade();
|
|
2784
|
+
} else {
|
|
2785
|
+
close();
|
|
2786
|
+
}
|
|
2787
|
+
});
|
|
2788
|
+
} else if (this.upgrading) {
|
|
2789
|
+
waitForUpgrade();
|
|
2790
|
+
} else {
|
|
2791
|
+
close();
|
|
2792
|
+
}
|
|
2793
|
+
}
|
|
2794
|
+
return this;
|
|
2795
|
+
}
|
|
2796
|
+
/**
|
|
2797
|
+
* Called upon transport error
|
|
2798
|
+
*
|
|
2799
|
+
* @private
|
|
2800
|
+
*/;
|
|
2801
|
+
_proto._onError = function _onError(err) {
|
|
2802
|
+
debug("socket error %j", err);
|
|
2803
|
+
SocketWithoutUpgrade.priorWebsocketSuccess = false;
|
|
2804
|
+
if (this.opts.tryAllTransports && this.transports.length > 1 && this.readyState === "opening") {
|
|
2805
|
+
debug("trying next transport");
|
|
2806
|
+
this.transports.shift();
|
|
2807
|
+
return this._open();
|
|
2808
|
+
}
|
|
2809
|
+
this.emitReserved("error", err);
|
|
2810
|
+
this._onClose("transport error", err);
|
|
2811
|
+
}
|
|
2812
|
+
/**
|
|
2813
|
+
* Called upon transport close.
|
|
2814
|
+
*
|
|
2815
|
+
* @private
|
|
2816
|
+
*/;
|
|
2817
|
+
_proto._onClose = function _onClose(reason, description) {
|
|
2818
|
+
if ("opening" === this.readyState || "open" === this.readyState || "closing" === this.readyState) {
|
|
2819
|
+
debug('socket close with reason: "%s"', reason);
|
|
2820
|
+
// clear timers
|
|
2821
|
+
this.clearTimeoutFn(this._pingTimeoutTimer);
|
|
2822
|
+
// stop event from firing again for transport
|
|
2823
|
+
this.transport.removeAllListeners("close");
|
|
2824
|
+
// ensure transport won't stay open
|
|
2825
|
+
this.transport.close();
|
|
2826
|
+
// ignore further transport communication
|
|
2827
|
+
this.transport.removeAllListeners();
|
|
2828
|
+
if (withEventListeners) {
|
|
2829
|
+
if (this._beforeunloadEventListener) {
|
|
2830
|
+
removeEventListener("beforeunload", this._beforeunloadEventListener, false);
|
|
2831
|
+
}
|
|
2832
|
+
if (this._offlineEventListener) {
|
|
2833
|
+
var i = OFFLINE_EVENT_LISTENERS.indexOf(this._offlineEventListener);
|
|
2834
|
+
if (i !== -1) {
|
|
2835
|
+
debug("removing listener for the 'offline' event");
|
|
2836
|
+
OFFLINE_EVENT_LISTENERS.splice(i, 1);
|
|
2837
|
+
}
|
|
2838
|
+
}
|
|
2839
|
+
}
|
|
2840
|
+
// set ready state
|
|
2841
|
+
this.readyState = "closed";
|
|
2842
|
+
// clear session id
|
|
2843
|
+
this.id = null;
|
|
2844
|
+
// emit close event
|
|
2845
|
+
this.emitReserved("close", reason, description);
|
|
2846
|
+
// clean buffers after, so users can still
|
|
2847
|
+
// grab the buffers on `close` event
|
|
2848
|
+
this.writeBuffer = [];
|
|
2849
|
+
this._prevBufferLen = 0;
|
|
2850
|
+
}
|
|
2851
|
+
};
|
|
2852
|
+
return SocketWithoutUpgrade;
|
|
2853
|
+
}(Emitter);
|
|
2854
|
+
SocketWithoutUpgrade.protocol = protocol;
|
|
2855
|
+
/**
|
|
2856
|
+
* This class provides a WebSocket-like interface to connect to an Engine.IO server. The connection will be established
|
|
2857
|
+
* with one of the available low-level transports, like HTTP long-polling, WebSocket or WebTransport.
|
|
2858
|
+
*
|
|
2859
|
+
* This class comes with an upgrade mechanism, which means that once the connection is established with the first
|
|
2860
|
+
* low-level transport, it will try to upgrade to a better transport.
|
|
2861
|
+
*
|
|
2862
|
+
* In order to allow tree-shaking, there are no transports included, that's why the `transports` option is mandatory.
|
|
2863
|
+
*
|
|
2864
|
+
* @example
|
|
2865
|
+
* import { SocketWithUpgrade, WebSocket } from "engine.io-client";
|
|
2866
|
+
*
|
|
2867
|
+
* const socket = new SocketWithUpgrade({
|
|
2868
|
+
* transports: [WebSocket]
|
|
2869
|
+
* });
|
|
2870
|
+
*
|
|
2871
|
+
* socket.on("open", () => {
|
|
2872
|
+
* socket.send("hello");
|
|
2873
|
+
* });
|
|
2874
|
+
*
|
|
2875
|
+
* @see SocketWithoutUpgrade
|
|
2876
|
+
* @see Socket
|
|
2877
|
+
*/
|
|
2878
|
+
var SocketWithUpgrade = /*#__PURE__*/function (_SocketWithoutUpgrade) {
|
|
2879
|
+
function SocketWithUpgrade() {
|
|
2880
|
+
var _this7;
|
|
2881
|
+
_this7 = _SocketWithoutUpgrade.apply(this, arguments) || this;
|
|
2882
|
+
_this7._upgrades = [];
|
|
2883
|
+
return _this7;
|
|
2884
|
+
}
|
|
2885
|
+
_inheritsLoose(SocketWithUpgrade, _SocketWithoutUpgrade);
|
|
2886
|
+
var _proto2 = SocketWithUpgrade.prototype;
|
|
2887
|
+
_proto2.onOpen = function onOpen() {
|
|
2888
|
+
_SocketWithoutUpgrade.prototype.onOpen.call(this);
|
|
2889
|
+
if ("open" === this.readyState && this.opts.upgrade) {
|
|
2890
|
+
debug("starting upgrade probes");
|
|
2891
|
+
for (var i = 0; i < this._upgrades.length; i++) {
|
|
2892
|
+
this._probe(this._upgrades[i]);
|
|
2893
|
+
}
|
|
2894
|
+
}
|
|
2895
|
+
}
|
|
2896
|
+
/**
|
|
2897
|
+
* Probes a transport.
|
|
2898
|
+
*
|
|
2899
|
+
* @param {String} name - transport name
|
|
2900
|
+
* @private
|
|
2901
|
+
*/;
|
|
2902
|
+
_proto2._probe = function _probe(name) {
|
|
2903
|
+
var _this8 = this;
|
|
2904
|
+
debug('probing transport "%s"', name);
|
|
2905
|
+
var transport = this.createTransport(name);
|
|
2906
|
+
var failed = false;
|
|
2907
|
+
SocketWithoutUpgrade.priorWebsocketSuccess = false;
|
|
2908
|
+
var onTransportOpen = function onTransportOpen() {
|
|
2909
|
+
if (failed) return;
|
|
2910
|
+
debug('probe transport "%s" opened', name);
|
|
2911
|
+
transport.send([{
|
|
2912
|
+
type: "ping",
|
|
2913
|
+
data: "probe"
|
|
2914
|
+
}]);
|
|
2915
|
+
transport.once("packet", function (msg) {
|
|
2916
|
+
if (failed) return;
|
|
2917
|
+
if ("pong" === msg.type && "probe" === msg.data) {
|
|
2918
|
+
debug('probe transport "%s" pong', name);
|
|
2919
|
+
_this8.upgrading = true;
|
|
2920
|
+
_this8.emitReserved("upgrading", transport);
|
|
2921
|
+
if (!transport) return;
|
|
2922
|
+
SocketWithoutUpgrade.priorWebsocketSuccess = "websocket" === transport.name;
|
|
2923
|
+
debug('pausing current transport "%s"', _this8.transport.name);
|
|
2924
|
+
_this8.transport.pause(function () {
|
|
2925
|
+
if (failed) return;
|
|
2926
|
+
if ("closed" === _this8.readyState) return;
|
|
2927
|
+
debug("changing transport and sending upgrade packet");
|
|
2928
|
+
cleanup();
|
|
2929
|
+
_this8.setTransport(transport);
|
|
2930
|
+
transport.send([{
|
|
2931
|
+
type: "upgrade"
|
|
2932
|
+
}]);
|
|
2933
|
+
_this8.emitReserved("upgrade", transport);
|
|
2934
|
+
transport = null;
|
|
2935
|
+
_this8.upgrading = false;
|
|
2936
|
+
_this8.flush();
|
|
2937
|
+
});
|
|
2938
|
+
} else {
|
|
2939
|
+
debug('probe transport "%s" failed', name);
|
|
2940
|
+
var err = new Error("probe error");
|
|
2941
|
+
// @ts-ignore
|
|
2942
|
+
err.transport = transport.name;
|
|
2943
|
+
_this8.emitReserved("upgradeError", err);
|
|
2944
|
+
}
|
|
2945
|
+
});
|
|
2946
|
+
};
|
|
2947
|
+
function freezeTransport() {
|
|
2948
|
+
if (failed) return;
|
|
2949
|
+
// Any callback called by transport should be ignored since now
|
|
2950
|
+
failed = true;
|
|
2951
|
+
cleanup();
|
|
2952
|
+
transport.close();
|
|
2953
|
+
transport = null;
|
|
2954
|
+
}
|
|
2955
|
+
// Handle any error that happens while probing
|
|
2956
|
+
var onerror = function onerror(err) {
|
|
2957
|
+
var error = new Error("probe error: " + err);
|
|
2958
|
+
// @ts-ignore
|
|
2959
|
+
error.transport = transport.name;
|
|
2960
|
+
freezeTransport();
|
|
2961
|
+
debug('probe transport "%s" failed because of error: %s', name, err);
|
|
2962
|
+
_this8.emitReserved("upgradeError", error);
|
|
2963
|
+
};
|
|
2964
|
+
function onTransportClose() {
|
|
2965
|
+
onerror("transport closed");
|
|
2966
|
+
}
|
|
2967
|
+
// When the socket is closed while we're probing
|
|
2968
|
+
function onclose() {
|
|
2969
|
+
onerror("socket closed");
|
|
2970
|
+
}
|
|
2971
|
+
// When the socket is upgraded while we're probing
|
|
2972
|
+
function onupgrade(to) {
|
|
2973
|
+
if (transport && to.name !== transport.name) {
|
|
2974
|
+
debug('"%s" works - aborting "%s"', to.name, transport.name);
|
|
2975
|
+
freezeTransport();
|
|
2976
|
+
}
|
|
2977
|
+
}
|
|
2978
|
+
// Remove all listeners on the transport and on self
|
|
2979
|
+
var cleanup = function cleanup() {
|
|
2980
|
+
transport.removeListener("open", onTransportOpen);
|
|
2981
|
+
transport.removeListener("error", onerror);
|
|
2982
|
+
transport.removeListener("close", onTransportClose);
|
|
2983
|
+
_this8.off("close", onclose);
|
|
2984
|
+
_this8.off("upgrading", onupgrade);
|
|
2985
|
+
};
|
|
2986
|
+
transport.once("open", onTransportOpen);
|
|
2987
|
+
transport.once("error", onerror);
|
|
2988
|
+
transport.once("close", onTransportClose);
|
|
2989
|
+
this.once("close", onclose);
|
|
2990
|
+
this.once("upgrading", onupgrade);
|
|
2991
|
+
if (this._upgrades.indexOf("webtransport") !== -1 && name !== "webtransport") {
|
|
2992
|
+
// favor WebTransport
|
|
2993
|
+
this.setTimeoutFn(function () {
|
|
2994
|
+
if (!failed) {
|
|
2995
|
+
transport.open();
|
|
2996
|
+
}
|
|
2997
|
+
}, 200);
|
|
2998
|
+
} else {
|
|
2999
|
+
transport.open();
|
|
3000
|
+
}
|
|
3001
|
+
};
|
|
3002
|
+
_proto2.onHandshake = function onHandshake(data) {
|
|
3003
|
+
this._upgrades = this._filterUpgrades(data.upgrades);
|
|
3004
|
+
_SocketWithoutUpgrade.prototype.onHandshake.call(this, data);
|
|
3005
|
+
}
|
|
3006
|
+
/**
|
|
3007
|
+
* Filters upgrades, returning only those matching client transports.
|
|
3008
|
+
*
|
|
3009
|
+
* @param {Array} upgrades - server upgrades
|
|
3010
|
+
* @private
|
|
3011
|
+
*/;
|
|
3012
|
+
_proto2._filterUpgrades = function _filterUpgrades(upgrades) {
|
|
3013
|
+
var filteredUpgrades = [];
|
|
3014
|
+
for (var i = 0; i < upgrades.length; i++) {
|
|
3015
|
+
if (~this.transports.indexOf(upgrades[i])) filteredUpgrades.push(upgrades[i]);
|
|
3016
|
+
}
|
|
3017
|
+
return filteredUpgrades;
|
|
3018
|
+
};
|
|
3019
|
+
return SocketWithUpgrade;
|
|
3020
|
+
}(SocketWithoutUpgrade);
|
|
3021
|
+
/**
|
|
3022
|
+
* This class provides a WebSocket-like interface to connect to an Engine.IO server. The connection will be established
|
|
3023
|
+
* with one of the available low-level transports, like HTTP long-polling, WebSocket or WebTransport.
|
|
3024
|
+
*
|
|
3025
|
+
* This class comes with an upgrade mechanism, which means that once the connection is established with the first
|
|
3026
|
+
* low-level transport, it will try to upgrade to a better transport.
|
|
3027
|
+
*
|
|
3028
|
+
* @example
|
|
3029
|
+
* import { Socket } from "engine.io-client";
|
|
3030
|
+
*
|
|
3031
|
+
* const socket = new Socket();
|
|
3032
|
+
*
|
|
3033
|
+
* socket.on("open", () => {
|
|
3034
|
+
* socket.send("hello");
|
|
3035
|
+
* });
|
|
3036
|
+
*
|
|
3037
|
+
* @see SocketWithoutUpgrade
|
|
3038
|
+
* @see SocketWithUpgrade
|
|
3039
|
+
*/
|
|
3040
|
+
var Socket = /*#__PURE__*/function (_SocketWithUpgrade) {
|
|
3041
|
+
function Socket(uri) {
|
|
3042
|
+
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
3043
|
+
var o = _typeof(uri) === "object" ? uri : opts;
|
|
3044
|
+
if (!o.transports || o.transports && typeof o.transports[0] === "string") {
|
|
3045
|
+
o.transports = (o.transports || ["polling", "websocket", "webtransport"]).map(function (transportName) {
|
|
3046
|
+
return transports[transportName];
|
|
3047
|
+
}).filter(function (t) {
|
|
3048
|
+
return !!t;
|
|
3049
|
+
});
|
|
3050
|
+
}
|
|
3051
|
+
return _SocketWithUpgrade.call(this, uri, o) || this;
|
|
3052
|
+
}
|
|
3053
|
+
_inheritsLoose(Socket, _SocketWithUpgrade);
|
|
3054
|
+
return Socket;
|
|
3055
|
+
}(SocketWithUpgrade);
|
|
3056
|
+
|
|
3057
|
+
var browserEntrypoint = (function (uri, opts) {
|
|
3058
|
+
return new Socket(uri, opts);
|
|
3059
|
+
});
|
|
3060
|
+
|
|
3061
|
+
return browserEntrypoint;
|
|
3062
|
+
|
|
3063
|
+
}));
|
|
3064
|
+
//# sourceMappingURL=engine.io.js.map
|