@cendarsoss/pusher-js 8.4.13 → 8.4.14
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/CHANGELOG.md +928 -928
- package/DELTA_USAGE.md +0 -0
- package/IMPORT_GUIDE.md +0 -0
- package/bun.lock +1819 -171
- package/dist/node/filter.js +2 -120
- package/dist/node/filter.js.map +1 -1
- package/dist/node/pusher.js +273 -917
- package/dist/node/pusher.js.map +1 -1
- package/dist/web/filter.mjs +2 -120
- package/dist/web/filter.mjs.map +1 -1
- package/dist/web/pusher.mjs +442 -1040
- package/dist/web/pusher.mjs.map +1 -1
- package/examples/delta-seamless-example.html +0 -0
- package/index.d.ts +12 -12
- package/interactive/package.json +2 -2
- package/interactive/public/bundle-entry.js +2 -6
- package/interactive/public/conflation-test.html +1 -3
- package/interactive/public/conflation-test.js +25 -26
- package/interactive/public/dist/bundle.js +21 -5845
- package/interactive/tsconfig.json +19 -0
- package/package.json +3 -3
- package/src/core/auth/auth_transports.js +2 -0
- package/src/core/auth/auth_transports.js.map +1 -0
- package/src/core/auth/channel_authorizer.js +35 -0
- package/src/core/auth/channel_authorizer.js.map +1 -0
- package/src/core/auth/deprecated_channel_authorizer.js +16 -0
- package/src/core/auth/deprecated_channel_authorizer.js.map +1 -0
- package/src/core/auth/options.js +6 -0
- package/src/core/auth/options.js.map +1 -0
- package/src/core/auth/user_authenticator.js +34 -0
- package/src/core/auth/user_authenticator.js.map +1 -0
- package/src/core/base64.js +40 -0
- package/src/core/base64.js.map +1 -0
- package/src/core/channels/channel.js +106 -0
- package/src/core/channels/channel.js.map +1 -0
- package/src/core/channels/channel_table.js +2 -0
- package/src/core/channels/channel_table.js.map +1 -0
- package/src/core/channels/channels.js +54 -0
- package/src/core/channels/channels.js.map +1 -0
- package/src/core/channels/encrypted_channel.js +91 -0
- package/src/core/channels/encrypted_channel.js.map +1 -0
- package/src/core/channels/filter.js +132 -0
- package/src/core/channels/filter.js.map +1 -0
- package/src/core/channels/members.js +52 -0
- package/src/core/channels/members.js.map +1 -0
- package/src/core/channels/metadata.js +2 -0
- package/src/core/channels/metadata.js.map +1 -0
- package/src/core/channels/presence_channel.js +97 -0
- package/src/core/channels/presence_channel.js.map +1 -0
- package/src/core/channels/private_channel.js +10 -0
- package/src/core/channels/private_channel.js.map +1 -0
- package/src/core/config.js +112 -0
- package/src/core/config.js.map +1 -0
- package/src/core/connection/callbacks.js +2 -0
- package/src/core/connection/callbacks.js.map +1 -0
- package/src/core/connection/connection.js +106 -0
- package/src/core/connection/connection.js.map +1 -0
- package/src/core/connection/connection_manager.js +255 -0
- package/src/core/connection/connection_manager.js.map +1 -0
- package/src/core/connection/connection_manager_options.js +2 -0
- package/src/core/connection/connection_manager_options.js.map +1 -0
- package/src/core/connection/handshake/handshake_payload.js +2 -0
- package/src/core/connection/handshake/handshake_payload.js.map +1 -0
- package/src/core/connection/handshake/index.js +54 -0
- package/src/core/connection/handshake/index.js.map +1 -0
- package/src/core/connection/protocol/action.js +2 -0
- package/src/core/connection/protocol/action.js.map +1 -0
- package/src/core/connection/protocol/message-types.js +2 -0
- package/src/core/connection/protocol/message-types.js.map +1 -0
- package/src/core/connection/protocol/protocol.js +102 -0
- package/src/core/connection/protocol/protocol.js.map +1 -0
- package/src/core/defaults.js +30 -0
- package/src/core/defaults.js.map +1 -0
- package/src/core/delta/channel_state.js +103 -0
- package/src/core/delta/channel_state.js.map +1 -0
- package/src/core/delta/channel_state.ts +3 -2
- package/src/core/delta/decoders.js +81 -0
- package/src/core/delta/decoders.js.map +1 -0
- package/{types/src/core/delta/index.d.ts → src/core/delta/index.js} +1 -0
- package/src/core/delta/index.js.map +1 -0
- package/src/core/delta/manager.js +327 -0
- package/src/core/delta/manager.js.map +1 -0
- package/src/core/delta/manager.ts +21 -40
- package/src/core/delta/types.js +2 -0
- package/src/core/delta/types.js.map +1 -0
- package/src/core/errors.js +56 -0
- package/src/core/errors.js.map +1 -0
- package/src/core/events/callback.js +2 -0
- package/src/core/events/callback.js.map +1 -0
- package/src/core/events/callback_registry.js +51 -0
- package/src/core/events/callback_registry.js.map +1 -0
- package/src/core/events/callback_table.js +2 -0
- package/src/core/events/callback_table.js.map +1 -0
- package/src/core/events/dispatcher.js +57 -0
- package/src/core/events/dispatcher.js.map +1 -0
- package/src/core/http/ajax.js +2 -0
- package/src/core/http/ajax.js.map +1 -0
- package/src/core/http/http_factory.js +2 -0
- package/src/core/http/http_factory.js.map +1 -0
- package/src/core/http/http_polling_socket.js +20 -0
- package/src/core/http/http_polling_socket.js.map +1 -0
- package/src/core/http/http_request.js +63 -0
- package/src/core/http/http_request.js.map +1 -0
- package/src/core/http/http_socket.js +171 -0
- package/src/core/http/http_socket.js.map +1 -0
- package/src/core/http/http_streaming_socket.js +16 -0
- package/src/core/http/http_streaming_socket.js.map +1 -0
- package/src/core/http/request_hooks.js +2 -0
- package/src/core/http/request_hooks.js.map +1 -0
- package/src/core/http/socket_hooks.js +2 -0
- package/src/core/http/socket_hooks.js.map +1 -0
- package/src/core/http/state.js +8 -0
- package/src/core/http/state.js.map +1 -0
- package/src/core/http/url_location.js +2 -0
- package/src/core/http/url_location.js.map +1 -0
- package/src/core/logger.js +53 -0
- package/src/core/logger.js.map +1 -0
- package/src/core/options.js +13 -0
- package/src/core/options.js.map +1 -0
- package/src/core/pusher-with-encryption.js +13 -1
- package/src/core/pusher-with-encryption.js.map +1 -0
- package/src/core/pusher.js +279 -10
- package/src/core/pusher.js.map +1 -0
- package/src/core/reachability.js +2 -0
- package/src/core/reachability.js.map +1 -0
- package/src/core/socket.js +2 -0
- package/src/core/socket.js.map +1 -0
- package/src/core/strategies/best_connected_ever_strategy.js +54 -0
- package/src/core/strategies/best_connected_ever_strategy.js.map +1 -0
- package/src/core/strategies/delayed_strategy.js +32 -0
- package/src/core/strategies/delayed_strategy.js.map +1 -0
- package/src/core/strategies/first_connected_strategy.js +18 -0
- package/src/core/strategies/first_connected_strategy.js.map +1 -0
- package/src/core/strategies/if_strategy.js +16 -0
- package/src/core/strategies/if_strategy.js.map +1 -0
- package/src/core/strategies/sequential_strategy.js +87 -0
- package/src/core/strategies/sequential_strategy.js.map +1 -0
- package/src/core/strategies/strategy.js +2 -0
- package/src/core/strategies/strategy.js.map +1 -0
- package/src/core/strategies/strategy_builder.js +42 -0
- package/src/core/strategies/strategy_builder.js.map +1 -0
- package/src/core/strategies/strategy_options.js +2 -0
- package/src/core/strategies/strategy_options.js.map +1 -0
- package/src/core/strategies/strategy_runner.js +2 -0
- package/src/core/strategies/strategy_runner.js.map +1 -0
- package/src/core/strategies/transport_strategy.js +97 -0
- package/src/core/strategies/transport_strategy.js.map +1 -0
- package/src/core/strategies/websocket_prioritized_cached_strategy.js +115 -0
- package/src/core/strategies/websocket_prioritized_cached_strategy.js.map +1 -0
- package/src/core/timeline/level.js +8 -0
- package/src/core/timeline/level.js.map +1 -0
- package/src/core/timeline/timeline.js +60 -0
- package/src/core/timeline/timeline.js.map +1 -0
- package/src/core/timeline/timeline_sender.js +14 -0
- package/src/core/timeline/timeline_sender.js.map +1 -0
- package/src/core/timeline/timeline_transport.js +2 -0
- package/src/core/timeline/timeline_transport.js.map +1 -0
- package/src/core/transports/assistant_to_the_transport_manager.js +42 -0
- package/src/core/transports/assistant_to_the_transport_manager.js.map +1 -0
- package/src/core/transports/ping_delay_options.js +2 -0
- package/src/core/transports/ping_delay_options.js.map +1 -0
- package/src/core/transports/transport.js +13 -0
- package/src/core/transports/transport.js.map +1 -0
- package/src/core/transports/transport_connection.js +146 -0
- package/src/core/transports/transport_connection.js.map +1 -0
- package/src/core/transports/transport_connection_options.js +2 -0
- package/src/core/transports/transport_connection_options.js.map +1 -0
- package/src/core/transports/transport_hooks.js +2 -0
- package/src/core/transports/transport_hooks.js.map +1 -0
- package/src/core/transports/transport_manager.js +20 -0
- package/src/core/transports/transport_manager.js.map +1 -0
- package/src/core/transports/transports_table.js +2 -0
- package/src/core/transports/transports_table.js.map +1 -0
- package/src/core/transports/url_scheme.js +2 -0
- package/src/core/transports/url_scheme.js.map +1 -0
- package/src/core/transports/url_schemes.js +37 -0
- package/src/core/transports/url_schemes.js.map +1 -0
- package/src/core/user.js +133 -0
- package/src/core/user.js.map +1 -0
- package/src/core/util.js +22 -0
- package/src/core/util.js.map +1 -0
- package/src/core/utils/collections.js +193 -0
- package/src/core/utils/collections.js.map +1 -0
- package/src/core/utils/factory.js +40 -0
- package/src/core/utils/factory.js.map +1 -0
- package/src/core/utils/flat_promise.js +10 -0
- package/src/core/utils/flat_promise.js.map +1 -0
- package/src/core/utils/timers/abstract_timer.js +21 -0
- package/src/core/utils/timers/abstract_timer.js.map +1 -0
- package/src/core/utils/timers/index.js +24 -0
- package/src/core/utils/timers/index.js.map +1 -0
- package/src/core/utils/timers/scheduling.js +2 -0
- package/src/core/utils/timers/scheduling.js.map +1 -0
- package/src/core/utils/timers/timed_callback.js +2 -0
- package/src/core/utils/timers/timed_callback.js.map +1 -0
- package/src/core/utils/url_store.js +38 -0
- package/src/core/utils/url_store.js.map +1 -0
- package/src/core/watchlist.js +25 -0
- package/src/core/watchlist.js.map +1 -0
- package/src/filter.js +2 -0
- package/src/filter.js.map +1 -0
- package/src/filter.ts +0 -0
- package/src/index.js +3 -0
- package/src/index.js.map +1 -0
- package/src/index.ts +1 -1
- package/src/runtimes/interface.js +2 -0
- package/src/runtimes/interface.js.map +1 -0
- package/src/runtimes/isomorphic/auth/xhr_auth.js +53 -0
- package/src/runtimes/isomorphic/auth/xhr_auth.js.map +1 -0
- package/src/runtimes/isomorphic/default_strategy.js +83 -0
- package/src/runtimes/isomorphic/default_strategy.js.map +1 -0
- package/src/runtimes/isomorphic/http/http.js +24 -0
- package/src/runtimes/isomorphic/http/http.js.map +1 -0
- package/src/runtimes/isomorphic/http/http_xhr_request.js +30 -0
- package/src/runtimes/isomorphic/http/http_xhr_request.js.map +1 -0
- package/src/runtimes/isomorphic/runtime.js +48 -0
- package/src/runtimes/isomorphic/runtime.js.map +1 -0
- package/src/runtimes/isomorphic/timeline/xhr_timeline.js +38 -0
- package/src/runtimes/isomorphic/timeline/xhr_timeline.js.map +1 -0
- package/src/runtimes/isomorphic/transports/transport_connection_initializer.js +13 -0
- package/src/runtimes/isomorphic/transports/transport_connection_initializer.js.map +1 -0
- package/src/runtimes/isomorphic/transports/transports.js +50 -0
- package/src/runtimes/isomorphic/transports/transports.js.map +1 -0
- package/src/runtimes/node/net_info.js +8 -0
- package/src/runtimes/node/net_info.js.map +1 -0
- package/src/runtimes/node/runtime.js +41 -0
- package/src/runtimes/node/runtime.js.map +1 -0
- package/src/runtimes/react-native/net_info.js +31 -0
- package/src/runtimes/react-native/net_info.js.map +1 -0
- package/src/runtimes/react-native/runtime.js +38 -0
- package/src/runtimes/react-native/runtime.js.map +1 -0
- package/src/runtimes/web/auth/jsonp_auth.js +25 -0
- package/src/runtimes/web/auth/jsonp_auth.js.map +1 -0
- package/src/runtimes/web/browser.js +2 -0
- package/src/runtimes/web/browser.js.map +1 -0
- package/src/runtimes/web/default_strategy.js +91 -0
- package/src/runtimes/web/default_strategy.js.map +1 -0
- package/src/runtimes/web/dom/dependencies.js +12 -0
- package/src/runtimes/web/dom/dependencies.js.map +1 -0
- package/src/runtimes/web/dom/dependency_loader.js +50 -0
- package/src/runtimes/web/dom/dependency_loader.js.map +1 -0
- package/src/runtimes/web/dom/jsonp_request.js +23 -0
- package/src/runtimes/web/dom/jsonp_request.js.map +1 -0
- package/src/runtimes/web/dom/script_receiver.js +2 -0
- package/src/runtimes/web/dom/script_receiver.js.map +1 -0
- package/src/runtimes/web/dom/script_receiver_factory.js +27 -0
- package/src/runtimes/web/dom/script_receiver_factory.js.map +1 -0
- package/src/runtimes/web/dom/script_request.js +61 -0
- package/src/runtimes/web/dom/script_request.js.map +1 -0
- package/src/runtimes/web/http/http.js +7 -0
- package/src/runtimes/web/http/http.js.map +1 -0
- package/src/runtimes/web/http/http_xdomain_request.js +33 -0
- package/src/runtimes/web/http/http_xdomain_request.js.map +1 -0
- package/src/runtimes/web/net_info.js +25 -0
- package/src/runtimes/web/net_info.js.map +1 -0
- package/src/runtimes/web/runtime.js +142 -0
- package/src/runtimes/web/runtime.js.map +1 -0
- package/src/runtimes/web/timeline/jsonp_timeline.js +26 -0
- package/src/runtimes/web/timeline/jsonp_timeline.js.map +1 -0
- package/src/runtimes/web/transports/transport_connection_initializer.js +30 -0
- package/src/runtimes/web/transports/transport_connection_initializer.js.map +1 -0
- package/src/runtimes/web/transports/transports.js +44 -0
- package/src/runtimes/web/transports/transports.js.map +1 -0
- package/src/runtimes/worker/auth/fetch_auth.js +44 -0
- package/src/runtimes/worker/auth/fetch_auth.js.map +1 -0
- package/src/runtimes/worker/net_info.js +8 -0
- package/src/runtimes/worker/net_info.js.map +1 -0
- package/src/runtimes/worker/runtime.js +43 -0
- package/src/runtimes/worker/runtime.js.map +1 -0
- package/src/runtimes/worker/timeline/fetch_timeline.js +31 -0
- package/src/runtimes/worker/timeline/fetch_timeline.js.map +1 -0
- package/tsconfig.json +24 -5
- package/vite.config.js +0 -0
- package/vite.config.node.js +0 -0
- package/interactive/public/delta-compression.js +0 -1090
- package/types/spec/javascripts/helpers/node/mock-dom-dependencies.d.ts +0 -1
- package/types/spec/javascripts/helpers/pusher_integration_class.d.ts +0 -4
- package/types/src/core/auth/auth_transports.d.ts +0 -9
- package/types/src/core/auth/channel_authorizer.d.ts +0 -3
- package/types/src/core/auth/deprecated_channel_authorizer.d.ts +0 -18
- package/types/src/core/auth/options.d.ts +0 -48
- package/types/src/core/auth/user_authenticator.d.ts +0 -3
- package/types/src/core/base64.d.ts +0 -1
- package/types/src/core/channels/channel.d.ts +0 -25
- package/types/src/core/channels/channel_table.d.ts +0 -5
- package/types/src/core/channels/channels.d.ts +0 -12
- package/types/src/core/channels/encrypted_channel.d.ts +0 -15
- package/types/src/core/channels/filter.d.ts +0 -33
- package/types/src/core/channels/members.d.ts +0 -14
- package/types/src/core/channels/metadata.d.ts +0 -4
- package/types/src/core/channels/presence_channel.d.ts +0 -13
- package/types/src/core/channels/private_channel.d.ts +0 -5
- package/types/src/core/config.d.ts +0 -31
- package/types/src/core/connection/callbacks.d.ts +0 -18
- package/types/src/core/connection/connection.d.ts +0 -16
- package/types/src/core/connection/connection_manager.d.ts +0 -50
- package/types/src/core/connection/connection_manager_options.d.ts +0 -11
- package/types/src/core/connection/handshake/handshake_payload.d.ts +0 -8
- package/types/src/core/connection/handshake/index.d.ts +0 -12
- package/types/src/core/connection/protocol/action.d.ts +0 -7
- package/types/src/core/connection/protocol/message-types.d.ts +0 -10
- package/types/src/core/connection/protocol/protocol.d.ts +0 -10
- package/types/src/core/defaults.d.ts +0 -26
- package/types/src/core/delta/channel_state.d.ts +0 -23
- package/types/src/core/delta/decoders.d.ts +0 -12
- package/types/src/core/delta/manager.d.ts +0 -27
- package/types/src/core/delta/types.d.ts +0 -50
- package/types/src/core/errors.d.ts +0 -28
- package/types/src/core/events/callback.d.ts +0 -5
- package/types/src/core/events/callback_registry.d.ts +0 -11
- package/types/src/core/events/callback_table.d.ts +0 -5
- package/types/src/core/events/dispatcher.d.ts +0 -14
- package/types/src/core/http/ajax.d.ts +0 -16
- package/types/src/core/http/http_factory.d.ts +0 -13
- package/types/src/core/http/http_polling_socket.d.ts +0 -3
- package/types/src/core/http/http_request.d.ts +0 -17
- package/types/src/core/http/http_socket.d.ts +0 -32
- package/types/src/core/http/http_streaming_socket.d.ts +0 -3
- package/types/src/core/http/request_hooks.d.ts +0 -6
- package/types/src/core/http/socket_hooks.d.ts +0 -8
- package/types/src/core/http/state.d.ts +0 -6
- package/types/src/core/http/url_location.d.ts +0 -5
- package/types/src/core/logger.d.ts +0 -11
- package/types/src/core/options.d.ts +0 -36
- package/types/src/core/pusher-with-encryption.d.ts +0 -5
- package/types/src/core/pusher.d.ts +0 -56
- package/types/src/core/reachability.d.ts +0 -5
- package/types/src/core/socket.d.ts +0 -12
- package/types/src/core/strategies/best_connected_ever_strategy.d.ts +0 -10
- package/types/src/core/strategies/delayed_strategy.d.ts +0 -15
- package/types/src/core/strategies/first_connected_strategy.d.ts +0 -8
- package/types/src/core/strategies/if_strategy.d.ts +0 -10
- package/types/src/core/strategies/sequential_strategy.d.ts +0 -16
- package/types/src/core/strategies/strategy.d.ts +0 -6
- package/types/src/core/strategies/strategy_builder.d.ts +0 -5
- package/types/src/core/strategies/strategy_options.d.ts +0 -16
- package/types/src/core/strategies/strategy_runner.d.ts +0 -5
- package/types/src/core/strategies/transport_strategy.d.ts +0 -15
- package/types/src/core/strategies/websocket_prioritized_cached_strategy.d.ts +0 -20
- package/types/src/core/timeline/level.d.ts +0 -6
- package/types/src/core/timeline/timeline.d.ts +0 -25
- package/types/src/core/timeline/timeline_sender.d.ts +0 -13
- package/types/src/core/timeline/timeline_transport.d.ts +0 -6
- package/types/src/core/transports/assistant_to_the_transport_manager.d.ts +0 -14
- package/types/src/core/transports/ping_delay_options.d.ts +0 -6
- package/types/src/core/transports/transport.d.ts +0 -8
- package/types/src/core/transports/transport_connection.d.ts +0 -35
- package/types/src/core/transports/transport_connection_options.d.ts +0 -6
- package/types/src/core/transports/transport_hooks.d.ts +0 -13
- package/types/src/core/transports/transport_manager.d.ts +0 -14
- package/types/src/core/transports/transports_table.d.ts +0 -10
- package/types/src/core/transports/url_scheme.d.ts +0 -11
- package/types/src/core/transports/url_schemes.d.ts +0 -4
- package/types/src/core/user.d.ts +0 -21
- package/types/src/core/util.d.ts +0 -8
- package/types/src/core/utils/collections.d.ts +0 -18
- package/types/src/core/utils/factory.d.ts +0 -29
- package/types/src/core/utils/flat_promise.d.ts +0 -6
- package/types/src/core/utils/timers/abstract_timer.d.ts +0 -10
- package/types/src/core/utils/timers/index.d.ts +0 -9
- package/types/src/core/utils/timers/scheduling.d.ts +0 -8
- package/types/src/core/utils/timers/timed_callback.d.ts +0 -4
- package/types/src/core/utils/url_store.d.ts +0 -4
- package/types/src/core/watchlist.d.ts +0 -8
- package/types/src/runtimes/interface.d.ts +0 -43
- package/types/src/runtimes/isomorphic/auth/xhr_auth.d.ts +0 -3
- package/types/src/runtimes/isomorphic/default_strategy.d.ts +0 -5
- package/types/src/runtimes/isomorphic/http/http.d.ts +0 -3
- package/types/src/runtimes/isomorphic/http/http_xhr_request.d.ts +0 -3
- package/types/src/runtimes/isomorphic/runtime.d.ts +0 -2
- package/types/src/runtimes/isomorphic/timeline/xhr_timeline.d.ts +0 -6
- package/types/src/runtimes/isomorphic/transports/transport_connection_initializer.d.ts +0 -1
- package/types/src/runtimes/isomorphic/transports/transports.d.ts +0 -5
- package/types/src/runtimes/node/net_info.d.ts +0 -6
- package/types/src/runtimes/node/runtime.d.ts +0 -3
- package/types/src/runtimes/react-native/net_info.d.ts +0 -8
- package/types/src/runtimes/react-native/runtime.d.ts +0 -3
- package/types/src/runtimes/web/auth/jsonp_auth.d.ts +0 -3
- package/types/src/runtimes/web/browser.d.ts +0 -19
- package/types/src/runtimes/web/default_strategy.d.ts +0 -5
- package/types/src/runtimes/web/dom/dependencies.d.ts +0 -4
- package/types/src/runtimes/web/dom/dependency_loader.d.ts +0 -10
- package/types/src/runtimes/web/dom/jsonp_request.d.ts +0 -10
- package/types/src/runtimes/web/dom/script_receiver.d.ts +0 -7
- package/types/src/runtimes/web/dom/script_receiver_factory.d.ts +0 -10
- package/types/src/runtimes/web/dom/script_request.d.ts +0 -9
- package/types/src/runtimes/web/http/http.d.ts +0 -2
- package/types/src/runtimes/web/http/http_xdomain_request.d.ts +0 -3
- package/types/src/runtimes/web/net_info.d.ts +0 -7
- package/types/src/runtimes/web/runtime.d.ts +0 -3
- package/types/src/runtimes/web/timeline/jsonp_timeline.d.ts +0 -6
- package/types/src/runtimes/web/transports/transport_connection_initializer.d.ts +0 -1
- package/types/src/runtimes/web/transports/transports.d.ts +0 -2
- package/types/src/runtimes/worker/auth/fetch_auth.d.ts +0 -3
- package/types/src/runtimes/worker/net_info.d.ts +0 -6
- package/types/src/runtimes/worker/runtime.d.ts +0 -3
- package/types/src/runtimes/worker/timeline/fetch_timeline.d.ts +0 -6
package/dist/node/pusher.js
CHANGED
|
@@ -41,14 +41,9 @@ class Timer {
|
|
|
41
41
|
}
|
|
42
42
|
}, delay);
|
|
43
43
|
}
|
|
44
|
-
/** Returns whether the timer is still running.
|
|
45
|
-
*
|
|
46
|
-
* @return {Boolean}
|
|
47
|
-
*/
|
|
48
44
|
isRunning() {
|
|
49
45
|
return this.timer !== null;
|
|
50
46
|
}
|
|
51
|
-
/** Aborts a timer when it's running. */
|
|
52
47
|
ensureAborted() {
|
|
53
48
|
if (this.timer) {
|
|
54
49
|
this.clear(this.timer);
|
|
@@ -89,14 +84,6 @@ var Util = {
|
|
|
89
84
|
defer(callback) {
|
|
90
85
|
return new OneOffTimer(0, callback);
|
|
91
86
|
},
|
|
92
|
-
/** Builds a function that will proxy a method call to its first argument.
|
|
93
|
-
*
|
|
94
|
-
* Allows partial application of arguments, so additional arguments are
|
|
95
|
-
* prepended to the argument list.
|
|
96
|
-
*
|
|
97
|
-
* @param {String} name method name
|
|
98
|
-
* @return {Function} proxy function
|
|
99
|
-
*/
|
|
100
87
|
method(name, ...args) {
|
|
101
88
|
var boundArguments = Array.prototype.slice.call(arguments, 1);
|
|
102
89
|
return function(object) {
|
|
@@ -239,10 +226,7 @@ function buildQueryString(data) {
|
|
|
239
226
|
var params = filterObject(data, function(value) {
|
|
240
227
|
return value !== void 0;
|
|
241
228
|
});
|
|
242
|
-
var query = map(
|
|
243
|
-
flatten(encodeParamsObject(params)),
|
|
244
|
-
Util.method("join", "=")
|
|
245
|
-
).join("&");
|
|
229
|
+
var query = map(flatten(encodeParamsObject(params)), Util.method("join", "=")).join("&");
|
|
246
230
|
return query;
|
|
247
231
|
}
|
|
248
232
|
function decycleObject(object) {
|
|
@@ -270,10 +254,7 @@ function decycleObject(object) {
|
|
|
270
254
|
nu = {};
|
|
271
255
|
for (name in value) {
|
|
272
256
|
if (Object.prototype.hasOwnProperty.call(value, name)) {
|
|
273
|
-
nu[name] = derez(
|
|
274
|
-
value[name],
|
|
275
|
-
path + "[" + JSON.stringify(name) + "]"
|
|
276
|
-
);
|
|
257
|
+
nu[name] = derez(value[name], path + "[" + JSON.stringify(name) + "]");
|
|
277
258
|
}
|
|
278
259
|
}
|
|
279
260
|
}
|
|
@@ -298,14 +279,11 @@ var Defaults = {
|
|
|
298
279
|
wsPort: 80,
|
|
299
280
|
wssPort: 443,
|
|
300
281
|
wsPath: "",
|
|
301
|
-
// DEPRECATED: SockJS fallback parameters
|
|
302
282
|
httpHost: "sockjs.pusher.com",
|
|
303
283
|
httpPort: 80,
|
|
304
284
|
httpsPort: 443,
|
|
305
285
|
httpPath: "/pusher",
|
|
306
|
-
// DEPRECATED: Stats
|
|
307
286
|
stats_host: "stats.pusher.com",
|
|
308
|
-
// DEPRECATED: Other settings
|
|
309
287
|
authEndpoint: "/pusher/auth",
|
|
310
288
|
authTransport: "ajax",
|
|
311
289
|
activityTimeout: 12e4,
|
|
@@ -370,30 +348,19 @@ class CallbackRegistry {
|
|
|
370
348
|
}
|
|
371
349
|
}
|
|
372
350
|
removeCallback(names, callback, context) {
|
|
373
|
-
apply(
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
);
|
|
382
|
-
if (this._callbacks[name].length === 0) {
|
|
383
|
-
delete this._callbacks[name];
|
|
384
|
-
}
|
|
385
|
-
},
|
|
386
|
-
this
|
|
387
|
-
);
|
|
351
|
+
apply(names, function(name) {
|
|
352
|
+
this._callbacks[name] = filter(this._callbacks[name] || [], function(binding) {
|
|
353
|
+
return callback && callback !== binding.fn || context && context !== binding.context;
|
|
354
|
+
});
|
|
355
|
+
if (this._callbacks[name].length === 0) {
|
|
356
|
+
delete this._callbacks[name];
|
|
357
|
+
}
|
|
358
|
+
}, this);
|
|
388
359
|
}
|
|
389
360
|
removeAllCallbacks(names) {
|
|
390
|
-
apply(
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
delete this._callbacks[name];
|
|
394
|
-
},
|
|
395
|
-
this
|
|
396
|
-
);
|
|
361
|
+
apply(names, function(name) {
|
|
362
|
+
delete this._callbacks[name];
|
|
363
|
+
}, this);
|
|
397
364
|
}
|
|
398
365
|
}
|
|
399
366
|
function prefix(name) {
|
|
@@ -422,10 +389,7 @@ class Dispatcher {
|
|
|
422
389
|
this.global_callbacks = [];
|
|
423
390
|
return this;
|
|
424
391
|
}
|
|
425
|
-
this.global_callbacks = filter(
|
|
426
|
-
this.global_callbacks || [],
|
|
427
|
-
(c) => c !== callback
|
|
428
|
-
);
|
|
392
|
+
this.global_callbacks = filter(this.global_callbacks || [], (c) => c !== callback);
|
|
429
393
|
return this;
|
|
430
394
|
}
|
|
431
395
|
unbind_all() {
|
|
@@ -458,7 +422,7 @@ let config = {
|
|
|
458
422
|
logToConsole: false
|
|
459
423
|
};
|
|
460
424
|
function setLoggerConfig(newConfig) {
|
|
461
|
-
config = {
|
|
425
|
+
config = Object.assign(Object.assign({}, config), newConfig);
|
|
462
426
|
}
|
|
463
427
|
class Logger {
|
|
464
428
|
constructor() {
|
|
@@ -516,24 +480,12 @@ class TransportConnection extends Dispatcher {
|
|
|
516
480
|
this.activityTimeout = options.activityTimeout;
|
|
517
481
|
this.id = this.timeline.generateUniqueID();
|
|
518
482
|
}
|
|
519
|
-
/** Checks whether the transport handles activity checks by itself.
|
|
520
|
-
*
|
|
521
|
-
* @return {Boolean}
|
|
522
|
-
*/
|
|
523
483
|
handlesActivityChecks() {
|
|
524
484
|
return Boolean(this.hooks.handlesActivityChecks);
|
|
525
485
|
}
|
|
526
|
-
/** Checks whether the transport supports the ping/pong API.
|
|
527
|
-
*
|
|
528
|
-
* @return {Boolean}
|
|
529
|
-
*/
|
|
530
486
|
supportsPing() {
|
|
531
487
|
return Boolean(this.hooks.supportsPing);
|
|
532
488
|
}
|
|
533
|
-
/** Tries to establish a connection.
|
|
534
|
-
*
|
|
535
|
-
* @returns {Boolean} false if transport is in invalid state
|
|
536
|
-
*/
|
|
537
489
|
connect() {
|
|
538
490
|
if (this.socket || this.state !== "initialized") {
|
|
539
491
|
return false;
|
|
@@ -553,10 +505,6 @@ class TransportConnection extends Dispatcher {
|
|
|
553
505
|
this.changeState("connecting");
|
|
554
506
|
return true;
|
|
555
507
|
}
|
|
556
|
-
/** Closes the connection.
|
|
557
|
-
*
|
|
558
|
-
* @return {Boolean} true if there was a connection to close
|
|
559
|
-
*/
|
|
560
508
|
close() {
|
|
561
509
|
if (this.socket) {
|
|
562
510
|
this.socket.close();
|
|
@@ -565,11 +513,6 @@ class TransportConnection extends Dispatcher {
|
|
|
565
513
|
return false;
|
|
566
514
|
}
|
|
567
515
|
}
|
|
568
|
-
/** Sends data over the open connection.
|
|
569
|
-
*
|
|
570
|
-
* @param {String} data
|
|
571
|
-
* @return {Boolean} true only when in the "open" state
|
|
572
|
-
*/
|
|
573
516
|
send(data) {
|
|
574
517
|
if (this.state === "open") {
|
|
575
518
|
Util.defer(() => {
|
|
@@ -582,7 +525,6 @@ class TransportConnection extends Dispatcher {
|
|
|
582
525
|
return false;
|
|
583
526
|
}
|
|
584
527
|
}
|
|
585
|
-
/** Sends a ping if the connection is open and transport supports it. */
|
|
586
528
|
ping() {
|
|
587
529
|
if (this.state === "open" && this.supportsPing()) {
|
|
588
530
|
this.socket.ping();
|
|
@@ -590,10 +532,7 @@ class TransportConnection extends Dispatcher {
|
|
|
590
532
|
}
|
|
591
533
|
onOpen() {
|
|
592
534
|
if (this.hooks.beforeOpen) {
|
|
593
|
-
this.hooks.beforeOpen(
|
|
594
|
-
this.socket,
|
|
595
|
-
this.hooks.urls.getPath(this.key, this.options)
|
|
596
|
-
);
|
|
535
|
+
this.hooks.beforeOpen(this.socket, this.hooks.urls.getPath(this.key, this.options));
|
|
597
536
|
}
|
|
598
537
|
this.changeState("open");
|
|
599
538
|
this.socket.onopen = void 0;
|
|
@@ -653,12 +592,10 @@ class TransportConnection extends Dispatcher {
|
|
|
653
592
|
}
|
|
654
593
|
changeState(state, params) {
|
|
655
594
|
this.state = state;
|
|
656
|
-
this.timeline.info(
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
})
|
|
661
|
-
);
|
|
595
|
+
this.timeline.info(this.buildTimelineMessage({
|
|
596
|
+
state,
|
|
597
|
+
params
|
|
598
|
+
}));
|
|
662
599
|
this.emit(state, params);
|
|
663
600
|
}
|
|
664
601
|
buildTimelineMessage(message) {
|
|
@@ -669,22 +606,9 @@ class Transport {
|
|
|
669
606
|
constructor(hooks2) {
|
|
670
607
|
this.hooks = hooks2;
|
|
671
608
|
}
|
|
672
|
-
/** Returns whether the transport is supported in the environment.
|
|
673
|
-
*
|
|
674
|
-
* @param {Object} envronment te environment details (encryption, settings)
|
|
675
|
-
* @returns {Boolean} true when the transport is supported
|
|
676
|
-
*/
|
|
677
609
|
isSupported(environment) {
|
|
678
610
|
return this.hooks.isSupported(environment);
|
|
679
611
|
}
|
|
680
|
-
/** Creates a transport connection.
|
|
681
|
-
*
|
|
682
|
-
* @param {String} name
|
|
683
|
-
* @param {Number} priority
|
|
684
|
-
* @param {String} key the application key
|
|
685
|
-
* @param {Object} options
|
|
686
|
-
* @returns {TransportConnection}
|
|
687
|
-
*/
|
|
688
612
|
createConnection(name, priority, key, options) {
|
|
689
613
|
return new TransportConnection(this.hooks, name, priority, key, options);
|
|
690
614
|
}
|
|
@@ -711,33 +635,23 @@ var httpConfiguration = {
|
|
|
711
635
|
return true;
|
|
712
636
|
}
|
|
713
637
|
};
|
|
714
|
-
var streamingConfiguration = extend(
|
|
715
|
-
{
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
);
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
getSocket: function(url) {
|
|
725
|
-
return NodeJS.HTTPFactory.createPollingSocket(url);
|
|
726
|
-
}
|
|
727
|
-
},
|
|
728
|
-
httpConfiguration
|
|
729
|
-
);
|
|
638
|
+
var streamingConfiguration = extend({
|
|
639
|
+
getSocket: function(url) {
|
|
640
|
+
return NodeJS.HTTPFactory.createStreamingSocket(url);
|
|
641
|
+
}
|
|
642
|
+
}, httpConfiguration);
|
|
643
|
+
var pollingConfiguration = extend({
|
|
644
|
+
getSocket: function(url) {
|
|
645
|
+
return NodeJS.HTTPFactory.createPollingSocket(url);
|
|
646
|
+
}
|
|
647
|
+
}, httpConfiguration);
|
|
730
648
|
var xhrConfiguration = {
|
|
731
649
|
isSupported: function() {
|
|
732
650
|
return NodeJS.isXHRSupported();
|
|
733
651
|
}
|
|
734
652
|
};
|
|
735
|
-
var XHRStreamingTransport = new Transport(
|
|
736
|
-
|
|
737
|
-
);
|
|
738
|
-
var XHRPollingTransport = new Transport(
|
|
739
|
-
extend({}, pollingConfiguration, xhrConfiguration)
|
|
740
|
-
);
|
|
653
|
+
var XHRStreamingTransport = new Transport(extend({}, streamingConfiguration, xhrConfiguration));
|
|
654
|
+
var XHRPollingTransport = new Transport(extend({}, pollingConfiguration, xhrConfiguration));
|
|
741
655
|
var Transports$2 = {
|
|
742
656
|
ws: WSTransport,
|
|
743
657
|
xhr_streaming: XHRStreamingTransport,
|
|
@@ -751,26 +665,11 @@ class AssistantToTheTransportManager {
|
|
|
751
665
|
this.maxPingDelay = options.maxPingDelay;
|
|
752
666
|
this.pingDelay = void 0;
|
|
753
667
|
}
|
|
754
|
-
/** Creates a transport connection.
|
|
755
|
-
*
|
|
756
|
-
* This function has the same API as Transport#createConnection.
|
|
757
|
-
*
|
|
758
|
-
* @param {String} name
|
|
759
|
-
* @param {Number} priority
|
|
760
|
-
* @param {String} key the application key
|
|
761
|
-
* @param {Object} options
|
|
762
|
-
* @returns {TransportConnection}
|
|
763
|
-
*/
|
|
764
668
|
createConnection(name, priority, key, options) {
|
|
765
669
|
options = extend({}, options, {
|
|
766
670
|
activityTimeout: this.pingDelay
|
|
767
671
|
});
|
|
768
|
-
var connection = this.transport.createConnection(
|
|
769
|
-
name,
|
|
770
|
-
priority,
|
|
771
|
-
key,
|
|
772
|
-
options
|
|
773
|
-
);
|
|
672
|
+
var connection = this.transport.createConnection(name, priority, key, options);
|
|
774
673
|
var openTimestamp = null;
|
|
775
674
|
var onOpen = function() {
|
|
776
675
|
connection.unbind("open", onOpen);
|
|
@@ -792,35 +691,13 @@ class AssistantToTheTransportManager {
|
|
|
792
691
|
connection.bind("open", onOpen);
|
|
793
692
|
return connection;
|
|
794
693
|
}
|
|
795
|
-
/** Returns whether the transport is supported in the environment.
|
|
796
|
-
*
|
|
797
|
-
* This function has the same API as Transport#isSupported. Might return false
|
|
798
|
-
* when the manager decides to kill the transport.
|
|
799
|
-
*
|
|
800
|
-
* @param {Object} environment the environment details (encryption, settings)
|
|
801
|
-
* @returns {Boolean} true when the transport is supported
|
|
802
|
-
*/
|
|
803
694
|
isSupported(environment) {
|
|
804
695
|
return this.manager.isAlive() && this.transport.isSupported(environment);
|
|
805
696
|
}
|
|
806
697
|
}
|
|
807
698
|
const Protocol = {
|
|
808
|
-
/**
|
|
809
|
-
* Decodes a message in a Pusher format.
|
|
810
|
-
*
|
|
811
|
-
* The MessageEvent we receive from the transport should contain a pusher event
|
|
812
|
-
* (https://pusher.com/docs/pusher_protocol#events) serialized as JSON in the
|
|
813
|
-
* data field
|
|
814
|
-
*
|
|
815
|
-
* The pusher event may contain a data field too, and it may also be
|
|
816
|
-
* serialised as JSON
|
|
817
|
-
*
|
|
818
|
-
* Throws errors when messages are not parse'able.
|
|
819
|
-
*
|
|
820
|
-
* @param {MessageEvent} messageEvent
|
|
821
|
-
* @return {PusherEvent}
|
|
822
|
-
*/
|
|
823
699
|
decodeMessage: function(messageEvent) {
|
|
700
|
+
var _a, _b;
|
|
824
701
|
try {
|
|
825
702
|
var messageData = JSON.parse(messageEvent.data);
|
|
826
703
|
var pusherEventData = messageData.data;
|
|
@@ -835,13 +712,12 @@ const Protocol = {
|
|
|
835
712
|
channel: messageData.channel,
|
|
836
713
|
data: pusherEventData,
|
|
837
714
|
rawMessage: messageEvent.data
|
|
838
|
-
// Preserve raw message for delta compression
|
|
839
715
|
};
|
|
840
716
|
if (messageData.user_id) {
|
|
841
717
|
pusherEvent.user_id = messageData.user_id;
|
|
842
718
|
}
|
|
843
|
-
const sequence = messageData.__delta_seq
|
|
844
|
-
const conflationKey = messageData.__conflation_key
|
|
719
|
+
const sequence = (_a = messageData.__delta_seq) !== null && _a !== void 0 ? _a : messageData.sequence;
|
|
720
|
+
const conflationKey = (_b = messageData.__conflation_key) !== null && _b !== void 0 ? _b : messageData.conflation_key;
|
|
845
721
|
if (typeof sequence === "number") {
|
|
846
722
|
pusherEvent.sequence = sequence;
|
|
847
723
|
}
|
|
@@ -853,29 +729,9 @@ const Protocol = {
|
|
|
853
729
|
throw { type: "MessageParseError", error: e, data: messageEvent.data };
|
|
854
730
|
}
|
|
855
731
|
},
|
|
856
|
-
/**
|
|
857
|
-
* Encodes a message to be sent.
|
|
858
|
-
*
|
|
859
|
-
* @param {PusherEvent} event
|
|
860
|
-
* @return {String}
|
|
861
|
-
*/
|
|
862
732
|
encodeMessage: function(event) {
|
|
863
733
|
return JSON.stringify(event);
|
|
864
734
|
},
|
|
865
|
-
/**
|
|
866
|
-
* Processes a handshake message and returns appropriate actions.
|
|
867
|
-
*
|
|
868
|
-
* Returns an object with an 'action' and other action-specific properties.
|
|
869
|
-
*
|
|
870
|
-
* There are three outcomes when calling this function. First is a successful
|
|
871
|
-
* connection attempt, when pusher:connection_established is received, which
|
|
872
|
-
* results in a 'connected' action with an 'id' property. When passed a
|
|
873
|
-
* pusher:error event, it returns a result with action appropriate to the
|
|
874
|
-
* close code and an error. Otherwise, it raises an exception.
|
|
875
|
-
*
|
|
876
|
-
* @param {String} message
|
|
877
|
-
* @result Object
|
|
878
|
-
*/
|
|
879
735
|
processHandshake: function(messageEvent) {
|
|
880
736
|
var message = Protocol.decodeMessage(messageEvent);
|
|
881
737
|
if (message.event === "pusher:connection_established") {
|
|
@@ -896,16 +752,6 @@ const Protocol = {
|
|
|
896
752
|
throw "Invalid handshake";
|
|
897
753
|
}
|
|
898
754
|
},
|
|
899
|
-
/**
|
|
900
|
-
* Dispatches the close event and returns an appropriate action name.
|
|
901
|
-
*
|
|
902
|
-
* See:
|
|
903
|
-
* 1. https://developer.mozilla.org/en-US/docs/WebSockets/WebSockets_reference/CloseEvent
|
|
904
|
-
* 2. http://pusher.com/docs/pusher_protocol
|
|
905
|
-
*
|
|
906
|
-
* @param {CloseEvent} closeEvent
|
|
907
|
-
* @return {String} close action name
|
|
908
|
-
*/
|
|
909
755
|
getCloseAction: function(closeEvent) {
|
|
910
756
|
if (closeEvent.code < 4e3) {
|
|
911
757
|
if (closeEvent.code >= 1002 && closeEvent.code <= 1004) {
|
|
@@ -925,15 +771,6 @@ const Protocol = {
|
|
|
925
771
|
return "refused";
|
|
926
772
|
}
|
|
927
773
|
},
|
|
928
|
-
/**
|
|
929
|
-
* Returns an error or null basing on the close event.
|
|
930
|
-
*
|
|
931
|
-
* Null is returned when connection was closed cleanly. Otherwise, an object
|
|
932
|
-
* with error details is returned.
|
|
933
|
-
*
|
|
934
|
-
* @param {CloseEvent} closeEvent
|
|
935
|
-
* @return {Object} error object
|
|
936
|
-
*/
|
|
937
774
|
getCloseError: function(closeEvent) {
|
|
938
775
|
if (closeEvent.code !== 1e3 && closeEvent.code !== 1001) {
|
|
939
776
|
return {
|
|
@@ -956,27 +793,12 @@ class Connection extends Dispatcher {
|
|
|
956
793
|
this.activityTimeout = transport.activityTimeout;
|
|
957
794
|
this.bindListeners();
|
|
958
795
|
}
|
|
959
|
-
/** Returns whether used transport handles activity checks by itself
|
|
960
|
-
*
|
|
961
|
-
* @returns {Boolean} true if activity checks are handled by the transport
|
|
962
|
-
*/
|
|
963
796
|
handlesActivityChecks() {
|
|
964
797
|
return this.transport.handlesActivityChecks();
|
|
965
798
|
}
|
|
966
|
-
/** Sends raw data.
|
|
967
|
-
*
|
|
968
|
-
* @param {String} data
|
|
969
|
-
*/
|
|
970
799
|
send(data) {
|
|
971
800
|
return this.transport.send(data);
|
|
972
801
|
}
|
|
973
|
-
/** Sends an event.
|
|
974
|
-
*
|
|
975
|
-
* @param {String} name
|
|
976
|
-
* @param {String} data
|
|
977
|
-
* @param {String} [channel]
|
|
978
|
-
* @returns {Boolean} whether message was sent or not
|
|
979
|
-
*/
|
|
980
802
|
send_event(name, data, channel) {
|
|
981
803
|
var event = { event: name, data };
|
|
982
804
|
if (channel) {
|
|
@@ -985,11 +807,6 @@ class Connection extends Dispatcher {
|
|
|
985
807
|
Logger$1.debug("Event sent", event);
|
|
986
808
|
return this.send(Protocol.encodeMessage(event));
|
|
987
809
|
}
|
|
988
|
-
/** Sends a ping message to the server.
|
|
989
|
-
*
|
|
990
|
-
* Basing on the underlying transport, it might send either transport's
|
|
991
|
-
* protocol-specific ping or pusher:ping event.
|
|
992
|
-
*/
|
|
993
810
|
ping() {
|
|
994
811
|
if (this.transport.supportsPing()) {
|
|
995
812
|
this.transport.ping();
|
|
@@ -997,7 +814,6 @@ class Connection extends Dispatcher {
|
|
|
997
814
|
this.send_event("pusher:ping", {});
|
|
998
815
|
}
|
|
999
816
|
}
|
|
1000
|
-
/** Closes the connection. */
|
|
1001
817
|
close() {
|
|
1002
818
|
this.transport.close();
|
|
1003
819
|
}
|
|
@@ -1113,9 +929,7 @@ class Handshake {
|
|
|
1113
929
|
this.transport.unbind("closed", this.onClosed);
|
|
1114
930
|
}
|
|
1115
931
|
finish(action, params) {
|
|
1116
|
-
this.callback(
|
|
1117
|
-
extend({ transport: this.transport, action }, params)
|
|
1118
|
-
);
|
|
932
|
+
this.callback(extend({ transport: this.transport, action }, params));
|
|
1119
933
|
}
|
|
1120
934
|
}
|
|
1121
935
|
class TimelineSender {
|
|
@@ -1127,10 +941,7 @@ class TimelineSender {
|
|
|
1127
941
|
if (this.timeline.isEmpty()) {
|
|
1128
942
|
return;
|
|
1129
943
|
}
|
|
1130
|
-
this.timeline.send(
|
|
1131
|
-
NodeJS.TimelineTransport.getAgent(this, useTLS),
|
|
1132
|
-
callback
|
|
1133
|
-
);
|
|
944
|
+
this.timeline.send(NodeJS.TimelineTransport.getAgent(this, useTLS), callback);
|
|
1134
945
|
}
|
|
1135
946
|
}
|
|
1136
947
|
class BadEventName extends Error {
|
|
@@ -1205,14 +1016,16 @@ const urlStore = {
|
|
|
1205
1016
|
const buildLogSuffix = function(key) {
|
|
1206
1017
|
const urlPrefix = "See:";
|
|
1207
1018
|
const urlObj = urlStore.urls[key];
|
|
1208
|
-
if (!urlObj)
|
|
1019
|
+
if (!urlObj)
|
|
1020
|
+
return "";
|
|
1209
1021
|
let url;
|
|
1210
1022
|
if (urlObj.fullUrl) {
|
|
1211
1023
|
url = urlObj.fullUrl;
|
|
1212
1024
|
} else if (urlObj.path) {
|
|
1213
1025
|
url = urlStore.baseUrl + urlObj.path;
|
|
1214
1026
|
}
|
|
1215
|
-
if (!url)
|
|
1027
|
+
if (!url)
|
|
1028
|
+
return "";
|
|
1216
1029
|
return `${urlPrefix} ${url}`;
|
|
1217
1030
|
};
|
|
1218
1031
|
const UrlStore = { buildLogSuffix };
|
|
@@ -1228,37 +1041,23 @@ class Channel extends Dispatcher {
|
|
|
1228
1041
|
this.subscriptionCancelled = false;
|
|
1229
1042
|
this.tagsFilter = null;
|
|
1230
1043
|
}
|
|
1231
|
-
/** Skips authorization, since public channels don't require it.
|
|
1232
|
-
*
|
|
1233
|
-
* @param {Function} callback
|
|
1234
|
-
*/
|
|
1235
1044
|
authorize(socketId, callback) {
|
|
1236
1045
|
return callback(null, { auth: "" });
|
|
1237
1046
|
}
|
|
1238
|
-
/** Triggers an event */
|
|
1239
1047
|
trigger(event, data) {
|
|
1240
1048
|
if (event.indexOf("client-") !== 0) {
|
|
1241
|
-
throw new BadEventName(
|
|
1242
|
-
"Event '" + event + "' does not start with 'client-'"
|
|
1243
|
-
);
|
|
1049
|
+
throw new BadEventName("Event '" + event + "' does not start with 'client-'");
|
|
1244
1050
|
}
|
|
1245
1051
|
if (!this.subscribed) {
|
|
1246
1052
|
var suffix = UrlStore.buildLogSuffix("triggeringClientEvents");
|
|
1247
|
-
Logger$1.warn(
|
|
1248
|
-
`Client event triggered before channel 'subscription_succeeded' event . ${suffix}`
|
|
1249
|
-
);
|
|
1053
|
+
Logger$1.warn(`Client event triggered before channel 'subscription_succeeded' event . ${suffix}`);
|
|
1250
1054
|
}
|
|
1251
1055
|
return this.pusher.send_event(event, data, this.name);
|
|
1252
1056
|
}
|
|
1253
|
-
/** Signals disconnection to the channel. For internal use only. */
|
|
1254
1057
|
disconnect() {
|
|
1255
1058
|
this.subscribed = false;
|
|
1256
1059
|
this.subscriptionPending = false;
|
|
1257
1060
|
}
|
|
1258
|
-
/** Handles a PusherEvent. For internal use only.
|
|
1259
|
-
*
|
|
1260
|
-
* @param {PusherEvent} event
|
|
1261
|
-
*/
|
|
1262
1061
|
handleEvent(event) {
|
|
1263
1062
|
var eventName = event.event;
|
|
1264
1063
|
var data = event.data;
|
|
@@ -1286,87 +1085,58 @@ class Channel extends Dispatcher {
|
|
|
1286
1085
|
}
|
|
1287
1086
|
this.emit("pusher:subscription_count", event.data);
|
|
1288
1087
|
}
|
|
1289
|
-
/** Sends a subscription request. For internal use only. */
|
|
1290
1088
|
subscribe() {
|
|
1291
1089
|
if (this.subscribed) {
|
|
1292
1090
|
return;
|
|
1293
1091
|
}
|
|
1294
1092
|
this.subscriptionPending = true;
|
|
1295
1093
|
this.subscriptionCancelled = false;
|
|
1296
|
-
this.authorize(
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
);
|
|
1313
|
-
} else {
|
|
1314
|
-
const subscribeData = {
|
|
1315
|
-
auth: data.auth,
|
|
1316
|
-
channel_data: data.channel_data,
|
|
1317
|
-
channel: this.name
|
|
1318
|
-
};
|
|
1319
|
-
if (this.tagsFilter) {
|
|
1320
|
-
subscribeData.tags_filter = this.tagsFilter;
|
|
1321
|
-
}
|
|
1322
|
-
this.pusher.send_event("pusher:subscribe", subscribeData);
|
|
1094
|
+
this.authorize(this.pusher.connection.socket_id, (error, data) => {
|
|
1095
|
+
if (error) {
|
|
1096
|
+
this.subscriptionPending = false;
|
|
1097
|
+
Logger$1.error(error.toString());
|
|
1098
|
+
this.emit("pusher:subscription_error", Object.assign({}, {
|
|
1099
|
+
type: "AuthError",
|
|
1100
|
+
error: error.message
|
|
1101
|
+
}, error instanceof HTTPAuthError ? { status: error.status } : {}));
|
|
1102
|
+
} else {
|
|
1103
|
+
const subscribeData = {
|
|
1104
|
+
auth: data.auth,
|
|
1105
|
+
channel_data: data.channel_data,
|
|
1106
|
+
channel: this.name
|
|
1107
|
+
};
|
|
1108
|
+
if (this.tagsFilter) {
|
|
1109
|
+
subscribeData.tags_filter = this.tagsFilter;
|
|
1323
1110
|
}
|
|
1111
|
+
this.pusher.send_event("pusher:subscribe", subscribeData);
|
|
1324
1112
|
}
|
|
1325
|
-
);
|
|
1113
|
+
});
|
|
1326
1114
|
}
|
|
1327
|
-
/** Sends an unsubscription request. For internal use only. */
|
|
1328
1115
|
unsubscribe() {
|
|
1329
1116
|
this.subscribed = false;
|
|
1330
1117
|
this.pusher.send_event("pusher:unsubscribe", {
|
|
1331
1118
|
channel: this.name
|
|
1332
1119
|
});
|
|
1333
1120
|
}
|
|
1334
|
-
/** Cancels an in progress subscription. For internal use only. */
|
|
1335
1121
|
cancelSubscription() {
|
|
1336
1122
|
this.subscriptionCancelled = true;
|
|
1337
1123
|
}
|
|
1338
|
-
/** Reinstates an in progress subscripiton. For internal use only. */
|
|
1339
1124
|
reinstateSubscription() {
|
|
1340
1125
|
this.subscriptionCancelled = false;
|
|
1341
1126
|
}
|
|
1342
1127
|
}
|
|
1343
1128
|
class PrivateChannel extends Channel {
|
|
1344
|
-
/** Authorizes the connection to use the channel.
|
|
1345
|
-
*
|
|
1346
|
-
* @param {String} socketId
|
|
1347
|
-
* @param {Function} callback
|
|
1348
|
-
*/
|
|
1349
1129
|
authorize(socketId, callback) {
|
|
1350
|
-
return this.pusher.config.channelAuthorizer(
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
},
|
|
1355
|
-
callback
|
|
1356
|
-
);
|
|
1130
|
+
return this.pusher.config.channelAuthorizer({
|
|
1131
|
+
channelName: this.name,
|
|
1132
|
+
socketId
|
|
1133
|
+
}, callback);
|
|
1357
1134
|
}
|
|
1358
1135
|
}
|
|
1359
1136
|
class Members {
|
|
1360
1137
|
constructor() {
|
|
1361
1138
|
this.reset();
|
|
1362
1139
|
}
|
|
1363
|
-
/** Returns member's info for given id.
|
|
1364
|
-
*
|
|
1365
|
-
* Resulting object containts two fields - id and info.
|
|
1366
|
-
*
|
|
1367
|
-
* @param {Number} id
|
|
1368
|
-
* @return {Object} member's info or null
|
|
1369
|
-
*/
|
|
1370
1140
|
get(id) {
|
|
1371
1141
|
if (Object.prototype.hasOwnProperty.call(this.members, id)) {
|
|
1372
1142
|
return {
|
|
@@ -1377,26 +1147,19 @@ class Members {
|
|
|
1377
1147
|
return null;
|
|
1378
1148
|
}
|
|
1379
1149
|
}
|
|
1380
|
-
/** Calls back for each member in unspecified order.
|
|
1381
|
-
*
|
|
1382
|
-
* @param {Function} callback
|
|
1383
|
-
*/
|
|
1384
1150
|
each(callback) {
|
|
1385
1151
|
objectApply(this.members, (member, id) => {
|
|
1386
1152
|
callback(this.get(id));
|
|
1387
1153
|
});
|
|
1388
1154
|
}
|
|
1389
|
-
/** Updates the id for connected member. For internal use only. */
|
|
1390
1155
|
setMyID(id) {
|
|
1391
1156
|
this.myID = id;
|
|
1392
1157
|
}
|
|
1393
|
-
/** Handles subscription data. For internal use only. */
|
|
1394
1158
|
onSubscription(subscriptionData) {
|
|
1395
1159
|
this.members = subscriptionData.presence.hash;
|
|
1396
1160
|
this.count = subscriptionData.presence.count;
|
|
1397
1161
|
this.me = this.get(this.myID);
|
|
1398
1162
|
}
|
|
1399
|
-
/** Adds a new member to the collection. For internal use only. */
|
|
1400
1163
|
addMember(memberData) {
|
|
1401
1164
|
if (this.get(memberData.user_id) === null) {
|
|
1402
1165
|
this.count++;
|
|
@@ -1404,7 +1167,6 @@ class Members {
|
|
|
1404
1167
|
this.members[memberData.user_id] = memberData.user_info;
|
|
1405
1168
|
return this.get(memberData.user_id);
|
|
1406
1169
|
}
|
|
1407
|
-
/** Adds a member from the collection. For internal use only. */
|
|
1408
1170
|
removeMember(memberData) {
|
|
1409
1171
|
var member = this.get(memberData.user_id);
|
|
1410
1172
|
if (member) {
|
|
@@ -1413,7 +1175,6 @@ class Members {
|
|
|
1413
1175
|
}
|
|
1414
1176
|
return member;
|
|
1415
1177
|
}
|
|
1416
|
-
/** Resets the collection to the initial state. For internal use only. */
|
|
1417
1178
|
reset() {
|
|
1418
1179
|
this.members = {};
|
|
1419
1180
|
this.count = 0;
|
|
@@ -1421,49 +1182,60 @@ class Members {
|
|
|
1421
1182
|
this.me = null;
|
|
1422
1183
|
}
|
|
1423
1184
|
}
|
|
1185
|
+
var __awaiter = function(thisArg, _arguments, P, generator) {
|
|
1186
|
+
function adopt(value) {
|
|
1187
|
+
return value instanceof P ? value : new P(function(resolve) {
|
|
1188
|
+
resolve(value);
|
|
1189
|
+
});
|
|
1190
|
+
}
|
|
1191
|
+
return new (P || (P = Promise))(function(resolve, reject) {
|
|
1192
|
+
function fulfilled(value) {
|
|
1193
|
+
try {
|
|
1194
|
+
step(generator.next(value));
|
|
1195
|
+
} catch (e) {
|
|
1196
|
+
reject(e);
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
function rejected(value) {
|
|
1200
|
+
try {
|
|
1201
|
+
step(generator["throw"](value));
|
|
1202
|
+
} catch (e) {
|
|
1203
|
+
reject(e);
|
|
1204
|
+
}
|
|
1205
|
+
}
|
|
1206
|
+
function step(result) {
|
|
1207
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
1208
|
+
}
|
|
1209
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
1210
|
+
});
|
|
1211
|
+
};
|
|
1424
1212
|
class PresenceChannel extends PrivateChannel {
|
|
1425
|
-
/** Adds presence channel functionality to private channels.
|
|
1426
|
-
*
|
|
1427
|
-
* @param {String} name
|
|
1428
|
-
* @param {Pusher} pusher
|
|
1429
|
-
*/
|
|
1430
1213
|
constructor(name, pusher) {
|
|
1431
1214
|
super(name, pusher);
|
|
1432
1215
|
this.members = new Members();
|
|
1433
1216
|
}
|
|
1434
|
-
/** Authorizes the connection as a member of the channel.
|
|
1435
|
-
*
|
|
1436
|
-
* @param {String} socketId
|
|
1437
|
-
* @param {Function} callback
|
|
1438
|
-
*/
|
|
1439
1217
|
authorize(socketId, callback) {
|
|
1440
|
-
super.authorize(socketId,
|
|
1218
|
+
super.authorize(socketId, (error, authData) => __awaiter(this, void 0, void 0, function* () {
|
|
1441
1219
|
if (!error) {
|
|
1442
1220
|
authData = authData;
|
|
1443
1221
|
if (authData.channel_data != null) {
|
|
1444
1222
|
var channelData = JSON.parse(authData.channel_data);
|
|
1445
1223
|
this.members.setMyID(channelData.user_id);
|
|
1446
1224
|
} else {
|
|
1447
|
-
|
|
1225
|
+
yield this.pusher.user.signinDonePromise;
|
|
1448
1226
|
if (this.pusher.user.user_data != null) {
|
|
1449
1227
|
this.members.setMyID(this.pusher.user.user_data.id);
|
|
1450
1228
|
} else {
|
|
1451
1229
|
let suffix = UrlStore.buildLogSuffix("authorizationEndpoint");
|
|
1452
|
-
Logger$1.error(
|
|
1453
|
-
`Invalid auth response for channel '${this.name}', expected 'channel_data' field. ${suffix}, or the user should be signed in.`
|
|
1454
|
-
);
|
|
1230
|
+
Logger$1.error(`Invalid auth response for channel '${this.name}', expected 'channel_data' field. ${suffix}, or the user should be signed in.`);
|
|
1455
1231
|
callback("Invalid auth response");
|
|
1456
1232
|
return;
|
|
1457
1233
|
}
|
|
1458
1234
|
}
|
|
1459
1235
|
}
|
|
1460
1236
|
callback(error, authData);
|
|
1461
|
-
});
|
|
1237
|
+
}));
|
|
1462
1238
|
}
|
|
1463
|
-
/** Handles presence and subscription events. For internal use only.
|
|
1464
|
-
*
|
|
1465
|
-
* @param {PusherEvent} event
|
|
1466
|
-
*/
|
|
1467
1239
|
handleEvent(event) {
|
|
1468
1240
|
var eventName = event.event;
|
|
1469
1241
|
if (eventName.indexOf("pusher_internal:") === 0) {
|
|
@@ -1509,56 +1281,36 @@ class PresenceChannel extends PrivateChannel {
|
|
|
1509
1281
|
this.emit("pusher:subscription_succeeded", this.members);
|
|
1510
1282
|
}
|
|
1511
1283
|
}
|
|
1512
|
-
/** Resets the channel state, including members map. For internal use only. */
|
|
1513
1284
|
disconnect() {
|
|
1514
1285
|
this.members.reset();
|
|
1515
1286
|
super.disconnect();
|
|
1516
1287
|
}
|
|
1517
1288
|
}
|
|
1518
1289
|
class EncryptedChannel extends PrivateChannel {
|
|
1519
|
-
constructor(name, pusher,
|
|
1290
|
+
constructor(name, pusher, nacl) {
|
|
1520
1291
|
super(name, pusher);
|
|
1521
1292
|
this.key = null;
|
|
1522
|
-
this.nacl =
|
|
1293
|
+
this.nacl = nacl;
|
|
1523
1294
|
}
|
|
1524
|
-
/** Authorizes the connection to use the channel.
|
|
1525
|
-
*
|
|
1526
|
-
* @param {String} socketId
|
|
1527
|
-
* @param {Function} callback
|
|
1528
|
-
*/
|
|
1529
1295
|
authorize(socketId, callback) {
|
|
1530
|
-
super.authorize(
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
callback(error, authData);
|
|
1535
|
-
return;
|
|
1536
|
-
}
|
|
1537
|
-
let sharedSecret = authData["shared_secret"];
|
|
1538
|
-
if (!sharedSecret) {
|
|
1539
|
-
callback(
|
|
1540
|
-
new Error(
|
|
1541
|
-
`No shared_secret key in auth payload for encrypted channel: ${this.name}`
|
|
1542
|
-
),
|
|
1543
|
-
null
|
|
1544
|
-
);
|
|
1545
|
-
return;
|
|
1546
|
-
}
|
|
1547
|
-
this.key = base64.decode(sharedSecret);
|
|
1548
|
-
delete authData["shared_secret"];
|
|
1549
|
-
callback(null, authData);
|
|
1296
|
+
super.authorize(socketId, (error, authData) => {
|
|
1297
|
+
if (error) {
|
|
1298
|
+
callback(error, authData);
|
|
1299
|
+
return;
|
|
1550
1300
|
}
|
|
1551
|
-
|
|
1301
|
+
let sharedSecret = authData["shared_secret"];
|
|
1302
|
+
if (!sharedSecret) {
|
|
1303
|
+
callback(new Error(`No shared_secret key in auth payload for encrypted channel: ${this.name}`), null);
|
|
1304
|
+
return;
|
|
1305
|
+
}
|
|
1306
|
+
this.key = base64.decode(sharedSecret);
|
|
1307
|
+
delete authData["shared_secret"];
|
|
1308
|
+
callback(null, authData);
|
|
1309
|
+
});
|
|
1552
1310
|
}
|
|
1553
1311
|
trigger(event, data) {
|
|
1554
|
-
throw new UnsupportedFeature(
|
|
1555
|
-
|
|
1556
|
-
);
|
|
1557
|
-
}
|
|
1558
|
-
/** Handles an event. For internal use only.
|
|
1559
|
-
*
|
|
1560
|
-
* @param {PusherEvent} event
|
|
1561
|
-
*/
|
|
1312
|
+
throw new UnsupportedFeature("Client events are not currently supported for encrypted channels");
|
|
1313
|
+
}
|
|
1562
1314
|
handleEvent(event) {
|
|
1563
1315
|
var eventName = event.event;
|
|
1564
1316
|
var data = event.data;
|
|
@@ -1570,48 +1322,34 @@ class EncryptedChannel extends PrivateChannel {
|
|
|
1570
1322
|
}
|
|
1571
1323
|
handleEncryptedEvent(event, data) {
|
|
1572
1324
|
if (!this.key) {
|
|
1573
|
-
Logger$1.debug(
|
|
1574
|
-
"Received encrypted event before key has been retrieved from the authEndpoint"
|
|
1575
|
-
);
|
|
1325
|
+
Logger$1.debug("Received encrypted event before key has been retrieved from the authEndpoint");
|
|
1576
1326
|
return;
|
|
1577
1327
|
}
|
|
1578
1328
|
if (!data.ciphertext || !data.nonce) {
|
|
1579
|
-
Logger$1.error(
|
|
1580
|
-
"Unexpected format for encrypted event, expected object with `ciphertext` and `nonce` fields, got: " + data
|
|
1581
|
-
);
|
|
1329
|
+
Logger$1.error("Unexpected format for encrypted event, expected object with `ciphertext` and `nonce` fields, got: " + data);
|
|
1582
1330
|
return;
|
|
1583
1331
|
}
|
|
1584
1332
|
let cipherText = base64.decode(data.ciphertext);
|
|
1585
1333
|
if (cipherText.length < this.nacl.secretbox.overheadLength) {
|
|
1586
|
-
Logger$1.error(
|
|
1587
|
-
`Expected encrypted event ciphertext length to be ${this.nacl.secretbox.overheadLength}, got: ${cipherText.length}`
|
|
1588
|
-
);
|
|
1334
|
+
Logger$1.error(`Expected encrypted event ciphertext length to be ${this.nacl.secretbox.overheadLength}, got: ${cipherText.length}`);
|
|
1589
1335
|
return;
|
|
1590
1336
|
}
|
|
1591
1337
|
let nonce = base64.decode(data.nonce);
|
|
1592
1338
|
if (nonce.length < this.nacl.secretbox.nonceLength) {
|
|
1593
|
-
Logger$1.error(
|
|
1594
|
-
`Expected encrypted event nonce length to be ${this.nacl.secretbox.nonceLength}, got: ${nonce.length}`
|
|
1595
|
-
);
|
|
1339
|
+
Logger$1.error(`Expected encrypted event nonce length to be ${this.nacl.secretbox.nonceLength}, got: ${nonce.length}`);
|
|
1596
1340
|
return;
|
|
1597
1341
|
}
|
|
1598
1342
|
let bytes = this.nacl.secretbox.open(cipherText, nonce, this.key);
|
|
1599
1343
|
if (bytes === null) {
|
|
1600
|
-
Logger$1.debug(
|
|
1601
|
-
"Failed to decrypt an event, probably because it was encrypted with a different key. Fetching a new key from the authEndpoint..."
|
|
1602
|
-
);
|
|
1344
|
+
Logger$1.debug("Failed to decrypt an event, probably because it was encrypted with a different key. Fetching a new key from the authEndpoint...");
|
|
1603
1345
|
this.authorize(this.pusher.connection.socket_id, (error, authData) => {
|
|
1604
1346
|
if (error) {
|
|
1605
|
-
Logger$1.error(
|
|
1606
|
-
`Failed to make a request to the authEndpoint: ${authData}. Unable to fetch new key, so dropping encrypted event`
|
|
1607
|
-
);
|
|
1347
|
+
Logger$1.error(`Failed to make a request to the authEndpoint: ${authData}. Unable to fetch new key, so dropping encrypted event`);
|
|
1608
1348
|
return;
|
|
1609
1349
|
}
|
|
1610
1350
|
bytes = this.nacl.secretbox.open(cipherText, nonce, this.key);
|
|
1611
1351
|
if (bytes === null) {
|
|
1612
|
-
Logger$1.error(
|
|
1613
|
-
`Failed to decrypt event with new key. Dropping encrypted event`
|
|
1614
|
-
);
|
|
1352
|
+
Logger$1.error(`Failed to decrypt event with new key. Dropping encrypted event`);
|
|
1615
1353
|
return;
|
|
1616
1354
|
}
|
|
1617
1355
|
this.emit(event, this.getDataToEmit(bytes));
|
|
@@ -1621,13 +1359,11 @@ class EncryptedChannel extends PrivateChannel {
|
|
|
1621
1359
|
}
|
|
1622
1360
|
this.emit(event, this.getDataToEmit(bytes));
|
|
1623
1361
|
}
|
|
1624
|
-
// Try and parse the decrypted bytes as JSON. If we can't parse it, just
|
|
1625
|
-
// return the utf-8 string
|
|
1626
1362
|
getDataToEmit(bytes) {
|
|
1627
1363
|
let raw = utf8.decode(bytes);
|
|
1628
1364
|
try {
|
|
1629
1365
|
return JSON.parse(raw);
|
|
1630
|
-
} catch {
|
|
1366
|
+
} catch (_a) {
|
|
1631
1367
|
return raw;
|
|
1632
1368
|
}
|
|
1633
1369
|
}
|
|
@@ -1642,9 +1378,7 @@ class ConnectionManager extends Dispatcher {
|
|
|
1642
1378
|
this.timeline = this.options.timeline;
|
|
1643
1379
|
this.usingTLS = this.options.useTLS;
|
|
1644
1380
|
this.errorCallbacks = this.buildErrorCallbacks();
|
|
1645
|
-
this.connectionCallbacks = this.buildConnectionCallbacks(
|
|
1646
|
-
this.errorCallbacks
|
|
1647
|
-
);
|
|
1381
|
+
this.connectionCallbacks = this.buildConnectionCallbacks(this.errorCallbacks);
|
|
1648
1382
|
this.handshakeCallbacks = this.buildHandshakeCallbacks(this.errorCallbacks);
|
|
1649
1383
|
var Network2 = NodeJS.getNetwork();
|
|
1650
1384
|
Network2.bind("online", () => {
|
|
@@ -1661,11 +1395,6 @@ class ConnectionManager extends Dispatcher {
|
|
|
1661
1395
|
});
|
|
1662
1396
|
this.updateStrategy();
|
|
1663
1397
|
}
|
|
1664
|
-
/** Establishes a connection to Pusher.
|
|
1665
|
-
*
|
|
1666
|
-
* Does nothing when connection is already established. See top-level doc
|
|
1667
|
-
* to find events emitted on connection attempts.
|
|
1668
|
-
*/
|
|
1669
1398
|
connect() {
|
|
1670
1399
|
if (this.connection || this.runner) {
|
|
1671
1400
|
return;
|
|
@@ -1678,10 +1407,6 @@ class ConnectionManager extends Dispatcher {
|
|
|
1678
1407
|
this.startConnecting();
|
|
1679
1408
|
this.setUnavailableTimer();
|
|
1680
1409
|
}
|
|
1681
|
-
/** Sends raw data.
|
|
1682
|
-
*
|
|
1683
|
-
* @param {String} data
|
|
1684
|
-
*/
|
|
1685
1410
|
send(data) {
|
|
1686
1411
|
if (this.connection) {
|
|
1687
1412
|
return this.connection.send(data);
|
|
@@ -1689,13 +1414,6 @@ class ConnectionManager extends Dispatcher {
|
|
|
1689
1414
|
return false;
|
|
1690
1415
|
}
|
|
1691
1416
|
}
|
|
1692
|
-
/** Sends an event.
|
|
1693
|
-
*
|
|
1694
|
-
* @param {String} name
|
|
1695
|
-
* @param {String} data
|
|
1696
|
-
* @param {String} [channel]
|
|
1697
|
-
* @returns {Boolean} whether message was sent or not
|
|
1698
|
-
*/
|
|
1699
1417
|
send_event(name, data, channel) {
|
|
1700
1418
|
if (this.connection) {
|
|
1701
1419
|
return this.connection.send_event(name, data, channel);
|
|
@@ -1703,7 +1421,6 @@ class ConnectionManager extends Dispatcher {
|
|
|
1703
1421
|
return false;
|
|
1704
1422
|
}
|
|
1705
1423
|
}
|
|
1706
|
-
/** Closes the connection. */
|
|
1707
1424
|
disconnect() {
|
|
1708
1425
|
this.disconnectInternally();
|
|
1709
1426
|
this.updateState("disconnected");
|
|
@@ -1825,11 +1542,7 @@ class ConnectionManager extends Dispatcher {
|
|
|
1825
1542
|
buildHandshakeCallbacks(errorCallbacks) {
|
|
1826
1543
|
return extend({}, errorCallbacks, {
|
|
1827
1544
|
connected: (handshake) => {
|
|
1828
|
-
this.activityTimeout = Math.min(
|
|
1829
|
-
this.options.activityTimeout,
|
|
1830
|
-
handshake.activityTimeout,
|
|
1831
|
-
handshake.connection.activityTimeout || Infinity
|
|
1832
|
-
);
|
|
1545
|
+
this.activityTimeout = Math.min(this.options.activityTimeout, handshake.activityTimeout, handshake.connection.activityTimeout || Infinity);
|
|
1833
1546
|
this.clearUnavailableTimer();
|
|
1834
1547
|
this.setConnection(handshake.connection);
|
|
1835
1548
|
this.socket_id = this.connection.id;
|
|
@@ -1890,10 +1603,7 @@ class ConnectionManager extends Dispatcher {
|
|
|
1890
1603
|
if (newStateDescription === "connected") {
|
|
1891
1604
|
newStateDescription += " with new socket ID " + data.socket_id;
|
|
1892
1605
|
}
|
|
1893
|
-
Logger$1.debug(
|
|
1894
|
-
"State changed",
|
|
1895
|
-
previousState + " -> " + newStateDescription
|
|
1896
|
-
);
|
|
1606
|
+
Logger$1.debug("State changed", previousState + " -> " + newStateDescription);
|
|
1897
1607
|
this.timeline.info({ state: newState, params: data });
|
|
1898
1608
|
this.emit("state_change", { previous: previousState, current: newState });
|
|
1899
1609
|
this.emit(newState, data);
|
|
@@ -1907,43 +1617,23 @@ class Channels {
|
|
|
1907
1617
|
constructor() {
|
|
1908
1618
|
this.channels = {};
|
|
1909
1619
|
}
|
|
1910
|
-
/** Creates or retrieves an existing channel by its name.
|
|
1911
|
-
*
|
|
1912
|
-
* @param {String} name
|
|
1913
|
-
* @param {Pusher} pusher
|
|
1914
|
-
* @return {Channel}
|
|
1915
|
-
*/
|
|
1916
1620
|
add(name, pusher) {
|
|
1917
1621
|
if (!this.channels[name]) {
|
|
1918
1622
|
this.channels[name] = createChannel(name, pusher);
|
|
1919
1623
|
}
|
|
1920
1624
|
return this.channels[name];
|
|
1921
1625
|
}
|
|
1922
|
-
/** Returns a list of all channels
|
|
1923
|
-
*
|
|
1924
|
-
* @return {Array}
|
|
1925
|
-
*/
|
|
1926
1626
|
all() {
|
|
1927
1627
|
return values(this.channels);
|
|
1928
1628
|
}
|
|
1929
|
-
/** Finds a channel by its name.
|
|
1930
|
-
*
|
|
1931
|
-
* @param {String} name
|
|
1932
|
-
* @return {Channel} channel or null if it doesn't exist
|
|
1933
|
-
*/
|
|
1934
1629
|
find(name) {
|
|
1935
1630
|
return this.channels[name];
|
|
1936
1631
|
}
|
|
1937
|
-
/** Removes a channel from the map.
|
|
1938
|
-
*
|
|
1939
|
-
* @param {String} name
|
|
1940
|
-
*/
|
|
1941
1632
|
remove(name) {
|
|
1942
1633
|
var channel = this.channels[name];
|
|
1943
1634
|
delete this.channels[name];
|
|
1944
1635
|
return channel;
|
|
1945
1636
|
}
|
|
1946
|
-
/** Proxies disconnection signal to all channels. */
|
|
1947
1637
|
disconnect() {
|
|
1948
1638
|
objectApply(this.channels, function(channel) {
|
|
1949
1639
|
channel.disconnect();
|
|
@@ -1963,9 +1653,7 @@ function createChannel(name, pusher) {
|
|
|
1963
1653
|
} else if (name.indexOf("presence-") === 0) {
|
|
1964
1654
|
return Factory.createPresenceChannel(name, pusher);
|
|
1965
1655
|
} else if (name.indexOf("#") === 0) {
|
|
1966
|
-
throw new BadChannelName(
|
|
1967
|
-
'Cannot create a channel with name "' + name + '".'
|
|
1968
|
-
);
|
|
1656
|
+
throw new BadChannelName('Cannot create a channel with name "' + name + '".');
|
|
1969
1657
|
} else {
|
|
1970
1658
|
return Factory.createChannel(name, pusher);
|
|
1971
1659
|
}
|
|
@@ -1986,8 +1674,8 @@ var Factory = {
|
|
|
1986
1674
|
createPresenceChannel(name, pusher) {
|
|
1987
1675
|
return new PresenceChannel(name, pusher);
|
|
1988
1676
|
},
|
|
1989
|
-
createEncryptedChannel(name, pusher,
|
|
1990
|
-
return new EncryptedChannel(name, pusher,
|
|
1677
|
+
createEncryptedChannel(name, pusher, nacl) {
|
|
1678
|
+
return new EncryptedChannel(name, pusher, nacl);
|
|
1991
1679
|
},
|
|
1992
1680
|
createTimelineSender(timeline, options) {
|
|
1993
1681
|
return new TimelineSender(timeline, options);
|
|
@@ -2004,25 +1692,15 @@ class TransportManager {
|
|
|
2004
1692
|
this.options = options || {};
|
|
2005
1693
|
this.livesLeft = this.options.lives || Infinity;
|
|
2006
1694
|
}
|
|
2007
|
-
/** Creates a assistant for the transport.
|
|
2008
|
-
*
|
|
2009
|
-
* @param {Transport} transport
|
|
2010
|
-
* @returns {AssistantToTheTransportManager}
|
|
2011
|
-
*/
|
|
2012
1695
|
getAssistant(transport) {
|
|
2013
1696
|
return Factory.createAssistantToTheTransportManager(this, transport, {
|
|
2014
1697
|
minPingDelay: this.options.minPingDelay,
|
|
2015
1698
|
maxPingDelay: this.options.maxPingDelay
|
|
2016
1699
|
});
|
|
2017
1700
|
}
|
|
2018
|
-
/** Returns whether the transport has any lives left.
|
|
2019
|
-
*
|
|
2020
|
-
* @returns {Boolean}
|
|
2021
|
-
*/
|
|
2022
1701
|
isAlive() {
|
|
2023
1702
|
return this.livesLeft > 0;
|
|
2024
1703
|
}
|
|
2025
|
-
/** Takes one life from the transport. */
|
|
2026
1704
|
reportDeath() {
|
|
2027
1705
|
this.livesLeft -= 1;
|
|
2028
1706
|
}
|
|
@@ -2058,23 +1736,13 @@ class SequentialStrategy {
|
|
|
2058
1736
|
timeout = Math.min(timeout, this.timeoutLimit);
|
|
2059
1737
|
}
|
|
2060
1738
|
}
|
|
2061
|
-
runner = this.tryStrategy(
|
|
2062
|
-
strategies[current],
|
|
2063
|
-
minPriority,
|
|
2064
|
-
{ timeout, failFast: this.failFast },
|
|
2065
|
-
tryNextStrategy
|
|
2066
|
-
);
|
|
1739
|
+
runner = this.tryStrategy(strategies[current], minPriority, { timeout, failFast: this.failFast }, tryNextStrategy);
|
|
2067
1740
|
} else {
|
|
2068
1741
|
callback(true);
|
|
2069
1742
|
}
|
|
2070
1743
|
}
|
|
2071
1744
|
};
|
|
2072
|
-
runner = this.tryStrategy(
|
|
2073
|
-
strategies[current],
|
|
2074
|
-
minPriority,
|
|
2075
|
-
{ timeout, failFast: this.failFast },
|
|
2076
|
-
tryNextStrategy
|
|
2077
|
-
);
|
|
1745
|
+
runner = this.tryStrategy(strategies[current], minPriority, { timeout, failFast: this.failFast }, tryNextStrategy);
|
|
2078
1746
|
return {
|
|
2079
1747
|
abort: function() {
|
|
2080
1748
|
runner.abort();
|
|
@@ -2194,12 +1862,10 @@ class WebSocketPrioritizedCachedStrategy {
|
|
|
2194
1862
|
transport: info.transport,
|
|
2195
1863
|
latency: info.latency
|
|
2196
1864
|
});
|
|
2197
|
-
strategies.push(
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
})
|
|
2202
|
-
);
|
|
1865
|
+
strategies.push(new SequentialStrategy([transport], {
|
|
1866
|
+
timeout: info.latency * 2 + 1e3,
|
|
1867
|
+
failFast: true
|
|
1868
|
+
}));
|
|
2203
1869
|
} else {
|
|
2204
1870
|
cacheSkipCount++;
|
|
2205
1871
|
}
|
|
@@ -2216,12 +1882,7 @@ class WebSocketPrioritizedCachedStrategy {
|
|
|
2216
1882
|
callback(error);
|
|
2217
1883
|
}
|
|
2218
1884
|
} else {
|
|
2219
|
-
storeTransportCache(
|
|
2220
|
-
usingTLS,
|
|
2221
|
-
handshake.transport.name,
|
|
2222
|
-
Util.now() - startTimestamp,
|
|
2223
|
-
cacheSkipCount
|
|
2224
|
-
);
|
|
1885
|
+
storeTransportCache(usingTLS, handshake.transport.name, Util.now() - startTimestamp, cacheSkipCount);
|
|
2225
1886
|
callback(null, handshake);
|
|
2226
1887
|
}
|
|
2227
1888
|
});
|
|
@@ -2331,15 +1992,12 @@ class FirstConnectedStrategy {
|
|
|
2331
1992
|
return this.strategy.isSupported();
|
|
2332
1993
|
}
|
|
2333
1994
|
connect(minPriority, callback) {
|
|
2334
|
-
var runner = this.strategy.connect(
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
if (handshake) {
|
|
2338
|
-
runner.abort();
|
|
2339
|
-
}
|
|
2340
|
-
callback(error, handshake);
|
|
1995
|
+
var runner = this.strategy.connect(minPriority, function(error, handshake) {
|
|
1996
|
+
if (handshake) {
|
|
1997
|
+
runner.abort();
|
|
2341
1998
|
}
|
|
2342
|
-
|
|
1999
|
+
callback(error, handshake);
|
|
2000
|
+
});
|
|
2343
2001
|
return runner;
|
|
2344
2002
|
}
|
|
2345
2003
|
}
|
|
@@ -2351,14 +2009,7 @@ function testSupportsStrategy(strategy) {
|
|
|
2351
2009
|
var getDefaultStrategy$1 = function(config2, baseOptions, defineTransport2) {
|
|
2352
2010
|
var definedTransports = {};
|
|
2353
2011
|
function defineTransportStrategy(name, type, priority, options, manager) {
|
|
2354
|
-
var transport = defineTransport2(
|
|
2355
|
-
config2,
|
|
2356
|
-
name,
|
|
2357
|
-
type,
|
|
2358
|
-
priority,
|
|
2359
|
-
options,
|
|
2360
|
-
manager
|
|
2361
|
-
);
|
|
2012
|
+
var transport = defineTransport2(config2, name, type, priority, options, manager);
|
|
2362
2013
|
definedTransports[name] = transport;
|
|
2363
2014
|
return transport;
|
|
2364
2015
|
}
|
|
@@ -2389,53 +2040,20 @@ var getDefaultStrategy$1 = function(config2, baseOptions, defineTransport2) {
|
|
|
2389
2040
|
minPingDelay: 1e4,
|
|
2390
2041
|
maxPingDelay: config2.activityTimeout
|
|
2391
2042
|
});
|
|
2392
|
-
var ws_transport = defineTransportStrategy(
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
ws_options,
|
|
2397
|
-
ws_manager
|
|
2398
|
-
);
|
|
2399
|
-
var wss_transport = defineTransportStrategy(
|
|
2400
|
-
"wss",
|
|
2401
|
-
"ws",
|
|
2402
|
-
3,
|
|
2403
|
-
wss_options,
|
|
2404
|
-
ws_manager
|
|
2405
|
-
);
|
|
2406
|
-
var xhr_streaming_transport = defineTransportStrategy(
|
|
2407
|
-
"xhr_streaming",
|
|
2408
|
-
"xhr_streaming",
|
|
2409
|
-
1,
|
|
2410
|
-
http_options,
|
|
2411
|
-
streaming_manager
|
|
2412
|
-
);
|
|
2413
|
-
var xhr_polling_transport = defineTransportStrategy(
|
|
2414
|
-
"xhr_polling",
|
|
2415
|
-
"xhr_polling",
|
|
2416
|
-
1,
|
|
2417
|
-
http_options
|
|
2418
|
-
);
|
|
2043
|
+
var ws_transport = defineTransportStrategy("ws", "ws", 3, ws_options, ws_manager);
|
|
2044
|
+
var wss_transport = defineTransportStrategy("wss", "ws", 3, wss_options, ws_manager);
|
|
2045
|
+
var xhr_streaming_transport = defineTransportStrategy("xhr_streaming", "xhr_streaming", 1, http_options, streaming_manager);
|
|
2046
|
+
var xhr_polling_transport = defineTransportStrategy("xhr_polling", "xhr_polling", 1, http_options);
|
|
2419
2047
|
var ws_loop = new SequentialStrategy([ws_transport], timeouts);
|
|
2420
2048
|
var wss_loop = new SequentialStrategy([wss_transport], timeouts);
|
|
2421
|
-
var streaming_loop = new SequentialStrategy(
|
|
2422
|
-
[xhr_streaming_transport],
|
|
2423
|
-
timeouts
|
|
2424
|
-
);
|
|
2049
|
+
var streaming_loop = new SequentialStrategy([xhr_streaming_transport], timeouts);
|
|
2425
2050
|
var polling_loop = new SequentialStrategy([xhr_polling_transport], timeouts);
|
|
2426
|
-
var http_loop = new SequentialStrategy(
|
|
2427
|
-
[
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
new DelayedStrategy(polling_loop, { delay: 4e3 })
|
|
2433
|
-
]),
|
|
2434
|
-
polling_loop
|
|
2435
|
-
)
|
|
2436
|
-
],
|
|
2437
|
-
timeouts
|
|
2438
|
-
);
|
|
2051
|
+
var http_loop = new SequentialStrategy([
|
|
2052
|
+
new IfStrategy(testSupportsStrategy(streaming_loop), new BestConnectedEverStrategy([
|
|
2053
|
+
streaming_loop,
|
|
2054
|
+
new DelayedStrategy(polling_loop, { delay: 4e3 })
|
|
2055
|
+
]), polling_loop)
|
|
2056
|
+
], timeouts);
|
|
2439
2057
|
var wsStrategy;
|
|
2440
2058
|
if (baseOptions.useTLS) {
|
|
2441
2059
|
wsStrategy = new BestConnectedEverStrategy([
|
|
@@ -2449,25 +2067,17 @@ var getDefaultStrategy$1 = function(config2, baseOptions, defineTransport2) {
|
|
|
2449
2067
|
new DelayedStrategy(http_loop, { delay: 5e3 })
|
|
2450
2068
|
]);
|
|
2451
2069
|
}
|
|
2452
|
-
return new WebSocketPrioritizedCachedStrategy(
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
{
|
|
2458
|
-
ttl: 18e5,
|
|
2459
|
-
timeline: baseOptions.timeline,
|
|
2460
|
-
useTLS: baseOptions.useTLS
|
|
2461
|
-
}
|
|
2462
|
-
);
|
|
2070
|
+
return new WebSocketPrioritizedCachedStrategy(new FirstConnectedStrategy(new IfStrategy(testSupportsStrategy(ws_transport), wsStrategy, http_loop)), definedTransports, {
|
|
2071
|
+
ttl: 18e5,
|
|
2072
|
+
timeline: baseOptions.timeline,
|
|
2073
|
+
useTLS: baseOptions.useTLS
|
|
2074
|
+
});
|
|
2463
2075
|
};
|
|
2464
2076
|
function transportConnectionInitializer$1() {
|
|
2465
2077
|
var self = this;
|
|
2466
|
-
self.timeline.info(
|
|
2467
|
-
self.
|
|
2468
|
-
|
|
2469
|
-
})
|
|
2470
|
-
);
|
|
2078
|
+
self.timeline.info(self.buildTimelineMessage({
|
|
2079
|
+
transport: self.name + (self.options.useTLS ? "s" : "")
|
|
2080
|
+
}));
|
|
2471
2081
|
if (self.hooks.isInitialized()) {
|
|
2472
2082
|
self.changeState("initialized");
|
|
2473
2083
|
} else {
|
|
@@ -2532,19 +2142,20 @@ class HTTPRequest extends Dispatcher {
|
|
|
2532
2142
|
return this.position === buffer.length && buffer.length > MAX_BUFFER_LENGTH;
|
|
2533
2143
|
}
|
|
2534
2144
|
}
|
|
2535
|
-
var State
|
|
2145
|
+
var State;
|
|
2146
|
+
(function(State2) {
|
|
2536
2147
|
State2[State2["CONNECTING"] = 0] = "CONNECTING";
|
|
2537
2148
|
State2[State2["OPEN"] = 1] = "OPEN";
|
|
2538
2149
|
State2[State2["CLOSED"] = 3] = "CLOSED";
|
|
2539
|
-
|
|
2540
|
-
|
|
2150
|
+
})(State || (State = {}));
|
|
2151
|
+
const State$1 = State;
|
|
2541
2152
|
var autoIncrement = 1;
|
|
2542
2153
|
class HTTPSocket {
|
|
2543
2154
|
constructor(hooks2, url) {
|
|
2544
2155
|
this.hooks = hooks2;
|
|
2545
2156
|
this.session = randomNumber(1e3) + "/" + randomString(8);
|
|
2546
2157
|
this.location = getLocation(url);
|
|
2547
|
-
this.readyState = State.CONNECTING;
|
|
2158
|
+
this.readyState = State$1.CONNECTING;
|
|
2548
2159
|
this.openStream();
|
|
2549
2160
|
}
|
|
2550
2161
|
send(payload) {
|
|
@@ -2556,14 +2167,10 @@ class HTTPSocket {
|
|
|
2556
2167
|
close(code, reason) {
|
|
2557
2168
|
this.onClose(code, reason, true);
|
|
2558
2169
|
}
|
|
2559
|
-
/** For internal use only */
|
|
2560
2170
|
sendRaw(payload) {
|
|
2561
|
-
if (this.readyState === State.OPEN) {
|
|
2171
|
+
if (this.readyState === State$1.OPEN) {
|
|
2562
2172
|
try {
|
|
2563
|
-
NodeJS.createSocketRequest(
|
|
2564
|
-
"POST",
|
|
2565
|
-
getUniqueURL(getSendURL(this.location, this.session))
|
|
2566
|
-
).start(payload);
|
|
2173
|
+
NodeJS.createSocketRequest("POST", getUniqueURL(getSendURL(this.location, this.session))).start(payload);
|
|
2567
2174
|
return true;
|
|
2568
2175
|
} catch (e) {
|
|
2569
2176
|
return false;
|
|
@@ -2572,15 +2179,13 @@ class HTTPSocket {
|
|
|
2572
2179
|
return false;
|
|
2573
2180
|
}
|
|
2574
2181
|
}
|
|
2575
|
-
/** For internal use only */
|
|
2576
2182
|
reconnect() {
|
|
2577
2183
|
this.closeStream();
|
|
2578
2184
|
this.openStream();
|
|
2579
2185
|
}
|
|
2580
|
-
/** For internal use only */
|
|
2581
2186
|
onClose(code, reason, wasClean) {
|
|
2582
2187
|
this.closeStream();
|
|
2583
|
-
this.readyState = State.CLOSED;
|
|
2188
|
+
this.readyState = State$1.CLOSED;
|
|
2584
2189
|
if (this.onclose) {
|
|
2585
2190
|
this.onclose({
|
|
2586
2191
|
code,
|
|
@@ -2593,7 +2198,7 @@ class HTTPSocket {
|
|
|
2593
2198
|
if (chunk.status !== 200) {
|
|
2594
2199
|
return;
|
|
2595
2200
|
}
|
|
2596
|
-
if (this.readyState === State.OPEN) {
|
|
2201
|
+
if (this.readyState === State$1.OPEN) {
|
|
2597
2202
|
this.onActivity();
|
|
2598
2203
|
}
|
|
2599
2204
|
var payload;
|
|
@@ -2623,11 +2228,11 @@ class HTTPSocket {
|
|
|
2623
2228
|
}
|
|
2624
2229
|
}
|
|
2625
2230
|
onOpen(options) {
|
|
2626
|
-
if (this.readyState === State.CONNECTING) {
|
|
2231
|
+
if (this.readyState === State$1.CONNECTING) {
|
|
2627
2232
|
if (options && options.hostname) {
|
|
2628
2233
|
this.location.base = replaceHost(this.location.base, options.hostname);
|
|
2629
2234
|
}
|
|
2630
|
-
this.readyState = State.OPEN;
|
|
2235
|
+
this.readyState = State$1.OPEN;
|
|
2631
2236
|
if (this.onopen) {
|
|
2632
2237
|
this.onopen();
|
|
2633
2238
|
}
|
|
@@ -2636,7 +2241,7 @@ class HTTPSocket {
|
|
|
2636
2241
|
}
|
|
2637
2242
|
}
|
|
2638
2243
|
onEvent(event) {
|
|
2639
|
-
if (this.readyState === State.OPEN && this.onmessage) {
|
|
2244
|
+
if (this.readyState === State$1.OPEN && this.onmessage) {
|
|
2640
2245
|
this.onmessage({ data: event });
|
|
2641
2246
|
}
|
|
2642
2247
|
}
|
|
@@ -2651,10 +2256,7 @@ class HTTPSocket {
|
|
|
2651
2256
|
}
|
|
2652
2257
|
}
|
|
2653
2258
|
openStream() {
|
|
2654
|
-
this.stream = NodeJS.createSocketRequest(
|
|
2655
|
-
"POST",
|
|
2656
|
-
getUniqueURL(this.hooks.getReceiveURL(this.location, this.session))
|
|
2657
|
-
);
|
|
2259
|
+
this.stream = NodeJS.createSocketRequest("POST", getUniqueURL(this.hooks.getReceiveURL(this.location, this.session)));
|
|
2658
2260
|
this.stream.bind("chunk", (chunk) => {
|
|
2659
2261
|
this.onChunk(chunk);
|
|
2660
2262
|
});
|
|
@@ -2796,11 +2398,9 @@ var Isomorphic = {
|
|
|
2796
2398
|
return void 0;
|
|
2797
2399
|
},
|
|
2798
2400
|
getClientFeatures() {
|
|
2799
|
-
return keys(
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
})
|
|
2803
|
-
);
|
|
2401
|
+
return keys(filterObject({ ws: Transports$2.ws }, function(t) {
|
|
2402
|
+
return t.isSupported({});
|
|
2403
|
+
}));
|
|
2804
2404
|
},
|
|
2805
2405
|
getProtocol() {
|
|
2806
2406
|
return "http:";
|
|
@@ -2834,11 +2434,11 @@ class NetInfo extends Dispatcher {
|
|
|
2834
2434
|
}
|
|
2835
2435
|
}
|
|
2836
2436
|
var Network = new NetInfo();
|
|
2837
|
-
var AuthRequestType
|
|
2437
|
+
var AuthRequestType;
|
|
2438
|
+
(function(AuthRequestType2) {
|
|
2838
2439
|
AuthRequestType2["UserAuthentication"] = "user-authentication";
|
|
2839
2440
|
AuthRequestType2["ChannelAuthorization"] = "channel-authorization";
|
|
2840
|
-
|
|
2841
|
-
})(AuthRequestType || {});
|
|
2441
|
+
})(AuthRequestType || (AuthRequestType = {}));
|
|
2842
2442
|
const ajax = function(context, query, authOptions, authRequestType, callback) {
|
|
2843
2443
|
const xhr2 = NodeJS.createXHR();
|
|
2844
2444
|
xhr2.open("POST", authOptions.endpoint, true);
|
|
@@ -2861,13 +2461,7 @@ const ajax = function(context, query, authOptions, authRequestType, callback) {
|
|
|
2861
2461
|
data = JSON.parse(xhr2.responseText);
|
|
2862
2462
|
parsed = true;
|
|
2863
2463
|
} catch (e) {
|
|
2864
|
-
callback(
|
|
2865
|
-
new HTTPAuthError(
|
|
2866
|
-
200,
|
|
2867
|
-
`JSON returned from ${authRequestType.toString()} endpoint was invalid, yet status code was 200. Data was: ${xhr2.responseText}`
|
|
2868
|
-
),
|
|
2869
|
-
null
|
|
2870
|
-
);
|
|
2464
|
+
callback(new HTTPAuthError(200, `JSON returned from ${authRequestType.toString()} endpoint was invalid, yet status code was 200. Data was: ${xhr2.responseText}`), null);
|
|
2871
2465
|
}
|
|
2872
2466
|
if (parsed) {
|
|
2873
2467
|
callback(null, data);
|
|
@@ -2879,18 +2473,10 @@ const ajax = function(context, query, authOptions, authRequestType, callback) {
|
|
|
2879
2473
|
suffix = UrlStore.buildLogSuffix("authenticationEndpoint");
|
|
2880
2474
|
break;
|
|
2881
2475
|
case AuthRequestType.ChannelAuthorization:
|
|
2882
|
-
suffix = `Clients must be authorized to join private or presence channels. ${UrlStore.buildLogSuffix(
|
|
2883
|
-
"authorizationEndpoint"
|
|
2884
|
-
)}`;
|
|
2476
|
+
suffix = `Clients must be authorized to join private or presence channels. ${UrlStore.buildLogSuffix("authorizationEndpoint")}`;
|
|
2885
2477
|
break;
|
|
2886
2478
|
}
|
|
2887
|
-
callback(
|
|
2888
|
-
new HTTPAuthError(
|
|
2889
|
-
xhr2.status,
|
|
2890
|
-
`Unable to retrieve auth string from ${authRequestType.toString()} endpoint - received status: ${xhr2.status} from ${authOptions.endpoint}. ${suffix}`
|
|
2891
|
-
),
|
|
2892
|
-
null
|
|
2893
|
-
);
|
|
2479
|
+
callback(new HTTPAuthError(xhr2.status, `Unable to retrieve auth string from ${authRequestType.toString()} endpoint - received status: ${xhr2.status} from ${authOptions.endpoint}. ${suffix}`), null);
|
|
2894
2480
|
}
|
|
2895
2481
|
}
|
|
2896
2482
|
};
|
|
@@ -2909,9 +2495,7 @@ var getAgent = function(sender, useTLS) {
|
|
|
2909
2495
|
if (xhr2.readyState === 4) {
|
|
2910
2496
|
let { status, responseText } = xhr2;
|
|
2911
2497
|
if (status !== 200) {
|
|
2912
|
-
Logger$1.debug(
|
|
2913
|
-
`TimelineSender Error: received ${status} from stats.pusher.com`
|
|
2914
|
-
);
|
|
2498
|
+
Logger$1.debug(`TimelineSender Error: received ${status} from stats.pusher.com`);
|
|
2915
2499
|
return;
|
|
2916
2500
|
}
|
|
2917
2501
|
try {
|
|
@@ -2977,12 +2561,13 @@ const NodeJS = {
|
|
|
2977
2561
|
return crypto.randomInt(max);
|
|
2978
2562
|
}
|
|
2979
2563
|
};
|
|
2980
|
-
var TimelineLevel
|
|
2564
|
+
var TimelineLevel;
|
|
2565
|
+
(function(TimelineLevel2) {
|
|
2981
2566
|
TimelineLevel2[TimelineLevel2["ERROR"] = 3] = "ERROR";
|
|
2982
2567
|
TimelineLevel2[TimelineLevel2["INFO"] = 6] = "INFO";
|
|
2983
2568
|
TimelineLevel2[TimelineLevel2["DEBUG"] = 7] = "DEBUG";
|
|
2984
|
-
|
|
2985
|
-
|
|
2569
|
+
})(TimelineLevel || (TimelineLevel = {}));
|
|
2570
|
+
const TimelineLevel$1 = TimelineLevel;
|
|
2986
2571
|
class Timeline {
|
|
2987
2572
|
constructor(key, session, options) {
|
|
2988
2573
|
this.key = key;
|
|
@@ -2994,40 +2579,35 @@ class Timeline {
|
|
|
2994
2579
|
}
|
|
2995
2580
|
log(level, event) {
|
|
2996
2581
|
if (level <= this.options.level) {
|
|
2997
|
-
this.events.push(
|
|
2998
|
-
extend({}, event, { timestamp: Util.now() })
|
|
2999
|
-
);
|
|
2582
|
+
this.events.push(extend({}, event, { timestamp: Util.now() }));
|
|
3000
2583
|
if (this.options.limit && this.events.length > this.options.limit) {
|
|
3001
2584
|
this.events.shift();
|
|
3002
2585
|
}
|
|
3003
2586
|
}
|
|
3004
2587
|
}
|
|
3005
2588
|
error(event) {
|
|
3006
|
-
this.log(TimelineLevel.ERROR, event);
|
|
2589
|
+
this.log(TimelineLevel$1.ERROR, event);
|
|
3007
2590
|
}
|
|
3008
2591
|
info(event) {
|
|
3009
|
-
this.log(TimelineLevel.INFO, event);
|
|
2592
|
+
this.log(TimelineLevel$1.INFO, event);
|
|
3010
2593
|
}
|
|
3011
2594
|
debug(event) {
|
|
3012
|
-
this.log(TimelineLevel.DEBUG, event);
|
|
2595
|
+
this.log(TimelineLevel$1.DEBUG, event);
|
|
3013
2596
|
}
|
|
3014
2597
|
isEmpty() {
|
|
3015
2598
|
return this.events.length === 0;
|
|
3016
2599
|
}
|
|
3017
2600
|
send(sendfn, callback) {
|
|
3018
|
-
var data = extend(
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
},
|
|
3029
|
-
this.options.params
|
|
3030
|
-
);
|
|
2601
|
+
var data = extend({
|
|
2602
|
+
session: this.session,
|
|
2603
|
+
bundle: this.sent + 1,
|
|
2604
|
+
key: this.key,
|
|
2605
|
+
lib: "js",
|
|
2606
|
+
version: this.options.version,
|
|
2607
|
+
cluster: this.options.cluster,
|
|
2608
|
+
features: this.options.features,
|
|
2609
|
+
timeline: this.events
|
|
2610
|
+
}, this.options.params);
|
|
3031
2611
|
this.events = [];
|
|
3032
2612
|
sendfn(data, (error, result) => {
|
|
3033
2613
|
if (!error) {
|
|
@@ -3051,20 +2631,11 @@ class TransportStrategy {
|
|
|
3051
2631
|
this.transport = transport;
|
|
3052
2632
|
this.options = options || {};
|
|
3053
2633
|
}
|
|
3054
|
-
/** Returns whether the transport is supported in the browser.
|
|
3055
|
-
*
|
|
3056
|
-
* @returns {Boolean}
|
|
3057
|
-
*/
|
|
3058
2634
|
isSupported() {
|
|
3059
2635
|
return this.transport.isSupported({
|
|
3060
2636
|
useTLS: this.options.useTLS
|
|
3061
2637
|
});
|
|
3062
2638
|
}
|
|
3063
|
-
/** Launches a connection attempt and returns a strategy runner.
|
|
3064
|
-
*
|
|
3065
|
-
* @param {Function} callback
|
|
3066
|
-
* @return {Object} strategy runner
|
|
3067
|
-
*/
|
|
3068
2639
|
connect(minPriority, callback) {
|
|
3069
2640
|
if (!this.isSupported()) {
|
|
3070
2641
|
return failAttempt(new UnsupportedStrategy$1(), callback);
|
|
@@ -3072,12 +2643,7 @@ class TransportStrategy {
|
|
|
3072
2643
|
return failAttempt(new TransportPriorityTooLow(), callback);
|
|
3073
2644
|
}
|
|
3074
2645
|
var connected = false;
|
|
3075
|
-
var transport = this.transport.createConnection(
|
|
3076
|
-
this.name,
|
|
3077
|
-
this.priority,
|
|
3078
|
-
this.options.key,
|
|
3079
|
-
this.options
|
|
3080
|
-
);
|
|
2646
|
+
var transport = this.transport.createConnection(this.name, this.priority, this.options.key, this.options);
|
|
3081
2647
|
var handshake = null;
|
|
3082
2648
|
var onInitialized = function() {
|
|
3083
2649
|
transport.unbind("initialized", onInitialized);
|
|
@@ -3158,16 +2724,8 @@ var defineTransport = function(config2, name, type, priority, options, manager)
|
|
|
3158
2724
|
var enabled = (!config2.enabledTransports || arrayIndexOf(config2.enabledTransports, name) !== -1) && (!config2.disabledTransports || arrayIndexOf(config2.disabledTransports, name) === -1);
|
|
3159
2725
|
var transport;
|
|
3160
2726
|
if (enabled) {
|
|
3161
|
-
options = Object.assign(
|
|
3162
|
-
|
|
3163
|
-
options
|
|
3164
|
-
);
|
|
3165
|
-
transport = new TransportStrategy(
|
|
3166
|
-
name,
|
|
3167
|
-
priority,
|
|
3168
|
-
manager ? manager.getAssistant(transportClass) : transportClass,
|
|
3169
|
-
options
|
|
3170
|
-
);
|
|
2727
|
+
options = Object.assign({ ignoreNullOrigin: config2.ignoreNullOrigin }, options);
|
|
2728
|
+
transport = new TransportStrategy(name, priority, manager ? manager.getAssistant(transportClass) : transportClass, options);
|
|
3171
2729
|
} else {
|
|
3172
2730
|
transport = UnsupportedStrategy2;
|
|
3173
2731
|
}
|
|
@@ -3198,9 +2756,7 @@ function validateOptions(options) {
|
|
|
3198
2756
|
throw "Options object must provide a cluster";
|
|
3199
2757
|
}
|
|
3200
2758
|
if ("disableStats" in options) {
|
|
3201
|
-
Logger$1.warn(
|
|
3202
|
-
"The disableStats option is deprecated in favor of enableStats"
|
|
3203
|
-
);
|
|
2759
|
+
Logger$1.warn("The disableStats option is deprecated in favor of enableStats");
|
|
3204
2760
|
}
|
|
3205
2761
|
}
|
|
3206
2762
|
const composeChannelQuery$1 = (params, authOptions) => {
|
|
@@ -3222,13 +2778,7 @@ const UserAuthenticator = (authOptions) => {
|
|
|
3222
2778
|
}
|
|
3223
2779
|
return (params, callback) => {
|
|
3224
2780
|
const query = composeChannelQuery$1(params, authOptions);
|
|
3225
|
-
NodeJS.getAuthorizers()[authOptions.transport](
|
|
3226
|
-
NodeJS,
|
|
3227
|
-
query,
|
|
3228
|
-
authOptions,
|
|
3229
|
-
AuthRequestType.UserAuthentication,
|
|
3230
|
-
callback
|
|
3231
|
-
);
|
|
2781
|
+
NodeJS.getAuthorizers()[authOptions.transport](NodeJS, query, authOptions, AuthRequestType.UserAuthentication, callback);
|
|
3232
2782
|
};
|
|
3233
2783
|
};
|
|
3234
2784
|
const composeChannelQuery = (params, authOptions) => {
|
|
@@ -3251,13 +2801,7 @@ const ChannelAuthorizer = (authOptions) => {
|
|
|
3251
2801
|
}
|
|
3252
2802
|
return (params, callback) => {
|
|
3253
2803
|
const query = composeChannelQuery(params, authOptions);
|
|
3254
|
-
NodeJS.getAuthorizers()[authOptions.transport](
|
|
3255
|
-
NodeJS,
|
|
3256
|
-
query,
|
|
3257
|
-
authOptions,
|
|
3258
|
-
AuthRequestType.ChannelAuthorization,
|
|
3259
|
-
callback
|
|
3260
|
-
);
|
|
2804
|
+
NodeJS.getAuthorizers()[authOptions.transport](NodeJS, query, authOptions, AuthRequestType.ChannelAuthorization, callback);
|
|
3261
2805
|
};
|
|
3262
2806
|
};
|
|
3263
2807
|
const ChannelAuthorizerProxy = (pusher, authOptions, channelAuthorizerGenerator) => {
|
|
@@ -3301,7 +2845,8 @@ function getConfig(opts, pusher) {
|
|
|
3301
2845
|
config2.enabledTransports = opts.enabledTransports;
|
|
3302
2846
|
if ("ignoreNullOrigin" in opts)
|
|
3303
2847
|
config2.ignoreNullOrigin = opts.ignoreNullOrigin;
|
|
3304
|
-
if ("timelineParams" in opts)
|
|
2848
|
+
if ("timelineParams" in opts)
|
|
2849
|
+
config2.timelineParams = opts.timelineParams;
|
|
3305
2850
|
if ("nacl" in opts) {
|
|
3306
2851
|
config2.nacl = opts.nacl;
|
|
3307
2852
|
}
|
|
@@ -3343,10 +2888,7 @@ function getEnableStatsConfig(opts) {
|
|
|
3343
2888
|
return false;
|
|
3344
2889
|
}
|
|
3345
2890
|
function buildUserAuthenticator(opts) {
|
|
3346
|
-
const userAuthentication = {
|
|
3347
|
-
...Defaults.userAuthentication,
|
|
3348
|
-
...opts.userAuthentication
|
|
3349
|
-
};
|
|
2891
|
+
const userAuthentication = Object.assign(Object.assign({}, Defaults.userAuthentication), opts.userAuthentication);
|
|
3350
2892
|
if ("customHandler" in userAuthentication && userAuthentication["customHandler"] != null) {
|
|
3351
2893
|
return userAuthentication["customHandler"];
|
|
3352
2894
|
}
|
|
@@ -3355,26 +2897,20 @@ function buildUserAuthenticator(opts) {
|
|
|
3355
2897
|
function buildChannelAuth(opts, pusher) {
|
|
3356
2898
|
let channelAuthorization;
|
|
3357
2899
|
if ("channelAuthorization" in opts) {
|
|
3358
|
-
channelAuthorization = {
|
|
3359
|
-
...Defaults.channelAuthorization,
|
|
3360
|
-
...opts.channelAuthorization
|
|
3361
|
-
};
|
|
2900
|
+
channelAuthorization = Object.assign(Object.assign({}, Defaults.channelAuthorization), opts.channelAuthorization);
|
|
3362
2901
|
} else {
|
|
3363
2902
|
channelAuthorization = {
|
|
3364
2903
|
transport: opts.authTransport || Defaults.authTransport,
|
|
3365
2904
|
endpoint: opts.authEndpoint || Defaults.authEndpoint
|
|
3366
2905
|
};
|
|
3367
2906
|
if ("auth" in opts) {
|
|
3368
|
-
if ("params" in opts.auth)
|
|
2907
|
+
if ("params" in opts.auth)
|
|
2908
|
+
channelAuthorization.params = opts.auth.params;
|
|
3369
2909
|
if ("headers" in opts.auth)
|
|
3370
2910
|
channelAuthorization.headers = opts.auth.headers;
|
|
3371
2911
|
}
|
|
3372
2912
|
if ("authorizer" in opts)
|
|
3373
|
-
channelAuthorization.customHandler = ChannelAuthorizerProxy(
|
|
3374
|
-
pusher,
|
|
3375
|
-
channelAuthorization,
|
|
3376
|
-
opts.authorizer
|
|
3377
|
-
);
|
|
2913
|
+
channelAuthorization.customHandler = ChannelAuthorizerProxy(pusher, channelAuthorization, opts.authorizer);
|
|
3378
2914
|
}
|
|
3379
2915
|
return channelAuthorization;
|
|
3380
2916
|
}
|
|
@@ -3472,12 +3008,9 @@ class UserFacade extends Dispatcher {
|
|
|
3472
3008
|
if (this.pusher.connection.state !== "connected") {
|
|
3473
3009
|
return;
|
|
3474
3010
|
}
|
|
3475
|
-
this.pusher.config.userAuthenticator(
|
|
3476
|
-
|
|
3477
|
-
|
|
3478
|
-
},
|
|
3479
|
-
this._onAuthorize
|
|
3480
|
-
);
|
|
3011
|
+
this.pusher.config.userAuthenticator({
|
|
3012
|
+
socketId: this.pusher.connection.socket_id
|
|
3013
|
+
}, this._onAuthorize);
|
|
3481
3014
|
}
|
|
3482
3015
|
_onSigninSuccess(data) {
|
|
3483
3016
|
try {
|
|
@@ -3488,9 +3021,7 @@ class UserFacade extends Dispatcher {
|
|
|
3488
3021
|
return;
|
|
3489
3022
|
}
|
|
3490
3023
|
if (typeof this.user_data.id !== "string" || this.user_data.id === "") {
|
|
3491
|
-
Logger$1.error(
|
|
3492
|
-
`user_data doesn't contain an id. user_data: ${this.user_data}`
|
|
3493
|
-
);
|
|
3024
|
+
Logger$1.error(`user_data doesn't contain an id. user_data: ${this.user_data}`);
|
|
3494
3025
|
this._cleanup();
|
|
3495
3026
|
return;
|
|
3496
3027
|
}
|
|
@@ -3505,10 +3036,7 @@ class UserFacade extends Dispatcher {
|
|
|
3505
3036
|
channel.subscribe();
|
|
3506
3037
|
}
|
|
3507
3038
|
};
|
|
3508
|
-
this.serverToUserChannel = new Channel(
|
|
3509
|
-
`#server-to-user-${this.user_data.id}`,
|
|
3510
|
-
this.pusher
|
|
3511
|
-
);
|
|
3039
|
+
this.serverToUserChannel = new Channel(`#server-to-user-${this.user_data.id}`, this.pusher);
|
|
3512
3040
|
this.serverToUserChannel.bind_global((eventName, data) => {
|
|
3513
3041
|
if (eventName.indexOf("pusher_internal:") === 0 || eventName.indexOf("pusher:") === 0) {
|
|
3514
3042
|
return;
|
|
@@ -3549,7 +3077,7 @@ class ChannelState {
|
|
|
3549
3077
|
constructor(channelName) {
|
|
3550
3078
|
this.channelName = channelName;
|
|
3551
3079
|
this.conflationKey = null;
|
|
3552
|
-
this.maxMessagesPerKey =
|
|
3080
|
+
this.maxMessagesPerKey = 30;
|
|
3553
3081
|
this.conflationCaches = /* @__PURE__ */ new Map();
|
|
3554
3082
|
this.baseMessage = null;
|
|
3555
3083
|
this.baseSequence = null;
|
|
@@ -3557,12 +3085,9 @@ class ChannelState {
|
|
|
3557
3085
|
this.deltaCount = 0;
|
|
3558
3086
|
this.fullMessageCount = 0;
|
|
3559
3087
|
}
|
|
3560
|
-
/**
|
|
3561
|
-
* Initialize cache from server sync
|
|
3562
|
-
*/
|
|
3563
3088
|
initializeFromCacheSync(data) {
|
|
3564
3089
|
this.conflationKey = data.conflation_key || null;
|
|
3565
|
-
this.maxMessagesPerKey = data.max_messages_per_key || 10;
|
|
3090
|
+
this.maxMessagesPerKey = Math.max(data.max_messages_per_key || 10, 30);
|
|
3566
3091
|
this.conflationCaches.clear();
|
|
3567
3092
|
if (data.states) {
|
|
3568
3093
|
for (const [key, messages] of Object.entries(data.states)) {
|
|
@@ -3574,18 +3099,11 @@ class ChannelState {
|
|
|
3574
3099
|
}
|
|
3575
3100
|
}
|
|
3576
3101
|
}
|
|
3577
|
-
/**
|
|
3578
|
-
* Set new base message (legacy - for non-conflation channels)
|
|
3579
|
-
*/
|
|
3580
3102
|
setBase(message, sequence) {
|
|
3581
3103
|
this.baseMessage = message;
|
|
3582
3104
|
this.baseSequence = sequence;
|
|
3583
3105
|
this.lastSequence = sequence;
|
|
3584
3106
|
}
|
|
3585
|
-
/**
|
|
3586
|
-
* Get base message for a conflation key at specific index
|
|
3587
|
-
* Note: baseIndex is the sequence number, not array index
|
|
3588
|
-
*/
|
|
3589
3107
|
getBaseMessage(conflationKeyValue, baseIndex) {
|
|
3590
3108
|
if (!this.conflationKey) {
|
|
3591
3109
|
return this.baseMessage;
|
|
@@ -3613,9 +3131,6 @@ class ChannelState {
|
|
|
3613
3131
|
}
|
|
3614
3132
|
return message.content;
|
|
3615
3133
|
}
|
|
3616
|
-
/**
|
|
3617
|
-
* Add or update message in conflation cache
|
|
3618
|
-
*/
|
|
3619
3134
|
updateConflationCache(conflationKeyValue, message, sequence) {
|
|
3620
3135
|
const key = conflationKeyValue || "";
|
|
3621
3136
|
let cache = this.conflationCaches.get(key);
|
|
@@ -3623,56 +3138,32 @@ class ChannelState {
|
|
|
3623
3138
|
cache = [];
|
|
3624
3139
|
this.conflationCaches.set(key, cache);
|
|
3625
3140
|
}
|
|
3626
|
-
if (cache.length > 0) {
|
|
3627
|
-
const lastCacheItem = cache[cache.length - 1];
|
|
3628
|
-
if (sequence <= lastCacheItem.sequence) {
|
|
3629
|
-
cache.length = 0;
|
|
3630
|
-
}
|
|
3631
|
-
}
|
|
3632
3141
|
cache.push({ content: message, sequence });
|
|
3633
3142
|
while (cache.length > this.maxMessagesPerKey) {
|
|
3634
3143
|
cache.shift();
|
|
3635
3144
|
}
|
|
3636
3145
|
}
|
|
3637
|
-
/**
|
|
3638
|
-
* Check if we have a valid base
|
|
3639
|
-
*/
|
|
3640
3146
|
hasBase() {
|
|
3641
3147
|
if (this.conflationKey) {
|
|
3642
3148
|
return this.conflationCaches.size > 0;
|
|
3643
3149
|
}
|
|
3644
3150
|
return this.baseMessage !== null && this.baseSequence !== null;
|
|
3645
3151
|
}
|
|
3646
|
-
/**
|
|
3647
|
-
* Validate sequence number
|
|
3648
|
-
*/
|
|
3649
3152
|
isValidSequence(sequence) {
|
|
3650
3153
|
if (this.lastSequence === null) {
|
|
3651
3154
|
return true;
|
|
3652
3155
|
}
|
|
3653
3156
|
return sequence > this.lastSequence;
|
|
3654
3157
|
}
|
|
3655
|
-
/**
|
|
3656
|
-
* Update sequence after processing a message
|
|
3657
|
-
*/
|
|
3658
3158
|
updateSequence(sequence) {
|
|
3659
3159
|
this.lastSequence = sequence;
|
|
3660
3160
|
}
|
|
3661
|
-
/**
|
|
3662
|
-
* Record delta received
|
|
3663
|
-
*/
|
|
3664
3161
|
recordDelta() {
|
|
3665
3162
|
this.deltaCount++;
|
|
3666
3163
|
}
|
|
3667
|
-
/**
|
|
3668
|
-
* Record full message received
|
|
3669
|
-
*/
|
|
3670
3164
|
recordFullMessage() {
|
|
3671
3165
|
this.fullMessageCount++;
|
|
3672
3166
|
}
|
|
3673
|
-
/**
|
|
3674
|
-
* Get statistics
|
|
3675
|
-
*/
|
|
3676
3167
|
getStats() {
|
|
3677
3168
|
return {
|
|
3678
3169
|
channelName: this.channelName,
|
|
@@ -3724,9 +3215,7 @@ class FossilDeltaDecoder {
|
|
|
3724
3215
|
}
|
|
3725
3216
|
return bytesToString(result);
|
|
3726
3217
|
} catch (error) {
|
|
3727
|
-
throw new Error(
|
|
3728
|
-
`Fossil delta decode failed: ${error.message} (base=${baseBytes.length}B delta=${deltaBytes.length}B)`
|
|
3729
|
-
);
|
|
3218
|
+
throw new Error(`Fossil delta decode failed: ${error.message} (base=${baseBytes.length}B delta=${deltaBytes.length}B)`);
|
|
3730
3219
|
}
|
|
3731
3220
|
}
|
|
3732
3221
|
}
|
|
@@ -3751,14 +3240,13 @@ class Xdelta3Decoder {
|
|
|
3751
3240
|
}
|
|
3752
3241
|
return bytesToString(result);
|
|
3753
3242
|
} catch (error) {
|
|
3754
|
-
throw new Error(
|
|
3755
|
-
`Xdelta3 decode failed: ${error.message} (base=${baseBytes.length}B delta=${deltaBytes.length}B)`
|
|
3756
|
-
);
|
|
3243
|
+
throw new Error(`Xdelta3 decode failed: ${error.message} (base=${baseBytes.length}B delta=${deltaBytes.length}B)`);
|
|
3757
3244
|
}
|
|
3758
3245
|
}
|
|
3759
3246
|
}
|
|
3760
3247
|
class DeltaCompressionManager {
|
|
3761
3248
|
constructor(options = {}, sendEventCallback) {
|
|
3249
|
+
this.defaultAlgorithm = "fossil";
|
|
3762
3250
|
this.options = {
|
|
3763
3251
|
enabled: options.enabled !== false,
|
|
3764
3252
|
algorithms: options.algorithms || ["fossil", "xdelta3"],
|
|
@@ -3779,14 +3267,9 @@ class DeltaCompressionManager {
|
|
|
3779
3267
|
this.sendEventCallback = sendEventCallback;
|
|
3780
3268
|
this.availableAlgorithms = this.detectAvailableAlgorithms();
|
|
3781
3269
|
if (this.availableAlgorithms.length === 0) {
|
|
3782
|
-
Logger$1.warn(
|
|
3783
|
-
"[DeltaCompression] No delta algorithms available. Please include fossil-delta or vcdiff-decoder libraries."
|
|
3784
|
-
);
|
|
3270
|
+
Logger$1.warn("[DeltaCompression] No delta algorithms available. Please include fossil-delta or vcdiff-decoder libraries.");
|
|
3785
3271
|
}
|
|
3786
3272
|
}
|
|
3787
|
-
/**
|
|
3788
|
-
* Detect which algorithm libraries are loaded
|
|
3789
|
-
*/
|
|
3790
3273
|
detectAvailableAlgorithms() {
|
|
3791
3274
|
const available = [];
|
|
3792
3275
|
if (FossilDeltaDecoder.isAvailable()) {
|
|
@@ -3799,9 +3282,6 @@ class DeltaCompressionManager {
|
|
|
3799
3282
|
}
|
|
3800
3283
|
return available;
|
|
3801
3284
|
}
|
|
3802
|
-
/**
|
|
3803
|
-
* Enable delta compression
|
|
3804
|
-
*/
|
|
3805
3285
|
enable() {
|
|
3806
3286
|
if (this.enabled || !this.options.enabled) {
|
|
3807
3287
|
return;
|
|
@@ -3810,9 +3290,7 @@ class DeltaCompressionManager {
|
|
|
3810
3290
|
this.log("No delta algorithms available, cannot enable");
|
|
3811
3291
|
return;
|
|
3812
3292
|
}
|
|
3813
|
-
const supportedAlgorithms = this.availableAlgorithms.filter(
|
|
3814
|
-
(algo) => this.options.algorithms.includes(algo)
|
|
3815
|
-
);
|
|
3293
|
+
const supportedAlgorithms = this.availableAlgorithms.filter((algo) => this.options.algorithms.includes(algo));
|
|
3816
3294
|
if (supportedAlgorithms.length === 0) {
|
|
3817
3295
|
this.log("No mutually supported algorithms");
|
|
3818
3296
|
return;
|
|
@@ -3822,26 +3300,16 @@ class DeltaCompressionManager {
|
|
|
3822
3300
|
algorithms: supportedAlgorithms
|
|
3823
3301
|
});
|
|
3824
3302
|
}
|
|
3825
|
-
/**
|
|
3826
|
-
* Disable delta compression
|
|
3827
|
-
* Note: We intentionally do NOT clear channelStates here.
|
|
3828
|
-
* This allows state to be preserved across enable/disable cycles,
|
|
3829
|
-
* which is important for reconnection scenarios and user toggling.
|
|
3830
|
-
* Use clearChannelState() if you need to explicitly clear state.
|
|
3831
|
-
*/
|
|
3832
3303
|
disable() {
|
|
3833
3304
|
this.enabled = false;
|
|
3834
3305
|
}
|
|
3835
|
-
/**
|
|
3836
|
-
* Handle delta compression enabled confirmation
|
|
3837
|
-
*/
|
|
3838
3306
|
handleEnabled(data) {
|
|
3839
3307
|
this.enabled = data.enabled || true;
|
|
3308
|
+
if (data.algorithm) {
|
|
3309
|
+
this.defaultAlgorithm = data.algorithm;
|
|
3310
|
+
}
|
|
3840
3311
|
this.log("Delta compression enabled", data);
|
|
3841
3312
|
}
|
|
3842
|
-
/**
|
|
3843
|
-
* Handle cache sync message (conflation keys)
|
|
3844
|
-
*/
|
|
3845
3313
|
handleCacheSync(channel, data) {
|
|
3846
3314
|
this.log("Received cache sync", {
|
|
3847
3315
|
channel,
|
|
@@ -3856,16 +3324,14 @@ class DeltaCompressionManager {
|
|
|
3856
3324
|
channelState.initializeFromCacheSync(data);
|
|
3857
3325
|
this.log("Cache initialized", channelState.getStats());
|
|
3858
3326
|
}
|
|
3859
|
-
/**
|
|
3860
|
-
* Handle delta-compressed message
|
|
3861
|
-
*/
|
|
3862
3327
|
handleDeltaMessage(channel, deltaData) {
|
|
3328
|
+
var _a;
|
|
3863
3329
|
let deltaBytes = null;
|
|
3864
3330
|
try {
|
|
3865
3331
|
const event = deltaData.event;
|
|
3866
3332
|
const delta = deltaData.delta;
|
|
3867
3333
|
const sequence = deltaData.seq;
|
|
3868
|
-
const algorithm = deltaData.algorithm || "fossil";
|
|
3334
|
+
const algorithm = deltaData.algorithm || this.defaultAlgorithm || "fossil";
|
|
3869
3335
|
const conflationKey = deltaData.conflation_key;
|
|
3870
3336
|
const baseIndex = deltaData.base_index;
|
|
3871
3337
|
this.log("Received delta message", {
|
|
@@ -3886,44 +3352,27 @@ class DeltaCompressionManager {
|
|
|
3886
3352
|
if (channelState.conflationKey) {
|
|
3887
3353
|
baseMessage = channelState.getBaseMessage(conflationKey, baseIndex);
|
|
3888
3354
|
if (!baseMessage) {
|
|
3889
|
-
this.error(
|
|
3890
|
-
|
|
3891
|
-
{
|
|
3892
|
-
path: "conflation",
|
|
3355
|
+
this.error(`No base message for channel ${channel}, key ${conflationKey}, index ${baseIndex}`);
|
|
3356
|
+
if (this.options.debug) {
|
|
3357
|
+
this.log("Current conflation cache snapshot", {
|
|
3893
3358
|
channel,
|
|
3894
|
-
|
|
3895
|
-
|
|
3896
|
-
|
|
3897
|
-
|
|
3898
|
-
channelStateBaseMessage: channelState.baseMessage ? "exists" : null,
|
|
3899
|
-
channelStateBaseSequence: channelState.baseSequence,
|
|
3900
|
-
channelStateLastSequence: channelState.lastSequence,
|
|
3901
|
-
conflationCacheKeys: Array.from(channelState.conflationCaches.keys()),
|
|
3902
|
-
conflationCacheSizes: Array.from(
|
|
3903
|
-
channelState.conflationCaches.entries()
|
|
3904
|
-
).map(([key, cache]) => ({ key, size: cache.length }))
|
|
3905
|
-
}
|
|
3906
|
-
);
|
|
3359
|
+
conflationKey: channelState.conflationKey,
|
|
3360
|
+
cacheSizes: Array.from(channelState.conflationCaches.entries()).map(([key, cache]) => ({ key, size: cache.length }))
|
|
3361
|
+
});
|
|
3362
|
+
}
|
|
3907
3363
|
this.requestResync(channel);
|
|
3908
3364
|
return null;
|
|
3909
3365
|
}
|
|
3910
3366
|
} else {
|
|
3911
3367
|
baseMessage = channelState.baseMessage;
|
|
3912
3368
|
if (!baseMessage) {
|
|
3913
|
-
this.error(
|
|
3914
|
-
|
|
3915
|
-
{
|
|
3916
|
-
path: "legacy",
|
|
3369
|
+
this.error(`No base message for channel ${channel}`);
|
|
3370
|
+
if (this.options.debug) {
|
|
3371
|
+
this.log("Channel state missing base", {
|
|
3917
3372
|
channel,
|
|
3918
|
-
|
|
3919
|
-
|
|
3920
|
-
|
|
3921
|
-
channelStateConflationKey: channelState.conflationKey,
|
|
3922
|
-
channelStateBaseMessage: null,
|
|
3923
|
-
channelStateBaseSequence: channelState.baseSequence,
|
|
3924
|
-
channelStateLastSequence: channelState.lastSequence
|
|
3925
|
-
}
|
|
3926
|
-
);
|
|
3373
|
+
lastSequence: channelState.lastSequence
|
|
3374
|
+
});
|
|
3375
|
+
}
|
|
3927
3376
|
this.requestResync(channel);
|
|
3928
3377
|
return null;
|
|
3929
3378
|
}
|
|
@@ -3932,10 +3381,7 @@ class DeltaCompressionManager {
|
|
|
3932
3381
|
let reconstructedMessage;
|
|
3933
3382
|
try {
|
|
3934
3383
|
if (algorithm === "fossil") {
|
|
3935
|
-
reconstructedMessage = FossilDeltaDecoder.apply(
|
|
3936
|
-
baseMessage,
|
|
3937
|
-
deltaBytes
|
|
3938
|
-
);
|
|
3384
|
+
reconstructedMessage = FossilDeltaDecoder.apply(baseMessage, deltaBytes);
|
|
3939
3385
|
} else if (algorithm === "xdelta3") {
|
|
3940
3386
|
reconstructedMessage = Xdelta3Decoder.apply(baseMessage, deltaBytes);
|
|
3941
3387
|
} else {
|
|
@@ -3945,11 +3391,7 @@ class DeltaCompressionManager {
|
|
|
3945
3391
|
throw decodeError;
|
|
3946
3392
|
}
|
|
3947
3393
|
if (channelState.conflationKey) {
|
|
3948
|
-
channelState.updateConflationCache(
|
|
3949
|
-
conflationKey,
|
|
3950
|
-
reconstructedMessage,
|
|
3951
|
-
sequence
|
|
3952
|
-
);
|
|
3394
|
+
channelState.updateConflationCache(conflationKey, reconstructedMessage, sequence);
|
|
3953
3395
|
} else {
|
|
3954
3396
|
channelState.setBase(reconstructedMessage, sequence);
|
|
3955
3397
|
}
|
|
@@ -3970,17 +3412,10 @@ class DeltaCompressionManager {
|
|
|
3970
3412
|
});
|
|
3971
3413
|
try {
|
|
3972
3414
|
const parsedMessage = JSON.parse(reconstructedMessage);
|
|
3973
|
-
let data = parsedMessage.data || parsedMessage;
|
|
3974
|
-
if (typeof data === "string") {
|
|
3975
|
-
try {
|
|
3976
|
-
data = JSON.parse(data);
|
|
3977
|
-
} catch (e) {
|
|
3978
|
-
}
|
|
3979
|
-
}
|
|
3980
3415
|
return {
|
|
3981
3416
|
event,
|
|
3982
3417
|
channel,
|
|
3983
|
-
data
|
|
3418
|
+
data: parsedMessage.data || parsedMessage
|
|
3984
3419
|
};
|
|
3985
3420
|
} catch (e) {
|
|
3986
3421
|
return {
|
|
@@ -3997,7 +3432,7 @@ class DeltaCompressionManager {
|
|
|
3997
3432
|
algorithm: deltaData.algorithm,
|
|
3998
3433
|
conflationKey: deltaData.conflation_key,
|
|
3999
3434
|
baseIndex: deltaData.base_index,
|
|
4000
|
-
deltaSize: deltaData.delta
|
|
3435
|
+
deltaSize: (_a = deltaData.delta) === null || _a === void 0 ? void 0 : _a.length,
|
|
4001
3436
|
decodedDeltaBytes: deltaBytes ? deltaBytes.length : "n/a",
|
|
4002
3437
|
message: error.message
|
|
4003
3438
|
});
|
|
@@ -4005,14 +3440,12 @@ class DeltaCompressionManager {
|
|
|
4005
3440
|
return null;
|
|
4006
3441
|
}
|
|
4007
3442
|
}
|
|
4008
|
-
/**
|
|
4009
|
-
* Handle regular (full) message with delta sequence markers
|
|
4010
|
-
*/
|
|
4011
3443
|
handleFullMessage(channel, rawMessage, sequence, conflationKey) {
|
|
3444
|
+
var _a, _b, _c;
|
|
4012
3445
|
if (!sequence && sequence !== 0) {
|
|
4013
3446
|
try {
|
|
4014
3447
|
const parsed = JSON.parse(rawMessage);
|
|
4015
|
-
const candidate = typeof parsed.data === "string" ? JSON.parse(parsed.data).__delta_seq
|
|
3448
|
+
const candidate = typeof parsed.data === "string" ? (_a = JSON.parse(parsed.data).__delta_seq) !== null && _a !== void 0 ? _a : parsed.__delta_seq : (_c = (_b = parsed.data) === null || _b === void 0 ? void 0 : _b.__delta_seq) !== null && _c !== void 0 ? _c : parsed.__delta_seq;
|
|
4016
3449
|
if (candidate === 0 || candidate) {
|
|
4017
3450
|
sequence = candidate;
|
|
4018
3451
|
} else {
|
|
@@ -4041,12 +3474,7 @@ class DeltaCompressionManager {
|
|
|
4041
3474
|
channelState.conflationKey = "enabled";
|
|
4042
3475
|
}
|
|
4043
3476
|
if (channelState.conflationKey && finalConflationKey !== void 0) {
|
|
4044
|
-
channelState.updateConflationCache(
|
|
4045
|
-
finalConflationKey,
|
|
4046
|
-
rawMessage,
|
|
4047
|
-
// Store raw message directly
|
|
4048
|
-
sequence
|
|
4049
|
-
);
|
|
3477
|
+
channelState.updateConflationCache(finalConflationKey, rawMessage, sequence);
|
|
4050
3478
|
this.log("Stored full message (conflation)", {
|
|
4051
3479
|
channel,
|
|
4052
3480
|
conflationKey: finalConflationKey,
|
|
@@ -4068,42 +3496,27 @@ class DeltaCompressionManager {
|
|
|
4068
3496
|
this.stats.totalBytesWithCompression += messageSize;
|
|
4069
3497
|
this.updateStats();
|
|
4070
3498
|
}
|
|
4071
|
-
/**
|
|
4072
|
-
* Request resync for a channel
|
|
4073
|
-
*/
|
|
4074
3499
|
requestResync(channel) {
|
|
4075
3500
|
this.log("Requesting resync for channel", channel);
|
|
4076
3501
|
this.sendEventCallback("pusher:delta_sync_error", { channel });
|
|
4077
3502
|
this.channelStates.delete(channel);
|
|
4078
3503
|
}
|
|
4079
|
-
/**
|
|
4080
|
-
* Update and emit stats
|
|
4081
|
-
*/
|
|
4082
3504
|
updateStats() {
|
|
4083
3505
|
if (this.options.onStats) {
|
|
4084
3506
|
this.options.onStats(this.getStats());
|
|
4085
3507
|
}
|
|
4086
3508
|
}
|
|
4087
|
-
/**
|
|
4088
|
-
* Get current statistics
|
|
4089
|
-
*/
|
|
4090
3509
|
getStats() {
|
|
4091
3510
|
const bandwidthSaved = this.stats.totalBytesWithoutCompression - this.stats.totalBytesWithCompression;
|
|
4092
3511
|
const bandwidthSavedPercent = this.stats.totalBytesWithoutCompression > 0 ? bandwidthSaved / this.stats.totalBytesWithoutCompression * 100 : 0;
|
|
4093
|
-
const channelStats = Array.from(this.channelStates.values()).map(
|
|
4094
|
-
|
|
4095
|
-
);
|
|
4096
|
-
return {
|
|
4097
|
-
...this.stats,
|
|
3512
|
+
const channelStats = Array.from(this.channelStates.values()).map((state) => state.getStats());
|
|
3513
|
+
return Object.assign(Object.assign({}, this.stats), {
|
|
4098
3514
|
bandwidthSaved,
|
|
4099
3515
|
bandwidthSavedPercent,
|
|
4100
3516
|
channelCount: this.channelStates.size,
|
|
4101
3517
|
channels: channelStats
|
|
4102
|
-
};
|
|
3518
|
+
});
|
|
4103
3519
|
}
|
|
4104
|
-
/**
|
|
4105
|
-
* Reset statistics
|
|
4106
|
-
*/
|
|
4107
3520
|
resetStats() {
|
|
4108
3521
|
this.stats = {
|
|
4109
3522
|
totalMessages: 0,
|
|
@@ -4115,9 +3528,6 @@ class DeltaCompressionManager {
|
|
|
4115
3528
|
};
|
|
4116
3529
|
this.updateStats();
|
|
4117
3530
|
}
|
|
4118
|
-
/**
|
|
4119
|
-
* Clear channel state
|
|
4120
|
-
*/
|
|
4121
3531
|
clearChannelState(channel) {
|
|
4122
3532
|
if (channel) {
|
|
4123
3533
|
this.channelStates.delete(channel);
|
|
@@ -4125,29 +3535,17 @@ class DeltaCompressionManager {
|
|
|
4125
3535
|
this.channelStates.clear();
|
|
4126
3536
|
}
|
|
4127
3537
|
}
|
|
4128
|
-
/**
|
|
4129
|
-
* Check if delta compression is enabled
|
|
4130
|
-
*/
|
|
4131
3538
|
isEnabled() {
|
|
4132
3539
|
return this.enabled;
|
|
4133
3540
|
}
|
|
4134
|
-
/**
|
|
4135
|
-
* Get available algorithms
|
|
4136
|
-
*/
|
|
4137
3541
|
getAvailableAlgorithms() {
|
|
4138
3542
|
return this.availableAlgorithms;
|
|
4139
3543
|
}
|
|
4140
|
-
/**
|
|
4141
|
-
* Log message (if debug enabled)
|
|
4142
|
-
*/
|
|
4143
3544
|
log(...args) {
|
|
4144
3545
|
if (this.options.debug) {
|
|
4145
3546
|
Logger$1.debug("[DeltaCompression]", ...args);
|
|
4146
3547
|
}
|
|
4147
3548
|
}
|
|
4148
|
-
/**
|
|
4149
|
-
* Log error
|
|
4150
|
-
*/
|
|
4151
3549
|
error(...args) {
|
|
4152
3550
|
Logger$1.error("[DeltaCompression]", ...args);
|
|
4153
3551
|
if (this.options.onError) {
|
|
@@ -4156,15 +3554,6 @@ class DeltaCompressionManager {
|
|
|
4156
3554
|
}
|
|
4157
3555
|
}
|
|
4158
3556
|
class Pusher {
|
|
4159
|
-
static {
|
|
4160
|
-
this.instances = [];
|
|
4161
|
-
}
|
|
4162
|
-
static {
|
|
4163
|
-
this.isReady = false;
|
|
4164
|
-
}
|
|
4165
|
-
static {
|
|
4166
|
-
this._logToConsole = false;
|
|
4167
|
-
}
|
|
4168
3557
|
static get logToConsole() {
|
|
4169
3558
|
return this._logToConsole;
|
|
4170
3559
|
}
|
|
@@ -4179,18 +3568,6 @@ class Pusher {
|
|
|
4179
3568
|
this._log = fn;
|
|
4180
3569
|
setLoggerConfig({ logToConsole: this._logToConsole, log: fn });
|
|
4181
3570
|
}
|
|
4182
|
-
static {
|
|
4183
|
-
this.Runtime = NodeJS;
|
|
4184
|
-
}
|
|
4185
|
-
static {
|
|
4186
|
-
this.ScriptReceivers = NodeJS.ScriptReceivers;
|
|
4187
|
-
}
|
|
4188
|
-
static {
|
|
4189
|
-
this.DependenciesReceivers = NodeJS.DependenciesReceivers;
|
|
4190
|
-
}
|
|
4191
|
-
static {
|
|
4192
|
-
this.auth_callbacks = NodeJS.auth_callbacks;
|
|
4193
|
-
}
|
|
4194
3571
|
static ready() {
|
|
4195
3572
|
Pusher.isReady = true;
|
|
4196
3573
|
for (var i = 0, l = Pusher.instances.length; i < l; i++) {
|
|
@@ -4198,11 +3575,9 @@ class Pusher {
|
|
|
4198
3575
|
}
|
|
4199
3576
|
}
|
|
4200
3577
|
static getClientFeatures() {
|
|
4201
|
-
return keys(
|
|
4202
|
-
|
|
4203
|
-
|
|
4204
|
-
})
|
|
4205
|
-
);
|
|
3578
|
+
return keys(filterObject({ ws: NodeJS.Transports.ws }, function(t) {
|
|
3579
|
+
return t.isSupported({});
|
|
3580
|
+
}));
|
|
4206
3581
|
}
|
|
4207
3582
|
constructor(app_key, options) {
|
|
4208
3583
|
checkAppKey(app_key);
|
|
@@ -4217,7 +3592,7 @@ class Pusher {
|
|
|
4217
3592
|
features: Pusher.getClientFeatures(),
|
|
4218
3593
|
params: this.config.timelineParams || {},
|
|
4219
3594
|
limit: 50,
|
|
4220
|
-
level: TimelineLevel.INFO,
|
|
3595
|
+
level: TimelineLevel$1.INFO,
|
|
4221
3596
|
version: Defaults.VERSION
|
|
4222
3597
|
});
|
|
4223
3598
|
if (this.config.enableStats) {
|
|
@@ -4238,17 +3613,15 @@ class Pusher {
|
|
|
4238
3613
|
useTLS: Boolean(this.config.useTLS)
|
|
4239
3614
|
});
|
|
4240
3615
|
if (options.deltaCompression !== void 0) {
|
|
4241
|
-
this.deltaCompression = new DeltaCompressionManager(
|
|
4242
|
-
options.deltaCompression || {},
|
|
4243
|
-
(event, data) => this.send_event(event, data)
|
|
4244
|
-
);
|
|
3616
|
+
this.deltaCompression = new DeltaCompressionManager(options.deltaCompression || {}, (event, data) => this.send_event(event, data));
|
|
4245
3617
|
}
|
|
4246
3618
|
this.connection.bind("connected", () => {
|
|
3619
|
+
var _a;
|
|
4247
3620
|
this.subscribeAll();
|
|
4248
3621
|
if (this.timelineSender) {
|
|
4249
3622
|
this.timelineSender.send(this.connection.isUsingTLS());
|
|
4250
3623
|
}
|
|
4251
|
-
if (this.deltaCompression && options.deltaCompression
|
|
3624
|
+
if (this.deltaCompression && ((_a = options.deltaCompression) === null || _a === void 0 ? void 0 : _a.enabled) === true) {
|
|
4252
3625
|
this.deltaCompression.enable();
|
|
4253
3626
|
}
|
|
4254
3627
|
});
|
|
@@ -4266,18 +3639,12 @@ class Pusher {
|
|
|
4266
3639
|
if (!channel) {
|
|
4267
3640
|
return;
|
|
4268
3641
|
}
|
|
4269
|
-
const reconstructedEvent = this.deltaCompression.handleDeltaMessage(
|
|
4270
|
-
event.channel,
|
|
4271
|
-
event.data
|
|
4272
|
-
);
|
|
3642
|
+
const reconstructedEvent = this.deltaCompression.handleDeltaMessage(event.channel, event.data);
|
|
4273
3643
|
if (reconstructedEvent) {
|
|
4274
3644
|
if (channel) {
|
|
4275
3645
|
channel.handleEvent(reconstructedEvent);
|
|
4276
3646
|
}
|
|
4277
|
-
this.global_emitter.emit(
|
|
4278
|
-
reconstructedEvent.event,
|
|
4279
|
-
reconstructedEvent.data
|
|
4280
|
-
);
|
|
3647
|
+
this.global_emitter.emit(reconstructedEvent.event, reconstructedEvent.data);
|
|
4281
3648
|
}
|
|
4282
3649
|
return;
|
|
4283
3650
|
}
|
|
@@ -4300,21 +3667,10 @@ class Pusher {
|
|
|
4300
3667
|
if (fullMessage && sequence !== void 0) {
|
|
4301
3668
|
fullMessage = fullMessage.replace(/,"__delta_seq":\d+/g, "");
|
|
4302
3669
|
fullMessage = fullMessage.replace(/"__delta_seq":\d+,/g, "");
|
|
4303
|
-
fullMessage = fullMessage.replace(
|
|
4304
|
-
|
|
4305
|
-
""
|
|
4306
|
-
);
|
|
4307
|
-
fullMessage = fullMessage.replace(
|
|
4308
|
-
/"__conflation_key":"[^"]*",/g,
|
|
4309
|
-
""
|
|
4310
|
-
);
|
|
3670
|
+
fullMessage = fullMessage.replace(/,"__conflation_key":"[^"]*"/g, "");
|
|
3671
|
+
fullMessage = fullMessage.replace(/"__conflation_key":"[^"]*",/g, "");
|
|
4311
3672
|
}
|
|
4312
|
-
this.deltaCompression.handleFullMessage(
|
|
4313
|
-
event.channel,
|
|
4314
|
-
fullMessage,
|
|
4315
|
-
sequence,
|
|
4316
|
-
conflationKey
|
|
4317
|
-
);
|
|
3673
|
+
this.deltaCompression.handleFullMessage(event.channel, fullMessage, sequence, conflationKey);
|
|
4318
3674
|
}
|
|
4319
3675
|
}
|
|
4320
3676
|
if (!internal) {
|
|
@@ -4425,25 +3781,25 @@ class Pusher {
|
|
|
4425
3781
|
signin() {
|
|
4426
3782
|
this.user.signin();
|
|
4427
3783
|
}
|
|
4428
|
-
/**
|
|
4429
|
-
* Get delta compression statistics
|
|
4430
|
-
* @returns {DeltaStats} Statistics about delta compression bandwidth savings
|
|
4431
|
-
*/
|
|
4432
3784
|
getDeltaStats() {
|
|
4433
3785
|
if (!this.deltaCompression) {
|
|
4434
3786
|
return null;
|
|
4435
3787
|
}
|
|
4436
3788
|
return this.deltaCompression.getStats();
|
|
4437
3789
|
}
|
|
4438
|
-
/**
|
|
4439
|
-
* Reset delta compression statistics
|
|
4440
|
-
*/
|
|
4441
3790
|
resetDeltaStats() {
|
|
4442
3791
|
if (this.deltaCompression) {
|
|
4443
3792
|
this.deltaCompression.resetStats();
|
|
4444
3793
|
}
|
|
4445
3794
|
}
|
|
4446
3795
|
}
|
|
3796
|
+
Pusher.instances = [];
|
|
3797
|
+
Pusher.isReady = false;
|
|
3798
|
+
Pusher._logToConsole = false;
|
|
3799
|
+
Pusher.Runtime = NodeJS;
|
|
3800
|
+
Pusher.ScriptReceivers = NodeJS.ScriptReceivers;
|
|
3801
|
+
Pusher.DependenciesReceivers = NodeJS.DependenciesReceivers;
|
|
3802
|
+
Pusher.auth_callbacks = NodeJS.auth_callbacks;
|
|
4447
3803
|
function checkAppKey(key) {
|
|
4448
3804
|
if (key === null || key === void 0) {
|
|
4449
3805
|
throw "You must pass your app key when you instantiate Pusher.";
|