@cendarsoss/pusher-js 8.4.11
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/.editorconfig +14 -0
- package/.github/ISSUE_TEMPLATE.md +11 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +14 -0
- package/.github/dependabot.yml +14 -0
- package/.github/stale.yml +26 -0
- package/.github/workflows/release.yml +112 -0
- package/.github/workflows/release_pr.yml +43 -0
- package/.github/workflows/run-tests.yml +62 -0
- package/.gitmodules +3 -0
- package/.prettierrc +2 -0
- package/CHANGELOG.md +928 -0
- package/DELTA_COMPRESSION.md +365 -0
- package/DELTA_USAGE.md +179 -0
- package/IMPLEMENTATION_SUMMARY.md +261 -0
- package/IMPORT_GUIDE.md +638 -0
- package/LIBRARY_STRUCTURE_ANALYSIS.md +940 -0
- package/LICENCE +19 -0
- package/Makefile +14 -0
- package/README.md +709 -0
- package/TAG_FILTERING_CLIENT.md +471 -0
- package/bower.json +19 -0
- package/bun.lock +2695 -0
- package/dist/node/filter.js +252 -0
- package/dist/node/filter.js.map +1 -0
- package/dist/node/pusher.js +4434 -0
- package/dist/node/pusher.js.map +1 -0
- package/dist/web/filter.mjs +252 -0
- package/dist/web/filter.mjs.map +1 -0
- package/dist/web/pusher.mjs +5889 -0
- package/dist/web/pusher.mjs.map +1 -0
- package/examples/delta-compression-example.html +372 -0
- package/examples/delta-seamless-example.html +185 -0
- package/index.d.ts +36 -0
- package/integration_tests_server/index.js +176 -0
- package/integration_tests_server/package-lock.json +1177 -0
- package/integration_tests_server/package.json +15 -0
- package/interactive/.env +16 -0
- package/interactive/CONFLATION_TEST.md +73 -0
- package/interactive/DELTA_COMPRESSION_TESTING.md +262 -0
- package/interactive/bun.lock +208 -0
- package/interactive/package-lock.json +1075 -0
- package/interactive/package.json +32 -0
- package/interactive/public/app.js +1363 -0
- package/interactive/public/bundle-entry.js +14 -0
- package/interactive/public/conflation-test.html +508 -0
- package/interactive/public/conflation-test.js +785 -0
- package/interactive/public/delta-compression.js +1090 -0
- package/interactive/public/dist/bundle.js +5857 -0
- package/interactive/public/index.html +392 -0
- package/interactive/public/main.js +20 -0
- package/interactive/public/style.css +823 -0
- package/interactive/server.js +246 -0
- package/interactive/test-bundle.html +89 -0
- package/interactive/test-delta.js +146 -0
- package/node.js +1 -0
- package/package.json +94 -0
- package/pusher-with-encryption/index.js +1 -0
- package/react-native/index.d.ts +29 -0
- package/react-native/index.js +1 -0
- package/spec/config/jasmine/helpers/reporter.js +14 -0
- package/spec/config/jasmine/integration.json +13 -0
- package/spec/config/jasmine/unit.json +13 -0
- package/spec/config/jasmine/webpack.integration.js +33 -0
- package/spec/config/jasmine/webpack.unit.js +30 -0
- package/spec/config/karma/available_browsers.json +4957 -0
- package/spec/config/karma/config.ci.js +25 -0
- package/spec/config/karma/config.common.js +50 -0
- package/spec/config/karma/config.integration.js +26 -0
- package/spec/config/karma/config.unit.js +10 -0
- package/spec/config/karma/config.worker.js +34 -0
- package/spec/config/karma/integration.js +24 -0
- package/spec/config/karma/unit.js +20 -0
- package/spec/javascripts/helpers/mocks.js +274 -0
- package/spec/javascripts/helpers/node/integration.js +33 -0
- package/spec/javascripts/helpers/node/mock-dom-dependencies.ts +1 -0
- package/spec/javascripts/helpers/pusher_integration.js +1 -0
- package/spec/javascripts/helpers/pusher_integration_class.ts +12 -0
- package/spec/javascripts/helpers/timers/promises.js +9 -0
- package/spec/javascripts/helpers/waitsFor.js +37 -0
- package/spec/javascripts/helpers/web/integration.js +44 -0
- package/spec/javascripts/helpers/worker/mock-dom-dependencies.js +1 -0
- package/spec/javascripts/integration/core/cluster_config_spec.js +153 -0
- package/spec/javascripts/integration/core/falling_back_spec.js +195 -0
- package/spec/javascripts/integration/core/pusher_spec/index.js +68 -0
- package/spec/javascripts/integration/core/pusher_spec/test_builder.js +715 -0
- package/spec/javascripts/integration/core/timeout_configuration_spec.js +200 -0
- package/spec/javascripts/integration/core/transport_lists_spec.js +103 -0
- package/spec/javascripts/integration/index.node.js +12 -0
- package/spec/javascripts/integration/index.web.js +63 -0
- package/spec/javascripts/integration/index.worker.js +13 -0
- package/spec/javascripts/integration/web/dom/jsonp_spec.js +97 -0
- package/spec/javascripts/integration/web/dom/script_request_spec.js +90 -0
- package/spec/javascripts/polyfills/index.js +105 -0
- package/spec/javascripts/unit/core/channels/channel_spec.js +355 -0
- package/spec/javascripts/unit/core/channels/channels_spec.js +94 -0
- package/spec/javascripts/unit/core/channels/encrypted_channel_spec.js +343 -0
- package/spec/javascripts/unit/core/channels/presence_channel_spec.js +553 -0
- package/spec/javascripts/unit/core/channels/private_channel_spec.js +182 -0
- package/spec/javascripts/unit/core/config_spec.js +507 -0
- package/spec/javascripts/unit/core/connection/connection_manager_spec.js +656 -0
- package/spec/javascripts/unit/core/connection/connection_spec.js +286 -0
- package/spec/javascripts/unit/core/connection/handshake_spec.js +160 -0
- package/spec/javascripts/unit/core/connection/protocol_spec.js +420 -0
- package/spec/javascripts/unit/core/defaults_spec.js +26 -0
- package/spec/javascripts/unit/core/events_dispatcher_spec.js +385 -0
- package/spec/javascripts/unit/core/http/http_polling_socket_spec.js +60 -0
- package/spec/javascripts/unit/core/http/http_request_spec.js +185 -0
- package/spec/javascripts/unit/core/http/http_socket_spec.js +370 -0
- package/spec/javascripts/unit/core/http/http_streaming_socket_spec.js +56 -0
- package/spec/javascripts/unit/core/http/http_xhr_request_spec.js +164 -0
- package/spec/javascripts/unit/core/logger_spec.js +133 -0
- package/spec/javascripts/unit/core/pusher_spec.js +613 -0
- package/spec/javascripts/unit/core/pusher_with_encryption_spec.js +18 -0
- package/spec/javascripts/unit/core/strategies/best_connected_ever_strategy_spec.js +104 -0
- package/spec/javascripts/unit/core/strategies/delayed_strategy_spec.js +95 -0
- package/spec/javascripts/unit/core/strategies/first_connected_strategy_spec.js +68 -0
- package/spec/javascripts/unit/core/strategies/if_strategy_spec.js +165 -0
- package/spec/javascripts/unit/core/strategies/sequential_strategy_spec.js +213 -0
- package/spec/javascripts/unit/core/strategies/transport_strategy_spec.js +250 -0
- package/spec/javascripts/unit/core/strategies/websocket_prioritized_cached_strategy_spec.js +400 -0
- package/spec/javascripts/unit/core/timeline/timeline_spec.js +153 -0
- package/spec/javascripts/unit/core/transports/assistant_to_the_transport_manager_spec.js +223 -0
- package/spec/javascripts/unit/core/transports/hosts_and_ports_spec.js +85 -0
- package/spec/javascripts/unit/core/transports/transport_connection_spec.js +585 -0
- package/spec/javascripts/unit/core/transports/transport_manager_spec.js +64 -0
- package/spec/javascripts/unit/core/user_spec.js +303 -0
- package/spec/javascripts/unit/core/utils/periodic_timer_spec.js +74 -0
- package/spec/javascripts/unit/core/utils/timers_spec.js +157 -0
- package/spec/javascripts/unit/core/utils/url_store_spec.js +14 -0
- package/spec/javascripts/unit/core/watchlist_spec.js +48 -0
- package/spec/javascripts/unit/core_with_runtime/auth/channel_authorizer_spec.js +137 -0
- package/spec/javascripts/unit/core_with_runtime/auth/deprecated_channel_authorizer_spec.js +48 -0
- package/spec/javascripts/unit/core_with_runtime/auth/user_authorizer_spec.js +128 -0
- package/spec/javascripts/unit/core_with_runtime/readme.md +5 -0
- package/spec/javascripts/unit/index.node.js +11 -0
- package/spec/javascripts/unit/index.web.js +12 -0
- package/spec/javascripts/unit/index.worker.js +11 -0
- package/spec/javascripts/unit/isomorphic/transports/hosts_and_ports_spec.js +82 -0
- package/spec/javascripts/unit/isomorphic/transports/transports_spec.js +202 -0
- package/spec/javascripts/unit/node/timeline_sender_spec.js +83 -0
- package/spec/javascripts/unit/web/dom/dependency_loader_spec.js +249 -0
- package/spec/javascripts/unit/web/dom/jsonp_request_spec.js +130 -0
- package/spec/javascripts/unit/web/dom/script_receiver_factory_spec.js +68 -0
- package/spec/javascripts/unit/web/http/http_xdomain_request_spec.js +222 -0
- package/spec/javascripts/unit/web/pusher_authorizer_spec.js +64 -0
- package/spec/javascripts/unit/web/timeline/timeline_sender_spec.js +131 -0
- package/spec/javascripts/unit/web/transports/hosts_and_ports_spec.js +127 -0
- package/spec/javascripts/unit/web/transports/transports_spec.js +444 -0
- package/spec/javascripts/unit/worker/channel_authorizer_spec.js +156 -0
- package/spec/javascripts/unit/worker/timeline_sender_spec.js +76 -0
- package/src/core/auth/auth_transports.ts +18 -0
- package/src/core/auth/channel_authorizer.ts +64 -0
- package/src/core/auth/deprecated_channel_authorizer.ts +56 -0
- package/src/core/auth/options.ts +76 -0
- package/src/core/auth/user_authenticator.ts +62 -0
- package/src/core/base64.ts +49 -0
- package/src/core/channels/channel.ts +173 -0
- package/src/core/channels/channel_table.ts +7 -0
- package/src/core/channels/channels.ts +86 -0
- package/src/core/channels/encrypted_channel.ts +150 -0
- package/src/core/channels/filter.ts +342 -0
- package/src/core/channels/members.ts +80 -0
- package/src/core/channels/metadata.ts +5 -0
- package/src/core/channels/presence_channel.ts +113 -0
- package/src/core/channels/private_channel.ts +25 -0
- package/src/core/config.ts +189 -0
- package/src/core/connection/callbacks.ts +21 -0
- package/src/core/connection/connection.ts +160 -0
- package/src/core/connection/connection_manager.ts +371 -0
- package/src/core/connection/connection_manager_options.ts +14 -0
- package/src/core/connection/handshake/handshake_payload.ts +10 -0
- package/src/core/connection/handshake/index.ts +90 -0
- package/src/core/connection/protocol/action.ts +8 -0
- package/src/core/connection/protocol/message-types.ts +11 -0
- package/src/core/connection/protocol/protocol.ts +166 -0
- package/src/core/defaults.ts +66 -0
- package/src/core/delta/channel_state.ts +194 -0
- package/src/core/delta/decoders.ts +129 -0
- package/src/core/delta/index.ts +10 -0
- package/src/core/delta/manager.ts +504 -0
- package/src/core/delta/types.ts +60 -0
- package/src/core/errors.ts +69 -0
- package/src/core/events/callback.ts +6 -0
- package/src/core/events/callback_registry.ts +75 -0
- package/src/core/events/callback_table.ts +7 -0
- package/src/core/events/dispatcher.ts +84 -0
- package/src/core/http/ajax.ts +24 -0
- package/src/core/http/http_factory.ts +16 -0
- package/src/core/http/http_polling_socket.ts +24 -0
- package/src/core/http/http_request.ts +81 -0
- package/src/core/http/http_socket.ts +220 -0
- package/src/core/http/http_streaming_socket.ts +19 -0
- package/src/core/http/request_hooks.ts +9 -0
- package/src/core/http/socket_hooks.ts +11 -0
- package/src/core/http/state.ts +7 -0
- package/src/core/http/url_location.ts +6 -0
- package/src/core/logger.ts +66 -0
- package/src/core/options.ts +61 -0
- package/src/core/pusher-licence.js +7 -0
- package/src/core/pusher-with-encryption.js +1 -0
- package/src/core/pusher-with-encryption.ts +14 -0
- package/src/core/pusher.js +10 -0
- package/src/core/pusher.ts +412 -0
- package/src/core/reachability.ts +7 -0
- package/src/core/socket.ts +14 -0
- package/src/core/strategies/best_connected_ever_strategy.ts +81 -0
- package/src/core/strategies/delayed_strategy.ts +48 -0
- package/src/core/strategies/first_connected_strategy.ts +31 -0
- package/src/core/strategies/if_strategy.ts +34 -0
- package/src/core/strategies/sequential_strategy.ts +129 -0
- package/src/core/strategies/strategy.ts +8 -0
- package/src/core/strategies/strategy_builder.ts +67 -0
- package/src/core/strategies/strategy_options.ts +18 -0
- package/src/core/strategies/strategy_runner.ts +6 -0
- package/src/core/strategies/transport_strategy.ts +144 -0
- package/src/core/strategies/websocket_prioritized_cached_strategy.ts +157 -0
- package/src/core/timeline/level.ts +7 -0
- package/src/core/timeline/timeline.ts +90 -0
- package/src/core/timeline/timeline_sender.ts +33 -0
- package/src/core/timeline/timeline_transport.ts +11 -0
- package/src/core/transports/assistant_to_the_transport_manager.ts +104 -0
- package/src/core/transports/ping_delay_options.ts +7 -0
- package/src/core/transports/transport.ts +54 -0
- package/src/core/transports/transport_connection.ts +241 -0
- package/src/core/transports/transport_connection_options.ts +8 -0
- package/src/core/transports/transport_hooks.ts +16 -0
- package/src/core/transports/transport_manager.ts +52 -0
- package/src/core/transports/transports_table.ts +12 -0
- package/src/core/transports/url_scheme.ts +13 -0
- package/src/core/transports/url_schemes.ts +47 -0
- package/src/core/user.ts +186 -0
- package/src/core/util.ts +34 -0
- package/src/core/utils/collections.ts +353 -0
- package/src/core/utils/factory.ts +79 -0
- package/src/core/utils/flat_promise.ts +10 -0
- package/src/core/utils/timers/abstract_timer.ts +39 -0
- package/src/core/utils/timers/index.ts +39 -0
- package/src/core/utils/timers/scheduling.ts +11 -0
- package/src/core/utils/timers/timed_callback.ts +5 -0
- package/src/core/utils/url_store.ts +48 -0
- package/src/core/watchlist.ts +31 -0
- package/src/d.ts/constants/index.d.ts +5 -0
- package/src/d.ts/faye-websocket/faye-websocket.d.ts +21 -0
- package/src/d.ts/global/global.d.ts +1 -0
- package/src/d.ts/module/module.d.ts +12 -0
- package/src/d.ts/tweetnacl-util/index.d.ts +6 -0
- package/src/d.ts/window/events.d.ts +4 -0
- package/src/d.ts/window/sockjs.d.ts +3 -0
- package/src/d.ts/window/websocket.d.ts +4 -0
- package/src/d.ts/window/xmlhttprequest.d.ts +3 -0
- package/src/filter.ts +5 -0
- package/src/index.ts +8 -0
- package/src/runtimes/interface.ts +60 -0
- package/src/runtimes/isomorphic/auth/xhr_auth.ts +90 -0
- package/src/runtimes/isomorphic/default_strategy.ts +155 -0
- package/src/runtimes/isomorphic/http/http.ts +32 -0
- package/src/runtimes/isomorphic/http/http_xhr_request.ts +35 -0
- package/src/runtimes/isomorphic/runtime.ts +62 -0
- package/src/runtimes/isomorphic/timeline/xhr_timeline.ts +50 -0
- package/src/runtimes/isomorphic/transports/transport_connection_initializer.ts +19 -0
- package/src/runtimes/isomorphic/transports/transports.ts +83 -0
- package/src/runtimes/node/net_info.ts +10 -0
- package/src/runtimes/node/runtime.ts +68 -0
- package/src/runtimes/react-native/net_info.ts +42 -0
- package/src/runtimes/react-native/runtime.ts +65 -0
- package/src/runtimes/web/auth/jsonp_auth.ts +51 -0
- package/src/runtimes/web/browser.ts +24 -0
- package/src/runtimes/web/default_strategy.ts +201 -0
- package/src/runtimes/web/dom/dependencies.ts +16 -0
- package/src/runtimes/web/dom/dependency_loader.ts +93 -0
- package/src/runtimes/web/dom/json2.js +486 -0
- package/src/runtimes/web/dom/jsonp_request.ts +52 -0
- package/src/runtimes/web/dom/script_receiver.ts +8 -0
- package/src/runtimes/web/dom/script_receiver_factory.ts +57 -0
- package/src/runtimes/web/dom/script_request.ts +85 -0
- package/src/runtimes/web/http/http.ts +8 -0
- package/src/runtimes/web/http/http_xdomain_request.ts +37 -0
- package/src/runtimes/web/net_info.ts +50 -0
- package/src/runtimes/web/runtime.ts +174 -0
- package/src/runtimes/web/timeline/jsonp_timeline.ts +34 -0
- package/src/runtimes/web/transports/transport_connection_initializer.ts +39 -0
- package/src/runtimes/web/transports/transports.ts +67 -0
- package/src/runtimes/worker/auth/fetch_auth.ts +69 -0
- package/src/runtimes/worker/net_info.ts +10 -0
- package/src/runtimes/worker/runtime.ts +75 -0
- package/src/runtimes/worker/timeline/fetch_timeline.ts +39 -0
- package/tsconfig.json +18 -0
- package/types/spec/javascripts/helpers/node/mock-dom-dependencies.d.ts +1 -0
- package/types/spec/javascripts/helpers/pusher_integration_class.d.ts +4 -0
- package/types/src/core/auth/auth_transports.d.ts +9 -0
- package/types/src/core/auth/channel_authorizer.d.ts +3 -0
- package/types/src/core/auth/deprecated_channel_authorizer.d.ts +18 -0
- package/types/src/core/auth/options.d.ts +48 -0
- package/types/src/core/auth/user_authenticator.d.ts +3 -0
- package/types/src/core/base64.d.ts +1 -0
- package/types/src/core/channels/channel.d.ts +25 -0
- package/types/src/core/channels/channel_table.d.ts +5 -0
- package/types/src/core/channels/channels.d.ts +12 -0
- package/types/src/core/channels/encrypted_channel.d.ts +15 -0
- package/types/src/core/channels/filter.d.ts +33 -0
- package/types/src/core/channels/members.d.ts +14 -0
- package/types/src/core/channels/metadata.d.ts +4 -0
- package/types/src/core/channels/presence_channel.d.ts +13 -0
- package/types/src/core/channels/private_channel.d.ts +5 -0
- package/types/src/core/config.d.ts +31 -0
- package/types/src/core/connection/callbacks.d.ts +18 -0
- package/types/src/core/connection/connection.d.ts +16 -0
- package/types/src/core/connection/connection_manager.d.ts +50 -0
- package/types/src/core/connection/connection_manager_options.d.ts +11 -0
- package/types/src/core/connection/handshake/handshake_payload.d.ts +8 -0
- package/types/src/core/connection/handshake/index.d.ts +12 -0
- package/types/src/core/connection/protocol/action.d.ts +7 -0
- package/types/src/core/connection/protocol/message-types.d.ts +10 -0
- package/types/src/core/connection/protocol/protocol.d.ts +10 -0
- package/types/src/core/defaults.d.ts +26 -0
- package/types/src/core/delta/channel_state.d.ts +23 -0
- package/types/src/core/delta/decoders.d.ts +12 -0
- package/types/src/core/delta/index.d.ts +4 -0
- package/types/src/core/delta/manager.d.ts +27 -0
- package/types/src/core/delta/types.d.ts +50 -0
- package/types/src/core/errors.d.ts +28 -0
- package/types/src/core/events/callback.d.ts +5 -0
- package/types/src/core/events/callback_registry.d.ts +11 -0
- package/types/src/core/events/callback_table.d.ts +5 -0
- package/types/src/core/events/dispatcher.d.ts +14 -0
- package/types/src/core/http/ajax.d.ts +16 -0
- package/types/src/core/http/http_factory.d.ts +13 -0
- package/types/src/core/http/http_polling_socket.d.ts +3 -0
- package/types/src/core/http/http_request.d.ts +17 -0
- package/types/src/core/http/http_socket.d.ts +32 -0
- package/types/src/core/http/http_streaming_socket.d.ts +3 -0
- package/types/src/core/http/request_hooks.d.ts +6 -0
- package/types/src/core/http/socket_hooks.d.ts +8 -0
- package/types/src/core/http/state.d.ts +6 -0
- package/types/src/core/http/url_location.d.ts +5 -0
- package/types/src/core/logger.d.ts +11 -0
- package/types/src/core/options.d.ts +36 -0
- package/types/src/core/pusher-with-encryption.d.ts +5 -0
- package/types/src/core/pusher.d.ts +56 -0
- package/types/src/core/reachability.d.ts +5 -0
- package/types/src/core/socket.d.ts +12 -0
- package/types/src/core/strategies/best_connected_ever_strategy.d.ts +10 -0
- package/types/src/core/strategies/delayed_strategy.d.ts +15 -0
- package/types/src/core/strategies/first_connected_strategy.d.ts +8 -0
- package/types/src/core/strategies/if_strategy.d.ts +10 -0
- package/types/src/core/strategies/sequential_strategy.d.ts +16 -0
- package/types/src/core/strategies/strategy.d.ts +6 -0
- package/types/src/core/strategies/strategy_builder.d.ts +5 -0
- package/types/src/core/strategies/strategy_options.d.ts +16 -0
- package/types/src/core/strategies/strategy_runner.d.ts +5 -0
- package/types/src/core/strategies/transport_strategy.d.ts +15 -0
- package/types/src/core/strategies/websocket_prioritized_cached_strategy.d.ts +20 -0
- package/types/src/core/timeline/level.d.ts +6 -0
- package/types/src/core/timeline/timeline.d.ts +25 -0
- package/types/src/core/timeline/timeline_sender.d.ts +13 -0
- package/types/src/core/timeline/timeline_transport.d.ts +6 -0
- package/types/src/core/transports/assistant_to_the_transport_manager.d.ts +14 -0
- package/types/src/core/transports/ping_delay_options.d.ts +6 -0
- package/types/src/core/transports/transport.d.ts +8 -0
- package/types/src/core/transports/transport_connection.d.ts +35 -0
- package/types/src/core/transports/transport_connection_options.d.ts +6 -0
- package/types/src/core/transports/transport_hooks.d.ts +13 -0
- package/types/src/core/transports/transport_manager.d.ts +14 -0
- package/types/src/core/transports/transports_table.d.ts +10 -0
- package/types/src/core/transports/url_scheme.d.ts +11 -0
- package/types/src/core/transports/url_schemes.d.ts +4 -0
- package/types/src/core/user.d.ts +21 -0
- package/types/src/core/util.d.ts +8 -0
- package/types/src/core/utils/collections.d.ts +18 -0
- package/types/src/core/utils/factory.d.ts +29 -0
- package/types/src/core/utils/flat_promise.d.ts +6 -0
- package/types/src/core/utils/timers/abstract_timer.d.ts +10 -0
- package/types/src/core/utils/timers/index.d.ts +9 -0
- package/types/src/core/utils/timers/scheduling.d.ts +8 -0
- package/types/src/core/utils/timers/timed_callback.d.ts +4 -0
- package/types/src/core/utils/url_store.d.ts +4 -0
- package/types/src/core/watchlist.d.ts +8 -0
- package/types/src/runtimes/interface.d.ts +43 -0
- package/types/src/runtimes/isomorphic/auth/xhr_auth.d.ts +3 -0
- package/types/src/runtimes/isomorphic/default_strategy.d.ts +5 -0
- package/types/src/runtimes/isomorphic/http/http.d.ts +3 -0
- package/types/src/runtimes/isomorphic/http/http_xhr_request.d.ts +3 -0
- package/types/src/runtimes/isomorphic/runtime.d.ts +2 -0
- package/types/src/runtimes/isomorphic/timeline/xhr_timeline.d.ts +6 -0
- package/types/src/runtimes/isomorphic/transports/transport_connection_initializer.d.ts +1 -0
- package/types/src/runtimes/isomorphic/transports/transports.d.ts +5 -0
- package/types/src/runtimes/node/net_info.d.ts +6 -0
- package/types/src/runtimes/node/runtime.d.ts +3 -0
- package/types/src/runtimes/react-native/net_info.d.ts +8 -0
- package/types/src/runtimes/react-native/runtime.d.ts +3 -0
- package/types/src/runtimes/web/auth/jsonp_auth.d.ts +3 -0
- package/types/src/runtimes/web/browser.d.ts +19 -0
- package/types/src/runtimes/web/default_strategy.d.ts +5 -0
- package/types/src/runtimes/web/dom/dependencies.d.ts +4 -0
- package/types/src/runtimes/web/dom/dependency_loader.d.ts +10 -0
- package/types/src/runtimes/web/dom/jsonp_request.d.ts +10 -0
- package/types/src/runtimes/web/dom/script_receiver.d.ts +7 -0
- package/types/src/runtimes/web/dom/script_receiver_factory.d.ts +10 -0
- package/types/src/runtimes/web/dom/script_request.d.ts +9 -0
- package/types/src/runtimes/web/http/http.d.ts +2 -0
- package/types/src/runtimes/web/http/http_xdomain_request.d.ts +3 -0
- package/types/src/runtimes/web/net_info.d.ts +7 -0
- package/types/src/runtimes/web/runtime.d.ts +3 -0
- package/types/src/runtimes/web/timeline/jsonp_timeline.d.ts +6 -0
- package/types/src/runtimes/web/transports/transport_connection_initializer.d.ts +1 -0
- package/types/src/runtimes/web/transports/transports.d.ts +2 -0
- package/types/src/runtimes/worker/auth/fetch_auth.d.ts +3 -0
- package/types/src/runtimes/worker/net_info.d.ts +6 -0
- package/types/src/runtimes/worker/runtime.d.ts +3 -0
- package/types/src/runtimes/worker/timeline/fetch_timeline.d.ts +6 -0
- package/vite.config.js +52 -0
- package/vite.config.node.js +72 -0
- package/webpack/config.node.js +26 -0
- package/webpack/config.react-native.js +35 -0
- package/webpack/config.shared.js +50 -0
- package/webpack/config.web.js +36 -0
- package/webpack/config.worker.js +42 -0
- package/webpack/dev.server.js +17 -0
- package/webpack/hosting_config.js +6 -0
- package/with-encryption/index.d.ts +29 -0
- package/with-encryption/index.js +4 -0
- package/worker/index.d.ts +29 -0
- package/worker/index.js +1 -0
- package/worker/with-encryption/index.d.ts +29 -0
- package/worker/with-encryption/index.js +1 -0
|
@@ -0,0 +1,585 @@
|
|
|
1
|
+
const TestEnv = require('testenv');
|
|
2
|
+
const Mocks = require('mocks');
|
|
3
|
+
const TransportConnection = require('core/transports/transport_connection').default;
|
|
4
|
+
const Collections = require('core/utils/collections');
|
|
5
|
+
const OneOffTimer = require('core/utils/timers').OneOffTimer;
|
|
6
|
+
const Dependencies = require('dom/dependencies').Dependencies;
|
|
7
|
+
const waitsFor = require('../../../helpers/waitsFor');
|
|
8
|
+
|
|
9
|
+
describe("TransportConnection", function() {
|
|
10
|
+
function getTransport(hooks, key, options) {
|
|
11
|
+
options = Collections.extend({
|
|
12
|
+
useTLS: false,
|
|
13
|
+
hostNonTLS: "example.com:12345",
|
|
14
|
+
hostTLS: "example.com:54321"
|
|
15
|
+
}, options);
|
|
16
|
+
|
|
17
|
+
return new TransportConnection(hooks, "test", 7, key, options);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
var urls;
|
|
21
|
+
var hooks;
|
|
22
|
+
var socket;
|
|
23
|
+
var timeline;
|
|
24
|
+
var transport;
|
|
25
|
+
var _DependenciesBackup;
|
|
26
|
+
|
|
27
|
+
beforeEach(function() {
|
|
28
|
+
if (TestEnv === "web") {
|
|
29
|
+
_DependenciesBackup = {
|
|
30
|
+
load: Dependencies.load,
|
|
31
|
+
getRoot: Dependencies.getRoot,
|
|
32
|
+
getPath: Dependencies.getPath
|
|
33
|
+
}
|
|
34
|
+
Dependencies.load = jasmine.createSpy("load")
|
|
35
|
+
Dependencies.getRoot = jasmine.createSpy("getRoot")
|
|
36
|
+
Dependencies.getPath = jasmine.createSpy("getPath")
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
timeline = Mocks.getTimeline();
|
|
40
|
+
timeline.generateUniqueID.and.returnValue(667);
|
|
41
|
+
|
|
42
|
+
urls = {
|
|
43
|
+
getInitial: function(key, params) {
|
|
44
|
+
return (params.useTLS ? "wss" : "ws") + "://test/" + key;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
socket = Mocks.getWebSocket();
|
|
48
|
+
hooks = {
|
|
49
|
+
urls: urls,
|
|
50
|
+
supportsPing: false,
|
|
51
|
+
isInitialized: jasmine.createSpy().and.returnValue(true),
|
|
52
|
+
getSocket: jasmine.createSpy().and.returnValue(socket)
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
transport = getTransport(hooks, "foo", {
|
|
56
|
+
timeline: timeline
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
afterEach(function(){
|
|
61
|
+
if (TestEnv === "web") {
|
|
62
|
+
Dependencies.load = _DependenciesBackup.load
|
|
63
|
+
Dependencies.getRoot = _DependenciesBackup.getRoot
|
|
64
|
+
Dependencies.getPath = _DependenciesBackup.getPath
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
describe("#activityTimeout", function() {
|
|
69
|
+
it("should be set to the value passed via options", function() {
|
|
70
|
+
var transport = getTransport(hooks, "xxx", {
|
|
71
|
+
timeline: timeline,
|
|
72
|
+
activityTimeout: 654321
|
|
73
|
+
});
|
|
74
|
+
expect(transport.activityTimeout).toEqual(654321);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("should be set to undefined if not passed via options", function() {
|
|
78
|
+
var transport = getTransport(hooks, "xxx", {
|
|
79
|
+
timeline: timeline
|
|
80
|
+
});
|
|
81
|
+
expect(transport.activityTimeout).toBe(undefined);
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
describe("#initialize", function() {
|
|
86
|
+
it("should log transport name with info level", function() {
|
|
87
|
+
transport.initialize();
|
|
88
|
+
expect(timeline.info).toHaveBeenCalledWith({
|
|
89
|
+
cid: 667,
|
|
90
|
+
transport: "test"
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it("should log transport name with an 's' suffix when using TLS", function() {
|
|
95
|
+
var transport = getTransport(hooks, "xxx", {
|
|
96
|
+
timeline: timeline,
|
|
97
|
+
useTLS: true
|
|
98
|
+
});
|
|
99
|
+
transport.initialize();
|
|
100
|
+
|
|
101
|
+
expect(timeline.info).toHaveBeenCalledWith({
|
|
102
|
+
cid: 667,
|
|
103
|
+
transport: "tests"
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
describe("if the transport is initialized", function() {
|
|
108
|
+
var hooks;
|
|
109
|
+
var transport;
|
|
110
|
+
|
|
111
|
+
beforeEach(function() {
|
|
112
|
+
hooks = {
|
|
113
|
+
supportsPing: false,
|
|
114
|
+
isInitialized: jasmine.createSpy().and.returnValue(true)
|
|
115
|
+
};
|
|
116
|
+
transport = getTransport(hooks, "foo", {
|
|
117
|
+
timeline: timeline
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it("should transition to 'initialized' immediately", function() {
|
|
122
|
+
var onInitialized = jasmine.createSpy("onInitialized");
|
|
123
|
+
transport.bind("initialized", onInitialized);
|
|
124
|
+
|
|
125
|
+
transport.initialize();
|
|
126
|
+
expect(onInitialized).toHaveBeenCalled();
|
|
127
|
+
expect(transport.state).toEqual("initialized");
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
describe("if the transport is not initialized", function() {
|
|
133
|
+
var hooks, transport;
|
|
134
|
+
|
|
135
|
+
beforeEach(function() {
|
|
136
|
+
hooks = {
|
|
137
|
+
file: "test",
|
|
138
|
+
isInitialized: jasmine.createSpy().and.returnValue(false),
|
|
139
|
+
getSocket: jasmine.createSpy().and.returnValue(socket)
|
|
140
|
+
};
|
|
141
|
+
transport = getTransport(hooks, "foo", {
|
|
142
|
+
timeline: timeline
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
if (TestEnv === "web") {
|
|
147
|
+
it("should transition to 'initializing' immediately", function() {
|
|
148
|
+
var onInitializing = jasmine.createSpy("onInitializing");
|
|
149
|
+
transport.bind("initializing", onInitializing);
|
|
150
|
+
|
|
151
|
+
transport.initialize();
|
|
152
|
+
expect(onInitializing).toHaveBeenCalled();
|
|
153
|
+
expect(transport.state).toEqual("initializing");
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it("should load the resource file (useTLS=false)", function() {
|
|
157
|
+
transport.initialize();
|
|
158
|
+
expect(Dependencies.load.calls.count()).toEqual(1);
|
|
159
|
+
expect(Dependencies.load).toHaveBeenCalledWith(
|
|
160
|
+
"test", { useTLS: false }, jasmine.any(Function)
|
|
161
|
+
);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it("should load the resource file (useTLS=true)", function() {
|
|
165
|
+
var transport = getTransport(hooks, "foo", {
|
|
166
|
+
useTLS: true,
|
|
167
|
+
timeline: timeline
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
transport.initialize();
|
|
171
|
+
expect(Dependencies.load.calls.count()).toEqual(1);
|
|
172
|
+
expect(Dependencies.load).toHaveBeenCalledWith(
|
|
173
|
+
"test", { useTLS: true }, jasmine.any(Function)
|
|
174
|
+
);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
describe("after loading the resource successfully", function() {
|
|
178
|
+
var onInitialized;
|
|
179
|
+
var loadCallback;
|
|
180
|
+
|
|
181
|
+
beforeEach(function() {
|
|
182
|
+
onInitialized = jasmine.createSpy("onInitialized");
|
|
183
|
+
loadCallback = jasmine.createSpy("loadCallback");
|
|
184
|
+
transport.bind("initialized", onInitialized);
|
|
185
|
+
|
|
186
|
+
transport.initialize();
|
|
187
|
+
// after loading the resource, isInitialized will return true
|
|
188
|
+
hooks.isInitialized.and.returnValue(true);
|
|
189
|
+
// fire the callback for the resource file load
|
|
190
|
+
Dependencies.load.calls.first().args[2](null, loadCallback);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it("should transition to 'initialized'", function() {
|
|
194
|
+
expect(onInitialized).toHaveBeenCalled();
|
|
195
|
+
expect(transport.state).toEqual("initialized");
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it("should call the load callback with true", function() {
|
|
199
|
+
expect(loadCallback).toHaveBeenCalledWith(true);
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
describe("after failing to load the resource", function() {
|
|
204
|
+
var onClosed;
|
|
205
|
+
var loadCallback;
|
|
206
|
+
|
|
207
|
+
beforeEach(function() {
|
|
208
|
+
onClosed = jasmine.createSpy("onClosed");
|
|
209
|
+
loadCallback = jasmine.createSpy("loadCallback");
|
|
210
|
+
transport.bind("closed", onClosed);
|
|
211
|
+
|
|
212
|
+
transport.initialize();
|
|
213
|
+
// after loading the resource, isInitialized will return true
|
|
214
|
+
hooks.isInitialized.and.returnValue(false);
|
|
215
|
+
// fire the callback for the resource file load
|
|
216
|
+
Dependencies.load.calls.first().args[2](null, loadCallback);
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it("should transition to 'closed'", function() {
|
|
220
|
+
expect(onClosed).toHaveBeenCalled();
|
|
221
|
+
expect(transport.state).toEqual("closed");
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it("should call the load callback with false", function() {
|
|
225
|
+
expect(loadCallback).toHaveBeenCalledWith(false);
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
} else {
|
|
229
|
+
// Needed so that the describe block isn't empty
|
|
230
|
+
it("dummy test", function() {
|
|
231
|
+
expect(true).toBe(true);
|
|
232
|
+
})
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
describe("#connect", function() {
|
|
238
|
+
it("should not create a socket if not initialized", function() {
|
|
239
|
+
transport.connect();
|
|
240
|
+
expect(hooks.getSocket).not.toHaveBeenCalled();
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
it("should create a non TLS socket by default", function() {
|
|
244
|
+
transport.initialize();
|
|
245
|
+
transport.connect();
|
|
246
|
+
expect(hooks.getSocket).toHaveBeenCalledWith(
|
|
247
|
+
"ws://test/foo", transport.options
|
|
248
|
+
);
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
it("should create a TLS socket if specified", function() {
|
|
252
|
+
var transport = getTransport(hooks, "bar", {
|
|
253
|
+
timeline: timeline,
|
|
254
|
+
useTLS: true
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
transport.initialize();
|
|
258
|
+
transport.connect();
|
|
259
|
+
expect(hooks.getSocket).toHaveBeenCalledWith(
|
|
260
|
+
"wss://test/bar", transport.options
|
|
261
|
+
);
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
it("should not transition to 'connecting' if not initialized", function() {
|
|
265
|
+
var onConnecting = jasmine.createSpy("onConnecting");
|
|
266
|
+
transport.bind("connecting", onConnecting);
|
|
267
|
+
|
|
268
|
+
transport.connect();
|
|
269
|
+
expect(transport.state).toEqual("new");
|
|
270
|
+
expect(onConnecting).not.toHaveBeenCalled();
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
it("should transition to 'connecting'", function() {
|
|
274
|
+
var onConnecting = jasmine.createSpy("onConnecting");
|
|
275
|
+
transport.bind("connecting", onConnecting);
|
|
276
|
+
|
|
277
|
+
transport.initialize();
|
|
278
|
+
transport.connect();
|
|
279
|
+
expect(transport.state).toEqual("connecting");
|
|
280
|
+
expect(onConnecting.calls.count()).toEqual(1);
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
it("should transition to 'open' after connection is established", function() {
|
|
284
|
+
var onOpen = jasmine.createSpy("onOpen");
|
|
285
|
+
transport.bind("open", onOpen);
|
|
286
|
+
|
|
287
|
+
transport.initialize();
|
|
288
|
+
transport.connect();
|
|
289
|
+
socket.onopen();
|
|
290
|
+
|
|
291
|
+
expect(transport.state).toEqual("open");
|
|
292
|
+
expect(onOpen.calls.count()).toEqual(1);
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
it("should emit the error raised by getSocket", async function() {
|
|
296
|
+
hooks.getSocket.and.throwError("test exception");
|
|
297
|
+
|
|
298
|
+
var onError = jasmine.createSpy("onError");
|
|
299
|
+
transport.bind("error", onError);
|
|
300
|
+
|
|
301
|
+
transport.initialize();
|
|
302
|
+
transport.connect();
|
|
303
|
+
|
|
304
|
+
await waitsFor(function() {
|
|
305
|
+
return onError.calls.count();
|
|
306
|
+
}, "error to be emitted", 50);
|
|
307
|
+
|
|
308
|
+
expect(onError.calls.count()).toBeGreaterThan(0);
|
|
309
|
+
expect(onError.calls.count()).toEqual(1);
|
|
310
|
+
expect(onError).toHaveBeenCalledWith({
|
|
311
|
+
type: "WebSocketError",
|
|
312
|
+
error: new Error ("test exception")
|
|
313
|
+
});
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
it("should transition to 'closed' when getSocket raises an error", async function() {
|
|
317
|
+
hooks.getSocket.and.throwError("test exception");
|
|
318
|
+
|
|
319
|
+
var onClosed = jasmine.createSpy("onClosed");
|
|
320
|
+
transport.bind("closed", onClosed);
|
|
321
|
+
|
|
322
|
+
transport.initialize();
|
|
323
|
+
transport.connect();
|
|
324
|
+
|
|
325
|
+
await waitsFor(function () {
|
|
326
|
+
return onClosed.calls.count();
|
|
327
|
+
}, "transitioning to 'closed'", 50);
|
|
328
|
+
|
|
329
|
+
expect(onClosed.calls.count()).toBeGreaterThan(0);
|
|
330
|
+
expect(onClosed.calls.count()).toEqual(1);
|
|
331
|
+
expect(transport.state).toEqual("closed");
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
it("should be idempotent", function() {
|
|
335
|
+
transport.initialize();
|
|
336
|
+
|
|
337
|
+
transport.connect();
|
|
338
|
+
expect(hooks.getSocket.calls.count()).toEqual(1);
|
|
339
|
+
expect(transport.state).toEqual("connecting");
|
|
340
|
+
|
|
341
|
+
var onConnecting = jasmine.createSpy("onConnecting");
|
|
342
|
+
transport.bind("connecting", onConnecting);
|
|
343
|
+
|
|
344
|
+
transport.connect();
|
|
345
|
+
expect(transport.state).toEqual("connecting");
|
|
346
|
+
expect(hooks.getSocket.calls.count()).toEqual(1);
|
|
347
|
+
expect(onConnecting).not.toHaveBeenCalled();
|
|
348
|
+
});
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
describe("#send", function() {
|
|
352
|
+
beforeEach(function() {
|
|
353
|
+
transport.initialize();
|
|
354
|
+
transport.connect();
|
|
355
|
+
socket.onopen();
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
it("should defer sending data to the socket", async function() {
|
|
359
|
+
socket.send.calls.reset();
|
|
360
|
+
|
|
361
|
+
expect(socket.send).not.toHaveBeenCalled();
|
|
362
|
+
|
|
363
|
+
let sendCall = transport.send('foobar');
|
|
364
|
+
|
|
365
|
+
await waitsFor(function () {
|
|
366
|
+
return socket.send.calls.count();
|
|
367
|
+
}, "socket.send to be called", 50);
|
|
368
|
+
|
|
369
|
+
expect(sendCall).toBe(true);
|
|
370
|
+
expect(socket.send.calls.count()).toEqual(1);
|
|
371
|
+
expect(socket.send).toHaveBeenCalledWith("foobar");
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
it("should not crash when socket is closed before next tick (will log to console only)", async function() {
|
|
375
|
+
transport.send("foobar");
|
|
376
|
+
transport.close();
|
|
377
|
+
socket.onclose({ wasClean: true });
|
|
378
|
+
var timer = new OneOffTimer(100, function() {});
|
|
379
|
+
|
|
380
|
+
await waitsFor(function () {
|
|
381
|
+
return !timer.isRunning();
|
|
382
|
+
}, "timer to run", 500);
|
|
383
|
+
});
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
describe("#ping", function() {
|
|
387
|
+
beforeEach(function() {
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
it("should call ping on the socket, if it supports it", function() {
|
|
391
|
+
var hooks = {
|
|
392
|
+
urls: urls,
|
|
393
|
+
supportsPing: true,
|
|
394
|
+
isInitialized: jasmine.createSpy().and.returnValue(true),
|
|
395
|
+
getSocket: jasmine.createSpy().and.returnValue(socket)
|
|
396
|
+
};
|
|
397
|
+
var transport = getTransport(hooks, "foo", {
|
|
398
|
+
timeline: timeline
|
|
399
|
+
});
|
|
400
|
+
socket.ping = jasmine.createSpy("ping");
|
|
401
|
+
|
|
402
|
+
transport.initialize();
|
|
403
|
+
transport.connect();
|
|
404
|
+
socket.onopen();
|
|
405
|
+
|
|
406
|
+
expect(socket.ping).not.toHaveBeenCalled();
|
|
407
|
+
transport.ping();
|
|
408
|
+
expect(socket.ping).toHaveBeenCalled();
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
it("should not fail if socket does not support ping", function() {
|
|
412
|
+
var hooks = {
|
|
413
|
+
urls: urls,
|
|
414
|
+
supportsPing: false,
|
|
415
|
+
isInitialized: jasmine.createSpy().and.returnValue(true),
|
|
416
|
+
getSocket: jasmine.createSpy().and.returnValue(socket)
|
|
417
|
+
};
|
|
418
|
+
var transport = getTransport(hooks, "foo", {
|
|
419
|
+
timeline: timeline
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
transport.initialize();
|
|
423
|
+
transport.connect();
|
|
424
|
+
socket.onopen();
|
|
425
|
+
|
|
426
|
+
transport.ping();
|
|
427
|
+
});
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
describe("#close", function() {
|
|
431
|
+
it("should call close on the socket and emit a 'closed' event", function() {
|
|
432
|
+
var onClosed = jasmine.createSpy("onClosed");
|
|
433
|
+
transport.bind("closed", onClosed);
|
|
434
|
+
|
|
435
|
+
transport.initialize();
|
|
436
|
+
transport.connect();
|
|
437
|
+
socket.onopen();
|
|
438
|
+
|
|
439
|
+
transport.close();
|
|
440
|
+
expect(socket.close).toHaveBeenCalled();
|
|
441
|
+
expect(onClosed).not.toHaveBeenCalled();
|
|
442
|
+
|
|
443
|
+
socket.onclose({ wasClean: true });
|
|
444
|
+
expect(onClosed).toHaveBeenCalledWith({ wasClean: true, code: undefined, reason: undefined });
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
it("should not fail if not open", function() {
|
|
448
|
+
transport.close();
|
|
449
|
+
});
|
|
450
|
+
});
|
|
451
|
+
|
|
452
|
+
describe("after receiving a message", function() {
|
|
453
|
+
beforeEach(function() {
|
|
454
|
+
transport.initialize();
|
|
455
|
+
transport.connect();
|
|
456
|
+
socket.onopen();
|
|
457
|
+
});
|
|
458
|
+
|
|
459
|
+
it("should emit message event with received object", function() {
|
|
460
|
+
var onMessage = jasmine.createSpy("onMessage");
|
|
461
|
+
transport.bind("message", onMessage);
|
|
462
|
+
|
|
463
|
+
socket.onmessage("ugabuga");
|
|
464
|
+
|
|
465
|
+
expect(transport.state).toEqual("open");
|
|
466
|
+
expect(onMessage).toHaveBeenCalledWith("ugabuga");
|
|
467
|
+
});
|
|
468
|
+
});
|
|
469
|
+
|
|
470
|
+
describe("after receiving an activity event if the socket supports ping", function() {
|
|
471
|
+
var hooks;
|
|
472
|
+
var transport;
|
|
473
|
+
|
|
474
|
+
beforeEach(function() {
|
|
475
|
+
hooks = {
|
|
476
|
+
urls: urls,
|
|
477
|
+
supportsPing: true,
|
|
478
|
+
isInitialized: jasmine.createSpy().and.returnValue(true),
|
|
479
|
+
getSocket: jasmine.createSpy().and.returnValue(socket)
|
|
480
|
+
};
|
|
481
|
+
transport = getTransport(hooks, "foo", {
|
|
482
|
+
timeline: timeline
|
|
483
|
+
});
|
|
484
|
+
|
|
485
|
+
transport.initialize();
|
|
486
|
+
transport.connect();
|
|
487
|
+
socket.onopen();
|
|
488
|
+
});
|
|
489
|
+
|
|
490
|
+
it("should emit an 'activity' event", function() {
|
|
491
|
+
var onActivity = jasmine.createSpy("onActivity");
|
|
492
|
+
transport.bind("activity", onActivity);
|
|
493
|
+
|
|
494
|
+
socket.onactivity();
|
|
495
|
+
expect(onActivity).toHaveBeenCalled();
|
|
496
|
+
});
|
|
497
|
+
});
|
|
498
|
+
|
|
499
|
+
describe("after receiving an error", function() {
|
|
500
|
+
beforeEach(function() {
|
|
501
|
+
transport.initialize();
|
|
502
|
+
transport.connect();
|
|
503
|
+
});
|
|
504
|
+
|
|
505
|
+
it("should emit errors", function() {
|
|
506
|
+
var onError = jasmine.createSpy("onError");
|
|
507
|
+
transport.bind("error", onError);
|
|
508
|
+
|
|
509
|
+
socket.onerror({ test: "We're doomed" });
|
|
510
|
+
|
|
511
|
+
// should emit the whole error, not stringify it
|
|
512
|
+
expect(onError).toHaveBeenCalledWith({
|
|
513
|
+
type: "WebSocketError",
|
|
514
|
+
error: {
|
|
515
|
+
test: "We're doomed"
|
|
516
|
+
}
|
|
517
|
+
});
|
|
518
|
+
expect(onError.calls.count()).toEqual(1);
|
|
519
|
+
});
|
|
520
|
+
|
|
521
|
+
it("should emit a closed event with correct params", function() {
|
|
522
|
+
var onClosed = jasmine.createSpy("onClosed");
|
|
523
|
+
transport.bind("closed", onClosed);
|
|
524
|
+
|
|
525
|
+
socket.onclose({
|
|
526
|
+
code: 1234,
|
|
527
|
+
reason: "testing",
|
|
528
|
+
wasClean: true,
|
|
529
|
+
foo: "bar"
|
|
530
|
+
});
|
|
531
|
+
|
|
532
|
+
expect(onClosed).toHaveBeenCalledWith({
|
|
533
|
+
code: 1234,
|
|
534
|
+
reason: "testing",
|
|
535
|
+
wasClean: true
|
|
536
|
+
});
|
|
537
|
+
expect(onClosed.calls.count()).toEqual(1);
|
|
538
|
+
expect(transport.state).toEqual("closed");
|
|
539
|
+
});
|
|
540
|
+
|
|
541
|
+
it("should emit a closed events without params when no details were provided", function() {
|
|
542
|
+
var onClosed = jasmine.createSpy("onClosed");
|
|
543
|
+
transport.bind("closed", onClosed);
|
|
544
|
+
|
|
545
|
+
socket.onclose();
|
|
546
|
+
|
|
547
|
+
expect(onClosed).toHaveBeenCalled();
|
|
548
|
+
expect(onClosed.calls.count()).toEqual(1);
|
|
549
|
+
});
|
|
550
|
+
|
|
551
|
+
it("should log an error as a string to timeline", function() {
|
|
552
|
+
socket.onerror({ toString: function() { return "error message"; }});
|
|
553
|
+
expect(timeline.error).toHaveBeenCalledWith({
|
|
554
|
+
cid: 667,
|
|
555
|
+
error: "error message"
|
|
556
|
+
});
|
|
557
|
+
});
|
|
558
|
+
});
|
|
559
|
+
|
|
560
|
+
describe("on state change", function () {
|
|
561
|
+
it("should log the new state to timeline", function() {
|
|
562
|
+
transport.initialize();
|
|
563
|
+
|
|
564
|
+
expect(timeline.info.calls.count()).toEqual(2);
|
|
565
|
+
expect(timeline.info).toHaveBeenCalledWith({
|
|
566
|
+
cid: 667,
|
|
567
|
+
transport: "test"
|
|
568
|
+
});
|
|
569
|
+
expect(timeline.info).toHaveBeenCalledWith({
|
|
570
|
+
cid: 667,
|
|
571
|
+
state: "initialized",
|
|
572
|
+
params: undefined,
|
|
573
|
+
});
|
|
574
|
+
|
|
575
|
+
transport.connect();
|
|
576
|
+
|
|
577
|
+
expect(timeline.info.calls.count()).toEqual(3);
|
|
578
|
+
expect(timeline.info).toHaveBeenCalledWith({
|
|
579
|
+
cid: 667,
|
|
580
|
+
state: "connecting",
|
|
581
|
+
params: undefined,
|
|
582
|
+
});
|
|
583
|
+
});
|
|
584
|
+
});
|
|
585
|
+
});
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
var Mocks = require("mocks");
|
|
2
|
+
var Factory = require('core/utils/factory').default;
|
|
3
|
+
var TransportManager = require('core/transports/transport_manager').default;
|
|
4
|
+
var AssistantToTheTransportManager = require('core/transports/assistant_to_the_transport_manager').default;
|
|
5
|
+
|
|
6
|
+
describe("TransportManager", function() {
|
|
7
|
+
it("should create an assistant for a transport class", function() {
|
|
8
|
+
var transportClass = Mocks.getTransportClass(true);
|
|
9
|
+
var assistant = Mocks.getAssistantToTheTransportManager();
|
|
10
|
+
var manager = new TransportManager({
|
|
11
|
+
minPingDelay: 1111,
|
|
12
|
+
maxPingDelay: 2222
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
spyOn(Factory, 'createAssistantToTheTransportManager').and.returnValue(assistant);
|
|
16
|
+
|
|
17
|
+
expect(manager.getAssistant(transportClass)).toBe(assistant);
|
|
18
|
+
expect(Factory.createAssistantToTheTransportManager).toHaveBeenCalledWith(
|
|
19
|
+
manager, transportClass, { minPingDelay: 1111, maxPingDelay: 2222 }
|
|
20
|
+
);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
describe("with initial two lives", function() {
|
|
24
|
+
var manager;
|
|
25
|
+
|
|
26
|
+
beforeEach(function() {
|
|
27
|
+
manager = new TransportManager({ lives: 2 });
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("should be alive in the beginning", function() {
|
|
31
|
+
expect(manager.isAlive()).toBe(true);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("should be alive after losing one life", function() {
|
|
35
|
+
manager.reportDeath();
|
|
36
|
+
expect(manager.isAlive()).toBe(true);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("should be dead after losing both lives", function() {
|
|
40
|
+
manager.reportDeath();
|
|
41
|
+
manager.reportDeath();
|
|
42
|
+
expect(manager.isAlive()).toBe(false);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
describe("with unlimited number of lives", function() {
|
|
47
|
+
var manager;
|
|
48
|
+
|
|
49
|
+
beforeEach(function() {
|
|
50
|
+
manager = new TransportManager();
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("should be alive in the beginning", function() {
|
|
54
|
+
expect(manager.isAlive()).toBe(true);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("should be alive after losing lots of lives", function() {
|
|
58
|
+
for (var i = 0; i < 666; i++) {
|
|
59
|
+
manager.reportDeath();
|
|
60
|
+
}
|
|
61
|
+
expect(manager.isAlive()).toBe(true);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
});
|