@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.
Files changed (397) hide show
  1. package/CHANGELOG.md +928 -928
  2. package/DELTA_USAGE.md +0 -0
  3. package/IMPORT_GUIDE.md +0 -0
  4. package/bun.lock +1819 -171
  5. package/dist/node/filter.js +2 -120
  6. package/dist/node/filter.js.map +1 -1
  7. package/dist/node/pusher.js +273 -917
  8. package/dist/node/pusher.js.map +1 -1
  9. package/dist/web/filter.mjs +2 -120
  10. package/dist/web/filter.mjs.map +1 -1
  11. package/dist/web/pusher.mjs +442 -1040
  12. package/dist/web/pusher.mjs.map +1 -1
  13. package/examples/delta-seamless-example.html +0 -0
  14. package/index.d.ts +12 -12
  15. package/interactive/package.json +2 -2
  16. package/interactive/public/bundle-entry.js +2 -6
  17. package/interactive/public/conflation-test.html +1 -3
  18. package/interactive/public/conflation-test.js +25 -26
  19. package/interactive/public/dist/bundle.js +21 -5845
  20. package/interactive/tsconfig.json +19 -0
  21. package/package.json +3 -3
  22. package/src/core/auth/auth_transports.js +2 -0
  23. package/src/core/auth/auth_transports.js.map +1 -0
  24. package/src/core/auth/channel_authorizer.js +35 -0
  25. package/src/core/auth/channel_authorizer.js.map +1 -0
  26. package/src/core/auth/deprecated_channel_authorizer.js +16 -0
  27. package/src/core/auth/deprecated_channel_authorizer.js.map +1 -0
  28. package/src/core/auth/options.js +6 -0
  29. package/src/core/auth/options.js.map +1 -0
  30. package/src/core/auth/user_authenticator.js +34 -0
  31. package/src/core/auth/user_authenticator.js.map +1 -0
  32. package/src/core/base64.js +40 -0
  33. package/src/core/base64.js.map +1 -0
  34. package/src/core/channels/channel.js +106 -0
  35. package/src/core/channels/channel.js.map +1 -0
  36. package/src/core/channels/channel_table.js +2 -0
  37. package/src/core/channels/channel_table.js.map +1 -0
  38. package/src/core/channels/channels.js +54 -0
  39. package/src/core/channels/channels.js.map +1 -0
  40. package/src/core/channels/encrypted_channel.js +91 -0
  41. package/src/core/channels/encrypted_channel.js.map +1 -0
  42. package/src/core/channels/filter.js +132 -0
  43. package/src/core/channels/filter.js.map +1 -0
  44. package/src/core/channels/members.js +52 -0
  45. package/src/core/channels/members.js.map +1 -0
  46. package/src/core/channels/metadata.js +2 -0
  47. package/src/core/channels/metadata.js.map +1 -0
  48. package/src/core/channels/presence_channel.js +97 -0
  49. package/src/core/channels/presence_channel.js.map +1 -0
  50. package/src/core/channels/private_channel.js +10 -0
  51. package/src/core/channels/private_channel.js.map +1 -0
  52. package/src/core/config.js +112 -0
  53. package/src/core/config.js.map +1 -0
  54. package/src/core/connection/callbacks.js +2 -0
  55. package/src/core/connection/callbacks.js.map +1 -0
  56. package/src/core/connection/connection.js +106 -0
  57. package/src/core/connection/connection.js.map +1 -0
  58. package/src/core/connection/connection_manager.js +255 -0
  59. package/src/core/connection/connection_manager.js.map +1 -0
  60. package/src/core/connection/connection_manager_options.js +2 -0
  61. package/src/core/connection/connection_manager_options.js.map +1 -0
  62. package/src/core/connection/handshake/handshake_payload.js +2 -0
  63. package/src/core/connection/handshake/handshake_payload.js.map +1 -0
  64. package/src/core/connection/handshake/index.js +54 -0
  65. package/src/core/connection/handshake/index.js.map +1 -0
  66. package/src/core/connection/protocol/action.js +2 -0
  67. package/src/core/connection/protocol/action.js.map +1 -0
  68. package/src/core/connection/protocol/message-types.js +2 -0
  69. package/src/core/connection/protocol/message-types.js.map +1 -0
  70. package/src/core/connection/protocol/protocol.js +102 -0
  71. package/src/core/connection/protocol/protocol.js.map +1 -0
  72. package/src/core/defaults.js +30 -0
  73. package/src/core/defaults.js.map +1 -0
  74. package/src/core/delta/channel_state.js +103 -0
  75. package/src/core/delta/channel_state.js.map +1 -0
  76. package/src/core/delta/channel_state.ts +3 -2
  77. package/src/core/delta/decoders.js +81 -0
  78. package/src/core/delta/decoders.js.map +1 -0
  79. package/{types/src/core/delta/index.d.ts → src/core/delta/index.js} +1 -0
  80. package/src/core/delta/index.js.map +1 -0
  81. package/src/core/delta/manager.js +327 -0
  82. package/src/core/delta/manager.js.map +1 -0
  83. package/src/core/delta/manager.ts +21 -40
  84. package/src/core/delta/types.js +2 -0
  85. package/src/core/delta/types.js.map +1 -0
  86. package/src/core/errors.js +56 -0
  87. package/src/core/errors.js.map +1 -0
  88. package/src/core/events/callback.js +2 -0
  89. package/src/core/events/callback.js.map +1 -0
  90. package/src/core/events/callback_registry.js +51 -0
  91. package/src/core/events/callback_registry.js.map +1 -0
  92. package/src/core/events/callback_table.js +2 -0
  93. package/src/core/events/callback_table.js.map +1 -0
  94. package/src/core/events/dispatcher.js +57 -0
  95. package/src/core/events/dispatcher.js.map +1 -0
  96. package/src/core/http/ajax.js +2 -0
  97. package/src/core/http/ajax.js.map +1 -0
  98. package/src/core/http/http_factory.js +2 -0
  99. package/src/core/http/http_factory.js.map +1 -0
  100. package/src/core/http/http_polling_socket.js +20 -0
  101. package/src/core/http/http_polling_socket.js.map +1 -0
  102. package/src/core/http/http_request.js +63 -0
  103. package/src/core/http/http_request.js.map +1 -0
  104. package/src/core/http/http_socket.js +171 -0
  105. package/src/core/http/http_socket.js.map +1 -0
  106. package/src/core/http/http_streaming_socket.js +16 -0
  107. package/src/core/http/http_streaming_socket.js.map +1 -0
  108. package/src/core/http/request_hooks.js +2 -0
  109. package/src/core/http/request_hooks.js.map +1 -0
  110. package/src/core/http/socket_hooks.js +2 -0
  111. package/src/core/http/socket_hooks.js.map +1 -0
  112. package/src/core/http/state.js +8 -0
  113. package/src/core/http/state.js.map +1 -0
  114. package/src/core/http/url_location.js +2 -0
  115. package/src/core/http/url_location.js.map +1 -0
  116. package/src/core/logger.js +53 -0
  117. package/src/core/logger.js.map +1 -0
  118. package/src/core/options.js +13 -0
  119. package/src/core/options.js.map +1 -0
  120. package/src/core/pusher-with-encryption.js +13 -1
  121. package/src/core/pusher-with-encryption.js.map +1 -0
  122. package/src/core/pusher.js +279 -10
  123. package/src/core/pusher.js.map +1 -0
  124. package/src/core/reachability.js +2 -0
  125. package/src/core/reachability.js.map +1 -0
  126. package/src/core/socket.js +2 -0
  127. package/src/core/socket.js.map +1 -0
  128. package/src/core/strategies/best_connected_ever_strategy.js +54 -0
  129. package/src/core/strategies/best_connected_ever_strategy.js.map +1 -0
  130. package/src/core/strategies/delayed_strategy.js +32 -0
  131. package/src/core/strategies/delayed_strategy.js.map +1 -0
  132. package/src/core/strategies/first_connected_strategy.js +18 -0
  133. package/src/core/strategies/first_connected_strategy.js.map +1 -0
  134. package/src/core/strategies/if_strategy.js +16 -0
  135. package/src/core/strategies/if_strategy.js.map +1 -0
  136. package/src/core/strategies/sequential_strategy.js +87 -0
  137. package/src/core/strategies/sequential_strategy.js.map +1 -0
  138. package/src/core/strategies/strategy.js +2 -0
  139. package/src/core/strategies/strategy.js.map +1 -0
  140. package/src/core/strategies/strategy_builder.js +42 -0
  141. package/src/core/strategies/strategy_builder.js.map +1 -0
  142. package/src/core/strategies/strategy_options.js +2 -0
  143. package/src/core/strategies/strategy_options.js.map +1 -0
  144. package/src/core/strategies/strategy_runner.js +2 -0
  145. package/src/core/strategies/strategy_runner.js.map +1 -0
  146. package/src/core/strategies/transport_strategy.js +97 -0
  147. package/src/core/strategies/transport_strategy.js.map +1 -0
  148. package/src/core/strategies/websocket_prioritized_cached_strategy.js +115 -0
  149. package/src/core/strategies/websocket_prioritized_cached_strategy.js.map +1 -0
  150. package/src/core/timeline/level.js +8 -0
  151. package/src/core/timeline/level.js.map +1 -0
  152. package/src/core/timeline/timeline.js +60 -0
  153. package/src/core/timeline/timeline.js.map +1 -0
  154. package/src/core/timeline/timeline_sender.js +14 -0
  155. package/src/core/timeline/timeline_sender.js.map +1 -0
  156. package/src/core/timeline/timeline_transport.js +2 -0
  157. package/src/core/timeline/timeline_transport.js.map +1 -0
  158. package/src/core/transports/assistant_to_the_transport_manager.js +42 -0
  159. package/src/core/transports/assistant_to_the_transport_manager.js.map +1 -0
  160. package/src/core/transports/ping_delay_options.js +2 -0
  161. package/src/core/transports/ping_delay_options.js.map +1 -0
  162. package/src/core/transports/transport.js +13 -0
  163. package/src/core/transports/transport.js.map +1 -0
  164. package/src/core/transports/transport_connection.js +146 -0
  165. package/src/core/transports/transport_connection.js.map +1 -0
  166. package/src/core/transports/transport_connection_options.js +2 -0
  167. package/src/core/transports/transport_connection_options.js.map +1 -0
  168. package/src/core/transports/transport_hooks.js +2 -0
  169. package/src/core/transports/transport_hooks.js.map +1 -0
  170. package/src/core/transports/transport_manager.js +20 -0
  171. package/src/core/transports/transport_manager.js.map +1 -0
  172. package/src/core/transports/transports_table.js +2 -0
  173. package/src/core/transports/transports_table.js.map +1 -0
  174. package/src/core/transports/url_scheme.js +2 -0
  175. package/src/core/transports/url_scheme.js.map +1 -0
  176. package/src/core/transports/url_schemes.js +37 -0
  177. package/src/core/transports/url_schemes.js.map +1 -0
  178. package/src/core/user.js +133 -0
  179. package/src/core/user.js.map +1 -0
  180. package/src/core/util.js +22 -0
  181. package/src/core/util.js.map +1 -0
  182. package/src/core/utils/collections.js +193 -0
  183. package/src/core/utils/collections.js.map +1 -0
  184. package/src/core/utils/factory.js +40 -0
  185. package/src/core/utils/factory.js.map +1 -0
  186. package/src/core/utils/flat_promise.js +10 -0
  187. package/src/core/utils/flat_promise.js.map +1 -0
  188. package/src/core/utils/timers/abstract_timer.js +21 -0
  189. package/src/core/utils/timers/abstract_timer.js.map +1 -0
  190. package/src/core/utils/timers/index.js +24 -0
  191. package/src/core/utils/timers/index.js.map +1 -0
  192. package/src/core/utils/timers/scheduling.js +2 -0
  193. package/src/core/utils/timers/scheduling.js.map +1 -0
  194. package/src/core/utils/timers/timed_callback.js +2 -0
  195. package/src/core/utils/timers/timed_callback.js.map +1 -0
  196. package/src/core/utils/url_store.js +38 -0
  197. package/src/core/utils/url_store.js.map +1 -0
  198. package/src/core/watchlist.js +25 -0
  199. package/src/core/watchlist.js.map +1 -0
  200. package/src/filter.js +2 -0
  201. package/src/filter.js.map +1 -0
  202. package/src/filter.ts +0 -0
  203. package/src/index.js +3 -0
  204. package/src/index.js.map +1 -0
  205. package/src/index.ts +1 -1
  206. package/src/runtimes/interface.js +2 -0
  207. package/src/runtimes/interface.js.map +1 -0
  208. package/src/runtimes/isomorphic/auth/xhr_auth.js +53 -0
  209. package/src/runtimes/isomorphic/auth/xhr_auth.js.map +1 -0
  210. package/src/runtimes/isomorphic/default_strategy.js +83 -0
  211. package/src/runtimes/isomorphic/default_strategy.js.map +1 -0
  212. package/src/runtimes/isomorphic/http/http.js +24 -0
  213. package/src/runtimes/isomorphic/http/http.js.map +1 -0
  214. package/src/runtimes/isomorphic/http/http_xhr_request.js +30 -0
  215. package/src/runtimes/isomorphic/http/http_xhr_request.js.map +1 -0
  216. package/src/runtimes/isomorphic/runtime.js +48 -0
  217. package/src/runtimes/isomorphic/runtime.js.map +1 -0
  218. package/src/runtimes/isomorphic/timeline/xhr_timeline.js +38 -0
  219. package/src/runtimes/isomorphic/timeline/xhr_timeline.js.map +1 -0
  220. package/src/runtimes/isomorphic/transports/transport_connection_initializer.js +13 -0
  221. package/src/runtimes/isomorphic/transports/transport_connection_initializer.js.map +1 -0
  222. package/src/runtimes/isomorphic/transports/transports.js +50 -0
  223. package/src/runtimes/isomorphic/transports/transports.js.map +1 -0
  224. package/src/runtimes/node/net_info.js +8 -0
  225. package/src/runtimes/node/net_info.js.map +1 -0
  226. package/src/runtimes/node/runtime.js +41 -0
  227. package/src/runtimes/node/runtime.js.map +1 -0
  228. package/src/runtimes/react-native/net_info.js +31 -0
  229. package/src/runtimes/react-native/net_info.js.map +1 -0
  230. package/src/runtimes/react-native/runtime.js +38 -0
  231. package/src/runtimes/react-native/runtime.js.map +1 -0
  232. package/src/runtimes/web/auth/jsonp_auth.js +25 -0
  233. package/src/runtimes/web/auth/jsonp_auth.js.map +1 -0
  234. package/src/runtimes/web/browser.js +2 -0
  235. package/src/runtimes/web/browser.js.map +1 -0
  236. package/src/runtimes/web/default_strategy.js +91 -0
  237. package/src/runtimes/web/default_strategy.js.map +1 -0
  238. package/src/runtimes/web/dom/dependencies.js +12 -0
  239. package/src/runtimes/web/dom/dependencies.js.map +1 -0
  240. package/src/runtimes/web/dom/dependency_loader.js +50 -0
  241. package/src/runtimes/web/dom/dependency_loader.js.map +1 -0
  242. package/src/runtimes/web/dom/jsonp_request.js +23 -0
  243. package/src/runtimes/web/dom/jsonp_request.js.map +1 -0
  244. package/src/runtimes/web/dom/script_receiver.js +2 -0
  245. package/src/runtimes/web/dom/script_receiver.js.map +1 -0
  246. package/src/runtimes/web/dom/script_receiver_factory.js +27 -0
  247. package/src/runtimes/web/dom/script_receiver_factory.js.map +1 -0
  248. package/src/runtimes/web/dom/script_request.js +61 -0
  249. package/src/runtimes/web/dom/script_request.js.map +1 -0
  250. package/src/runtimes/web/http/http.js +7 -0
  251. package/src/runtimes/web/http/http.js.map +1 -0
  252. package/src/runtimes/web/http/http_xdomain_request.js +33 -0
  253. package/src/runtimes/web/http/http_xdomain_request.js.map +1 -0
  254. package/src/runtimes/web/net_info.js +25 -0
  255. package/src/runtimes/web/net_info.js.map +1 -0
  256. package/src/runtimes/web/runtime.js +142 -0
  257. package/src/runtimes/web/runtime.js.map +1 -0
  258. package/src/runtimes/web/timeline/jsonp_timeline.js +26 -0
  259. package/src/runtimes/web/timeline/jsonp_timeline.js.map +1 -0
  260. package/src/runtimes/web/transports/transport_connection_initializer.js +30 -0
  261. package/src/runtimes/web/transports/transport_connection_initializer.js.map +1 -0
  262. package/src/runtimes/web/transports/transports.js +44 -0
  263. package/src/runtimes/web/transports/transports.js.map +1 -0
  264. package/src/runtimes/worker/auth/fetch_auth.js +44 -0
  265. package/src/runtimes/worker/auth/fetch_auth.js.map +1 -0
  266. package/src/runtimes/worker/net_info.js +8 -0
  267. package/src/runtimes/worker/net_info.js.map +1 -0
  268. package/src/runtimes/worker/runtime.js +43 -0
  269. package/src/runtimes/worker/runtime.js.map +1 -0
  270. package/src/runtimes/worker/timeline/fetch_timeline.js +31 -0
  271. package/src/runtimes/worker/timeline/fetch_timeline.js.map +1 -0
  272. package/tsconfig.json +24 -5
  273. package/vite.config.js +0 -0
  274. package/vite.config.node.js +0 -0
  275. package/interactive/public/delta-compression.js +0 -1090
  276. package/types/spec/javascripts/helpers/node/mock-dom-dependencies.d.ts +0 -1
  277. package/types/spec/javascripts/helpers/pusher_integration_class.d.ts +0 -4
  278. package/types/src/core/auth/auth_transports.d.ts +0 -9
  279. package/types/src/core/auth/channel_authorizer.d.ts +0 -3
  280. package/types/src/core/auth/deprecated_channel_authorizer.d.ts +0 -18
  281. package/types/src/core/auth/options.d.ts +0 -48
  282. package/types/src/core/auth/user_authenticator.d.ts +0 -3
  283. package/types/src/core/base64.d.ts +0 -1
  284. package/types/src/core/channels/channel.d.ts +0 -25
  285. package/types/src/core/channels/channel_table.d.ts +0 -5
  286. package/types/src/core/channels/channels.d.ts +0 -12
  287. package/types/src/core/channels/encrypted_channel.d.ts +0 -15
  288. package/types/src/core/channels/filter.d.ts +0 -33
  289. package/types/src/core/channels/members.d.ts +0 -14
  290. package/types/src/core/channels/metadata.d.ts +0 -4
  291. package/types/src/core/channels/presence_channel.d.ts +0 -13
  292. package/types/src/core/channels/private_channel.d.ts +0 -5
  293. package/types/src/core/config.d.ts +0 -31
  294. package/types/src/core/connection/callbacks.d.ts +0 -18
  295. package/types/src/core/connection/connection.d.ts +0 -16
  296. package/types/src/core/connection/connection_manager.d.ts +0 -50
  297. package/types/src/core/connection/connection_manager_options.d.ts +0 -11
  298. package/types/src/core/connection/handshake/handshake_payload.d.ts +0 -8
  299. package/types/src/core/connection/handshake/index.d.ts +0 -12
  300. package/types/src/core/connection/protocol/action.d.ts +0 -7
  301. package/types/src/core/connection/protocol/message-types.d.ts +0 -10
  302. package/types/src/core/connection/protocol/protocol.d.ts +0 -10
  303. package/types/src/core/defaults.d.ts +0 -26
  304. package/types/src/core/delta/channel_state.d.ts +0 -23
  305. package/types/src/core/delta/decoders.d.ts +0 -12
  306. package/types/src/core/delta/manager.d.ts +0 -27
  307. package/types/src/core/delta/types.d.ts +0 -50
  308. package/types/src/core/errors.d.ts +0 -28
  309. package/types/src/core/events/callback.d.ts +0 -5
  310. package/types/src/core/events/callback_registry.d.ts +0 -11
  311. package/types/src/core/events/callback_table.d.ts +0 -5
  312. package/types/src/core/events/dispatcher.d.ts +0 -14
  313. package/types/src/core/http/ajax.d.ts +0 -16
  314. package/types/src/core/http/http_factory.d.ts +0 -13
  315. package/types/src/core/http/http_polling_socket.d.ts +0 -3
  316. package/types/src/core/http/http_request.d.ts +0 -17
  317. package/types/src/core/http/http_socket.d.ts +0 -32
  318. package/types/src/core/http/http_streaming_socket.d.ts +0 -3
  319. package/types/src/core/http/request_hooks.d.ts +0 -6
  320. package/types/src/core/http/socket_hooks.d.ts +0 -8
  321. package/types/src/core/http/state.d.ts +0 -6
  322. package/types/src/core/http/url_location.d.ts +0 -5
  323. package/types/src/core/logger.d.ts +0 -11
  324. package/types/src/core/options.d.ts +0 -36
  325. package/types/src/core/pusher-with-encryption.d.ts +0 -5
  326. package/types/src/core/pusher.d.ts +0 -56
  327. package/types/src/core/reachability.d.ts +0 -5
  328. package/types/src/core/socket.d.ts +0 -12
  329. package/types/src/core/strategies/best_connected_ever_strategy.d.ts +0 -10
  330. package/types/src/core/strategies/delayed_strategy.d.ts +0 -15
  331. package/types/src/core/strategies/first_connected_strategy.d.ts +0 -8
  332. package/types/src/core/strategies/if_strategy.d.ts +0 -10
  333. package/types/src/core/strategies/sequential_strategy.d.ts +0 -16
  334. package/types/src/core/strategies/strategy.d.ts +0 -6
  335. package/types/src/core/strategies/strategy_builder.d.ts +0 -5
  336. package/types/src/core/strategies/strategy_options.d.ts +0 -16
  337. package/types/src/core/strategies/strategy_runner.d.ts +0 -5
  338. package/types/src/core/strategies/transport_strategy.d.ts +0 -15
  339. package/types/src/core/strategies/websocket_prioritized_cached_strategy.d.ts +0 -20
  340. package/types/src/core/timeline/level.d.ts +0 -6
  341. package/types/src/core/timeline/timeline.d.ts +0 -25
  342. package/types/src/core/timeline/timeline_sender.d.ts +0 -13
  343. package/types/src/core/timeline/timeline_transport.d.ts +0 -6
  344. package/types/src/core/transports/assistant_to_the_transport_manager.d.ts +0 -14
  345. package/types/src/core/transports/ping_delay_options.d.ts +0 -6
  346. package/types/src/core/transports/transport.d.ts +0 -8
  347. package/types/src/core/transports/transport_connection.d.ts +0 -35
  348. package/types/src/core/transports/transport_connection_options.d.ts +0 -6
  349. package/types/src/core/transports/transport_hooks.d.ts +0 -13
  350. package/types/src/core/transports/transport_manager.d.ts +0 -14
  351. package/types/src/core/transports/transports_table.d.ts +0 -10
  352. package/types/src/core/transports/url_scheme.d.ts +0 -11
  353. package/types/src/core/transports/url_schemes.d.ts +0 -4
  354. package/types/src/core/user.d.ts +0 -21
  355. package/types/src/core/util.d.ts +0 -8
  356. package/types/src/core/utils/collections.d.ts +0 -18
  357. package/types/src/core/utils/factory.d.ts +0 -29
  358. package/types/src/core/utils/flat_promise.d.ts +0 -6
  359. package/types/src/core/utils/timers/abstract_timer.d.ts +0 -10
  360. package/types/src/core/utils/timers/index.d.ts +0 -9
  361. package/types/src/core/utils/timers/scheduling.d.ts +0 -8
  362. package/types/src/core/utils/timers/timed_callback.d.ts +0 -4
  363. package/types/src/core/utils/url_store.d.ts +0 -4
  364. package/types/src/core/watchlist.d.ts +0 -8
  365. package/types/src/runtimes/interface.d.ts +0 -43
  366. package/types/src/runtimes/isomorphic/auth/xhr_auth.d.ts +0 -3
  367. package/types/src/runtimes/isomorphic/default_strategy.d.ts +0 -5
  368. package/types/src/runtimes/isomorphic/http/http.d.ts +0 -3
  369. package/types/src/runtimes/isomorphic/http/http_xhr_request.d.ts +0 -3
  370. package/types/src/runtimes/isomorphic/runtime.d.ts +0 -2
  371. package/types/src/runtimes/isomorphic/timeline/xhr_timeline.d.ts +0 -6
  372. package/types/src/runtimes/isomorphic/transports/transport_connection_initializer.d.ts +0 -1
  373. package/types/src/runtimes/isomorphic/transports/transports.d.ts +0 -5
  374. package/types/src/runtimes/node/net_info.d.ts +0 -6
  375. package/types/src/runtimes/node/runtime.d.ts +0 -3
  376. package/types/src/runtimes/react-native/net_info.d.ts +0 -8
  377. package/types/src/runtimes/react-native/runtime.d.ts +0 -3
  378. package/types/src/runtimes/web/auth/jsonp_auth.d.ts +0 -3
  379. package/types/src/runtimes/web/browser.d.ts +0 -19
  380. package/types/src/runtimes/web/default_strategy.d.ts +0 -5
  381. package/types/src/runtimes/web/dom/dependencies.d.ts +0 -4
  382. package/types/src/runtimes/web/dom/dependency_loader.d.ts +0 -10
  383. package/types/src/runtimes/web/dom/jsonp_request.d.ts +0 -10
  384. package/types/src/runtimes/web/dom/script_receiver.d.ts +0 -7
  385. package/types/src/runtimes/web/dom/script_receiver_factory.d.ts +0 -10
  386. package/types/src/runtimes/web/dom/script_request.d.ts +0 -9
  387. package/types/src/runtimes/web/http/http.d.ts +0 -2
  388. package/types/src/runtimes/web/http/http_xdomain_request.d.ts +0 -3
  389. package/types/src/runtimes/web/net_info.d.ts +0 -7
  390. package/types/src/runtimes/web/runtime.d.ts +0 -3
  391. package/types/src/runtimes/web/timeline/jsonp_timeline.d.ts +0 -6
  392. package/types/src/runtimes/web/transports/transport_connection_initializer.d.ts +0 -1
  393. package/types/src/runtimes/web/transports/transports.d.ts +0 -2
  394. package/types/src/runtimes/worker/auth/fetch_auth.d.ts +0 -3
  395. package/types/src/runtimes/worker/net_info.d.ts +0 -6
  396. package/types/src/runtimes/worker/runtime.d.ts +0 -3
  397. package/types/src/runtimes/worker/timeline/fetch_timeline.d.ts +0 -6
