@blade-hq/agent-client 1.1.1 → 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +48 -25
- package/dist/blade-client.d.ts +2 -14
- package/dist/index.d.ts +5 -2
- package/dist/index.js +212 -106
- package/dist/index.js.map +1 -1
- package/dist/resources/models.d.ts +15 -0
- package/dist/resources/sessions.d.ts +8 -1
- package/dist/session/agent-session.d.ts +10 -0
- package/dist/session/definition.d.ts +49 -0
- package/dist/shared/projection/helpers.d.ts +1 -1
- package/dist/types/rest.d.ts +378 -10
- package/dist/version.d.ts +4 -42
- package/node_modules/@ark/schema/LICENSE +7 -0
- package/node_modules/@ark/schema/README.md +18 -0
- package/node_modules/@ark/schema/out/config.d.ts +58 -0
- package/node_modules/@ark/schema/out/config.js +95 -0
- package/node_modules/@ark/schema/out/constraint.d.ts +67 -0
- package/node_modules/@ark/schema/out/constraint.js +136 -0
- package/node_modules/@ark/schema/out/generic.d.ts +73 -0
- package/node_modules/@ark/schema/out/generic.js +76 -0
- package/node_modules/@ark/schema/out/index.d.ts +47 -0
- package/node_modules/@ark/schema/out/index.js +47 -0
- package/node_modules/@ark/schema/out/intrinsic.d.ts +24 -0
- package/node_modules/@ark/schema/out/intrinsic.js +56 -0
- package/node_modules/@ark/schema/out/kinds.d.ts +73 -0
- package/node_modules/@ark/schema/out/kinds.js +71 -0
- package/node_modules/@ark/schema/out/module.d.ts +24 -0
- package/node_modules/@ark/schema/out/module.js +15 -0
- package/node_modules/@ark/schema/out/node.d.ts +154 -0
- package/node_modules/@ark/schema/out/node.js +438 -0
- package/node_modules/@ark/schema/out/parse.d.ts +52 -0
- package/node_modules/@ark/schema/out/parse.js +215 -0
- package/node_modules/@ark/schema/out/predicate.d.ts +52 -0
- package/node_modules/@ark/schema/out/predicate.js +63 -0
- package/node_modules/@ark/schema/out/refinements/after.d.ts +41 -0
- package/node_modules/@ark/schema/out/refinements/after.js +35 -0
- package/node_modules/@ark/schema/out/refinements/before.d.ts +41 -0
- package/node_modules/@ark/schema/out/refinements/before.js +41 -0
- package/node_modules/@ark/schema/out/refinements/divisor.d.ts +43 -0
- package/node_modules/@ark/schema/out/refinements/divisor.js +58 -0
- package/node_modules/@ark/schema/out/refinements/exactLength.d.ts +49 -0
- package/node_modules/@ark/schema/out/refinements/exactLength.js +55 -0
- package/node_modules/@ark/schema/out/refinements/kinds.d.ts +34 -0
- package/node_modules/@ark/schema/out/refinements/kinds.js +25 -0
- package/node_modules/@ark/schema/out/refinements/max.d.ts +37 -0
- package/node_modules/@ark/schema/out/refinements/max.js +45 -0
- package/node_modules/@ark/schema/out/refinements/maxLength.d.ts +40 -0
- package/node_modules/@ark/schema/out/refinements/maxLength.js +49 -0
- package/node_modules/@ark/schema/out/refinements/min.d.ts +37 -0
- package/node_modules/@ark/schema/out/refinements/min.js +39 -0
- package/node_modules/@ark/schema/out/refinements/minLength.d.ts +40 -0
- package/node_modules/@ark/schema/out/refinements/minLength.js +47 -0
- package/node_modules/@ark/schema/out/refinements/pattern.d.ts +43 -0
- package/node_modules/@ark/schema/out/refinements/pattern.js +52 -0
- package/node_modules/@ark/schema/out/refinements/range.d.ts +106 -0
- package/node_modules/@ark/schema/out/refinements/range.js +103 -0
- package/node_modules/@ark/schema/out/roots/alias.d.ts +45 -0
- package/node_modules/@ark/schema/out/roots/alias.js +115 -0
- package/node_modules/@ark/schema/out/roots/basis.d.ts +12 -0
- package/node_modules/@ark/schema/out/roots/basis.js +26 -0
- package/node_modules/@ark/schema/out/roots/domain.d.ts +45 -0
- package/node_modules/@ark/schema/out/roots/domain.js +72 -0
- package/node_modules/@ark/schema/out/roots/intersection.d.ts +98 -0
- package/node_modules/@ark/schema/out/roots/intersection.js +292 -0
- package/node_modules/@ark/schema/out/roots/morph.d.ts +62 -0
- package/node_modules/@ark/schema/out/roots/morph.js +159 -0
- package/node_modules/@ark/schema/out/roots/proto.d.ts +53 -0
- package/node_modules/@ark/schema/out/roots/proto.js +101 -0
- package/node_modules/@ark/schema/out/roots/root.d.ts +145 -0
- package/node_modules/@ark/schema/out/roots/root.js +455 -0
- package/node_modules/@ark/schema/out/roots/union.d.ts +99 -0
- package/node_modules/@ark/schema/out/roots/union.js +718 -0
- package/node_modules/@ark/schema/out/roots/unit.d.ts +41 -0
- package/node_modules/@ark/schema/out/roots/unit.js +86 -0
- package/node_modules/@ark/schema/out/roots/utils.d.ts +3 -0
- package/node_modules/@ark/schema/out/roots/utils.js +6 -0
- package/node_modules/@ark/schema/out/scope.d.ts +158 -0
- package/node_modules/@ark/schema/out/scope.js +481 -0
- package/node_modules/@ark/schema/out/shared/compile.d.ts +62 -0
- package/node_modules/@ark/schema/out/shared/compile.js +145 -0
- package/node_modules/@ark/schema/out/shared/declare.d.ts +80 -0
- package/node_modules/@ark/schema/out/shared/declare.js +1 -0
- package/node_modules/@ark/schema/out/shared/disjoint.d.ts +41 -0
- package/node_modules/@ark/schema/out/shared/disjoint.js +65 -0
- package/node_modules/@ark/schema/out/shared/errors.d.ts +145 -0
- package/node_modules/@ark/schema/out/shared/errors.js +252 -0
- package/node_modules/@ark/schema/out/shared/implement.d.ts +151 -0
- package/node_modules/@ark/schema/out/shared/implement.js +98 -0
- package/node_modules/@ark/schema/out/shared/intersections.d.ts +10 -0
- package/node_modules/@ark/schema/out/shared/intersections.js +132 -0
- package/node_modules/@ark/schema/out/shared/jsonSchema.d.ts +93 -0
- package/node_modules/@ark/schema/out/shared/jsonSchema.js +1 -0
- package/node_modules/@ark/schema/out/shared/registry.d.ts +7 -0
- package/node_modules/@ark/schema/out/shared/registry.js +10 -0
- package/node_modules/@ark/schema/out/shared/standardSchema.d.ts +122 -0
- package/node_modules/@ark/schema/out/shared/standardSchema.js +2 -0
- package/node_modules/@ark/schema/out/shared/toJsonSchema.d.ts +139 -0
- package/node_modules/@ark/schema/out/shared/toJsonSchema.js +40 -0
- package/node_modules/@ark/schema/out/shared/traversal.d.ts +117 -0
- package/node_modules/@ark/schema/out/shared/traversal.js +226 -0
- package/node_modules/@ark/schema/out/shared/utils.d.ts +34 -0
- package/node_modules/@ark/schema/out/shared/utils.js +8 -0
- package/node_modules/@ark/schema/out/structure/index.d.ts +46 -0
- package/node_modules/@ark/schema/out/structure/index.js +89 -0
- package/node_modules/@ark/schema/out/structure/optional.d.ts +49 -0
- package/node_modules/@ark/schema/out/structure/optional.js +127 -0
- package/node_modules/@ark/schema/out/structure/prop.d.ts +45 -0
- package/node_modules/@ark/schema/out/structure/prop.js +85 -0
- package/node_modules/@ark/schema/out/structure/required.d.ts +39 -0
- package/node_modules/@ark/schema/out/structure/required.js +38 -0
- package/node_modules/@ark/schema/out/structure/sequence.d.ts +110 -0
- package/node_modules/@ark/schema/out/structure/sequence.js +521 -0
- package/node_modules/@ark/schema/out/structure/shared.d.ts +4 -0
- package/node_modules/@ark/schema/out/structure/shared.js +4 -0
- package/node_modules/@ark/schema/out/structure/structure.d.ts +113 -0
- package/node_modules/@ark/schema/out/structure/structure.js +747 -0
- package/node_modules/@ark/schema/package.json +51 -0
- package/node_modules/@ark/util/LICENSE +7 -0
- package/node_modules/@ark/util/out/arrays.d.ts +166 -0
- package/node_modules/@ark/util/out/arrays.js +147 -0
- package/node_modules/@ark/util/out/clone.d.ts +4 -0
- package/node_modules/@ark/util/out/clone.js +33 -0
- package/node_modules/@ark/util/out/describe.d.ts +25 -0
- package/node_modules/@ark/util/out/describe.js +1 -0
- package/node_modules/@ark/util/out/domain.d.ts +48 -0
- package/node_modules/@ark/util/out/domain.js +25 -0
- package/node_modules/@ark/util/out/errors.d.ts +29 -0
- package/node_modules/@ark/util/out/errors.js +17 -0
- package/node_modules/@ark/util/out/flatMorph.d.ts +41 -0
- package/node_modules/@ark/util/out/flatMorph.js +24 -0
- package/node_modules/@ark/util/out/functions.d.ts +33 -0
- package/node_modules/@ark/util/out/functions.js +53 -0
- package/node_modules/@ark/util/out/generics.d.ts +59 -0
- package/node_modules/@ark/util/out/generics.js +5 -0
- package/node_modules/@ark/util/out/get.d.ts +9 -0
- package/node_modules/@ark/util/out/get.js +7 -0
- package/node_modules/@ark/util/out/hkt.d.ts +27 -0
- package/node_modules/@ark/util/out/hkt.js +5 -0
- package/node_modules/@ark/util/out/index.d.ts +24 -0
- package/node_modules/@ark/util/out/index.js +24 -0
- package/node_modules/@ark/util/out/intersections.d.ts +50 -0
- package/node_modules/@ark/util/out/intersections.js +1 -0
- package/node_modules/@ark/util/out/isomorphic.d.ts +5 -0
- package/node_modules/@ark/util/out/isomorphic.js +19 -0
- package/node_modules/@ark/util/out/keys.d.ts +18 -0
- package/node_modules/@ark/util/out/keys.js +1 -0
- package/node_modules/@ark/util/out/lazily.d.ts +1 -0
- package/node_modules/@ark/util/out/lazily.js +16 -0
- package/node_modules/@ark/util/out/numbers.d.ts +72 -0
- package/node_modules/@ark/util/out/numbers.js +138 -0
- package/node_modules/@ark/util/out/objectKinds.d.ts +205 -0
- package/node_modules/@ark/util/out/objectKinds.js +150 -0
- package/node_modules/@ark/util/out/path.d.ts +22 -0
- package/node_modules/@ark/util/out/path.js +65 -0
- package/node_modules/@ark/util/out/primitive.d.ts +16 -0
- package/node_modules/@ark/util/out/primitive.js +3 -0
- package/node_modules/@ark/util/out/records.d.ts +183 -0
- package/node_modules/@ark/util/out/records.js +63 -0
- package/node_modules/@ark/util/out/registry.d.ts +21 -0
- package/node_modules/@ark/util/out/registry.js +49 -0
- package/node_modules/@ark/util/out/scanner.d.ts +44 -0
- package/node_modules/@ark/util/out/scanner.js +87 -0
- package/node_modules/@ark/util/out/serialize.d.ts +34 -0
- package/node_modules/@ark/util/out/serialize.js +150 -0
- package/node_modules/@ark/util/out/strings.d.ts +33 -0
- package/node_modules/@ark/util/out/strings.js +59 -0
- package/node_modules/@ark/util/out/traits.d.ts +89 -0
- package/node_modules/@ark/util/out/traits.js +75 -0
- package/node_modules/@ark/util/out/unionToTuple.d.ts +14 -0
- package/node_modules/@ark/util/out/unionToTuple.js +1 -0
- package/node_modules/@ark/util/package.json +39 -0
- package/node_modules/@ark/util/tsconfig.base.json +18 -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/arkregex/LICENSE +7 -0
- package/node_modules/arkregex/README.md +61 -0
- package/node_modules/arkregex/out/charset.d.ts +15 -0
- package/node_modules/arkregex/out/charset.js +1 -0
- package/node_modules/arkregex/out/escape.d.ts +29 -0
- package/node_modules/arkregex/out/escape.js +10 -0
- package/node_modules/arkregex/out/execArray.d.ts +23 -0
- package/node_modules/arkregex/out/execArray.js +1 -0
- package/node_modules/arkregex/out/group.d.ts +33 -0
- package/node_modules/arkregex/out/group.js +6 -0
- package/node_modules/arkregex/out/index.d.ts +1 -0
- package/node_modules/arkregex/out/index.js +1 -0
- package/node_modules/arkregex/out/parse.d.ts +10 -0
- package/node_modules/arkregex/out/parse.js +1 -0
- package/node_modules/arkregex/out/quantify.d.ts +43 -0
- package/node_modules/arkregex/out/quantify.js +2 -0
- package/node_modules/arkregex/out/regex.d.ts +38 -0
- package/node_modules/arkregex/out/regex.js +2 -0
- package/node_modules/arkregex/out/state.d.ts +359 -0
- package/node_modules/arkregex/out/state.js +2 -0
- package/node_modules/arkregex/package.json +42 -0
- package/node_modules/arktype/LICENSE +7 -0
- package/node_modules/arktype/README.md +157 -0
- package/node_modules/arktype/out/attributes.d.ts +104 -0
- package/node_modules/arktype/out/attributes.js +3 -0
- package/node_modules/arktype/out/config.d.ts +35 -0
- package/node_modules/arktype/out/config.js +3 -0
- package/node_modules/arktype/out/declare.d.ts +35 -0
- package/node_modules/arktype/out/declare.js +1 -0
- package/node_modules/arktype/out/fn.d.ts +61 -0
- package/node_modules/arktype/out/fn.js +54 -0
- package/node_modules/arktype/out/generic.d.ts +118 -0
- package/node_modules/arktype/out/generic.js +37 -0
- package/node_modules/arktype/out/index.d.ts +12 -0
- package/node_modules/arktype/out/index.js +9 -0
- package/node_modules/arktype/out/keywords/Array.d.ts +20 -0
- package/node_modules/arktype/out/keywords/Array.js +21 -0
- package/node_modules/arktype/out/keywords/FormData.d.ts +15 -0
- package/node_modules/arktype/out/keywords/FormData.js +40 -0
- package/node_modules/arktype/out/keywords/TypedArray.d.ts +19 -0
- package/node_modules/arktype/out/keywords/TypedArray.js +16 -0
- package/node_modules/arktype/out/keywords/builtins.d.ts +18 -0
- package/node_modules/arktype/out/keywords/builtins.js +11 -0
- package/node_modules/arktype/out/keywords/constructors.d.ts +31 -0
- package/node_modules/arktype/out/keywords/constructors.js +16 -0
- package/node_modules/arktype/out/keywords/keywords.d.ts +70 -0
- package/node_modules/arktype/out/keywords/keywords.js +48 -0
- package/node_modules/arktype/out/keywords/number.d.ts +23 -0
- package/node_modules/arktype/out/keywords/number.js +49 -0
- package/node_modules/arktype/out/keywords/string.d.ts +334 -0
- package/node_modules/arktype/out/keywords/string.js +463 -0
- package/node_modules/arktype/out/keywords/ts.d.ts +108 -0
- package/node_modules/arktype/out/keywords/ts.js +82 -0
- package/node_modules/arktype/out/match.d.ts +152 -0
- package/node_modules/arktype/out/match.js +95 -0
- package/node_modules/arktype/out/module.d.ts +22 -0
- package/node_modules/arktype/out/module.js +3 -0
- package/node_modules/arktype/out/nary.d.ts +473 -0
- package/node_modules/arktype/out/nary.js +1 -0
- package/node_modules/arktype/out/parser/ast/bounds.d.ts +18 -0
- package/node_modules/arktype/out/parser/ast/bounds.js +1 -0
- package/node_modules/arktype/out/parser/ast/default.d.ts +8 -0
- package/node_modules/arktype/out/parser/ast/default.js +1 -0
- package/node_modules/arktype/out/parser/ast/divisor.d.ts +9 -0
- package/node_modules/arktype/out/parser/ast/divisor.js +1 -0
- package/node_modules/arktype/out/parser/ast/generic.d.ts +17 -0
- package/node_modules/arktype/out/parser/ast/generic.js +1 -0
- package/node_modules/arktype/out/parser/ast/infer.d.ts +25 -0
- package/node_modules/arktype/out/parser/ast/infer.js +1 -0
- package/node_modules/arktype/out/parser/ast/keyof.d.ts +7 -0
- package/node_modules/arktype/out/parser/ast/keyof.js +1 -0
- package/node_modules/arktype/out/parser/ast/utils.d.ts +8 -0
- package/node_modules/arktype/out/parser/ast/utils.js +1 -0
- package/node_modules/arktype/out/parser/ast/validate.d.ts +30 -0
- package/node_modules/arktype/out/parser/ast/validate.js +3 -0
- package/node_modules/arktype/out/parser/definition.d.ts +30 -0
- package/node_modules/arktype/out/parser/definition.js +74 -0
- package/node_modules/arktype/out/parser/objectLiteral.d.ts +70 -0
- package/node_modules/arktype/out/parser/objectLiteral.js +113 -0
- package/node_modules/arktype/out/parser/property.d.ts +34 -0
- package/node_modules/arktype/out/parser/property.js +16 -0
- package/node_modules/arktype/out/parser/reduce/dynamic.d.ts +42 -0
- package/node_modules/arktype/out/parser/reduce/dynamic.js +153 -0
- package/node_modules/arktype/out/parser/reduce/shared.d.ts +39 -0
- package/node_modules/arktype/out/parser/reduce/shared.js +25 -0
- package/node_modules/arktype/out/parser/reduce/static.d.ts +186 -0
- package/node_modules/arktype/out/parser/reduce/static.js +1 -0
- package/node_modules/arktype/out/parser/shift/operand/date.d.ts +11 -0
- package/node_modules/arktype/out/parser/shift/operand/date.js +23 -0
- package/node_modules/arktype/out/parser/shift/operand/enclosed.d.ts +57 -0
- package/node_modules/arktype/out/parser/shift/operand/enclosed.js +78 -0
- package/node_modules/arktype/out/parser/shift/operand/genericArgs.d.ts +27 -0
- package/node_modules/arktype/out/parser/shift/operand/genericArgs.js +16 -0
- package/node_modules/arktype/out/parser/shift/operand/operand.d.ts +8 -0
- package/node_modules/arktype/out/parser/shift/operand/operand.js +16 -0
- package/node_modules/arktype/out/parser/shift/operand/unenclosed.d.ts +43 -0
- package/node_modules/arktype/out/parser/shift/operand/unenclosed.js +59 -0
- package/node_modules/arktype/out/parser/shift/operator/bounds.d.ts +24 -0
- package/node_modules/arktype/out/parser/shift/operator/bounds.js +91 -0
- package/node_modules/arktype/out/parser/shift/operator/brand.d.ts +7 -0
- package/node_modules/arktype/out/parser/shift/operator/brand.js +6 -0
- package/node_modules/arktype/out/parser/shift/operator/default.d.ts +24 -0
- package/node_modules/arktype/out/parser/shift/operator/default.js +15 -0
- package/node_modules/arktype/out/parser/shift/operator/divisor.d.ts +8 -0
- package/node_modules/arktype/out/parser/shift/operator/divisor.js +13 -0
- package/node_modules/arktype/out/parser/shift/operator/operator.d.ts +14 -0
- package/node_modules/arktype/out/parser/shift/operator/operator.js +28 -0
- package/node_modules/arktype/out/parser/shift/tokens.d.ts +33 -0
- package/node_modules/arktype/out/parser/shift/tokens.js +37 -0
- package/node_modules/arktype/out/parser/string.d.ts +30 -0
- package/node_modules/arktype/out/parser/string.js +42 -0
- package/node_modules/arktype/out/parser/tupleExpressions.d.ts +79 -0
- package/node_modules/arktype/out/parser/tupleExpressions.js +75 -0
- package/node_modules/arktype/out/parser/tupleLiteral.d.ts +95 -0
- package/node_modules/arktype/out/parser/tupleLiteral.js +128 -0
- package/node_modules/arktype/out/scope.d.ts +158 -0
- package/node_modules/arktype/out/scope.js +106 -0
- package/node_modules/arktype/out/type.d.ts +144 -0
- package/node_modules/arktype/out/type.js +55 -0
- package/node_modules/arktype/out/variants/array.d.ts +12 -0
- package/node_modules/arktype/out/variants/array.js +1 -0
- package/node_modules/arktype/out/variants/base.d.ts +542 -0
- package/node_modules/arktype/out/variants/base.js +1 -0
- package/node_modules/arktype/out/variants/date.d.ts +10 -0
- package/node_modules/arktype/out/variants/date.js +1 -0
- package/node_modules/arktype/out/variants/instantiate.d.ts +12 -0
- package/node_modules/arktype/out/variants/instantiate.js +1 -0
- package/node_modules/arktype/out/variants/number.d.ts +11 -0
- package/node_modules/arktype/out/variants/number.js +1 -0
- package/node_modules/arktype/out/variants/object.d.ts +107 -0
- package/node_modules/arktype/out/variants/object.js +1 -0
- package/node_modules/arktype/out/variants/string.d.ts +15 -0
- package/node_modules/arktype/out/variants/string.js +1 -0
- package/node_modules/arktype/package.json +57 -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/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/ws/LICENSE +20 -0
- package/node_modules/ws/README.md +548 -0
- package/node_modules/ws/browser.js +8 -0
- package/node_modules/ws/index.js +13 -0
- package/node_modules/ws/lib/buffer-util.js +131 -0
- package/node_modules/ws/lib/constants.js +18 -0
- package/node_modules/ws/lib/event-target.js +292 -0
- package/node_modules/ws/lib/extension.js +203 -0
- package/node_modules/ws/lib/limiter.js +55 -0
- package/node_modules/ws/lib/permessage-deflate.js +528 -0
- package/node_modules/ws/lib/receiver.js +706 -0
- package/node_modules/ws/lib/sender.js +602 -0
- package/node_modules/ws/lib/stream.js +161 -0
- package/node_modules/ws/lib/subprotocol.js +62 -0
- package/node_modules/ws/lib/validation.js +152 -0
- package/node_modules/ws/lib/websocket-server.js +550 -0
- package/node_modules/ws/lib/websocket.js +1388 -0
- package/node_modules/ws/package.json +69 -0
- package/node_modules/ws/wrapper.mjs +8 -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/package.json +34 -4
- package/public-api.md +85 -23
|
@@ -0,0 +1,756 @@
|
|
|
1
|
+
import { transports as DEFAULT_TRANSPORTS } from "./transports/index.js";
|
|
2
|
+
import { installTimerFunctions, byteLength } from "./util.js";
|
|
3
|
+
import { decode } from "./contrib/parseqs.js";
|
|
4
|
+
import { parse } from "./contrib/parseuri.js";
|
|
5
|
+
import { Emitter } from "@socket.io/component-emitter";
|
|
6
|
+
import { protocol } from "engine.io-parser";
|
|
7
|
+
import { createCookieJar, defaultBinaryType, nextTick, } from "./globals.node.js";
|
|
8
|
+
import debugModule from "debug"; // debug()
|
|
9
|
+
const debug = debugModule("engine.io-client:socket"); // debug()
|
|
10
|
+
const withEventListeners = typeof addEventListener === "function" &&
|
|
11
|
+
typeof removeEventListener === "function";
|
|
12
|
+
const OFFLINE_EVENT_LISTENERS = [];
|
|
13
|
+
if (withEventListeners) {
|
|
14
|
+
// within a ServiceWorker, any event handler for the 'offline' event must be added on the initial evaluation of the
|
|
15
|
+
// script, so we create one single event listener here which will forward the event to the socket instances
|
|
16
|
+
addEventListener("offline", () => {
|
|
17
|
+
debug("closing %d connection(s) because the network was lost", OFFLINE_EVENT_LISTENERS.length);
|
|
18
|
+
OFFLINE_EVENT_LISTENERS.forEach((listener) => listener());
|
|
19
|
+
}, false);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* This class provides a WebSocket-like interface to connect to an Engine.IO server. The connection will be established
|
|
23
|
+
* with one of the available low-level transports, like HTTP long-polling, WebSocket or WebTransport.
|
|
24
|
+
*
|
|
25
|
+
* This class comes without upgrade mechanism, which means that it will keep the first low-level transport that
|
|
26
|
+
* successfully establishes the connection.
|
|
27
|
+
*
|
|
28
|
+
* In order to allow tree-shaking, there are no transports included, that's why the `transports` option is mandatory.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* import { SocketWithoutUpgrade, WebSocket } from "engine.io-client";
|
|
32
|
+
*
|
|
33
|
+
* const socket = new SocketWithoutUpgrade({
|
|
34
|
+
* transports: [WebSocket]
|
|
35
|
+
* });
|
|
36
|
+
*
|
|
37
|
+
* socket.on("open", () => {
|
|
38
|
+
* socket.send("hello");
|
|
39
|
+
* });
|
|
40
|
+
*
|
|
41
|
+
* @see SocketWithUpgrade
|
|
42
|
+
* @see Socket
|
|
43
|
+
*/
|
|
44
|
+
export class SocketWithoutUpgrade extends Emitter {
|
|
45
|
+
/**
|
|
46
|
+
* Socket constructor.
|
|
47
|
+
*
|
|
48
|
+
* @param {String|Object} uri - uri or options
|
|
49
|
+
* @param {Object} opts - options
|
|
50
|
+
*/
|
|
51
|
+
constructor(uri, opts) {
|
|
52
|
+
super();
|
|
53
|
+
this.binaryType = defaultBinaryType;
|
|
54
|
+
this.writeBuffer = [];
|
|
55
|
+
this._prevBufferLen = 0;
|
|
56
|
+
this._pingInterval = -1;
|
|
57
|
+
this._pingTimeout = -1;
|
|
58
|
+
this._maxPayload = -1;
|
|
59
|
+
/**
|
|
60
|
+
* The expiration timestamp of the {@link _pingTimeoutTimer} object is tracked, in case the timer is throttled and the
|
|
61
|
+
* callback is not fired on time. This can happen for example when a laptop is suspended or when a phone is locked.
|
|
62
|
+
*/
|
|
63
|
+
this._pingTimeoutTime = Infinity;
|
|
64
|
+
if (uri && "object" === typeof uri) {
|
|
65
|
+
opts = uri;
|
|
66
|
+
uri = null;
|
|
67
|
+
}
|
|
68
|
+
if (uri) {
|
|
69
|
+
const parsedUri = parse(uri);
|
|
70
|
+
opts.hostname = parsedUri.host;
|
|
71
|
+
opts.secure =
|
|
72
|
+
parsedUri.protocol === "https" || parsedUri.protocol === "wss";
|
|
73
|
+
opts.port = parsedUri.port;
|
|
74
|
+
if (parsedUri.query)
|
|
75
|
+
opts.query = parsedUri.query;
|
|
76
|
+
}
|
|
77
|
+
else if (opts.host) {
|
|
78
|
+
opts.hostname = parse(opts.host).host;
|
|
79
|
+
}
|
|
80
|
+
installTimerFunctions(this, opts);
|
|
81
|
+
this.secure =
|
|
82
|
+
null != opts.secure
|
|
83
|
+
? opts.secure
|
|
84
|
+
: typeof location !== "undefined" && "https:" === location.protocol;
|
|
85
|
+
if (opts.hostname && !opts.port) {
|
|
86
|
+
// if no port is specified manually, use the protocol default
|
|
87
|
+
opts.port = this.secure ? "443" : "80";
|
|
88
|
+
}
|
|
89
|
+
this.hostname =
|
|
90
|
+
opts.hostname ||
|
|
91
|
+
(typeof location !== "undefined" ? location.hostname : "localhost");
|
|
92
|
+
this.port =
|
|
93
|
+
opts.port ||
|
|
94
|
+
(typeof location !== "undefined" && location.port
|
|
95
|
+
? location.port
|
|
96
|
+
: this.secure
|
|
97
|
+
? "443"
|
|
98
|
+
: "80");
|
|
99
|
+
this.transports = [];
|
|
100
|
+
this._transportsByName = {};
|
|
101
|
+
opts.transports.forEach((t) => {
|
|
102
|
+
const transportName = t.prototype.name;
|
|
103
|
+
this.transports.push(transportName);
|
|
104
|
+
this._transportsByName[transportName] = t;
|
|
105
|
+
});
|
|
106
|
+
this.opts = Object.assign({
|
|
107
|
+
path: "/engine.io",
|
|
108
|
+
agent: false,
|
|
109
|
+
withCredentials: false,
|
|
110
|
+
upgrade: true,
|
|
111
|
+
timestampParam: "t",
|
|
112
|
+
rememberUpgrade: false,
|
|
113
|
+
addTrailingSlash: true,
|
|
114
|
+
rejectUnauthorized: true,
|
|
115
|
+
perMessageDeflate: {
|
|
116
|
+
threshold: 1024,
|
|
117
|
+
},
|
|
118
|
+
transportOptions: {},
|
|
119
|
+
closeOnBeforeunload: false,
|
|
120
|
+
}, opts);
|
|
121
|
+
this.opts.path =
|
|
122
|
+
this.opts.path.replace(/\/$/, "") +
|
|
123
|
+
(this.opts.addTrailingSlash ? "/" : "");
|
|
124
|
+
if (typeof this.opts.query === "string") {
|
|
125
|
+
this.opts.query = decode(this.opts.query);
|
|
126
|
+
}
|
|
127
|
+
if (withEventListeners) {
|
|
128
|
+
if (this.opts.closeOnBeforeunload) {
|
|
129
|
+
// Firefox closes the connection when the "beforeunload" event is emitted but not Chrome. This event listener
|
|
130
|
+
// ensures every browser behaves the same (no "disconnect" event at the Socket.IO level when the page is
|
|
131
|
+
// closed/reloaded)
|
|
132
|
+
this._beforeunloadEventListener = () => {
|
|
133
|
+
if (this.transport) {
|
|
134
|
+
// silently close the transport
|
|
135
|
+
this.transport.removeAllListeners();
|
|
136
|
+
this.transport.close();
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
addEventListener("beforeunload", this._beforeunloadEventListener, false);
|
|
140
|
+
}
|
|
141
|
+
if (this.hostname !== "localhost") {
|
|
142
|
+
debug("adding listener for the 'offline' event");
|
|
143
|
+
this._offlineEventListener = () => {
|
|
144
|
+
this._onClose("transport close", {
|
|
145
|
+
description: "network connection lost",
|
|
146
|
+
});
|
|
147
|
+
};
|
|
148
|
+
OFFLINE_EVENT_LISTENERS.push(this._offlineEventListener);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (this.opts.withCredentials) {
|
|
152
|
+
this._cookieJar = createCookieJar();
|
|
153
|
+
}
|
|
154
|
+
this._open();
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Creates transport of the given type.
|
|
158
|
+
*
|
|
159
|
+
* @param {String} name - transport name
|
|
160
|
+
* @return {Transport}
|
|
161
|
+
* @private
|
|
162
|
+
*/
|
|
163
|
+
createTransport(name) {
|
|
164
|
+
debug('creating transport "%s"', name);
|
|
165
|
+
const query = Object.assign({}, this.opts.query);
|
|
166
|
+
// append engine.io protocol identifier
|
|
167
|
+
query.EIO = protocol;
|
|
168
|
+
// transport name
|
|
169
|
+
query.transport = name;
|
|
170
|
+
// session id if we already have one
|
|
171
|
+
if (this.id)
|
|
172
|
+
query.sid = this.id;
|
|
173
|
+
const opts = Object.assign({}, this.opts, {
|
|
174
|
+
query,
|
|
175
|
+
socket: this,
|
|
176
|
+
hostname: this.hostname,
|
|
177
|
+
secure: this.secure,
|
|
178
|
+
port: this.port,
|
|
179
|
+
}, this.opts.transportOptions[name]);
|
|
180
|
+
debug("options: %j", opts);
|
|
181
|
+
return new this._transportsByName[name](opts);
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Initializes transport to use and starts probe.
|
|
185
|
+
*
|
|
186
|
+
* @private
|
|
187
|
+
*/
|
|
188
|
+
_open() {
|
|
189
|
+
if (this.transports.length === 0) {
|
|
190
|
+
// Emit error on next tick so it can be listened to
|
|
191
|
+
this.setTimeoutFn(() => {
|
|
192
|
+
this.emitReserved("error", "No transports available");
|
|
193
|
+
}, 0);
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
const transportName = this.opts.rememberUpgrade &&
|
|
197
|
+
SocketWithoutUpgrade.priorWebsocketSuccess &&
|
|
198
|
+
this.transports.indexOf("websocket") !== -1
|
|
199
|
+
? "websocket"
|
|
200
|
+
: this.transports[0];
|
|
201
|
+
this.readyState = "opening";
|
|
202
|
+
const transport = this.createTransport(transportName);
|
|
203
|
+
transport.open();
|
|
204
|
+
this.setTransport(transport);
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Sets the current transport. Disables the existing one (if any).
|
|
208
|
+
*
|
|
209
|
+
* @private
|
|
210
|
+
*/
|
|
211
|
+
setTransport(transport) {
|
|
212
|
+
debug("setting transport %s", transport.name);
|
|
213
|
+
if (this.transport) {
|
|
214
|
+
debug("clearing existing transport %s", this.transport.name);
|
|
215
|
+
this.transport.removeAllListeners();
|
|
216
|
+
}
|
|
217
|
+
// set up transport
|
|
218
|
+
this.transport = transport;
|
|
219
|
+
// set up transport listeners
|
|
220
|
+
transport
|
|
221
|
+
.on("drain", this._onDrain.bind(this))
|
|
222
|
+
.on("packet", this._onPacket.bind(this))
|
|
223
|
+
.on("error", this._onError.bind(this))
|
|
224
|
+
.on("close", (reason) => this._onClose("transport close", reason));
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Called when connection is deemed open.
|
|
228
|
+
*
|
|
229
|
+
* @private
|
|
230
|
+
*/
|
|
231
|
+
onOpen() {
|
|
232
|
+
debug("socket open");
|
|
233
|
+
this.readyState = "open";
|
|
234
|
+
SocketWithoutUpgrade.priorWebsocketSuccess =
|
|
235
|
+
"websocket" === this.transport.name;
|
|
236
|
+
this.emitReserved("open");
|
|
237
|
+
this.flush();
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Handles a packet.
|
|
241
|
+
*
|
|
242
|
+
* @private
|
|
243
|
+
*/
|
|
244
|
+
_onPacket(packet) {
|
|
245
|
+
if ("opening" === this.readyState ||
|
|
246
|
+
"open" === this.readyState ||
|
|
247
|
+
"closing" === this.readyState) {
|
|
248
|
+
debug('socket receive: type "%s", data "%s"', packet.type, packet.data);
|
|
249
|
+
this.emitReserved("packet", packet);
|
|
250
|
+
// Socket is live - any packet counts
|
|
251
|
+
this.emitReserved("heartbeat");
|
|
252
|
+
switch (packet.type) {
|
|
253
|
+
case "open":
|
|
254
|
+
this.onHandshake(JSON.parse(packet.data));
|
|
255
|
+
break;
|
|
256
|
+
case "ping":
|
|
257
|
+
this._sendPacket("pong");
|
|
258
|
+
this.emitReserved("ping");
|
|
259
|
+
this.emitReserved("pong");
|
|
260
|
+
this._resetPingTimeout();
|
|
261
|
+
break;
|
|
262
|
+
case "error":
|
|
263
|
+
const err = new Error("server error");
|
|
264
|
+
// @ts-ignore
|
|
265
|
+
err.code = packet.data;
|
|
266
|
+
this._onError(err);
|
|
267
|
+
break;
|
|
268
|
+
case "message":
|
|
269
|
+
this.emitReserved("data", packet.data);
|
|
270
|
+
this.emitReserved("message", packet.data);
|
|
271
|
+
break;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
else {
|
|
275
|
+
debug('packet received with socket readyState "%s"', this.readyState);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Called upon handshake completion.
|
|
280
|
+
*
|
|
281
|
+
* @param {Object} data - handshake obj
|
|
282
|
+
* @private
|
|
283
|
+
*/
|
|
284
|
+
onHandshake(data) {
|
|
285
|
+
this.emitReserved("handshake", data);
|
|
286
|
+
this.id = data.sid;
|
|
287
|
+
this.transport.query.sid = data.sid;
|
|
288
|
+
this._pingInterval = data.pingInterval;
|
|
289
|
+
this._pingTimeout = data.pingTimeout;
|
|
290
|
+
this._maxPayload = data.maxPayload;
|
|
291
|
+
this.onOpen();
|
|
292
|
+
// In case open handler closes socket
|
|
293
|
+
if ("closed" === this.readyState)
|
|
294
|
+
return;
|
|
295
|
+
this._resetPingTimeout();
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Sets and resets ping timeout timer based on server pings.
|
|
299
|
+
*
|
|
300
|
+
* @private
|
|
301
|
+
*/
|
|
302
|
+
_resetPingTimeout() {
|
|
303
|
+
this.clearTimeoutFn(this._pingTimeoutTimer);
|
|
304
|
+
const delay = this._pingInterval + this._pingTimeout;
|
|
305
|
+
this._pingTimeoutTime = Date.now() + delay;
|
|
306
|
+
this._pingTimeoutTimer = this.setTimeoutFn(() => {
|
|
307
|
+
this._onClose("ping timeout");
|
|
308
|
+
}, delay);
|
|
309
|
+
if (this.opts.autoUnref) {
|
|
310
|
+
this._pingTimeoutTimer.unref();
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Called on `drain` event
|
|
315
|
+
*
|
|
316
|
+
* @private
|
|
317
|
+
*/
|
|
318
|
+
_onDrain() {
|
|
319
|
+
this.writeBuffer.splice(0, this._prevBufferLen);
|
|
320
|
+
// setting prevBufferLen = 0 is very important
|
|
321
|
+
// for example, when upgrading, upgrade packet is sent over,
|
|
322
|
+
// and a nonzero prevBufferLen could cause problems on `drain`
|
|
323
|
+
this._prevBufferLen = 0;
|
|
324
|
+
if (0 === this.writeBuffer.length) {
|
|
325
|
+
this.emitReserved("drain");
|
|
326
|
+
}
|
|
327
|
+
else {
|
|
328
|
+
this.flush();
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Flush write buffers.
|
|
333
|
+
*
|
|
334
|
+
* @private
|
|
335
|
+
*/
|
|
336
|
+
flush() {
|
|
337
|
+
if ("closed" !== this.readyState &&
|
|
338
|
+
this.transport.writable &&
|
|
339
|
+
!this.upgrading &&
|
|
340
|
+
this.writeBuffer.length) {
|
|
341
|
+
const packets = this._getWritablePackets();
|
|
342
|
+
debug("flushing %d packets in socket", packets.length);
|
|
343
|
+
this.transport.send(packets);
|
|
344
|
+
// keep track of current length of writeBuffer
|
|
345
|
+
// splice writeBuffer and callbackBuffer on `drain`
|
|
346
|
+
this._prevBufferLen = packets.length;
|
|
347
|
+
this.emitReserved("flush");
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Ensure the encoded size of the writeBuffer is below the maxPayload value sent by the server (only for HTTP
|
|
352
|
+
* long-polling)
|
|
353
|
+
*
|
|
354
|
+
* @private
|
|
355
|
+
*/
|
|
356
|
+
_getWritablePackets() {
|
|
357
|
+
const shouldCheckPayloadSize = this._maxPayload &&
|
|
358
|
+
this.transport.name === "polling" &&
|
|
359
|
+
this.writeBuffer.length > 1;
|
|
360
|
+
if (!shouldCheckPayloadSize) {
|
|
361
|
+
return this.writeBuffer;
|
|
362
|
+
}
|
|
363
|
+
let payloadSize = 1; // first packet type
|
|
364
|
+
for (let i = 0; i < this.writeBuffer.length; i++) {
|
|
365
|
+
const data = this.writeBuffer[i].data;
|
|
366
|
+
if (data) {
|
|
367
|
+
payloadSize += byteLength(data);
|
|
368
|
+
}
|
|
369
|
+
if (i > 0 && payloadSize > this._maxPayload) {
|
|
370
|
+
debug("only send %d out of %d packets", i, this.writeBuffer.length);
|
|
371
|
+
return this.writeBuffer.slice(0, i);
|
|
372
|
+
}
|
|
373
|
+
payloadSize += 2; // separator + packet type
|
|
374
|
+
}
|
|
375
|
+
debug("payload size is %d (max: %d)", payloadSize, this._maxPayload);
|
|
376
|
+
return this.writeBuffer;
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* Checks whether the heartbeat timer has expired but the socket has not yet been notified.
|
|
380
|
+
*
|
|
381
|
+
* Note: this method is private for now because it does not really fit the WebSocket API, but if we put it in the
|
|
382
|
+
* `write()` method then the message would not be buffered by the Socket.IO client.
|
|
383
|
+
*
|
|
384
|
+
* @return {boolean}
|
|
385
|
+
* @private
|
|
386
|
+
*/
|
|
387
|
+
/* private */ _hasPingExpired() {
|
|
388
|
+
if (!this._pingTimeoutTime)
|
|
389
|
+
return true;
|
|
390
|
+
const hasExpired = Date.now() > this._pingTimeoutTime;
|
|
391
|
+
if (hasExpired) {
|
|
392
|
+
debug("throttled timer detected, scheduling connection close");
|
|
393
|
+
this._pingTimeoutTime = 0;
|
|
394
|
+
nextTick(() => {
|
|
395
|
+
this._onClose("ping timeout");
|
|
396
|
+
}, this.setTimeoutFn);
|
|
397
|
+
}
|
|
398
|
+
return hasExpired;
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Sends a message.
|
|
402
|
+
*
|
|
403
|
+
* @param {String} msg - message.
|
|
404
|
+
* @param {Object} options.
|
|
405
|
+
* @param {Function} fn - callback function.
|
|
406
|
+
* @return {Socket} for chaining.
|
|
407
|
+
*/
|
|
408
|
+
write(msg, options, fn) {
|
|
409
|
+
this._sendPacket("message", msg, options, fn);
|
|
410
|
+
return this;
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* Sends a message. Alias of {@link Socket#write}.
|
|
414
|
+
*
|
|
415
|
+
* @param {String} msg - message.
|
|
416
|
+
* @param {Object} options.
|
|
417
|
+
* @param {Function} fn - callback function.
|
|
418
|
+
* @return {Socket} for chaining.
|
|
419
|
+
*/
|
|
420
|
+
send(msg, options, fn) {
|
|
421
|
+
this._sendPacket("message", msg, options, fn);
|
|
422
|
+
return this;
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* Sends a packet.
|
|
426
|
+
*
|
|
427
|
+
* @param {String} type: packet type.
|
|
428
|
+
* @param {String} data.
|
|
429
|
+
* @param {Object} options.
|
|
430
|
+
* @param {Function} fn - callback function.
|
|
431
|
+
* @private
|
|
432
|
+
*/
|
|
433
|
+
_sendPacket(type, data, options, fn) {
|
|
434
|
+
if ("function" === typeof data) {
|
|
435
|
+
fn = data;
|
|
436
|
+
data = undefined;
|
|
437
|
+
}
|
|
438
|
+
if ("function" === typeof options) {
|
|
439
|
+
fn = options;
|
|
440
|
+
options = null;
|
|
441
|
+
}
|
|
442
|
+
if ("closing" === this.readyState || "closed" === this.readyState) {
|
|
443
|
+
return;
|
|
444
|
+
}
|
|
445
|
+
options = options || {};
|
|
446
|
+
options.compress = false !== options.compress;
|
|
447
|
+
const packet = {
|
|
448
|
+
type: type,
|
|
449
|
+
data: data,
|
|
450
|
+
options: options,
|
|
451
|
+
};
|
|
452
|
+
this.emitReserved("packetCreate", packet);
|
|
453
|
+
this.writeBuffer.push(packet);
|
|
454
|
+
if (fn)
|
|
455
|
+
this.once("flush", fn);
|
|
456
|
+
this.flush();
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* Closes the connection.
|
|
460
|
+
*/
|
|
461
|
+
close() {
|
|
462
|
+
const close = () => {
|
|
463
|
+
this._onClose("forced close");
|
|
464
|
+
debug("socket closing - telling transport to close");
|
|
465
|
+
this.transport.close();
|
|
466
|
+
};
|
|
467
|
+
const cleanupAndClose = () => {
|
|
468
|
+
this.off("upgrade", cleanupAndClose);
|
|
469
|
+
this.off("upgradeError", cleanupAndClose);
|
|
470
|
+
close();
|
|
471
|
+
};
|
|
472
|
+
const waitForUpgrade = () => {
|
|
473
|
+
// wait for upgrade to finish since we can't send packets while pausing a transport
|
|
474
|
+
this.once("upgrade", cleanupAndClose);
|
|
475
|
+
this.once("upgradeError", cleanupAndClose);
|
|
476
|
+
};
|
|
477
|
+
if ("opening" === this.readyState || "open" === this.readyState) {
|
|
478
|
+
this.readyState = "closing";
|
|
479
|
+
if (this.writeBuffer.length) {
|
|
480
|
+
this.once("drain", () => {
|
|
481
|
+
if (this.upgrading) {
|
|
482
|
+
waitForUpgrade();
|
|
483
|
+
}
|
|
484
|
+
else {
|
|
485
|
+
close();
|
|
486
|
+
}
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
else if (this.upgrading) {
|
|
490
|
+
waitForUpgrade();
|
|
491
|
+
}
|
|
492
|
+
else {
|
|
493
|
+
close();
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
return this;
|
|
497
|
+
}
|
|
498
|
+
/**
|
|
499
|
+
* Called upon transport error
|
|
500
|
+
*
|
|
501
|
+
* @private
|
|
502
|
+
*/
|
|
503
|
+
_onError(err) {
|
|
504
|
+
debug("socket error %j", err);
|
|
505
|
+
SocketWithoutUpgrade.priorWebsocketSuccess = false;
|
|
506
|
+
if (this.opts.tryAllTransports &&
|
|
507
|
+
this.transports.length > 1 &&
|
|
508
|
+
this.readyState === "opening") {
|
|
509
|
+
debug("trying next transport");
|
|
510
|
+
this.transports.shift();
|
|
511
|
+
return this._open();
|
|
512
|
+
}
|
|
513
|
+
this.emitReserved("error", err);
|
|
514
|
+
this._onClose("transport error", err);
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* Called upon transport close.
|
|
518
|
+
*
|
|
519
|
+
* @private
|
|
520
|
+
*/
|
|
521
|
+
_onClose(reason, description) {
|
|
522
|
+
if ("opening" === this.readyState ||
|
|
523
|
+
"open" === this.readyState ||
|
|
524
|
+
"closing" === this.readyState) {
|
|
525
|
+
debug('socket close with reason: "%s"', reason);
|
|
526
|
+
// clear timers
|
|
527
|
+
this.clearTimeoutFn(this._pingTimeoutTimer);
|
|
528
|
+
// stop event from firing again for transport
|
|
529
|
+
this.transport.removeAllListeners("close");
|
|
530
|
+
// ensure transport won't stay open
|
|
531
|
+
this.transport.close();
|
|
532
|
+
// ignore further transport communication
|
|
533
|
+
this.transport.removeAllListeners();
|
|
534
|
+
if (withEventListeners) {
|
|
535
|
+
if (this._beforeunloadEventListener) {
|
|
536
|
+
removeEventListener("beforeunload", this._beforeunloadEventListener, false);
|
|
537
|
+
}
|
|
538
|
+
if (this._offlineEventListener) {
|
|
539
|
+
const i = OFFLINE_EVENT_LISTENERS.indexOf(this._offlineEventListener);
|
|
540
|
+
if (i !== -1) {
|
|
541
|
+
debug("removing listener for the 'offline' event");
|
|
542
|
+
OFFLINE_EVENT_LISTENERS.splice(i, 1);
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
// set ready state
|
|
547
|
+
this.readyState = "closed";
|
|
548
|
+
// clear session id
|
|
549
|
+
this.id = null;
|
|
550
|
+
// emit close event
|
|
551
|
+
this.emitReserved("close", reason, description);
|
|
552
|
+
// clean buffers after, so users can still
|
|
553
|
+
// grab the buffers on `close` event
|
|
554
|
+
this.writeBuffer = [];
|
|
555
|
+
this._prevBufferLen = 0;
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
SocketWithoutUpgrade.protocol = protocol;
|
|
560
|
+
/**
|
|
561
|
+
* This class provides a WebSocket-like interface to connect to an Engine.IO server. The connection will be established
|
|
562
|
+
* with one of the available low-level transports, like HTTP long-polling, WebSocket or WebTransport.
|
|
563
|
+
*
|
|
564
|
+
* This class comes with an upgrade mechanism, which means that once the connection is established with the first
|
|
565
|
+
* low-level transport, it will try to upgrade to a better transport.
|
|
566
|
+
*
|
|
567
|
+
* In order to allow tree-shaking, there are no transports included, that's why the `transports` option is mandatory.
|
|
568
|
+
*
|
|
569
|
+
* @example
|
|
570
|
+
* import { SocketWithUpgrade, WebSocket } from "engine.io-client";
|
|
571
|
+
*
|
|
572
|
+
* const socket = new SocketWithUpgrade({
|
|
573
|
+
* transports: [WebSocket]
|
|
574
|
+
* });
|
|
575
|
+
*
|
|
576
|
+
* socket.on("open", () => {
|
|
577
|
+
* socket.send("hello");
|
|
578
|
+
* });
|
|
579
|
+
*
|
|
580
|
+
* @see SocketWithoutUpgrade
|
|
581
|
+
* @see Socket
|
|
582
|
+
*/
|
|
583
|
+
export class SocketWithUpgrade extends SocketWithoutUpgrade {
|
|
584
|
+
constructor() {
|
|
585
|
+
super(...arguments);
|
|
586
|
+
this._upgrades = [];
|
|
587
|
+
}
|
|
588
|
+
onOpen() {
|
|
589
|
+
super.onOpen();
|
|
590
|
+
if ("open" === this.readyState && this.opts.upgrade) {
|
|
591
|
+
debug("starting upgrade probes");
|
|
592
|
+
for (let i = 0; i < this._upgrades.length; i++) {
|
|
593
|
+
this._probe(this._upgrades[i]);
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
/**
|
|
598
|
+
* Probes a transport.
|
|
599
|
+
*
|
|
600
|
+
* @param {String} name - transport name
|
|
601
|
+
* @private
|
|
602
|
+
*/
|
|
603
|
+
_probe(name) {
|
|
604
|
+
debug('probing transport "%s"', name);
|
|
605
|
+
let transport = this.createTransport(name);
|
|
606
|
+
let failed = false;
|
|
607
|
+
SocketWithoutUpgrade.priorWebsocketSuccess = false;
|
|
608
|
+
const onTransportOpen = () => {
|
|
609
|
+
if (failed)
|
|
610
|
+
return;
|
|
611
|
+
debug('probe transport "%s" opened', name);
|
|
612
|
+
transport.send([{ type: "ping", data: "probe" }]);
|
|
613
|
+
transport.once("packet", (msg) => {
|
|
614
|
+
if (failed)
|
|
615
|
+
return;
|
|
616
|
+
if ("pong" === msg.type && "probe" === msg.data) {
|
|
617
|
+
debug('probe transport "%s" pong', name);
|
|
618
|
+
this.upgrading = true;
|
|
619
|
+
this.emitReserved("upgrading", transport);
|
|
620
|
+
if (!transport)
|
|
621
|
+
return;
|
|
622
|
+
SocketWithoutUpgrade.priorWebsocketSuccess =
|
|
623
|
+
"websocket" === transport.name;
|
|
624
|
+
debug('pausing current transport "%s"', this.transport.name);
|
|
625
|
+
this.transport.pause(() => {
|
|
626
|
+
if (failed)
|
|
627
|
+
return;
|
|
628
|
+
if ("closed" === this.readyState)
|
|
629
|
+
return;
|
|
630
|
+
debug("changing transport and sending upgrade packet");
|
|
631
|
+
cleanup();
|
|
632
|
+
this.setTransport(transport);
|
|
633
|
+
transport.send([{ type: "upgrade" }]);
|
|
634
|
+
this.emitReserved("upgrade", transport);
|
|
635
|
+
transport = null;
|
|
636
|
+
this.upgrading = false;
|
|
637
|
+
this.flush();
|
|
638
|
+
});
|
|
639
|
+
}
|
|
640
|
+
else {
|
|
641
|
+
debug('probe transport "%s" failed', name);
|
|
642
|
+
const err = new Error("probe error");
|
|
643
|
+
// @ts-ignore
|
|
644
|
+
err.transport = transport.name;
|
|
645
|
+
this.emitReserved("upgradeError", err);
|
|
646
|
+
}
|
|
647
|
+
});
|
|
648
|
+
};
|
|
649
|
+
function freezeTransport() {
|
|
650
|
+
if (failed)
|
|
651
|
+
return;
|
|
652
|
+
// Any callback called by transport should be ignored since now
|
|
653
|
+
failed = true;
|
|
654
|
+
cleanup();
|
|
655
|
+
transport.close();
|
|
656
|
+
transport = null;
|
|
657
|
+
}
|
|
658
|
+
// Handle any error that happens while probing
|
|
659
|
+
const onerror = (err) => {
|
|
660
|
+
const error = new Error("probe error: " + err);
|
|
661
|
+
// @ts-ignore
|
|
662
|
+
error.transport = transport.name;
|
|
663
|
+
freezeTransport();
|
|
664
|
+
debug('probe transport "%s" failed because of error: %s', name, err);
|
|
665
|
+
this.emitReserved("upgradeError", error);
|
|
666
|
+
};
|
|
667
|
+
function onTransportClose() {
|
|
668
|
+
onerror("transport closed");
|
|
669
|
+
}
|
|
670
|
+
// When the socket is closed while we're probing
|
|
671
|
+
function onclose() {
|
|
672
|
+
onerror("socket closed");
|
|
673
|
+
}
|
|
674
|
+
// When the socket is upgraded while we're probing
|
|
675
|
+
function onupgrade(to) {
|
|
676
|
+
if (transport && to.name !== transport.name) {
|
|
677
|
+
debug('"%s" works - aborting "%s"', to.name, transport.name);
|
|
678
|
+
freezeTransport();
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
// Remove all listeners on the transport and on self
|
|
682
|
+
const cleanup = () => {
|
|
683
|
+
transport.removeListener("open", onTransportOpen);
|
|
684
|
+
transport.removeListener("error", onerror);
|
|
685
|
+
transport.removeListener("close", onTransportClose);
|
|
686
|
+
this.off("close", onclose);
|
|
687
|
+
this.off("upgrading", onupgrade);
|
|
688
|
+
};
|
|
689
|
+
transport.once("open", onTransportOpen);
|
|
690
|
+
transport.once("error", onerror);
|
|
691
|
+
transport.once("close", onTransportClose);
|
|
692
|
+
this.once("close", onclose);
|
|
693
|
+
this.once("upgrading", onupgrade);
|
|
694
|
+
if (this._upgrades.indexOf("webtransport") !== -1 &&
|
|
695
|
+
name !== "webtransport") {
|
|
696
|
+
// favor WebTransport
|
|
697
|
+
this.setTimeoutFn(() => {
|
|
698
|
+
if (!failed) {
|
|
699
|
+
transport.open();
|
|
700
|
+
}
|
|
701
|
+
}, 200);
|
|
702
|
+
}
|
|
703
|
+
else {
|
|
704
|
+
transport.open();
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
onHandshake(data) {
|
|
708
|
+
this._upgrades = this._filterUpgrades(data.upgrades);
|
|
709
|
+
super.onHandshake(data);
|
|
710
|
+
}
|
|
711
|
+
/**
|
|
712
|
+
* Filters upgrades, returning only those matching client transports.
|
|
713
|
+
*
|
|
714
|
+
* @param {Array} upgrades - server upgrades
|
|
715
|
+
* @private
|
|
716
|
+
*/
|
|
717
|
+
_filterUpgrades(upgrades) {
|
|
718
|
+
const filteredUpgrades = [];
|
|
719
|
+
for (let i = 0; i < upgrades.length; i++) {
|
|
720
|
+
if (~this.transports.indexOf(upgrades[i]))
|
|
721
|
+
filteredUpgrades.push(upgrades[i]);
|
|
722
|
+
}
|
|
723
|
+
return filteredUpgrades;
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
/**
|
|
727
|
+
* This class provides a WebSocket-like interface to connect to an Engine.IO server. The connection will be established
|
|
728
|
+
* with one of the available low-level transports, like HTTP long-polling, WebSocket or WebTransport.
|
|
729
|
+
*
|
|
730
|
+
* This class comes with an upgrade mechanism, which means that once the connection is established with the first
|
|
731
|
+
* low-level transport, it will try to upgrade to a better transport.
|
|
732
|
+
*
|
|
733
|
+
* @example
|
|
734
|
+
* import { Socket } from "engine.io-client";
|
|
735
|
+
*
|
|
736
|
+
* const socket = new Socket();
|
|
737
|
+
*
|
|
738
|
+
* socket.on("open", () => {
|
|
739
|
+
* socket.send("hello");
|
|
740
|
+
* });
|
|
741
|
+
*
|
|
742
|
+
* @see SocketWithoutUpgrade
|
|
743
|
+
* @see SocketWithUpgrade
|
|
744
|
+
*/
|
|
745
|
+
export class Socket extends SocketWithUpgrade {
|
|
746
|
+
constructor(uri, opts = {}) {
|
|
747
|
+
const o = typeof uri === "object" ? uri : opts;
|
|
748
|
+
if (!o.transports ||
|
|
749
|
+
(o.transports && typeof o.transports[0] === "string")) {
|
|
750
|
+
o.transports = (o.transports || ["polling", "websocket", "webtransport"])
|
|
751
|
+
.map((transportName) => DEFAULT_TRANSPORTS[transportName])
|
|
752
|
+
.filter((t) => !!t);
|
|
753
|
+
}
|
|
754
|
+
super(uri, o);
|
|
755
|
+
}
|
|
756
|
+
}
|