@@ -23,24 +23,18 @@ class ScriptReceiverFactory {
23
23
  delete this[receiver.number];
24
24
  }
25
25
  }
26
- var ScriptReceivers = new ScriptReceiverFactory(
27
- "_pusher_script_",
28
- "Pusher.ScriptReceivers"
29
- );
26
+ var ScriptReceivers = new ScriptReceiverFactory("_pusher_script_", "Pusher.ScriptReceivers");
30
27
  var Defaults = {
31
28
  VERSION: "8.4.0",
32
29
  PROTOCOL: 7,
33
30
  wsPort: 80,
34
31
  wssPort: 443,
35
32
  wsPath: "",
36
- // DEPRECATED: SockJS fallback parameters
37
33
  httpHost: "sockjs.pusher.com",
38
34
  httpPort: 80,
39
35
  httpsPort: 443,
40
36
  httpPath: "/pusher",
41
- // DEPRECATED: Stats
42
37
  stats_host: "stats.pusher.com",
43
- // DEPRECATED: Other settings
44
38
  authEndpoint: "/pusher/auth",
45
39
  authTransport: "ajax",
46
40
  activityTimeout: 12e4,
@@ -54,7 +48,6 @@ var Defaults = {
54
48
  endpoint: "/pusher/auth",
55
49
  transport: "ajax"
56
50
  },
57
- // CDN configuration
58
51
  cdn_http: "//js.pusher.com/",
59
52
  cdn_https: "//js.pusher.com/",
60
53
  dependency_suffix: ""
@@ -65,11 +58,6 @@ class DependencyLoader {
65
58
  this.receivers = options.receivers || ScriptReceivers;
66
59
  this.loading = {};
67
60
  }
68
- /** Loads the dependency from CDN.
69
- *
70
- * @param {String} name
71
- * @param {Function} callback
72
- */
73
61
  load(name, options, callback) {
74
62
  var self = this;
75
63
  if (self.loading[name] && self.loading[name].length > 0) {
@@ -95,10 +83,6 @@ class DependencyLoader {
95
83
  request.send(receiver);
96
84
  }
97
85
  }
98
- /** Returns a root URL for pusher-js CDN.
99
- *
100
- * @returns {String}
101
- */
102
86
  getRoot(options) {
103
87
  var cdn;
104
88
  var protocol = Runtime.getDocument().location.protocol;
@@ -109,19 +93,11 @@ class DependencyLoader {
109
93
  }
110
94
  return cdn.replace(/\/*$/, "") + "/" + this.options.version;
111
95
  }
112
- /** Returns a full path to a dependency file.
113
- *
114
- * @param {String} name
115
- * @returns {String}
116
- */
117
96
  getPath(name, options) {
118
97
  return this.getRoot(options) + "/" + name + this.options.suffix + ".js";
119
98
  }
120
99
  }
121
- var DependenciesReceivers = new ScriptReceiverFactory(
122
- "_pusher_dependencies",
123
- "Pusher.DependenciesReceivers"
124
- );
100
+ var DependenciesReceivers = new ScriptReceiverFactory("_pusher_dependencies", "Pusher.DependenciesReceivers");
125
101
  var Dependencies = new DependencyLoader({
126
102
  cdn_http: Defaults.cdn_http,
127
103
  cdn_https: Defaults.cdn_https,
@@ -152,22 +128,24 @@ const urlStore = {
152
128
  const buildLogSuffix = function(key) {
153
129
  const urlPrefix = "See:";
154
130
  const urlObj = urlStore.urls[key];
155
- if (!urlObj) return "";
131
+ if (!urlObj)
132
+ return "";
156
133
  let url;
157
134
  if (urlObj.fullUrl) {
158
135
  url = urlObj.fullUrl;
159
136
  } else if (urlObj.path) {
160
137
  url = urlStore.baseUrl + urlObj.path;
161
138
  }
162
- if (!url) return "";
139
+ if (!url)
140
+ return "";
163
141
  return `${urlPrefix} ${url}`;
164
142
  };
165
143
  const urlStore$1 = { buildLogSuffix };
166
- var AuthRequestType = /* @__PURE__ */ ((AuthRequestType2) => {
144
+ var AuthRequestType;
145
+ (function(AuthRequestType2) {
167
146
  AuthRequestType2["UserAuthentication"] = "user-authentication";
168
147
  AuthRequestType2["ChannelAuthorization"] = "channel-authorization";
169
- return AuthRequestType2;
170
- })(AuthRequestType || {});
148
+ })(AuthRequestType || (AuthRequestType = {}));
171
149
  class BadEventName extends Error {
172
150
  constructor(msg) {
173
151
  super(msg);
@@ -245,13 +223,7 @@ const ajax = function(context, query, authOptions, authRequestType, callback) {
245
223
  data = JSON.parse(xhr.responseText);
246
224
  parsed = true;
247
225
  } catch (e) {
248
- callback(
249
- new HTTPAuthError(
250
- 200,
251
- `JSON returned from ${authRequestType.toString()} endpoint was invalid, yet status code was 200. Data was: ${xhr.responseText}`
252
- ),
253
- null
254
- );
226
+ callback(new HTTPAuthError(200, `JSON returned from ${authRequestType.toString()} endpoint was invalid, yet status code was 200. Data was: ${xhr.responseText}`), null);
255
227
  }
256
228
  if (parsed) {
257
229
  callback(null, data);
@@ -263,18 +235,10 @@ const ajax = function(context, query, authOptions, authRequestType, callback) {
263
235
  suffix = urlStore$1.buildLogSuffix("authenticationEndpoint");
264
236
  break;
265
237
  case AuthRequestType.ChannelAuthorization:
266
- suffix = `Clients must be authorized to join private or presence channels. ${urlStore$1.buildLogSuffix(
267
- "authorizationEndpoint"
268
- )}`;
238
+ suffix = `Clients must be authorized to join private or presence channels. ${urlStore$1.buildLogSuffix("authorizationEndpoint")}`;
269
239
  break;
270
240
  }
271
- callback(
272
- new HTTPAuthError(
273
- xhr.status,
274
- `Unable to retrieve auth string from ${authRequestType.toString()} endpoint - received status: ${xhr.status} from ${authOptions.endpoint}. ${suffix}`
275
- ),
276
- null
277
- );
241
+ callback(new HTTPAuthError(xhr.status, `Unable to retrieve auth string from ${authRequestType.toString()} endpoint - received status: ${xhr.status} from ${authOptions.endpoint}. ${suffix}`), null);
278
242
  }
279
243
  }
280
244
  };
@@ -316,14 +280,9 @@ class Timer {
316
280
  }
317
281
  }, delay);
318
282
  }
319
- /** Returns whether the timer is still running.
320
- *
321
- * @return {Boolean}
322
- */
323
283
  isRunning() {
324
284
  return this.timer !== null;
325
285
  }
326
- /** Aborts a timer when it's running. */
327
286
  ensureAborted() {
328
287
  if (this.timer) {
329
288
  this.clear(this.timer);
@@ -364,14 +323,6 @@ var Util = {
364
323
  defer(callback) {
365
324
  return new OneOffTimer(0, callback);
366
325
  },
367
- /** Builds a function that will proxy a method call to its first argument.
368
- *
369
- * Allows partial application of arguments, so additional arguments are
370
- * prepended to the argument list.
371
- *
372
- * @param {String} name method name
373
- * @return {Function} proxy function
374
- */
375
326
  method(name, ...args) {
376
327
  var boundArguments = Array.prototype.slice.call(arguments, 1);
377
328
  return function(object) {
@@ -514,10 +465,7 @@ function buildQueryString(data) {
514
465
  var params = filterObject(data, function(value) {
515
466
  return value !== void 0;
516
467
  });
517
- var query = map(
518
- flatten(encodeParamsObject(params)),
519
- Util.method("join", "=")
520
- ).join("&");
468
+ var query = map(flatten(encodeParamsObject(params)), Util.method("join", "=")).join("&");
521
469
  return query;
522
470
  }
523
471
  function decycleObject(object) {
@@ -545,10 +493,7 @@ function decycleObject(object) {
545
493
  nu = {};
546
494
  for (name in value) {
547
495
  if (Object.prototype.hasOwnProperty.call(value, name)) {
548
- nu[name] = derez(
549
- value[name],
550
- path + "[" + JSON.stringify(name) + "]"
551
- );
496
+ nu[name] = derez(value[name], path + "[" + JSON.stringify(name) + "]");
552
497
  }
553
498
  }
554
499
  }
@@ -571,7 +516,7 @@ let config = {
571
516
  logToConsole: false
572
517
  };
573
518
  function setLoggerConfig(newConfig) {
574
- config = { ...config, ...newConfig };
519
+ config = Object.assign(Object.assign({}, config), newConfig);
575
520
  }
576
521
  class Logger {
577
522
  constructor() {
@@ -617,9 +562,7 @@ class Logger {
617
562
  const Logger$1 = new Logger();
618
563
  var jsonp$1 = function(context, query, authOptions, authRequestType, callback) {
619
564
  if (authOptions.headers !== void 0 || authOptions.headersProvider != null) {
620
- Logger$1.warn(
621
- `To send headers with the ${authRequestType.toString()} request, you must use AJAX, rather than JSONP.`
622
- );
565
+ Logger$1.warn(`To send headers with the ${authRequestType.toString()} request, you must use AJAX, rather than JSONP.`);
623
566
  }
624
567
  var callbackName = context.nextAuthCallbackID.toString();
625
568
  context.nextAuthCallbackID++;
@@ -673,7 +616,6 @@ class ScriptRequest {
673
616
  head.insertBefore(self.errorScript, self.script.nextSibling);
674
617
  }
675
618
  }
676
- /** Cleans up the DOM remains of the script request. */
677
619
  cleanup() {
678
620
  if (this.script) {
679
621
  this.script.onload = this.script.onerror = null;
@@ -689,31 +631,6 @@ class ScriptRequest {
689
631
  this.errorScript = null;
690
632
  }
691
633
  }
692
- class JSONPRequest {
693
- constructor(url, data) {
694
- this.url = url;
695
- this.data = data;
696
- }
697
- /** Sends the actual JSONP request.
698
- *
699
- * @param {ScriptReceiver} receiver
700
- */
701
- send(receiver) {
702
- if (this.request) {
703
- return;
704
- }
705
- var query = buildQueryString(this.data);
706
- var url = this.url + "/" + receiver.number + "?" + query;
707
- this.request = Runtime.createScriptRequest(url);
708
- this.request.send(receiver);
709
- }
710
- /** Cleans up the DOM remains of the JSONP request. */
711
- cleanup() {
712
- if (this.request) {
713
- this.request.cleanup();
714
- }
715
- }
716
- }
717
634
  var getAgent = function(sender, useTLS) {
718
635
  return function(data, callback) {
719
636
  var scheme = "http" + (useTLS ? "s" : "") + "://";
@@ -794,30 +711,19 @@ class CallbackRegistry {
794
711
  }
795
712
  }
796
713
  removeCallback(names, callback, context) {
797
- apply(
798
- names,
799
- function(name) {
800
- this._callbacks[name] = filter(
801
- this._callbacks[name] || [],
802
- function(binding) {
803
- return callback && callback !== binding.fn || context && context !== binding.context;
804
- }
805
- );
806
- if (this._callbacks[name].length === 0) {
807
- delete this._callbacks[name];
808
- }
809
- },
810
- this
811
- );
714
+ apply(names, function(name) {
715
+ this._callbacks[name] = filter(this._callbacks[name] || [], function(binding) {
716
+ return callback && callback !== binding.fn || context && context !== binding.context;
717
+ });
718
+ if (this._callbacks[name].length === 0) {
719
+ delete this._callbacks[name];
720
+ }
721
+ }, this);
812
722
  }
813
723
  removeAllCallbacks(names) {
814
- apply(
815
- names,
816
- function(name) {
817
- delete this._callbacks[name];
818
- },
819
- this
820
- );
724
+ apply(names, function(name) {
725
+ delete this._callbacks[name];
726
+ }, this);
821
727
  }
822
728
  }
823
729
  function prefix(name) {
@@ -846,10 +752,7 @@ class Dispatcher {
846
752
  this.global_callbacks = [];
847
753
  return this;
848
754
  }
849
- this.global_callbacks = filter(
850
- this.global_callbacks || [],
851
- (c) => c !== callback
852
- );
755
+ this.global_callbacks = filter(this.global_callbacks || [], (c) => c !== callback);
853
756
  return this;
854
757
  }
855
758
  unbind_all() {
@@ -892,24 +795,12 @@ class TransportConnection extends Dispatcher {
892
795
  this.activityTimeout = options.activityTimeout;
893
796
  this.id = this.timeline.generateUniqueID();
894
797
  }
895
- /** Checks whether the transport handles activity checks by itself.
896
- *
897
- * @return {Boolean}
898
- */
899
798
  handlesActivityChecks() {
900
799
  return Boolean(this.hooks.handlesActivityChecks);
901
800
  }
902
- /** Checks whether the transport supports the ping/pong API.
903
- *
904
- * @return {Boolean}
905
- */
906
801
  supportsPing() {
907
802
  return Boolean(this.hooks.supportsPing);
908
803
  }
909
- /** Tries to establish a connection.
910
- *
911
- * @returns {Boolean} false if transport is in invalid state
912
- */
913
804
  connect() {
914
805
  if (this.socket || this.state !== "initialized") {
915
806
  return false;
@@ -929,10 +820,6 @@ class TransportConnection extends Dispatcher {
929
820
  this.changeState("connecting");
930
821
  return true;
931
822
  }
932
- /** Closes the connection.
933
- *
934
- * @return {Boolean} true if there was a connection to close
935
- */
936
823
  close() {
937
824
  if (this.socket) {
938
825
  this.socket.close();
@@ -941,11 +828,6 @@ class TransportConnection extends Dispatcher {
941
828
  return false;
942
829
  }
943
830
  }
944
- /** Sends data over the open connection.
945
- *
946
- * @param {String} data
947
- * @return {Boolean} true only when in the "open" state
948
- */
949
831
  send(data) {
950
832
  if (this.state === "open") {
951
833
  Util.defer(() => {
@@ -958,7 +840,6 @@ class TransportConnection extends Dispatcher {
958
840
  return false;
959
841
  }
960
842
  }
961
- /** Sends a ping if the connection is open and transport supports it. */
962
843
  ping() {
963
844
  if (this.state === "open" && this.supportsPing()) {
964
845
  this.socket.ping();
@@ -966,10 +847,7 @@ class TransportConnection extends Dispatcher {
966
847
  }
967
848
  onOpen() {
968
849
  if (this.hooks.beforeOpen) {
969
- this.hooks.beforeOpen(
970
- this.socket,
971
- this.hooks.urls.getPath(this.key, this.options)
972
- );
850
+ this.hooks.beforeOpen(this.socket, this.hooks.urls.getPath(this.key, this.options));
973
851
  }
974
852
  this.changeState("open");
975
853
  this.socket.onopen = void 0;
@@ -1029,12 +907,10 @@ class TransportConnection extends Dispatcher {
1029
907
  }
1030
908
  changeState(state, params) {
1031
909
  this.state = state;
1032
- this.timeline.info(
1033
- this.buildTimelineMessage({
1034
- state,
1035
- params
1036
- })
1037
- );
910
+ this.timeline.info(this.buildTimelineMessage({
911
+ state,
912
+ params
913
+ }));
1038
914
  this.emit(state, params);
1039
915
  }
1040
916
  buildTimelineMessage(message) {
@@ -1045,22 +921,9 @@ class Transport {
1045
921
  constructor(hooks2) {
1046
922
  this.hooks = hooks2;
1047
923
  }
1048
- /** Returns whether the transport is supported in the environment.
1049
- *
1050
- * @param {Object} envronment te environment details (encryption, settings)
1051
- * @returns {Boolean} true when the transport is supported
1052
- */
1053
924
  isSupported(environment) {
1054
925
  return this.hooks.isSupported(environment);
1055
926
  }
1056
- /** Creates a transport connection.
1057
- *
1058
- * @param {String} name
1059
- * @param {Number} priority
1060
- * @param {String} key the application key
1061
- * @param {Object} options
1062
- * @returns {TransportConnection}
1063
- */
1064
927
  createConnection(name, priority, key, options) {
1065
928
  return new TransportConnection(this.hooks, name, priority, key, options);
1066
929
  }
@@ -1087,33 +950,23 @@ var httpConfiguration = {
1087
950
  return true;
1088
951
  }
1089
952
  };
1090
- var streamingConfiguration = extend(
1091
- {
1092
- getSocket: function(url) {
1093
- return Runtime.HTTPFactory.createStreamingSocket(url);
1094
- }
1095
- },
1096
- httpConfiguration
1097
- );
1098
- var pollingConfiguration = extend(
1099
- {
1100
- getSocket: function(url) {
1101
- return Runtime.HTTPFactory.createPollingSocket(url);
1102
- }
1103
- },
1104
- httpConfiguration
1105
- );
953
+ var streamingConfiguration = extend({
954
+ getSocket: function(url) {
955
+ return Runtime.HTTPFactory.createStreamingSocket(url);
956
+ }
957
+ }, httpConfiguration);
958
+ var pollingConfiguration = extend({
959
+ getSocket: function(url) {
960
+ return Runtime.HTTPFactory.createPollingSocket(url);
961
+ }
962
+ }, httpConfiguration);
1106
963
  var xhrConfiguration = {
1107
964
  isSupported: function() {
1108
965
  return Runtime.isXHRSupported();
1109
966
  }
1110
967
  };
1111
- var XHRStreamingTransport = new Transport(
1112
- extend({}, streamingConfiguration, xhrConfiguration)
1113
- );
1114
- var XHRPollingTransport = new Transport(
1115
- extend({}, pollingConfiguration, xhrConfiguration)
1116
- );
968
+ var XHRStreamingTransport = new Transport(extend({}, streamingConfiguration, xhrConfiguration));
969
+ var XHRPollingTransport = new Transport(extend({}, pollingConfiguration, xhrConfiguration));
1117
970
  var Transports$1 = {
1118
971
  ws: WSTransport,
1119
972
  xhr_streaming: XHRStreamingTransport,
@@ -1139,11 +992,9 @@ var SockJSTransport = new Transport({
1139
992
  });
1140
993
  },
1141
994
  beforeOpen: function(socket, path) {
1142
- socket.send(
1143
- JSON.stringify({
1144
- path
1145
- })
1146
- );
995
+ socket.send(JSON.stringify({
996
+ path
997
+ }));
1147
998
  }
1148
999
  });
1149
1000
  var xdrConfiguration = {
@@ -1152,12 +1003,8 @@ var xdrConfiguration = {
1152
1003
  return yes;
1153
1004
  }
1154
1005
  };
1155
- var XDRStreamingTransport = new Transport(
1156
- extend({}, streamingConfiguration, xdrConfiguration)
1157
- );
1158
- var XDRPollingTransport = new Transport(
1159
- extend({}, pollingConfiguration, xdrConfiguration)
1160
- );
1006
+ var XDRStreamingTransport = new Transport(extend({}, streamingConfiguration, xdrConfiguration));
1007
+ var XDRPollingTransport = new Transport(extend({}, pollingConfiguration, xdrConfiguration));
1161
1008
  Transports$1.xdr_streaming = XDRStreamingTransport;
1162
1009
  Transports$1.xdr_polling = XDRPollingTransport;
1163
1010
  Transports$1.sockjs = SockJSTransport;
@@ -1166,30 +1013,14 @@ class NetInfo extends Dispatcher {
1166
1013
  super();
1167
1014
  var self = this;
1168
1015
  if (window.addEventListener !== void 0) {
1169
- window.addEventListener(
1170
- "online",
1171
- function() {
1172
- self.emit("online");
1173
- },
1174
- false
1175
- );
1176
- window.addEventListener(
1177
- "offline",
1178
- function() {
1179
- self.emit("offline");
1180
- },
1181
- false
1182
- );
1016
+ window.addEventListener("online", function() {
1017
+ self.emit("online");
1018
+ }, false);
1019
+ window.addEventListener("offline", function() {
1020
+ self.emit("offline");
1021
+ }, false);
1183
1022
  }
1184
1023
  }
1185
- /** Returns whether browser is online or not
1186
- *
1187
- * Offline means definitely offline (no connection to router).
1188
- * Inverse does NOT mean definitely online (only currently supported in Safari
1189
- * and even there only means the device has a connection to the router).
1190
- *
1191
- * @return {Boolean}
1192
- */
1193
1024
  isOnline() {
1194
1025
  if (window.navigator.onLine === void 0) {
1195
1026
  return true;
@@ -1207,26 +1038,11 @@ class AssistantToTheTransportManager {
1207
1038
  this.maxPingDelay = options.maxPingDelay;
1208
1039
  this.pingDelay = void 0;
1209
1040
  }
1210
- /** Creates a transport connection.
1211
- *
1212
- * This function has the same API as Transport#createConnection.
1213
- *
1214
- * @param {String} name
1215
- * @param {Number} priority
1216
- * @param {String} key the application key
1217
- * @param {Object} options
1218
- * @returns {TransportConnection}
1219
- */
1220
1041
  createConnection(name, priority, key, options) {
1221
1042
  options = extend({}, options, {
1222
1043
  activityTimeout: this.pingDelay
1223
1044
  });
1224
- var connection = this.transport.createConnection(
1225
- name,
1226
- priority,
1227
- key,
1228
- options
1229
- );
1045
+ var connection = this.transport.createConnection(name, priority, key, options);
1230
1046
  var openTimestamp = null;
1231
1047
  var onOpen = function() {
1232
1048
  connection.unbind("open", onOpen);
@@ -1248,35 +1064,13 @@ class AssistantToTheTransportManager {
1248
1064
  connection.bind("open", onOpen);
1249
1065
  return connection;
1250
1066
  }
1251
- /** Returns whether the transport is supported in the environment.
1252
- *
1253
- * This function has the same API as Transport#isSupported. Might return false
1254
- * when the manager decides to kill the transport.
1255
- *
1256
- * @param {Object} environment the environment details (encryption, settings)
1257
- * @returns {Boolean} true when the transport is supported
1258
- */
1259
1067
  isSupported(environment) {
1260
1068
  return this.manager.isAlive() && this.transport.isSupported(environment);
1261
1069
  }
1262
1070
  }
1263
1071
  const Protocol = {
1264
- /**
1265
- * Decodes a message in a Pusher format.
1266
- *
1267
- * The MessageEvent we receive from the transport should contain a pusher event
1268
- * (https://pusher.com/docs/pusher_protocol#events) serialized as JSON in the
1269
- * data field
1270
- *
1271
- * The pusher event may contain a data field too, and it may also be
1272
- * serialised as JSON
1273
- *
1274
- * Throws errors when messages are not parse'able.
1275
- *
1276
- * @param {MessageEvent} messageEvent
1277
- * @return {PusherEvent}
1278
- */
1279
1072
  decodeMessage: function(messageEvent) {
1073
+ var _a, _b;
1280
1074
  try {
1281
1075
  var messageData = JSON.parse(messageEvent.data);
1282
1076
  var pusherEventData = messageData.data;
@@ -1291,13 +1085,12 @@ const Protocol = {
1291
1085
  channel: messageData.channel,
1292
1086
  data: pusherEventData,
1293
1087
  rawMessage: messageEvent.data
1294
- // Preserve raw message for delta compression
1295
1088
  };
1296
1089
  if (messageData.user_id) {
1297
1090
  pusherEvent.user_id = messageData.user_id;
1298
1091
  }
1299
- const sequence = messageData.__delta_seq ?? messageData.sequence;
1300
- const conflationKey = messageData.__conflation_key ?? messageData.conflation_key;
1092
+ const sequence = (_a = messageData.__delta_seq) !== null && _a !== void 0 ? _a : messageData.sequence;
1093
+ const conflationKey = (_b = messageData.__conflation_key) !== null && _b !== void 0 ? _b : messageData.conflation_key;
1301
1094
  if (typeof sequence === "number") {
1302
1095
  pusherEvent.sequence = sequence;
1303
1096
  }
@@ -1309,29 +1102,9 @@ const Protocol = {
1309
1102
  throw { type: "MessageParseError", error: e, data: messageEvent.data };
1310
1103
  }
1311
1104
  },
1312
- /**
1313
- * Encodes a message to be sent.
1314
- *
1315
- * @param {PusherEvent} event
1316
- * @return {String}
1317
- */
1318
1105
  encodeMessage: function(event) {
1319
1106
  return JSON.stringify(event);
1320
1107
  },
1321
- /**
1322
- * Processes a handshake message and returns appropriate actions.
1323
- *
1324
- * Returns an object with an 'action' and other action-specific properties.
1325
- *
1326
- * There are three outcomes when calling this function. First is a successful
1327
- * connection attempt, when pusher:connection_established is received, which
1328
- * results in a 'connected' action with an 'id' property. When passed a
1329
- * pusher:error event, it returns a result with action appropriate to the
1330
- * close code and an error. Otherwise, it raises an exception.
1331
- *
1332
- * @param {String} message
1333
- * @result Object
1334
- */
1335
1108
  processHandshake: function(messageEvent) {
1336
1109
  var message = Protocol.decodeMessage(messageEvent);
1337
1110
  if (message.event === "pusher:connection_established") {
@@ -1352,16 +1125,6 @@ const Protocol = {
1352
1125
  throw "Invalid handshake";
1353
1126
  }
1354
1127
  },
1355
- /**
1356
- * Dispatches the close event and returns an appropriate action name.
1357
- *
1358
- * See:
1359
- * 1. https://developer.mozilla.org/en-US/docs/WebSockets/WebSockets_reference/CloseEvent
1360
- * 2. http://pusher.com/docs/pusher_protocol
1361
- *
1362
- * @param {CloseEvent} closeEvent
1363
- * @return {String} close action name
1364
- */
1365
1128
  getCloseAction: function(closeEvent) {
1366
1129
  if (closeEvent.code < 4e3) {
1367
1130
  if (closeEvent.code >= 1002 && closeEvent.code <= 1004) {
@@ -1381,15 +1144,6 @@ const Protocol = {
1381
1144
  return "refused";
1382
1145
  }
1383
1146
  },
1384
- /**
1385
- * Returns an error or null basing on the close event.
1386
- *
1387
- * Null is returned when connection was closed cleanly. Otherwise, an object
1388
- * with error details is returned.
1389
- *
1390
- * @param {CloseEvent} closeEvent
1391
- * @return {Object} error object
1392
- */
1393
1147
  getCloseError: function(closeEvent) {
1394
1148
  if (closeEvent.code !== 1e3 && closeEvent.code !== 1001) {
1395
1149
  return {
@@ -1412,27 +1166,12 @@ class Connection extends Dispatcher {
1412
1166
  this.activityTimeout = transport.activityTimeout;
1413
1167
  this.bindListeners();
1414
1168
  }
1415
- /** Returns whether used transport handles activity checks by itself
1416
- *
1417
- * @returns {Boolean} true if activity checks are handled by the transport
1418
- */
1419
1169
  handlesActivityChecks() {
1420
1170
  return this.transport.handlesActivityChecks();
1421
1171
  }
1422
- /** Sends raw data.
1423
- *
1424
- * @param {String} data
1425
- */
1426
1172
  send(data) {
1427
1173
  return this.transport.send(data);
1428
1174
  }
1429
- /** Sends an event.
1430
- *
1431
- * @param {String} name
1432
- * @param {String} data
1433
- * @param {String} [channel]
1434
- * @returns {Boolean} whether message was sent or not
1435
- */
1436
1175
  send_event(name, data, channel) {
1437
1176
  var event = { event: name, data };
1438
1177
  if (channel) {
@@ -1441,11 +1180,6 @@ class Connection extends Dispatcher {
1441
1180
  Logger$1.debug("Event sent", event);
1442
1181
  return this.send(Protocol.encodeMessage(event));
1443
1182
  }
1444
- /** Sends a ping message to the server.
1445
- *
1446
- * Basing on the underlying transport, it might send either transport's
1447
- * protocol-specific ping or pusher:ping event.
1448
- */
1449
1183
  ping() {
1450
1184
  if (this.transport.supportsPing()) {
1451
1185
  this.transport.ping();
@@ -1453,7 +1187,6 @@ class Connection extends Dispatcher {
1453
1187
  this.send_event("pusher:ping", {});
1454
1188
  }
1455
1189
  }
1456
- /** Closes the connection. */
1457
1190
  close() {
1458
1191
  this.transport.close();
1459
1192
  }
@@ -1569,9 +1302,7 @@ class Handshake {
1569
1302
  this.transport.unbind("closed", this.onClosed);
1570
1303
  }
1571
1304
  finish(action, params) {
1572
- this.callback(
1573
- extend({ transport: this.transport, action }, params)
1574
- );
1305
+ this.callback(extend({ transport: this.transport, action }, params));
1575
1306
  }
1576
1307
  }
1577
1308
  class TimelineSender {
@@ -1583,10 +1314,7 @@ class TimelineSender {
1583
1314
  if (this.timeline.isEmpty()) {
1584
1315
  return;
1585
1316
  }
1586
- this.timeline.send(
1587
- Runtime.TimelineTransport.getAgent(this, useTLS),
1588
- callback
1589
- );
1317
+ this.timeline.send(Runtime.TimelineTransport.getAgent(this, useTLS), callback);
1590
1318
  }
1591
1319
  }
1592
1320
  class Channel extends Dispatcher {
@@ -1601,37 +1329,23 @@ class Channel extends Dispatcher {
1601
1329
  this.subscriptionCancelled = false;
1602
1330
  this.tagsFilter = null;
1603
1331
  }
1604
- /** Skips authorization, since public channels don't require it.
1605
- *
1606
- * @param {Function} callback
1607
- */
1608
1332
  authorize(socketId, callback) {
1609
1333
  return callback(null, { auth: "" });
1610
1334
  }
1611
- /** Triggers an event */
1612
1335
  trigger(event, data) {
1613
1336
  if (event.indexOf("client-") !== 0) {
1614
- throw new BadEventName(
1615
- "Event '" + event + "' does not start with 'client-'"
1616
- );
1337
+ throw new BadEventName("Event '" + event + "' does not start with 'client-'");
1617
1338
  }
1618
1339
  if (!this.subscribed) {
1619
1340
  var suffix = urlStore$1.buildLogSuffix("triggeringClientEvents");
1620
- Logger$1.warn(
1621
- `Client event triggered before channel 'subscription_succeeded' event . ${suffix}`
1622
- );
1341
+ Logger$1.warn(`Client event triggered before channel 'subscription_succeeded' event . ${suffix}`);
1623
1342
  }
1624
1343
  return this.pusher.send_event(event, data, this.name);
1625
1344
  }
1626
- /** Signals disconnection to the channel. For internal use only. */
1627
1345
  disconnect() {
1628
1346
  this.subscribed = false;
1629
1347
  this.subscriptionPending = false;
1630
1348
  }
1631
- /** Handles a PusherEvent. For internal use only.
1632
- *
1633
- * @param {PusherEvent} event
1634
- */
1635
1349
  handleEvent(event) {
1636
1350
  var eventName = event.event;
1637
1351
  var data = event.data;
@@ -1659,87 +1373,58 @@ class Channel extends Dispatcher {
1659
1373
  }
1660
1374
  this.emit("pusher:subscription_count", event.data);
1661
1375
  }
1662
- /** Sends a subscription request. For internal use only. */
1663
1376
  subscribe() {
1664
1377
  if (this.subscribed) {
1665
1378
  return;
1666
1379
  }
1667
1380
  this.subscriptionPending = true;
1668
1381
  this.subscriptionCancelled = false;
1669
- this.authorize(
1670
- this.pusher.connection.socket_id,
1671
- (error, data) => {
1672
- if (error) {
1673
- this.subscriptionPending = false;
1674
- Logger$1.error(error.toString());
1675
- this.emit(
1676
- "pusher:subscription_error",
1677
- Object.assign(
1678
- {},
1679
- {
1680
- type: "AuthError",
1681
- error: error.message
1682
- },
1683
- error instanceof HTTPAuthError ? { status: error.status } : {}
1684
- )
1685
- );
1686
- } else {
1687
- const subscribeData = {
1688
- auth: data.auth,
1689
- channel_data: data.channel_data,
1690
- channel: this.name
1691
- };
1692
- if (this.tagsFilter) {
1693
- subscribeData.tags_filter = this.tagsFilter;
1694
- }
1695
- this.pusher.send_event("pusher:subscribe", subscribeData);
1382
+ this.authorize(this.pusher.connection.socket_id, (error, data) => {
1383
+ if (error) {
1384
+ this.subscriptionPending = false;
1385
+ Logger$1.error(error.toString());
1386
+ this.emit("pusher:subscription_error", Object.assign({}, {
1387
+ type: "AuthError",
1388
+ error: error.message
1389
+ }, error instanceof HTTPAuthError ? { status: error.status } : {}));
1390
+ } else {
1391
+ const subscribeData = {
1392
+ auth: data.auth,
1393
+ channel_data: data.channel_data,
1394
+ channel: this.name
1395
+ };
1396
+ if (this.tagsFilter) {
1397
+ subscribeData.tags_filter = this.tagsFilter;
1696
1398
  }
1399
+ this.pusher.send_event("pusher:subscribe", subscribeData);
1697
1400
  }
1698
- );
1401
+ });
1699
1402
  }
1700
- /** Sends an unsubscription request. For internal use only. */
1701
1403
  unsubscribe() {
1702
1404
  this.subscribed = false;
1703
1405
  this.pusher.send_event("pusher:unsubscribe", {
1704
1406
  channel: this.name
1705
1407
  });
1706
1408
  }
1707
- /** Cancels an in progress subscription. For internal use only. */
1708
1409
  cancelSubscription() {
1709
1410
  this.subscriptionCancelled = true;
1710
1411
  }
1711
- /** Reinstates an in progress subscripiton. For internal use only. */
1712
1412
  reinstateSubscription() {
1713
1413
  this.subscriptionCancelled = false;
1714
1414
  }
1715
1415
  }
1716
1416
  class PrivateChannel extends Channel {
1717
- /** Authorizes the connection to use the channel.
1718
- *
1719
- * @param {String} socketId
1720
- * @param {Function} callback
1721
- */
1722
1417
  authorize(socketId, callback) {
1723
- return this.pusher.config.channelAuthorizer(
1724
- {
1725
- channelName: this.name,
1726
- socketId
1727
- },
1728
- callback
1729
- );
1418
+ return this.pusher.config.channelAuthorizer({
1419
+ channelName: this.name,
1420
+ socketId
1421
+ }, callback);
1730
1422
  }
1731
1423
  }
1732
1424
  class Members {
1733
1425
  constructor() {
1734
1426
  this.reset();
1735
1427
  }
1736
- /** Returns member's info for given id.
1737
- *
1738
- * Resulting object containts two fields - id and info.
1739
- *
1740
- * @param {Number} id
1741
- * @return {Object} member's info or null
1742
- */
1743
1428
  get(id) {
1744
1429
  if (Object.prototype.hasOwnProperty.call(this.members, id)) {
1745
1430
  return {
@@ -1750,26 +1435,19 @@ class Members {
1750
1435
  return null;
1751
1436
  }
1752
1437
  }
1753
- /** Calls back for each member in unspecified order.
1754
- *
1755
- * @param {Function} callback
1756
- */
1757
1438
  each(callback) {
1758
1439
  objectApply(this.members, (member, id) => {
1759
1440
  callback(this.get(id));
1760
1441
  });
1761
1442
  }
1762
- /** Updates the id for connected member. For internal use only. */
1763
1443
  setMyID(id) {
1764
1444
  this.myID = id;
1765
1445
  }
1766
- /** Handles subscription data. For internal use only. */
1767
1446
  onSubscription(subscriptionData) {
1768
1447
  this.members = subscriptionData.presence.hash;
1769
1448
  this.count = subscriptionData.presence.count;
1770
1449
  this.me = this.get(this.myID);
1771
1450
  }
1772
- /** Adds a new member to the collection. For internal use only. */
1773
1451
  addMember(memberData) {
1774
1452
  if (this.get(memberData.user_id) === null) {
1775
1453
  this.count++;
@@ -1777,7 +1455,6 @@ class Members {
1777
1455
  this.members[memberData.user_id] = memberData.user_info;
1778
1456
  return this.get(memberData.user_id);
1779
1457
  }
1780
- /** Adds a member from the collection. For internal use only. */
1781
1458
  removeMember(memberData) {
1782
1459
  var member = this.get(memberData.user_id);
1783
1460
  if (member) {
@@ -1786,7 +1463,6 @@ class Members {
1786
1463
  }
1787
1464
  return member;
1788
1465
  }
1789
- /** Resets the collection to the initial state. For internal use only. */
1790
1466
  reset() {
1791
1467
  this.members = {};
1792
1468
  this.count = 0;
@@ -1794,49 +1470,60 @@ class Members {
1794
1470
  this.me = null;
1795
1471
  }
1796
1472
  }
1473
+ var __awaiter = function(thisArg, _arguments, P, generator) {
1474
+ function adopt(value) {
1475
+ return value instanceof P ? value : new P(function(resolve) {
1476
+ resolve(value);
1477
+ });
1478
+ }
1479
+ return new (P || (P = Promise))(function(resolve, reject) {
1480
+ function fulfilled(value) {
1481
+ try {
1482
+ step(generator.next(value));
1483
+ } catch (e) {
1484
+ reject(e);
1485
+ }
1486
+ }
1487
+ function rejected(value) {
1488
+ try {
1489
+ step(generator["throw"](value));
1490
+ } catch (e) {
1491
+ reject(e);
1492
+ }
1493
+ }
1494
+ function step(result) {
1495
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
1496
+ }
1497
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
1498
+ });
1499
+ };
1797
1500
  class PresenceChannel extends PrivateChannel {
1798
- /** Adds presence channel functionality to private channels.
1799
- *
1800
- * @param {String} name
1801
- * @param {Pusher} pusher
1802
- */
1803
1501
  constructor(name, pusher) {
1804
1502
  super(name, pusher);
1805
1503
  this.members = new Members();
1806
1504
  }
1807
- /** Authorizes the connection as a member of the channel.
1808
- *
1809
- * @param {String} socketId
1810
- * @param {Function} callback
1811
- */
1812
1505
  authorize(socketId, callback) {
1813
- super.authorize(socketId, async (error, authData) => {
1506
+ super.authorize(socketId, (error, authData) => __awaiter(this, void 0, void 0, function* () {
1814
1507
  if (!error) {
1815
1508
  authData = authData;
1816
1509
  if (authData.channel_data != null) {
1817
1510
  var channelData = JSON.parse(authData.channel_data);
1818
1511
  this.members.setMyID(channelData.user_id);
1819
1512
  } else {
1820
- await this.pusher.user.signinDonePromise;
1513
+ yield this.pusher.user.signinDonePromise;
1821
1514
  if (this.pusher.user.user_data != null) {
1822
1515
  this.members.setMyID(this.pusher.user.user_data.id);
1823
1516
  } else {
1824
1517
  let suffix = urlStore$1.buildLogSuffix("authorizationEndpoint");
1825
- Logger$1.error(
1826
- `Invalid auth response for channel '${this.name}', expected 'channel_data' field. ${suffix}, or the user should be signed in.`
1827
- );
1518
+ Logger$1.error(`Invalid auth response for channel '${this.name}', expected 'channel_data' field. ${suffix}, or the user should be signed in.`);
1828
1519
  callback("Invalid auth response");
1829
1520
  return;
1830
1521
  }
1831
1522
  }
1832
1523
  }
1833
1524
  callback(error, authData);
1834
- });
1525
+ }));
1835
1526
  }
1836
- /** Handles presence and subscription events. For internal use only.
1837
- *
1838
- * @param {PusherEvent} event
1839
- */
1840
1527
  handleEvent(event) {
1841
1528
  var eventName = event.event;
1842
1529
  if (eventName.indexOf("pusher_internal:") === 0) {
@@ -1882,7 +1569,6 @@ class PresenceChannel extends PrivateChannel {
1882
1569
  this.emit("pusher:subscription_succeeded", this.members);
1883
1570
  }
1884
1571
  }
1885
- /** Resets the channel state, including members map. For internal use only. */
1886
1572
  disconnect() {
1887
1573
  this.members.reset();
1888
1574
  super.disconnect();
@@ -2224,49 +1910,30 @@ function requireBase64() {
2224
1910
  }
2225
1911
  var base64Exports = requireBase64();
2226
1912
  class EncryptedChannel extends PrivateChannel {
2227
- constructor(name, pusher, nacl2) {
1913
+ constructor(name, pusher, nacl) {
2228
1914
  super(name, pusher);
2229
1915
  this.key = null;
2230
- this.nacl = nacl2;
1916
+ this.nacl = nacl;
2231
1917
  }
2232
- /** Authorizes the connection to use the channel.
2233
- *
2234
- * @param {String} socketId
2235
- * @param {Function} callback
2236
- */
2237
1918
  authorize(socketId, callback) {
2238
- super.authorize(
2239
- socketId,
2240
- (error, authData) => {
2241
- if (error) {
2242
- callback(error, authData);
2243
- return;
2244
- }
2245
- let sharedSecret = authData["shared_secret"];
2246
- if (!sharedSecret) {
2247
- callback(
2248
- new Error(
2249
- `No shared_secret key in auth payload for encrypted channel: ${this.name}`
2250
- ),
2251
- null
2252
- );
2253
- return;
2254
- }
2255
- this.key = base64Exports.decode(sharedSecret);
2256
- delete authData["shared_secret"];
2257
- callback(null, authData);
1919
+ super.authorize(socketId, (error, authData) => {
1920
+ if (error) {
1921
+ callback(error, authData);
1922
+ return;
2258
1923
  }
2259
- );
1924
+ let sharedSecret = authData["shared_secret"];
1925
+ if (!sharedSecret) {
1926
+ callback(new Error(`No shared_secret key in auth payload for encrypted channel: ${this.name}`), null);
1927
+ return;
1928
+ }
1929
+ this.key = base64Exports.decode(sharedSecret);
1930
+ delete authData["shared_secret"];
1931
+ callback(null, authData);
1932
+ });
2260
1933
  }
2261
1934
  trigger(event, data) {
2262
- throw new UnsupportedFeature(
2263
- "Client events are not currently supported for encrypted channels"
2264
- );
1935
+ throw new UnsupportedFeature("Client events are not currently supported for encrypted channels");
2265
1936
  }
2266
- /** Handles an event. For internal use only.
2267
- *
2268
- * @param {PusherEvent} event
2269
- */
2270
1937
  handleEvent(event) {
2271
1938
  var eventName = event.event;
2272
1939
  var data = event.data;
@@ -2278,48 +1945,34 @@ class EncryptedChannel extends PrivateChannel {
2278
1945
  }
2279
1946
  handleEncryptedEvent(event, data) {
2280
1947
  if (!this.key) {
2281
- Logger$1.debug(
2282
- "Received encrypted event before key has been retrieved from the authEndpoint"
2283
- );
1948
+ Logger$1.debug("Received encrypted event before key has been retrieved from the authEndpoint");
2284
1949
  return;
2285
1950
  }
2286
1951
  if (!data.ciphertext || !data.nonce) {
2287
- Logger$1.error(
2288
- "Unexpected format for encrypted event, expected object with `ciphertext` and `nonce` fields, got: " + data
2289
- );
1952
+ Logger$1.error("Unexpected format for encrypted event, expected object with `ciphertext` and `nonce` fields, got: " + data);
2290
1953
  return;
2291
1954
  }
2292
1955
  let cipherText = base64Exports.decode(data.ciphertext);
2293
1956
  if (cipherText.length < this.nacl.secretbox.overheadLength) {
2294
- Logger$1.error(
2295
- `Expected encrypted event ciphertext length to be ${this.nacl.secretbox.overheadLength}, got: ${cipherText.length}`
2296
- );
1957
+ Logger$1.error(`Expected encrypted event ciphertext length to be ${this.nacl.secretbox.overheadLength}, got: ${cipherText.length}`);
2297
1958
  return;
2298
1959
  }
2299
1960
  let nonce = base64Exports.decode(data.nonce);
2300
1961
  if (nonce.length < this.nacl.secretbox.nonceLength) {
2301
- Logger$1.error(
2302
- `Expected encrypted event nonce length to be ${this.nacl.secretbox.nonceLength}, got: ${nonce.length}`
2303
- );
1962
+ Logger$1.error(`Expected encrypted event nonce length to be ${this.nacl.secretbox.nonceLength}, got: ${nonce.length}`);
2304
1963
  return;
2305
1964
  }
2306
1965
  let bytes = this.nacl.secretbox.open(cipherText, nonce, this.key);
2307
1966
  if (bytes === null) {
2308
- Logger$1.debug(
2309
- "Failed to decrypt an event, probably because it was encrypted with a different key. Fetching a new key from the authEndpoint..."
2310
- );
1967
+ Logger$1.debug("Failed to decrypt an event, probably because it was encrypted with a different key. Fetching a new key from the authEndpoint...");
2311
1968
  this.authorize(this.pusher.connection.socket_id, (error, authData) => {
2312
1969
  if (error) {
2313
- Logger$1.error(
2314
- `Failed to make a request to the authEndpoint: ${authData}. Unable to fetch new key, so dropping encrypted event`
2315
- );
1970
+ Logger$1.error(`Failed to make a request to the authEndpoint: ${authData}. Unable to fetch new key, so dropping encrypted event`);
2316
1971
  return;
2317
1972
  }
2318
1973
  bytes = this.nacl.secretbox.open(cipherText, nonce, this.key);
2319
1974
  if (bytes === null) {
2320
- Logger$1.error(
2321
- `Failed to decrypt event with new key. Dropping encrypted event`
2322
- );
1975
+ Logger$1.error(`Failed to decrypt event with new key. Dropping encrypted event`);
2323
1976
  return;
2324
1977
  }
2325
1978
  this.emit(event, this.getDataToEmit(bytes));
@@ -2329,13 +1982,11 @@ class EncryptedChannel extends PrivateChannel {
2329
1982
  }
2330
1983
  this.emit(event, this.getDataToEmit(bytes));
2331
1984
  }
2332
- // Try and parse the decrypted bytes as JSON. If we can't parse it, just
2333
- // return the utf-8 string
2334
1985
  getDataToEmit(bytes) {
2335
1986
  let raw = utf8Exports.decode(bytes);
2336
1987
  try {
2337
1988
  return JSON.parse(raw);
2338
- } catch {
1989
+ } catch (_a) {
2339
1990
  return raw;
2340
1991
  }
2341
1992
  }
@@ -2350,9 +2001,7 @@ class ConnectionManager extends Dispatcher {
2350
2001
  this.timeline = this.options.timeline;
2351
2002
  this.usingTLS = this.options.useTLS;
2352
2003
  this.errorCallbacks = this.buildErrorCallbacks();
2353
- this.connectionCallbacks = this.buildConnectionCallbacks(
2354
- this.errorCallbacks
2355
- );
2004
+ this.connectionCallbacks = this.buildConnectionCallbacks(this.errorCallbacks);
2356
2005
  this.handshakeCallbacks = this.buildHandshakeCallbacks(this.errorCallbacks);
2357
2006
  var Network2 = Runtime.getNetwork();
2358
2007
  Network2.bind("online", () => {
@@ -2369,11 +2018,6 @@ class ConnectionManager extends Dispatcher {
2369
2018
  });
2370
2019
  this.updateStrategy();
2371
2020
  }
2372
- /** Establishes a connection to Pusher.
2373
- *
2374
- * Does nothing when connection is already established. See top-level doc
2375
- * to find events emitted on connection attempts.
2376
- */
2377
2021
  connect() {
2378
2022
  if (this.connection || this.runner) {
2379
2023
  return;
@@ -2386,10 +2030,6 @@ class ConnectionManager extends Dispatcher {
2386
2030
  this.startConnecting();
2387
2031
  this.setUnavailableTimer();
2388
2032
  }
2389
- /** Sends raw data.
2390
- *
2391
- * @param {String} data
2392
- */
2393
2033
  send(data) {
2394
2034
  if (this.connection) {
2395
2035
  return this.connection.send(data);
@@ -2397,13 +2037,6 @@ class ConnectionManager extends Dispatcher {
2397
2037
  return false;
2398
2038
  }
2399
2039
  }
2400
- /** Sends an event.
2401
- *
2402
- * @param {String} name
2403
- * @param {String} data
2404
- * @param {String} [channel]
2405
- * @returns {Boolean} whether message was sent or not
2406
- */
2407
2040
  send_event(name, data, channel) {
2408
2041
  if (this.connection) {
2409
2042
  return this.connection.send_event(name, data, channel);
@@ -2411,7 +2044,6 @@ class ConnectionManager extends Dispatcher {
2411
2044
  return false;
2412
2045
  }
2413
2046
  }
2414
- /** Closes the connection. */
2415
2047
  disconnect() {
2416
2048
  this.disconnectInternally();
2417
2049
  this.updateState("disconnected");
@@ -2533,11 +2165,7 @@ class ConnectionManager extends Dispatcher {
2533
2165
  buildHandshakeCallbacks(errorCallbacks) {
2534
2166
  return extend({}, errorCallbacks, {
2535
2167
  connected: (handshake) => {
2536
- this.activityTimeout = Math.min(
2537
- this.options.activityTimeout,
2538
- handshake.activityTimeout,
2539
- handshake.connection.activityTimeout || Infinity
2540
- );
2168
+ this.activityTimeout = Math.min(this.options.activityTimeout, handshake.activityTimeout, handshake.connection.activityTimeout || Infinity);
2541
2169
  this.clearUnavailableTimer();
2542
2170
  this.setConnection(handshake.connection);
2543
2171
  this.socket_id = this.connection.id;
@@ -2598,10 +2226,7 @@ class ConnectionManager extends Dispatcher {
2598
2226
  if (newStateDescription === "connected") {
2599
2227
  newStateDescription += " with new socket ID " + data.socket_id;
2600
2228
  }
2601
- Logger$1.debug(
2602
- "State changed",
2603
- previousState + " -> " + newStateDescription
2604
- );
2229
+ Logger$1.debug("State changed", previousState + " -> " + newStateDescription);
2605
2230
  this.timeline.info({ state: newState, params: data });
2606
2231
  this.emit("state_change", { previous: previousState, current: newState });
2607
2232
  this.emit(newState, data);
@@ -2615,43 +2240,23 @@ class Channels {
2615
2240
  constructor() {
2616
2241
  this.channels = {};
2617
2242
  }
2618
- /** Creates or retrieves an existing channel by its name.
2619
- *
2620
- * @param {String} name
2621
- * @param {Pusher} pusher
2622
- * @return {Channel}
2623
- */
2624
2243
  add(name, pusher) {
2625
2244
  if (!this.channels[name]) {
2626
2245
  this.channels[name] = createChannel(name, pusher);
2627
2246
  }
2628
2247
  return this.channels[name];
2629
2248
  }
2630
- /** Returns a list of all channels
2631
- *
2632
- * @return {Array}
2633
- */
2634
2249
  all() {
2635
2250
  return values(this.channels);
2636
2251
  }
2637
- /** Finds a channel by its name.
2638
- *
2639
- * @param {String} name
2640
- * @return {Channel} channel or null if it doesn't exist
2641
- */
2642
2252
  find(name) {
2643
2253
  return this.channels[name];
2644
2254
  }
2645
- /** Removes a channel from the map.
2646
- *
2647
- * @param {String} name
2648
- */
2649
2255
  remove(name) {
2650
2256
  var channel = this.channels[name];
2651
2257
  delete this.channels[name];
2652
2258
  return channel;
2653
2259
  }
2654
- /** Proxies disconnection signal to all channels. */
2655
2260
  disconnect() {
2656
2261
  objectApply(this.channels, function(channel) {
2657
2262
  channel.disconnect();
@@ -2671,9 +2276,7 @@ function createChannel(name, pusher) {
2671
2276
  } else if (name.indexOf("presence-") === 0) {
2672
2277
  return Factory.createPresenceChannel(name, pusher);
2673
2278
  } else if (name.indexOf("#") === 0) {
2674
- throw new BadChannelName(
2675
- 'Cannot create a channel with name "' + name + '".'
2676
- );
2279
+ throw new BadChannelName('Cannot create a channel with name "' + name + '".');
2677
2280
  } else {
2678
2281
  return Factory.createChannel(name, pusher);
2679
2282
  }
@@ -2694,8 +2297,8 @@ var Factory = {
2694
2297
  createPresenceChannel(name, pusher) {
2695
2298
  return new PresenceChannel(name, pusher);
2696
2299
  },
2697
- createEncryptedChannel(name, pusher, nacl2) {
2698
- return new EncryptedChannel(name, pusher, nacl2);
2300
+ createEncryptedChannel(name, pusher, nacl) {
2301
+ return new EncryptedChannel(name, pusher, nacl);
2699
2302
  },
2700
2303
  createTimelineSender(timeline, options) {
2701
2304
  return new TimelineSender(timeline, options);
@@ -2712,25 +2315,15 @@ class TransportManager {
2712
2315
  this.options = options || {};
2713
2316
  this.livesLeft = this.options.lives || Infinity;
2714
2317
  }
2715
- /** Creates a assistant for the transport.
2716
- *
2717
- * @param {Transport} transport
2718
- * @returns {AssistantToTheTransportManager}
2719
- */
2720
2318
  getAssistant(transport) {
2721
2319
  return Factory.createAssistantToTheTransportManager(this, transport, {
2722
2320
  minPingDelay: this.options.minPingDelay,
2723
2321
  maxPingDelay: this.options.maxPingDelay
2724
2322
  });
2725
2323
  }
2726
- /** Returns whether the transport has any lives left.
2727
- *
2728
- * @returns {Boolean}
2729
- */
2730
2324
  isAlive() {
2731
2325
  return this.livesLeft > 0;
2732
2326
  }
2733
- /** Takes one life from the transport. */
2734
2327
  reportDeath() {
2735
2328
  this.livesLeft -= 1;
2736
2329
  }
@@ -2766,23 +2359,13 @@ class SequentialStrategy {
2766
2359
  timeout = Math.min(timeout, this.timeoutLimit);
2767
2360
  }
2768
2361
  }
2769
- runner = this.tryStrategy(
2770
- strategies[current],
2771
- minPriority,
2772
- { timeout, failFast: this.failFast },
2773
- tryNextStrategy
2774
- );
2362
+ runner = this.tryStrategy(strategies[current], minPriority, { timeout, failFast: this.failFast }, tryNextStrategy);
2775
2363
  } else {
2776
2364
  callback(true);
2777
2365
  }
2778
2366
  }
2779
2367
  };
2780
- runner = this.tryStrategy(
2781
- strategies[current],
2782
- minPriority,
2783
- { timeout, failFast: this.failFast },
2784
- tryNextStrategy
2785
- );
2368
+ runner = this.tryStrategy(strategies[current], minPriority, { timeout, failFast: this.failFast }, tryNextStrategy);
2786
2369
  return {
2787
2370
  abort: function() {
2788
2371
  runner.abort();
@@ -2902,12 +2485,10 @@ class WebSocketPrioritizedCachedStrategy {
2902
2485
  transport: info.transport,
2903
2486
  latency: info.latency
2904
2487
  });
2905
- strategies.push(
2906
- new SequentialStrategy([transport], {
2907
- timeout: info.latency * 2 + 1e3,
2908
- failFast: true
2909
- })
2910
- );
2488
+ strategies.push(new SequentialStrategy([transport], {
2489
+ timeout: info.latency * 2 + 1e3,
2490
+ failFast: true
2491
+ }));
2911
2492
  } else {
2912
2493
  cacheSkipCount++;
2913
2494
  }
@@ -2924,12 +2505,7 @@ class WebSocketPrioritizedCachedStrategy {
2924
2505
  callback(error);
2925
2506
  }
2926
2507
  } else {
2927
- storeTransportCache(
2928
- usingTLS,
2929
- handshake.transport.name,
2930
- Util.now() - startTimestamp,
2931
- cacheSkipCount
2932
- );
2508
+ storeTransportCache(usingTLS, handshake.transport.name, Util.now() - startTimestamp, cacheSkipCount);
2933
2509
  callback(null, handshake);
2934
2510
  }
2935
2511
  });
@@ -3039,15 +2615,12 @@ class FirstConnectedStrategy {
3039
2615
  return this.strategy.isSupported();
3040
2616
  }
3041
2617
  connect(minPriority, callback) {
3042
- var runner = this.strategy.connect(
3043
- minPriority,
3044
- function(error, handshake) {
3045
- if (handshake) {
3046
- runner.abort();
3047
- }
3048
- callback(error, handshake);
2618
+ var runner = this.strategy.connect(minPriority, function(error, handshake) {
2619
+ if (handshake) {
2620
+ runner.abort();
3049
2621
  }
3050
- );
2622
+ callback(error, handshake);
2623
+ });
3051
2624
  return runner;
3052
2625
  }
3053
2626
  }
@@ -3059,14 +2632,7 @@ function testSupportsStrategy(strategy) {
3059
2632
  var getDefaultStrategy = function(config2, baseOptions, defineTransport2) {
3060
2633
  var definedTransports = {};
3061
2634
  function defineTransportStrategy(name, type, priority, options, manager) {
3062
- var transport = defineTransport2(
3063
- config2,
3064
- name,
3065
- type,
3066
- priority,
3067
- options,
3068
- manager
3069
- );
2635
+ var transport = defineTransport2(config2, name, type, priority, options, manager);
3070
2636
  definedTransports[name] = transport;
3071
2637
  return transport;
3072
2638
  }
@@ -3097,93 +2663,29 @@ var getDefaultStrategy = function(config2, baseOptions, defineTransport2) {
3097
2663
  minPingDelay: 1e4,
3098
2664
  maxPingDelay: config2.activityTimeout
3099
2665
  });
3100
- var ws_transport = defineTransportStrategy(
3101
- "ws",
3102
- "ws",
3103
- 3,
3104
- ws_options,
3105
- ws_manager
3106
- );
3107
- var wss_transport = defineTransportStrategy(
3108
- "wss",
3109
- "ws",
3110
- 3,
3111
- wss_options,
3112
- ws_manager
3113
- );
3114
- var sockjs_transport = defineTransportStrategy(
3115
- "sockjs",
3116
- "sockjs",
3117
- 1,
3118
- sockjs_options
3119
- );
3120
- var xhr_streaming_transport = defineTransportStrategy(
3121
- "xhr_streaming",
3122
- "xhr_streaming",
3123
- 1,
3124
- sockjs_options,
3125
- streaming_manager
3126
- );
3127
- var xdr_streaming_transport = defineTransportStrategy(
3128
- "xdr_streaming",
3129
- "xdr_streaming",
3130
- 1,
3131
- sockjs_options,
3132
- streaming_manager
3133
- );
3134
- var xhr_polling_transport = defineTransportStrategy(
3135
- "xhr_polling",
3136
- "xhr_polling",
3137
- 1,
3138
- sockjs_options
3139
- );
3140
- var xdr_polling_transport = defineTransportStrategy(
3141
- "xdr_polling",
3142
- "xdr_polling",
3143
- 1,
3144
- sockjs_options
3145
- );
2666
+ var ws_transport = defineTransportStrategy("ws", "ws", 3, ws_options, ws_manager);
2667
+ var wss_transport = defineTransportStrategy("wss", "ws", 3, wss_options, ws_manager);
2668
+ var sockjs_transport = defineTransportStrategy("sockjs", "sockjs", 1, sockjs_options);
2669
+ var xhr_streaming_transport = defineTransportStrategy("xhr_streaming", "xhr_streaming", 1, sockjs_options, streaming_manager);
2670
+ var xdr_streaming_transport = defineTransportStrategy("xdr_streaming", "xdr_streaming", 1, sockjs_options, streaming_manager);
2671
+ var xhr_polling_transport = defineTransportStrategy("xhr_polling", "xhr_polling", 1, sockjs_options);
2672
+ var xdr_polling_transport = defineTransportStrategy("xdr_polling", "xdr_polling", 1, sockjs_options);
3146
2673
  var ws_loop = new SequentialStrategy([ws_transport], timeouts);
3147
2674
  var wss_loop = new SequentialStrategy([wss_transport], timeouts);
3148
2675
  var sockjs_loop = new SequentialStrategy([sockjs_transport], timeouts);
3149
- var streaming_loop = new SequentialStrategy(
3150
- [
3151
- new IfStrategy(
3152
- testSupportsStrategy(xhr_streaming_transport),
3153
- xhr_streaming_transport,
3154
- xdr_streaming_transport
3155
- )
3156
- ],
3157
- timeouts
3158
- );
3159
- var polling_loop = new SequentialStrategy(
3160
- [
3161
- new IfStrategy(
3162
- testSupportsStrategy(xhr_polling_transport),
3163
- xhr_polling_transport,
3164
- xdr_polling_transport
3165
- )
3166
- ],
3167
- timeouts
3168
- );
3169
- var http_loop = new SequentialStrategy(
3170
- [
3171
- new IfStrategy(
3172
- testSupportsStrategy(streaming_loop),
3173
- new BestConnectedEverStrategy([
3174
- streaming_loop,
3175
- new DelayedStrategy(polling_loop, { delay: 4e3 })
3176
- ]),
3177
- polling_loop
3178
- )
3179
- ],
3180
- timeouts
3181
- );
3182
- var http_fallback_loop = new IfStrategy(
3183
- testSupportsStrategy(http_loop),
3184
- http_loop,
3185
- sockjs_loop
3186
- );
2676
+ var streaming_loop = new SequentialStrategy([
2677
+ new IfStrategy(testSupportsStrategy(xhr_streaming_transport), xhr_streaming_transport, xdr_streaming_transport)
2678
+ ], timeouts);
2679
+ var polling_loop = new SequentialStrategy([
2680
+ new IfStrategy(testSupportsStrategy(xhr_polling_transport), xhr_polling_transport, xdr_polling_transport)
2681
+ ], timeouts);
2682
+ var http_loop = new SequentialStrategy([
2683
+ new IfStrategy(testSupportsStrategy(streaming_loop), new BestConnectedEverStrategy([
2684
+ streaming_loop,
2685
+ new DelayedStrategy(polling_loop, { delay: 4e3 })
2686
+ ]), polling_loop)
2687
+ ], timeouts);
2688
+ var http_fallback_loop = new IfStrategy(testSupportsStrategy(http_loop), http_loop, sockjs_loop);
3187
2689
  var wsStrategy;
3188
2690
  if (baseOptions.useTLS) {
3189
2691
  wsStrategy = new BestConnectedEverStrategy([
@@ -3197,49 +2699,33 @@ var getDefaultStrategy = function(config2, baseOptions, defineTransport2) {
3197
2699
  new DelayedStrategy(http_fallback_loop, { delay: 5e3 })
3198
2700
  ]);
3199
2701
  }
3200
- return new WebSocketPrioritizedCachedStrategy(
3201
- new FirstConnectedStrategy(
3202
- new IfStrategy(
3203
- testSupportsStrategy(ws_transport),
3204
- wsStrategy,
3205
- http_fallback_loop
3206
- )
3207
- ),
3208
- definedTransports,
3209
- {
3210
- ttl: 18e5,
3211
- timeline: baseOptions.timeline,
3212
- useTLS: baseOptions.useTLS
3213
- }
3214
- );
2702
+ return new WebSocketPrioritizedCachedStrategy(new FirstConnectedStrategy(new IfStrategy(testSupportsStrategy(ws_transport), wsStrategy, http_fallback_loop)), definedTransports, {
2703
+ ttl: 18e5,
2704
+ timeline: baseOptions.timeline,
2705
+ useTLS: baseOptions.useTLS
2706
+ });
3215
2707
  };
3216
2708
  function transportConnectionInitializer() {
3217
2709
  var self = this;
3218
- self.timeline.info(
3219
- self.buildTimelineMessage({
3220
- transport: self.name + (self.options.useTLS ? "s" : "")
3221
- })
3222
- );
2710
+ self.timeline.info(self.buildTimelineMessage({
2711
+ transport: self.name + (self.options.useTLS ? "s" : "")
2712
+ }));
3223
2713
  if (self.hooks.isInitialized()) {
3224
2714
  self.changeState("initialized");
3225
2715
  } else if (self.hooks.file) {
3226
2716
  self.changeState("initializing");
3227
- Dependencies.load(
3228
- self.hooks.file,
3229
- { useTLS: self.options.useTLS },
3230
- function(error, callback) {
3231
- if (self.hooks.isInitialized()) {
3232
- self.changeState("initialized");
3233
- callback(true);
3234
- } else {
3235
- if (error) {
3236
- self.onError(error);
3237
- }
3238
- self.onClose();
3239
- callback(false);
2717
+ Dependencies.load(self.hooks.file, { useTLS: self.options.useTLS }, function(error, callback) {
2718
+ if (self.hooks.isInitialized()) {
2719
+ self.changeState("initialized");
2720
+ callback(true);
2721
+ } else {
2722
+ if (error) {
2723
+ self.onError(error);
3240
2724
  }
2725
+ self.onClose();
2726
+ callback(false);
3241
2727
  }
3242
- );
2728
+ });
3243
2729
  } else {
3244
2730
  self.onClose();
3245
2731
  }
@@ -3332,12 +2818,12 @@ class HTTPRequest extends Dispatcher {
3332
2818
  return this.position === buffer.length && buffer.length > MAX_BUFFER_LENGTH;
3333
2819
  }
3334
2820
  }
3335
- var State = /* @__PURE__ */ ((State2) => {
2821
+ var State;
2822
+ (function(State2) {
3336
2823
  State2[State2["CONNECTING"] = 0] = "CONNECTING";
3337
2824
  State2[State2["OPEN"] = 1] = "OPEN";
3338
2825
  State2[State2["CLOSED"] = 3] = "CLOSED";
3339
- return State2;
3340
- })(State || {});
2826
+ })(State || (State = {}));
3341
2827
  var autoIncrement = 1;
3342
2828
  class HTTPSocket {
3343
2829
  constructor(hooks2, url) {
@@ -3356,14 +2842,10 @@ class HTTPSocket {
3356
2842
  close(code, reason) {
3357
2843
  this.onClose(code, reason, true);
3358
2844
  }
3359
- /** For internal use only */
3360
2845
  sendRaw(payload) {
3361
2846
  if (this.readyState === State.OPEN) {
3362
2847
  try {
3363
- Runtime.createSocketRequest(
3364
- "POST",
3365
- getUniqueURL(getSendURL(this.location, this.session))
3366
- ).start(payload);
2848
+ Runtime.createSocketRequest("POST", getUniqueURL(getSendURL(this.location, this.session))).start(payload);
3367
2849
  return true;
3368
2850
  } catch (e) {
3369
2851
  return false;
@@ -3372,12 +2854,10 @@ class HTTPSocket {
3372
2854
  return false;
3373
2855
  }
3374
2856
  }
3375
- /** For internal use only */
3376
2857
  reconnect() {
3377
2858
  this.closeStream();
3378
2859
  this.openStream();
3379
2860
  }
3380
- /** For internal use only */
3381
2861
  onClose(code, reason, wasClean) {
3382
2862
  this.closeStream();
3383
2863
  this.readyState = State.CLOSED;
@@ -3451,10 +2931,7 @@ class HTTPSocket {
3451
2931
  }
3452
2932
  }
3453
2933
  openStream() {
3454
- this.stream = Runtime.createSocketRequest(
3455
- "POST",
3456
- getUniqueURL(this.hooks.getReceiveURL(this.location, this.session))
3457
- );
2934
+ this.stream = Runtime.createSocketRequest("POST", getUniqueURL(this.hooks.getReceiveURL(this.location, this.session)));
3458
2935
  this.stream.bind("chunk", (chunk) => {
3459
2936
  this.onChunk(chunk);
3460
2937
  });
@@ -3587,6 +3064,146 @@ var HTTP = {
3587
3064
  HTTP.createXDR = function(method, url) {
3588
3065
  return this.createRequest(hooks$3, method, url);
3589
3066
  };
3067
+ var Runtime$1 = {
3068
+ nextAuthCallbackID: 1,
3069
+ auth_callbacks: {},
3070
+ ScriptReceivers,
3071
+ DependenciesReceivers,
3072
+ getDefaultStrategy,
3073
+ Transports: Transports$1,
3074
+ transportConnectionInitializer,
3075
+ HTTPFactory: HTTP,
3076
+ TimelineTransport: jsonp,
3077
+ getXHRAPI() {
3078
+ return window.XMLHttpRequest;
3079
+ },
3080
+ getWebSocketAPI() {
3081
+ return window.WebSocket || window.MozWebSocket;
3082
+ },
3083
+ setup(PusherClass) {
3084
+ window.Pusher = PusherClass;
3085
+ var initializeOnDocumentBody = () => {
3086
+ this.onDocumentBody(PusherClass.ready);
3087
+ };
3088
+ if (!window.JSON) {
3089
+ Dependencies.load("json2", {}, initializeOnDocumentBody);
3090
+ } else {
3091
+ initializeOnDocumentBody();
3092
+ }
3093
+ },
3094
+ getDocument() {
3095
+ return document;
3096
+ },
3097
+ getProtocol() {
3098
+ return this.getDocument().location.protocol;
3099
+ },
3100
+ getAuthorizers() {
3101
+ return { ajax, jsonp: jsonp$1 };
3102
+ },
3103
+ onDocumentBody(callback) {
3104
+ if (document.body) {
3105
+ callback();
3106
+ } else {
3107
+ setTimeout(() => {
3108
+ this.onDocumentBody(callback);
3109
+ }, 0);
3110
+ }
3111
+ },
3112
+ createJSONPRequest(url, data) {
3113
+ return new JSONPRequest(url, data);
3114
+ },
3115
+ createScriptRequest(src) {
3116
+ return new ScriptRequest(src);
3117
+ },
3118
+ getLocalStorage() {
3119
+ try {
3120
+ return window.localStorage;
3121
+ } catch (e) {
3122
+ return void 0;
3123
+ }
3124
+ },
3125
+ createXHR() {
3126
+ if (this.getXHRAPI()) {
3127
+ return this.createXMLHttpRequest();
3128
+ } else {
3129
+ return this.createMicrosoftXHR();
3130
+ }
3131
+ },
3132
+ createXMLHttpRequest() {
3133
+ var Constructor = this.getXHRAPI();
3134
+ return new Constructor();
3135
+ },
3136
+ createMicrosoftXHR() {
3137
+ return new ActiveXObject("Microsoft.XMLHTTP");
3138
+ },
3139
+ getNetwork() {
3140
+ return Network;
3141
+ },
3142
+ createWebSocket(url) {
3143
+ var Constructor = this.getWebSocketAPI();
3144
+ return new Constructor(url);
3145
+ },
3146
+ createSocketRequest(method, url) {
3147
+ if (this.isXHRSupported()) {
3148
+ return this.HTTPFactory.createXHR(method, url);
3149
+ } else if (this.isXDRSupported(url.indexOf("https:") === 0)) {
3150
+ return this.HTTPFactory.createXDR(method, url);
3151
+ } else {
3152
+ throw "Cross-origin HTTP requests are not supported";
3153
+ }
3154
+ },
3155
+ isXHRSupported() {
3156
+ var Constructor = this.getXHRAPI();
3157
+ return Boolean(Constructor) && new Constructor().withCredentials !== void 0;
3158
+ },
3159
+ isXDRSupported(useTLS) {
3160
+ var protocol = useTLS ? "https:" : "http:";
3161
+ var documentProtocol = this.getProtocol();
3162
+ return Boolean(window["XDomainRequest"]) && documentProtocol === protocol;
3163
+ },
3164
+ addUnloadListener(listener) {
3165
+ if (window.addEventListener !== void 0) {
3166
+ window.addEventListener("unload", listener, false);
3167
+ } else if (window.attachEvent !== void 0) {
3168
+ window.attachEvent("onunload", listener);
3169
+ }
3170
+ },
3171
+ removeUnloadListener(listener) {
3172
+ if (window.addEventListener !== void 0) {
3173
+ window.removeEventListener("unload", listener, false);
3174
+ } else if (window.detachEvent !== void 0) {
3175
+ window.detachEvent("onunload", listener);
3176
+ }
3177
+ },
3178
+ randomInt(max) {
3179
+ const random = function() {
3180
+ const crypto = window.crypto || window["msCrypto"];
3181
+ const random2 = crypto.getRandomValues(new Uint32Array(1))[0];
3182
+ return random2 / Math.pow(2, 32);
3183
+ };
3184
+ return Math.floor(random() * max);
3185
+ }
3186
+ };
3187
+ class JSONPRequest {
3188
+ constructor(url, data) {
3189
+ this.url = url;
3190
+ this.data = data;
3191
+ }
3192
+ send(receiver) {
3193
+ if (this.request) {
3194
+ return;
3195
+ }
3196
+ var query = buildQueryString(this.data);
3197
+ var url = this.url + "/" + receiver.number + "?" + query;
3198
+ this.request = Runtime$1.createScriptRequest(url);
3199
+ this.request.send(receiver);
3200
+ }
3201
+ cleanup() {
3202
+ if (this.request) {
3203
+ this.request.cleanup();
3204
+ }
3205
+ }
3206
+ }
3590
3207
  var Runtime = {
3591
3208
  // for jsonp auth
3592
3209
  nextAuthCallbackID: 1,
@@ -3708,12 +3325,13 @@ var Runtime = {
3708
3325
  return Math.floor(random() * max);
3709
3326
  }
3710
3327
  };
3711
- var TimelineLevel = /* @__PURE__ */ ((TimelineLevel2) => {
3328
+ var TimelineLevel;
3329
+ (function(TimelineLevel2) {
3712
3330
  TimelineLevel2[TimelineLevel2["ERROR"] = 3] = "ERROR";
3713
3331
  TimelineLevel2[TimelineLevel2["INFO"] = 6] = "INFO";
3714
3332
  TimelineLevel2[TimelineLevel2["DEBUG"] = 7] = "DEBUG";
3715
- return TimelineLevel2;
3716
- })(TimelineLevel || {});
3333
+ })(TimelineLevel || (TimelineLevel = {}));
3334
+ const TimelineLevel$1 = TimelineLevel;
3717
3335
  class Timeline {
3718
3336
  constructor(key, session, options) {
3719
3337
  this.key = key;
@@ -3725,40 +3343,35 @@ class Timeline {
3725
3343
  }
3726
3344
  log(level, event) {
3727
3345
  if (level <= this.options.level) {
3728
- this.events.push(
3729
- extend({}, event, { timestamp: Util.now() })
3730
- );
3346
+ this.events.push(extend({}, event, { timestamp: Util.now() }));
3731
3347
  if (this.options.limit && this.events.length > this.options.limit) {
3732
3348
  this.events.shift();
3733
3349
  }
3734
3350
  }
3735
3351
  }
3736
3352
  error(event) {
3737
- this.log(TimelineLevel.ERROR, event);
3353
+ this.log(TimelineLevel$1.ERROR, event);
3738
3354
  }
3739
3355
  info(event) {
3740
- this.log(TimelineLevel.INFO, event);
3356
+ this.log(TimelineLevel$1.INFO, event);
3741
3357
  }
3742
3358
  debug(event) {
3743
- this.log(TimelineLevel.DEBUG, event);
3359
+ this.log(TimelineLevel$1.DEBUG, event);
3744
3360
  }
3745
3361
  isEmpty() {
3746
3362
  return this.events.length === 0;
3747
3363
  }
3748
3364
  send(sendfn, callback) {
3749
- var data = extend(
3750
- {
3751
- session: this.session,
3752
- bundle: this.sent + 1,
3753
- key: this.key,
3754
- lib: "js",
3755
- version: this.options.version,
3756
- cluster: this.options.cluster,
3757
- features: this.options.features,
3758
- timeline: this.events
3759
- },
3760
- this.options.params
3761
- );
3365
+ var data = extend({
3366
+ session: this.session,
3367
+ bundle: this.sent + 1,
3368
+ key: this.key,
3369
+ lib: "js",
3370
+ version: this.options.version,
3371
+ cluster: this.options.cluster,
3372
+ features: this.options.features,
3373
+ timeline: this.events
3374
+ }, this.options.params);
3762
3375
  this.events = [];
3763
3376
  sendfn(data, (error, result) => {
3764
3377
  if (!error) {
@@ -3782,20 +3395,11 @@ class TransportStrategy {
3782
3395
  this.transport = transport;
3783
3396
  this.options = options || {};
3784
3397
  }
3785
- /** Returns whether the transport is supported in the browser.
3786
- *
3787
- * @returns {Boolean}
3788
- */
3789
3398
  isSupported() {
3790
3399
  return this.transport.isSupported({
3791
3400
  useTLS: this.options.useTLS
3792
3401
  });
3793
3402
  }
3794
- /** Launches a connection attempt and returns a strategy runner.
3795
- *
3796
- * @param {Function} callback
3797
- * @return {Object} strategy runner
3798
- */
3799
3403
  connect(minPriority, callback) {
3800
3404
  if (!this.isSupported()) {
3801
3405
  return failAttempt(new UnsupportedStrategy$1(), callback);
@@ -3803,12 +3407,7 @@ class TransportStrategy {
3803
3407
  return failAttempt(new TransportPriorityTooLow(), callback);
3804
3408
  }
3805
3409
  var connected = false;
3806
- var transport = this.transport.createConnection(
3807
- this.name,
3808
- this.priority,
3809
- this.options.key,
3810
- this.options
3811
- );
3410
+ var transport = this.transport.createConnection(this.name, this.priority, this.options.key, this.options);
3812
3411
  var handshake = null;
3813
3412
  var onInitialized = function() {
3814
3413
  transport.unbind("initialized", onInitialized);
@@ -3889,16 +3488,8 @@ var defineTransport = function(config2, name, type, priority, options, manager)
3889
3488
  var enabled = (!config2.enabledTransports || arrayIndexOf(config2.enabledTransports, name) !== -1) && (!config2.disabledTransports || arrayIndexOf(config2.disabledTransports, name) === -1);
3890
3489
  var transport;
3891
3490
  if (enabled) {
3892
- options = Object.assign(
3893
- { ignoreNullOrigin: config2.ignoreNullOrigin },
3894
- options
3895
- );
3896
- transport = new TransportStrategy(
3897
- name,
3898
- priority,
3899
- manager ? manager.getAssistant(transportClass) : transportClass,
3900
- options
3901
- );
3491
+ options = Object.assign({ ignoreNullOrigin: config2.ignoreNullOrigin }, options);
3492
+ transport = new TransportStrategy(name, priority, manager ? manager.getAssistant(transportClass) : transportClass, options);
3902
3493
  } else {
3903
3494
  transport = UnsupportedStrategy2;
3904
3495
  }
@@ -3929,9 +3520,7 @@ function validateOptions(options) {
3929
3520
  throw "Options object must provide a cluster";
3930
3521
  }
3931
3522
  if ("disableStats" in options) {
3932
- Logger$1.warn(
3933
- "The disableStats option is deprecated in favor of enableStats"
3934
- );
3523
+ Logger$1.warn("The disableStats option is deprecated in favor of enableStats");
3935
3524
  }
3936
3525
  }
3937
3526
  const composeChannelQuery$1 = (params, authOptions) => {
@@ -3953,13 +3542,7 @@ const UserAuthenticator = (authOptions) => {
3953
3542
  }
3954
3543
  return (params, callback) => {
3955
3544
  const query = composeChannelQuery$1(params, authOptions);
3956
- Runtime.getAuthorizers()[authOptions.transport](
3957
- Runtime,
3958
- query,
3959
- authOptions,
3960
- AuthRequestType.UserAuthentication,
3961
- callback
3962
- );
3545
+ Runtime.getAuthorizers()[authOptions.transport](Runtime, query, authOptions, AuthRequestType.UserAuthentication, callback);
3963
3546
  };
3964
3547
  };
3965
3548
  const composeChannelQuery = (params, authOptions) => {
@@ -3982,13 +3565,7 @@ const ChannelAuthorizer = (authOptions) => {
3982
3565
  }
3983
3566
  return (params, callback) => {
3984
3567
  const query = composeChannelQuery(params, authOptions);
3985
- Runtime.getAuthorizers()[authOptions.transport](
3986
- Runtime,
3987
- query,
3988
- authOptions,
3989
- AuthRequestType.ChannelAuthorization,
3990
- callback
3991
- );
3568
+ Runtime.getAuthorizers()[authOptions.transport](Runtime, query, authOptions, AuthRequestType.ChannelAuthorization, callback);
3992
3569
  };
3993
3570
  };
3994
3571
  const ChannelAuthorizerProxy = (pusher, authOptions, channelAuthorizerGenerator) => {
@@ -4032,7 +3609,8 @@ function getConfig(opts, pusher) {
4032
3609
  config2.enabledTransports = opts.enabledTransports;
4033
3610
  if ("ignoreNullOrigin" in opts)
4034
3611
  config2.ignoreNullOrigin = opts.ignoreNullOrigin;
4035
- if ("timelineParams" in opts) config2.timelineParams = opts.timelineParams;
3612
+ if ("timelineParams" in opts)
3613
+ config2.timelineParams = opts.timelineParams;
4036
3614
  if ("nacl" in opts) {
4037
3615
  config2.nacl = opts.nacl;
4038
3616
  }
@@ -4074,10 +3652,7 @@ function getEnableStatsConfig(opts) {
4074
3652
  return false;
4075
3653
  }
4076
3654
  function buildUserAuthenticator(opts) {
4077
- const userAuthentication = {
4078
- ...Defaults.userAuthentication,
4079
- ...opts.userAuthentication
4080
- };
3655
+ const userAuthentication = Object.assign(Object.assign({}, Defaults.userAuthentication), opts.userAuthentication);
4081
3656
  if ("customHandler" in userAuthentication && userAuthentication["customHandler"] != null) {
4082
3657
  return userAuthentication["customHandler"];
4083
3658
  }
@@ -4086,26 +3661,20 @@ function buildUserAuthenticator(opts) {
4086
3661
  function buildChannelAuth(opts, pusher) {
4087
3662
  let channelAuthorization;
4088
3663
  if ("channelAuthorization" in opts) {
4089
- channelAuthorization = {
4090
- ...Defaults.channelAuthorization,
4091
- ...opts.channelAuthorization
4092
- };
3664
+ channelAuthorization = Object.assign(Object.assign({}, Defaults.channelAuthorization), opts.channelAuthorization);
4093
3665
  } else {
4094
3666
  channelAuthorization = {
4095
3667
  transport: opts.authTransport || Defaults.authTransport,
4096
3668
  endpoint: opts.authEndpoint || Defaults.authEndpoint
4097
3669
  };
4098
3670
  if ("auth" in opts) {
4099
- if ("params" in opts.auth) channelAuthorization.params = opts.auth.params;
3671
+ if ("params" in opts.auth)
3672
+ channelAuthorization.params = opts.auth.params;
4100
3673
  if ("headers" in opts.auth)
4101
3674
  channelAuthorization.headers = opts.auth.headers;
4102
3675
  }
4103
3676
  if ("authorizer" in opts)
4104
- channelAuthorization.customHandler = ChannelAuthorizerProxy(
4105
- pusher,
4106
- channelAuthorization,
4107
- opts.authorizer
4108
- );
3677
+ channelAuthorization.customHandler = ChannelAuthorizerProxy(pusher, channelAuthorization, opts.authorizer);
4109
3678
  }
4110
3679
  return channelAuthorization;
4111
3680
  }
@@ -4203,12 +3772,9 @@ class UserFacade extends Dispatcher {
4203
3772
  if (this.pusher.connection.state !== "connected") {
4204
3773
  return;
4205
3774
  }
4206
- this.pusher.config.userAuthenticator(
4207
- {
4208
- socketId: this.pusher.connection.socket_id
4209
- },
4210
- this._onAuthorize
4211
- );
3775
+ this.pusher.config.userAuthenticator({
3776
+ socketId: this.pusher.connection.socket_id
3777
+ }, this._onAuthorize);
4212
3778
  }
4213
3779
  _onSigninSuccess(data) {
4214
3780
  try {
@@ -4219,9 +3785,7 @@ class UserFacade extends Dispatcher {
4219
3785
  return;
4220
3786
  }
4221
3787
  if (typeof this.user_data.id !== "string" || this.user_data.id === "") {
4222
- Logger$1.error(
4223
- `user_data doesn't contain an id. user_data: ${this.user_data}`
4224
- );
3788
+ Logger$1.error(`user_data doesn't contain an id. user_data: ${this.user_data}`);
4225
3789
  this._cleanup();
4226
3790
  return;
4227
3791
  }
@@ -4236,10 +3800,7 @@ class UserFacade extends Dispatcher {
4236
3800
  channel.subscribe();
4237
3801
  }
4238
3802
  };
4239
- this.serverToUserChannel = new Channel(
4240
- `#server-to-user-${this.user_data.id}`,
4241
- this.pusher
4242
- );
3803
+ this.serverToUserChannel = new Channel(`#server-to-user-${this.user_data.id}`, this.pusher);
4243
3804
  this.serverToUserChannel.bind_global((eventName, data) => {
4244
3805
  if (eventName.indexOf("pusher_internal:") === 0 || eventName.indexOf("pusher:") === 0) {
4245
3806
  return;
@@ -4280,7 +3841,7 @@ class ChannelState {
4280
3841
  constructor(channelName) {
4281
3842
  this.channelName = channelName;
4282
3843
  this.conflationKey = null;
4283
- this.maxMessagesPerKey = 10;
3844
+ this.maxMessagesPerKey = 30;
4284
3845
  this.conflationCaches = /* @__PURE__ */ new Map();
4285
3846
  this.baseMessage = null;
4286
3847
  this.baseSequence = null;
@@ -4288,12 +3849,9 @@ class ChannelState {
4288
3849
  this.deltaCount = 0;
4289
3850
  this.fullMessageCount = 0;
4290
3851
  }
4291
- /**
4292
- * Initialize cache from server sync
4293
- */
4294
3852
  initializeFromCacheSync(data) {
4295
3853
  this.conflationKey = data.conflation_key || null;
4296
- this.maxMessagesPerKey = data.max_messages_per_key || 10;
3854
+ this.maxMessagesPerKey = Math.max(data.max_messages_per_key || 10, 30);
4297
3855
  this.conflationCaches.clear();
4298
3856
  if (data.states) {
4299
3857
  for (const [key, messages] of Object.entries(data.states)) {
@@ -4305,18 +3863,11 @@ class ChannelState {
4305
3863
  }
4306
3864
  }
4307
3865
  }
4308
- /**
4309
- * Set new base message (legacy - for non-conflation channels)
4310
- */
4311
3866
  setBase(message, sequence) {
4312
3867
  this.baseMessage = message;
4313
3868
  this.baseSequence = sequence;
4314
3869
  this.lastSequence = sequence;
4315
3870
  }
4316
- /**
4317
- * Get base message for a conflation key at specific index
4318
- * Note: baseIndex is the sequence number, not array index
4319
- */
4320
3871
  getBaseMessage(conflationKeyValue, baseIndex) {
4321
3872
  if (!this.conflationKey) {
4322
3873
  return this.baseMessage;
@@ -4344,9 +3895,6 @@ class ChannelState {
4344
3895
  }
4345
3896
  return message.content;
4346
3897
  }
4347
- /**
4348
- * Add or update message in conflation cache
4349
- */
4350
3898
  updateConflationCache(conflationKeyValue, message, sequence) {
4351
3899
  const key = conflationKeyValue || "";
4352
3900
  let cache = this.conflationCaches.get(key);
@@ -4354,56 +3902,32 @@ class ChannelState {
4354
3902
  cache = [];
4355
3903
  this.conflationCaches.set(key, cache);
4356
3904
  }
4357
- if (cache.length > 0) {
4358
- const lastCacheItem = cache[cache.length - 1];
4359
- if (sequence <= lastCacheItem.sequence) {
4360
- cache.length = 0;
4361
- }
4362
- }
4363
3905
  cache.push({ content: message, sequence });
4364
3906
  while (cache.length > this.maxMessagesPerKey) {
4365
3907
  cache.shift();
4366
3908
  }
4367
3909
  }
4368
- /**
4369
- * Check if we have a valid base
4370
- */
4371
3910
  hasBase() {
4372
3911
  if (this.conflationKey) {
4373
3912
  return this.conflationCaches.size > 0;
4374
3913
  }
4375
3914
  return this.baseMessage !== null && this.baseSequence !== null;
4376
3915
  }
4377
- /**
4378
- * Validate sequence number
4379
- */
4380
3916
  isValidSequence(sequence) {
4381
3917
  if (this.lastSequence === null) {
4382
3918
  return true;
4383
3919
  }
4384
3920
  return sequence > this.lastSequence;
4385
3921
  }
4386
- /**
4387
- * Update sequence after processing a message
4388
- */
4389
3922
  updateSequence(sequence) {
4390
3923
  this.lastSequence = sequence;
4391
3924
  }
4392
- /**
4393
- * Record delta received
4394
- */
4395
3925
  recordDelta() {
4396
3926
  this.deltaCount++;
4397
3927
  }
4398
- /**
4399
- * Record full message received
4400
- */
4401
3928
  recordFullMessage() {
4402
3929
  this.fullMessageCount++;
4403
3930
  }
4404
- /**
4405
- * Get statistics
4406
- */
4407
3931
  getStats() {
4408
3932
  return {
4409
3933
  channelName: this.channelName,
@@ -5190,9 +4714,7 @@ class FossilDeltaDecoder {
5190
4714
  }
5191
4715
  return bytesToString(result);
5192
4716
  } catch (error) {
5193
- throw new Error(
5194
- `Fossil delta decode failed: ${error.message} (base=${baseBytes.length}B delta=${deltaBytes.length}B)`
5195
- );
4717
+ throw new Error(`Fossil delta decode failed: ${error.message} (base=${baseBytes.length}B delta=${deltaBytes.length}B)`);
5196
4718
  }
5197
4719
  }
5198
4720
  }
@@ -5217,14 +4739,13 @@ class Xdelta3Decoder {
5217
4739
  }
5218
4740
  return bytesToString(result);
5219
4741
  } catch (error) {
5220
- throw new Error(
5221
- `Xdelta3 decode failed: ${error.message} (base=${baseBytes.length}B delta=${deltaBytes.length}B)`
5222
- );
4742
+ throw new Error(`Xdelta3 decode failed: ${error.message} (base=${baseBytes.length}B delta=${deltaBytes.length}B)`);
5223
4743
  }
5224
4744
  }
5225
4745
  }
5226
4746
  class DeltaCompressionManager {
5227
4747
  constructor(options = {}, sendEventCallback) {
4748
+ this.defaultAlgorithm = "fossil";
5228
4749
  this.options = {
5229
4750
  enabled: options.enabled !== false,
5230
4751
  algorithms: options.algorithms || ["fossil", "xdelta3"],
@@ -5245,14 +4766,9 @@ class DeltaCompressionManager {
5245
4766
  this.sendEventCallback = sendEventCallback;
5246
4767
  this.availableAlgorithms = this.detectAvailableAlgorithms();
5247
4768
  if (this.availableAlgorithms.length === 0) {
5248
- Logger$1.warn(
5249
- "[DeltaCompression] No delta algorithms available. Please include fossil-delta or vcdiff-decoder libraries."
5250
- );
4769
+ Logger$1.warn("[DeltaCompression] No delta algorithms available. Please include fossil-delta or vcdiff-decoder libraries.");
5251
4770
  }
5252
4771
  }
5253
- /**
5254
- * Detect which algorithm libraries are loaded
5255
- */
5256
4772
  detectAvailableAlgorithms() {
5257
4773
  const available = [];
5258
4774
  if (FossilDeltaDecoder.isAvailable()) {
@@ -5265,9 +4781,6 @@ class DeltaCompressionManager {
5265
4781
  }
5266
4782
  return available;
5267
4783
  }
5268
- /**
5269
- * Enable delta compression
5270
- */
5271
4784
  enable() {
5272
4785
  if (this.enabled || !this.options.enabled) {
5273
4786
  return;
@@ -5276,9 +4789,7 @@ class DeltaCompressionManager {
5276
4789
  this.log("No delta algorithms available, cannot enable");
5277
4790
  return;
5278
4791
  }
5279
- const supportedAlgorithms = this.availableAlgorithms.filter(
5280
- (algo) => this.options.algorithms.includes(algo)
5281
- );
4792
+ const supportedAlgorithms = this.availableAlgorithms.filter((algo) => this.options.algorithms.includes(algo));
5282
4793
  if (supportedAlgorithms.length === 0) {
5283
4794
  this.log("No mutually supported algorithms");
5284
4795
  return;
@@ -5288,26 +4799,16 @@ class DeltaCompressionManager {
5288
4799
  algorithms: supportedAlgorithms
5289
4800
  });
5290
4801
  }
5291
- /**
5292
- * Disable delta compression
5293
- * Note: We intentionally do NOT clear channelStates here.
5294
- * This allows state to be preserved across enable/disable cycles,
5295
- * which is important for reconnection scenarios and user toggling.
5296
- * Use clearChannelState() if you need to explicitly clear state.
5297
- */
5298
4802
  disable() {
5299
4803
  this.enabled = false;
5300
4804
  }
5301
- /**
5302
- * Handle delta compression enabled confirmation
5303
- */
5304
4805
  handleEnabled(data) {
5305
4806
  this.enabled = data.enabled || true;
4807
+ if (data.algorithm) {
4808
+ this.defaultAlgorithm = data.algorithm;
4809
+ }
5306
4810
  this.log("Delta compression enabled", data);
5307
4811
  }
5308
- /**
5309
- * Handle cache sync message (conflation keys)
5310
- */
5311
4812
  handleCacheSync(channel, data) {
5312
4813
  this.log("Received cache sync", {
5313
4814
  channel,
@@ -5322,16 +4823,14 @@ class DeltaCompressionManager {
5322
4823
  channelState.initializeFromCacheSync(data);
5323
4824
  this.log("Cache initialized", channelState.getStats());
5324
4825
  }
5325
- /**
5326
- * Handle delta-compressed message
5327
- */
5328
4826
  handleDeltaMessage(channel, deltaData) {
4827
+ var _a;
5329
4828
  let deltaBytes = null;
5330
4829
  try {
5331
4830
  const event = deltaData.event;
5332
4831
  const delta2 = deltaData.delta;
5333
4832
  const sequence = deltaData.seq;
5334
- const algorithm = deltaData.algorithm || "fossil";
4833
+ const algorithm = deltaData.algorithm || this.defaultAlgorithm || "fossil";
5335
4834
  const conflationKey = deltaData.conflation_key;
5336
4835
  const baseIndex = deltaData.base_index;
5337
4836
  this.log("Received delta message", {
@@ -5352,44 +4851,27 @@ class DeltaCompressionManager {
5352
4851
  if (channelState.conflationKey) {
5353
4852
  baseMessage = channelState.getBaseMessage(conflationKey, baseIndex);
5354
4853
  if (!baseMessage) {
5355
- this.error(
5356
- `No base message (conflation path) for channel ${channel}`,
5357
- {
5358
- path: "conflation",
4854
+ this.error(`No base message for channel ${channel}, key ${conflationKey}, index ${baseIndex}`);
4855
+ if (this.options.debug) {
4856
+ this.log("Current conflation cache snapshot", {
5359
4857
  channel,
5360
- deltaConflationKey: conflationKey,
5361
- deltaBaseIndex: baseIndex,
5362
- deltaSeq: sequence,
5363
- channelStateConflationKey: channelState.conflationKey,
5364
- channelStateBaseMessage: channelState.baseMessage ? "exists" : null,
5365
- channelStateBaseSequence: channelState.baseSequence,
5366
- channelStateLastSequence: channelState.lastSequence,
5367
- conflationCacheKeys: Array.from(channelState.conflationCaches.keys()),
5368
- conflationCacheSizes: Array.from(
5369
- channelState.conflationCaches.entries()
5370
- ).map(([key, cache]) => ({ key, size: cache.length }))
5371
- }
5372
- );
4858
+ conflationKey: channelState.conflationKey,
4859
+ cacheSizes: Array.from(channelState.conflationCaches.entries()).map(([key, cache]) => ({ key, size: cache.length }))
4860
+ });
4861
+ }
5373
4862
  this.requestResync(channel);
5374
4863
  return null;
5375
4864
  }
5376
4865
  } else {
5377
4866
  baseMessage = channelState.baseMessage;
5378
4867
  if (!baseMessage) {
5379
- this.error(
5380
- `No base message (legacy path) for channel ${channel}`,
5381
- {
5382
- path: "legacy",
4868
+ this.error(`No base message for channel ${channel}`);
4869
+ if (this.options.debug) {
4870
+ this.log("Channel state missing base", {
5383
4871
  channel,
5384
- deltaConflationKey: conflationKey,
5385
- deltaBaseIndex: baseIndex,
5386
- deltaSeq: sequence,
5387
- channelStateConflationKey: channelState.conflationKey,
5388
- channelStateBaseMessage: null,
5389
- channelStateBaseSequence: channelState.baseSequence,
5390
- channelStateLastSequence: channelState.lastSequence
5391
- }
5392
- );
4872
+ lastSequence: channelState.lastSequence
4873
+ });
4874
+ }
5393
4875
  this.requestResync(channel);
5394
4876
  return null;
5395
4877
  }
@@ -5398,10 +4880,7 @@ class DeltaCompressionManager {
5398
4880
  let reconstructedMessage;
5399
4881
  try {
5400
4882
  if (algorithm === "fossil") {
5401
- reconstructedMessage = FossilDeltaDecoder.apply(
5402
- baseMessage,
5403
- deltaBytes
5404
- );
4883
+ reconstructedMessage = FossilDeltaDecoder.apply(baseMessage, deltaBytes);
5405
4884
  } else if (algorithm === "xdelta3") {
5406
4885
  reconstructedMessage = Xdelta3Decoder.apply(baseMessage, deltaBytes);
5407
4886
  } else {
@@ -5411,11 +4890,7 @@ class DeltaCompressionManager {
5411
4890
  throw decodeError;
5412
4891
  }
5413
4892
  if (channelState.conflationKey) {
5414
- channelState.updateConflationCache(
5415
- conflationKey,
5416
- reconstructedMessage,
5417
- sequence
5418
- );
4893
+ channelState.updateConflationCache(conflationKey, reconstructedMessage, sequence);
5419
4894
  } else {
5420
4895
  channelState.setBase(reconstructedMessage, sequence);
5421
4896
  }
@@ -5436,17 +4911,10 @@ class DeltaCompressionManager {
5436
4911
  });
5437
4912
  try {
5438
4913
  const parsedMessage = JSON.parse(reconstructedMessage);
5439
- let data = parsedMessage.data || parsedMessage;
5440
- if (typeof data === "string") {
5441
- try {
5442
- data = JSON.parse(data);
5443
- } catch (e) {
5444
- }
5445
- }
5446
4914
  return {
5447
4915
  event,
5448
4916
  channel,
5449
- data
4917
+ data: parsedMessage.data || parsedMessage
5450
4918
  };
5451
4919
  } catch (e) {
5452
4920
  return {
@@ -5463,7 +4931,7 @@ class DeltaCompressionManager {
5463
4931
  algorithm: deltaData.algorithm,
5464
4932
  conflationKey: deltaData.conflation_key,
5465
4933
  baseIndex: deltaData.base_index,
5466
- deltaSize: deltaData.delta?.length,
4934
+ deltaSize: (_a = deltaData.delta) === null || _a === void 0 ? void 0 : _a.length,
5467
4935
  decodedDeltaBytes: deltaBytes ? deltaBytes.length : "n/a",
5468
4936
  message: error.message
5469
4937
  });
@@ -5471,14 +4939,12 @@ class DeltaCompressionManager {
5471
4939
  return null;
5472
4940
  }
5473
4941
  }
5474
- /**
5475
- * Handle regular (full) message with delta sequence markers
5476
- */
5477
4942
  handleFullMessage(channel, rawMessage, sequence, conflationKey) {
4943
+ var _a, _b, _c;
5478
4944
  if (!sequence && sequence !== 0) {
5479
4945
  try {
5480
4946
  const parsed = JSON.parse(rawMessage);
5481
- const candidate = typeof parsed.data === "string" ? JSON.parse(parsed.data).__delta_seq ?? parsed.__delta_seq : parsed.data?.__delta_seq ?? parsed.__delta_seq;
4947
+ 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;
5482
4948
  if (candidate === 0 || candidate) {
5483
4949
  sequence = candidate;
5484
4950
  } else {
@@ -5507,12 +4973,7 @@ class DeltaCompressionManager {
5507
4973
  channelState.conflationKey = "enabled";
5508
4974
  }
5509
4975
  if (channelState.conflationKey && finalConflationKey !== void 0) {
5510
- channelState.updateConflationCache(
5511
- finalConflationKey,
5512
- rawMessage,
5513
- // Store raw message directly
5514
- sequence
5515
- );
4976
+ channelState.updateConflationCache(finalConflationKey, rawMessage, sequence);
5516
4977
  this.log("Stored full message (conflation)", {
5517
4978
  channel,
5518
4979
  conflationKey: finalConflationKey,
@@ -5534,42 +4995,27 @@ class DeltaCompressionManager {
5534
4995
  this.stats.totalBytesWithCompression += messageSize;
5535
4996
  this.updateStats();
5536
4997
  }
5537
- /**
5538
- * Request resync for a channel
5539
- */
5540
4998
  requestResync(channel) {
5541
4999
  this.log("Requesting resync for channel", channel);
5542
5000
  this.sendEventCallback("pusher:delta_sync_error", { channel });
5543
5001
  this.channelStates.delete(channel);
5544
5002
  }
5545
- /**
5546
- * Update and emit stats
5547
- */
5548
5003
  updateStats() {
5549
5004
  if (this.options.onStats) {
5550
5005
  this.options.onStats(this.getStats());
5551
5006
  }
5552
5007
  }
5553
- /**
5554
- * Get current statistics
5555
- */
5556
5008
  getStats() {
5557
5009
  const bandwidthSaved = this.stats.totalBytesWithoutCompression - this.stats.totalBytesWithCompression;
5558
5010
  const bandwidthSavedPercent = this.stats.totalBytesWithoutCompression > 0 ? bandwidthSaved / this.stats.totalBytesWithoutCompression * 100 : 0;
5559
- const channelStats = Array.from(this.channelStates.values()).map(
5560
- (state) => state.getStats()
5561
- );
5562
- return {
5563
- ...this.stats,
5011
+ const channelStats = Array.from(this.channelStates.values()).map((state) => state.getStats());
5012
+ return Object.assign(Object.assign({}, this.stats), {
5564
5013
  bandwidthSaved,
5565
5014
  bandwidthSavedPercent,
5566
5015
  channelCount: this.channelStates.size,
5567
5016
  channels: channelStats
5568
- };
5017
+ });
5569
5018
  }
5570
- /**
5571
- * Reset statistics
5572
- */
5573
5019
  resetStats() {
5574
5020
  this.stats = {
5575
5021
  totalMessages: 0,
@@ -5581,9 +5027,6 @@ class DeltaCompressionManager {
5581
5027
  };
5582
5028
  this.updateStats();
5583
5029
  }
5584
- /**
5585
- * Clear channel state
5586
- */
5587
5030
  clearChannelState(channel) {
5588
5031
  if (channel) {
5589
5032
  this.channelStates.delete(channel);
@@ -5591,29 +5034,17 @@ class DeltaCompressionManager {
5591
5034
  this.channelStates.clear();
5592
5035
  }
5593
5036
  }
5594
- /**
5595
- * Check if delta compression is enabled
5596
- */
5597
5037
  isEnabled() {
5598
5038
  return this.enabled;
5599
5039
  }
5600
- /**
5601
- * Get available algorithms
5602
- */
5603
5040
  getAvailableAlgorithms() {
5604
5041
  return this.availableAlgorithms;
5605
5042
  }
5606
- /**
5607
- * Log message (if debug enabled)
5608
- */
5609
5043
  log(...args) {
5610
5044
  if (this.options.debug) {
5611
5045
  Logger$1.debug("[DeltaCompression]", ...args);
5612
5046
  }
5613
5047
  }
5614
- /**
5615
- * Log error
5616
- */
5617
5048
  error(...args) {
5618
5049
  Logger$1.error("[DeltaCompression]", ...args);
5619
5050
  if (this.options.onError) {
@@ -5621,7 +5052,7 @@ class DeltaCompressionManager {
5621
5052
  }
5622
5053
  }
5623
5054
  }
5624
- const _Pusher = class _Pusher {
5055
+ class Pusher {
5625
5056
  static get logToConsole() {
5626
5057
  return this._logToConsole;
5627
5058
  }
@@ -5637,17 +5068,15 @@ const _Pusher = class _Pusher {
5637
5068
  setLoggerConfig({ logToConsole: this._logToConsole, log: fn });
5638
5069
  }
5639
5070
  static ready() {
5640
- _Pusher.isReady = true;
5641
- for (var i = 0, l = _Pusher.instances.length; i < l; i++) {
5642
- _Pusher.instances[i].connect();
5071
+ Pusher.isReady = true;
5072
+ for (var i = 0, l = Pusher.instances.length; i < l; i++) {
5073
+ Pusher.instances[i].connect();
5643
5074
  }
5644
5075
  }
5645
5076
  static getClientFeatures() {
5646
- return keys(
5647
- filterObject({ ws: Runtime.Transports.ws }, function(t) {
5648
- return t.isSupported({});
5649
- })
5650
- );
5077
+ return keys(filterObject({ ws: Runtime.Transports.ws }, function(t) {
5078
+ return t.isSupported({});
5079
+ }));
5651
5080
  }
5652
5081
  constructor(app_key, options) {
5653
5082
  checkAppKey(app_key);
@@ -5659,10 +5088,10 @@ const _Pusher = class _Pusher {
5659
5088
  this.sessionID = Runtime.randomInt(1e9);
5660
5089
  this.timeline = new Timeline(this.key, this.sessionID, {
5661
5090
  cluster: this.config.cluster,
5662
- features: _Pusher.getClientFeatures(),
5091
+ features: Pusher.getClientFeatures(),
5663
5092
  params: this.config.timelineParams || {},
5664
5093
  limit: 50,
5665
- level: TimelineLevel.INFO,
5094
+ level: TimelineLevel$1.INFO,
5666
5095
  version: Defaults.VERSION
5667
5096
  });
5668
5097
  if (this.config.enableStats) {
@@ -5683,17 +5112,15 @@ const _Pusher = class _Pusher {
5683
5112
  useTLS: Boolean(this.config.useTLS)
5684
5113
  });
5685
5114
  if (options.deltaCompression !== void 0) {
5686
- this.deltaCompression = new DeltaCompressionManager(
5687
- options.deltaCompression || {},
5688
- (event, data) => this.send_event(event, data)
5689
- );
5115
+ this.deltaCompression = new DeltaCompressionManager(options.deltaCompression || {}, (event, data) => this.send_event(event, data));
5690
5116
  }
5691
5117
  this.connection.bind("connected", () => {
5118
+ var _a;
5692
5119
  this.subscribeAll();
5693
5120
  if (this.timelineSender) {
5694
5121
  this.timelineSender.send(this.connection.isUsingTLS());
5695
5122
  }
5696
- if (this.deltaCompression && options.deltaCompression?.enabled === true) {
5123
+ if (this.deltaCompression && ((_a = options.deltaCompression) === null || _a === void 0 ? void 0 : _a.enabled) === true) {
5697
5124
  this.deltaCompression.enable();
5698
5125
  }
5699
5126
  });
@@ -5711,18 +5138,12 @@ const _Pusher = class _Pusher {
5711
5138
  if (!channel) {
5712
5139
  return;
5713
5140
  }
5714
- const reconstructedEvent = this.deltaCompression.handleDeltaMessage(
5715
- event.channel,
5716
- event.data
5717
- );
5141
+ const reconstructedEvent = this.deltaCompression.handleDeltaMessage(event.channel, event.data);
5718
5142
  if (reconstructedEvent) {
5719
5143
  if (channel) {
5720
5144
  channel.handleEvent(reconstructedEvent);
5721
5145
  }
5722
- this.global_emitter.emit(
5723
- reconstructedEvent.event,
5724
- reconstructedEvent.data
5725
- );
5146
+ this.global_emitter.emit(reconstructedEvent.event, reconstructedEvent.data);
5726
5147
  }
5727
5148
  return;
5728
5149
  }
@@ -5745,21 +5166,10 @@ const _Pusher = class _Pusher {
5745
5166
  if (fullMessage && sequence !== void 0) {
5746
5167
  fullMessage = fullMessage.replace(/,"__delta_seq":\d+/g, "");
5747
5168
  fullMessage = fullMessage.replace(/"__delta_seq":\d+,/g, "");
5748
- fullMessage = fullMessage.replace(
5749
- /,"__conflation_key":"[^"]*"/g,
5750
- ""
5751
- );
5752
- fullMessage = fullMessage.replace(
5753
- /"__conflation_key":"[^"]*",/g,
5754
- ""
5755
- );
5169
+ fullMessage = fullMessage.replace(/,"__conflation_key":"[^"]*"/g, "");
5170
+ fullMessage = fullMessage.replace(/"__conflation_key":"[^"]*",/g, "");
5756
5171
  }
5757
- this.deltaCompression.handleFullMessage(
5758
- event.channel,
5759
- fullMessage,
5760
- sequence,
5761
- conflationKey
5762
- );
5172
+ this.deltaCompression.handleFullMessage(event.channel, fullMessage, sequence, conflationKey);
5763
5173
  }
5764
5174
  }
5765
5175
  if (!internal) {
@@ -5775,10 +5185,10 @@ const _Pusher = class _Pusher {
5775
5185
  this.connection.bind("error", (err) => {
5776
5186
  Logger$1.warn(err);
5777
5187
  });
5778
- _Pusher.instances.push(this);
5779
- this.timeline.info({ instances: _Pusher.instances.length });
5188
+ Pusher.instances.push(this);
5189
+ this.timeline.info({ instances: Pusher.instances.length });
5780
5190
  this.user = new UserFacade(this);
5781
- if (_Pusher.isReady) {
5191
+ if (Pusher.isReady) {
5782
5192
  this.connect();
5783
5193
  }
5784
5194
  }
@@ -5870,33 +5280,25 @@ const _Pusher = class _Pusher {
5870
5280
  signin() {
5871
5281
  this.user.signin();
5872
5282
  }
5873
- /**
5874
- * Get delta compression statistics
5875
- * @returns {DeltaStats} Statistics about delta compression bandwidth savings
5876
- */
5877
5283
  getDeltaStats() {
5878
5284
  if (!this.deltaCompression) {
5879
5285
  return null;
5880
5286
  }
5881
5287
  return this.deltaCompression.getStats();
5882
5288
  }
5883
- /**
5884
- * Reset delta compression statistics
5885
- */
5886
5289
  resetDeltaStats() {
5887
5290
  if (this.deltaCompression) {
5888
5291
  this.deltaCompression.resetStats();
5889
5292
  }
5890
5293
  }
5891
- };
5892
- _Pusher.instances = [];
5893
- _Pusher.isReady = false;
5894
- _Pusher._logToConsole = false;
5895
- _Pusher.Runtime = Runtime;
5896
- _Pusher.ScriptReceivers = Runtime.ScriptReceivers;
5897
- _Pusher.DependenciesReceivers = Runtime.DependenciesReceivers;
5898
- _Pusher.auth_callbacks = Runtime.auth_callbacks;
5899
- let Pusher = _Pusher;
5294
+ }
5295
+ Pusher.instances = [];
5296
+ Pusher.isReady = false;
5297
+ Pusher._logToConsole = false;
5298
+ Pusher.Runtime = Runtime;
5299
+ Pusher.ScriptReceivers = Runtime.ScriptReceivers;
5300
+ Pusher.DependenciesReceivers = Runtime.DependenciesReceivers;
5301
+ Pusher.auth_callbacks = Runtime.auth_callbacks;
5900
5302
  function checkAppKey(key) {
5901
5303
  if (key === null || key === void 0) {
5902
5304
  throw "You must pass your app key when you instantiate Pusher.";