pingerchips-js 1.0.0-a

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 (434) hide show
  1. package/.editorconfig +14 -0
  2. package/.github/ISSUE_TEMPLATE.md +11 -0
  3. package/.github/PULL_REQUEST_TEMPLATE.md +14 -0
  4. package/.github/dependabot.yml +14 -0
  5. package/.github/stale.yml +26 -0
  6. package/.github/workflows/release.yml +112 -0
  7. package/.github/workflows/release_pr.yml +43 -0
  8. package/.github/workflows/run-tests.yml +62 -0
  9. package/.gitmodules +3 -0
  10. package/.prettierrc +2 -0
  11. package/CHANGELOG.md +924 -0
  12. package/LICENCE +19 -0
  13. package/Makefile +78 -0
  14. package/README.md +707 -0
  15. package/bower.json +28 -0
  16. package/dist/node/pusher.js +10870 -0
  17. package/dist/node/pusher.js.map +1 -0
  18. package/dist/react-native/pusher.js +9 -0
  19. package/dist/react-native/pusher.js.map +1 -0
  20. package/dist/web/json2.js +486 -0
  21. package/dist/web/json2.min.js +1 -0
  22. package/dist/web/pusher-with-encryption.js +7009 -0
  23. package/dist/web/pusher-with-encryption.js.map +1 -0
  24. package/dist/web/pusher-with-encryption.min.js +9 -0
  25. package/dist/web/pusher-with-encryption.min.js.map +1 -0
  26. package/dist/web/pusher.js +4587 -0
  27. package/dist/web/pusher.js.map +1 -0
  28. package/dist/web/pusher.min.js +9 -0
  29. package/dist/web/pusher.min.js.map +1 -0
  30. package/dist/web/sockjs.js +2435 -0
  31. package/dist/web/sockjs.min.js +89 -0
  32. package/dist/worker/pusher-with-encryption.worker.js +6622 -0
  33. package/dist/worker/pusher-with-encryption.worker.js.map +1 -0
  34. package/dist/worker/pusher-with-encryption.worker.min.js +9 -0
  35. package/dist/worker/pusher-with-encryption.worker.min.js.map +1 -0
  36. package/dist/worker/pusher.worker.js +4200 -0
  37. package/dist/worker/pusher.worker.js.map +1 -0
  38. package/dist/worker/pusher.worker.min.js +9 -0
  39. package/dist/worker/pusher.worker.min.js.map +1 -0
  40. package/index.d.ts +29 -0
  41. package/integration_tests_server/index.js +176 -0
  42. package/integration_tests_server/package-lock.json +1177 -0
  43. package/integration_tests_server/package.json +15 -0
  44. package/node.js +1 -0
  45. package/package.json +70 -0
  46. package/pusher-with-encryption/index.js +1 -0
  47. package/react-native/index.d.ts +29 -0
  48. package/react-native/index.js +1 -0
  49. package/spec/config/jasmine/helpers/reporter.js +14 -0
  50. package/spec/config/jasmine/integration.json +13 -0
  51. package/spec/config/jasmine/unit.json +13 -0
  52. package/spec/config/jasmine/webpack.integration.js +33 -0
  53. package/spec/config/jasmine/webpack.unit.js +30 -0
  54. package/spec/config/karma/available_browsers.json +4957 -0
  55. package/spec/config/karma/config.ci.js +25 -0
  56. package/spec/config/karma/config.common.js +50 -0
  57. package/spec/config/karma/config.integration.js +26 -0
  58. package/spec/config/karma/config.unit.js +10 -0
  59. package/spec/config/karma/config.worker.js +34 -0
  60. package/spec/config/karma/integration.js +24 -0
  61. package/spec/config/karma/unit.js +20 -0
  62. package/spec/javascripts/helpers/mocks.js +274 -0
  63. package/spec/javascripts/helpers/node/integration.js +33 -0
  64. package/spec/javascripts/helpers/node/mock-dom-dependencies.ts +1 -0
  65. package/spec/javascripts/helpers/pusher_integration.js +1 -0
  66. package/spec/javascripts/helpers/pusher_integration_class.ts +12 -0
  67. package/spec/javascripts/helpers/timers/promises.js +9 -0
  68. package/spec/javascripts/helpers/waitsFor.js +37 -0
  69. package/spec/javascripts/helpers/web/integration.js +44 -0
  70. package/spec/javascripts/helpers/worker/mock-dom-dependencies.js +1 -0
  71. package/spec/javascripts/integration/core/cluster_config_spec.js +153 -0
  72. package/spec/javascripts/integration/core/falling_back_spec.js +195 -0
  73. package/spec/javascripts/integration/core/pusher_spec/index.js +68 -0
  74. package/spec/javascripts/integration/core/pusher_spec/test_builder.js +715 -0
  75. package/spec/javascripts/integration/core/timeout_configuration_spec.js +200 -0
  76. package/spec/javascripts/integration/core/transport_lists_spec.js +103 -0
  77. package/spec/javascripts/integration/index.node.js +12 -0
  78. package/spec/javascripts/integration/index.web.js +63 -0
  79. package/spec/javascripts/integration/index.worker.js +13 -0
  80. package/spec/javascripts/integration/web/dom/jsonp_spec.js +97 -0
  81. package/spec/javascripts/integration/web/dom/script_request_spec.js +90 -0
  82. package/spec/javascripts/polyfills/index.js +105 -0
  83. package/spec/javascripts/unit/core/channels/channel_spec.js +355 -0
  84. package/spec/javascripts/unit/core/channels/channels_spec.js +94 -0
  85. package/spec/javascripts/unit/core/channels/encrypted_channel_spec.js +343 -0
  86. package/spec/javascripts/unit/core/channels/presence_channel_spec.js +553 -0
  87. package/spec/javascripts/unit/core/channels/private_channel_spec.js +182 -0
  88. package/spec/javascripts/unit/core/config_spec.js +507 -0
  89. package/spec/javascripts/unit/core/connection/connection_manager_spec.js +656 -0
  90. package/spec/javascripts/unit/core/connection/connection_spec.js +286 -0
  91. package/spec/javascripts/unit/core/connection/handshake_spec.js +160 -0
  92. package/spec/javascripts/unit/core/connection/protocol_spec.js +420 -0
  93. package/spec/javascripts/unit/core/defaults_spec.js +26 -0
  94. package/spec/javascripts/unit/core/events_dispatcher_spec.js +385 -0
  95. package/spec/javascripts/unit/core/http/http_polling_socket_spec.js +60 -0
  96. package/spec/javascripts/unit/core/http/http_request_spec.js +185 -0
  97. package/spec/javascripts/unit/core/http/http_socket_spec.js +370 -0
  98. package/spec/javascripts/unit/core/http/http_streaming_socket_spec.js +56 -0
  99. package/spec/javascripts/unit/core/http/http_xhr_request_spec.js +164 -0
  100. package/spec/javascripts/unit/core/logger_spec.js +133 -0
  101. package/spec/javascripts/unit/core/pusher_spec.js +613 -0
  102. package/spec/javascripts/unit/core/pusher_with_encryption_spec.js +18 -0
  103. package/spec/javascripts/unit/core/strategies/best_connected_ever_strategy_spec.js +104 -0
  104. package/spec/javascripts/unit/core/strategies/delayed_strategy_spec.js +95 -0
  105. package/spec/javascripts/unit/core/strategies/first_connected_strategy_spec.js +68 -0
  106. package/spec/javascripts/unit/core/strategies/if_strategy_spec.js +165 -0
  107. package/spec/javascripts/unit/core/strategies/sequential_strategy_spec.js +213 -0
  108. package/spec/javascripts/unit/core/strategies/transport_strategy_spec.js +250 -0
  109. package/spec/javascripts/unit/core/strategies/websocket_prioritized_cached_strategy_spec.js +400 -0
  110. package/spec/javascripts/unit/core/timeline/timeline_spec.js +153 -0
  111. package/spec/javascripts/unit/core/transports/assistant_to_the_transport_manager_spec.js +223 -0
  112. package/spec/javascripts/unit/core/transports/hosts_and_ports_spec.js +85 -0
  113. package/spec/javascripts/unit/core/transports/transport_connection_spec.js +585 -0
  114. package/spec/javascripts/unit/core/transports/transport_manager_spec.js +64 -0
  115. package/spec/javascripts/unit/core/user_spec.js +303 -0
  116. package/spec/javascripts/unit/core/utils/periodic_timer_spec.js +74 -0
  117. package/spec/javascripts/unit/core/utils/timers_spec.js +157 -0
  118. package/spec/javascripts/unit/core/utils/url_store_spec.js +14 -0
  119. package/spec/javascripts/unit/core/watchlist_spec.js +48 -0
  120. package/spec/javascripts/unit/core_with_runtime/auth/channel_authorizer_spec.js +137 -0
  121. package/spec/javascripts/unit/core_with_runtime/auth/deprecated_channel_authorizer_spec.js +48 -0
  122. package/spec/javascripts/unit/core_with_runtime/auth/user_authorizer_spec.js +128 -0
  123. package/spec/javascripts/unit/core_with_runtime/readme.md +5 -0
  124. package/spec/javascripts/unit/index.node.js +11 -0
  125. package/spec/javascripts/unit/index.web.js +12 -0
  126. package/spec/javascripts/unit/index.worker.js +11 -0
  127. package/spec/javascripts/unit/isomorphic/transports/hosts_and_ports_spec.js +82 -0
  128. package/spec/javascripts/unit/isomorphic/transports/transports_spec.js +202 -0
  129. package/spec/javascripts/unit/node/timeline_sender_spec.js +83 -0
  130. package/spec/javascripts/unit/web/dom/dependency_loader_spec.js +249 -0
  131. package/spec/javascripts/unit/web/dom/jsonp_request_spec.js +130 -0
  132. package/spec/javascripts/unit/web/dom/script_receiver_factory_spec.js +68 -0
  133. package/spec/javascripts/unit/web/http/http_xdomain_request_spec.js +222 -0
  134. package/spec/javascripts/unit/web/pusher_authorizer_spec.js +64 -0
  135. package/spec/javascripts/unit/web/timeline/timeline_sender_spec.js +131 -0
  136. package/spec/javascripts/unit/web/transports/hosts_and_ports_spec.js +127 -0
  137. package/spec/javascripts/unit/web/transports/transports_spec.js +444 -0
  138. package/spec/javascripts/unit/worker/channel_authorizer_spec.js +156 -0
  139. package/spec/javascripts/unit/worker/timeline_sender_spec.js +76 -0
  140. package/src/core/auth/auth_transports.ts +18 -0
  141. package/src/core/auth/channel_authorizer.ts +64 -0
  142. package/src/core/auth/deprecated_channel_authorizer.ts +58 -0
  143. package/src/core/auth/options.ts +78 -0
  144. package/src/core/auth/user_authenticator.ts +62 -0
  145. package/src/core/base64.ts +49 -0
  146. package/src/core/channels/channel.ts +163 -0
  147. package/src/core/channels/channel_table.ts +7 -0
  148. package/src/core/channels/channels.ts +85 -0
  149. package/src/core/channels/encrypted_channel.ts +149 -0
  150. package/src/core/channels/members.ts +80 -0
  151. package/src/core/channels/metadata.ts +5 -0
  152. package/src/core/channels/presence_channel.ts +113 -0
  153. package/src/core/channels/private_channel.ts +25 -0
  154. package/src/core/config.ts +189 -0
  155. package/src/core/connection/callbacks.ts +21 -0
  156. package/src/core/connection/connection.ts +160 -0
  157. package/src/core/connection/connection_manager.ts +371 -0
  158. package/src/core/connection/connection_manager_options.ts +14 -0
  159. package/src/core/connection/handshake/handshake_payload.ts +10 -0
  160. package/src/core/connection/handshake/index.ts +90 -0
  161. package/src/core/connection/protocol/action.ts +8 -0
  162. package/src/core/connection/protocol/message-types.ts +8 -0
  163. package/src/core/connection/protocol/protocol.ts +154 -0
  164. package/src/core/defaults.ts +66 -0
  165. package/src/core/errors.ts +69 -0
  166. package/src/core/events/callback.ts +6 -0
  167. package/src/core/events/callback_registry.ts +75 -0
  168. package/src/core/events/callback_table.ts +7 -0
  169. package/src/core/events/dispatcher.ts +84 -0
  170. package/src/core/http/ajax.ts +24 -0
  171. package/src/core/http/http_factory.ts +16 -0
  172. package/src/core/http/http_polling_socket.ts +24 -0
  173. package/src/core/http/http_request.ts +81 -0
  174. package/src/core/http/http_socket.ts +220 -0
  175. package/src/core/http/http_streaming_socket.ts +19 -0
  176. package/src/core/http/request_hooks.ts +9 -0
  177. package/src/core/http/socket_hooks.ts +11 -0
  178. package/src/core/http/state.ts +7 -0
  179. package/src/core/http/url_location.ts +6 -0
  180. package/src/core/logger.ts +53 -0
  181. package/src/core/options.ts +59 -0
  182. package/src/core/pusher-licence.js +7 -0
  183. package/src/core/pusher-with-encryption.js +1 -0
  184. package/src/core/pusher-with-encryption.ts +14 -0
  185. package/src/core/pusher.js +2 -0
  186. package/src/core/pusher.ts +249 -0
  187. package/src/core/reachability.ts +7 -0
  188. package/src/core/socket.ts +14 -0
  189. package/src/core/strategies/best_connected_ever_strategy.ts +81 -0
  190. package/src/core/strategies/delayed_strategy.ts +48 -0
  191. package/src/core/strategies/first_connected_strategy.ts +28 -0
  192. package/src/core/strategies/if_strategy.ts +34 -0
  193. package/src/core/strategies/sequential_strategy.ts +129 -0
  194. package/src/core/strategies/strategy.ts +8 -0
  195. package/src/core/strategies/strategy_builder.ts +67 -0
  196. package/src/core/strategies/strategy_options.ts +18 -0
  197. package/src/core/strategies/strategy_runner.ts +6 -0
  198. package/src/core/strategies/transport_strategy.ts +144 -0
  199. package/src/core/strategies/websocket_prioritized_cached_strategy.ts +157 -0
  200. package/src/core/timeline/level.ts +7 -0
  201. package/src/core/timeline/timeline.ts +90 -0
  202. package/src/core/timeline/timeline_sender.ts +33 -0
  203. package/src/core/timeline/timeline_transport.ts +11 -0
  204. package/src/core/transports/assistant_to_the_transport_manager.ts +104 -0
  205. package/src/core/transports/ping_delay_options.ts +7 -0
  206. package/src/core/transports/transport.ts +54 -0
  207. package/src/core/transports/transport_connection.ts +241 -0
  208. package/src/core/transports/transport_connection_options.ts +8 -0
  209. package/src/core/transports/transport_hooks.ts +16 -0
  210. package/src/core/transports/transport_manager.ts +52 -0
  211. package/src/core/transports/transports_table.ts +12 -0
  212. package/src/core/transports/url_scheme.ts +13 -0
  213. package/src/core/transports/url_schemes.ts +47 -0
  214. package/src/core/user.ts +186 -0
  215. package/src/core/util.ts +34 -0
  216. package/src/core/utils/collections.ts +353 -0
  217. package/src/core/utils/factory.ts +75 -0
  218. package/src/core/utils/flat_promise.ts +10 -0
  219. package/src/core/utils/timers/abstract_timer.ts +39 -0
  220. package/src/core/utils/timers/index.ts +39 -0
  221. package/src/core/utils/timers/scheduling.ts +11 -0
  222. package/src/core/utils/timers/timed_callback.ts +5 -0
  223. package/src/core/utils/url_store.ts +48 -0
  224. package/src/core/watchlist.ts +31 -0
  225. package/src/d.ts/constants/index.d.ts +5 -0
  226. package/src/d.ts/faye-websocket/faye-websocket.d.ts +21 -0
  227. package/src/d.ts/global/global.d.ts +1 -0
  228. package/src/d.ts/module/module.d.ts +12 -0
  229. package/src/d.ts/tweetnacl-util/index.d.ts +6 -0
  230. package/src/d.ts/window/events.d.ts +4 -0
  231. package/src/d.ts/window/sockjs.d.ts +3 -0
  232. package/src/d.ts/window/websocket.d.ts +4 -0
  233. package/src/d.ts/window/xmlhttprequest.d.ts +3 -0
  234. package/src/runtimes/interface.ts +59 -0
  235. package/src/runtimes/isomorphic/auth/xhr_auth.ts +90 -0
  236. package/src/runtimes/isomorphic/default_strategy.ts +155 -0
  237. package/src/runtimes/isomorphic/http/http.ts +32 -0
  238. package/src/runtimes/isomorphic/http/http_xhr_request.ts +35 -0
  239. package/src/runtimes/isomorphic/runtime.ts +62 -0
  240. package/src/runtimes/isomorphic/timeline/xhr_timeline.ts +50 -0
  241. package/src/runtimes/isomorphic/transports/transport_connection_initializer.ts +19 -0
  242. package/src/runtimes/isomorphic/transports/transports.ts +81 -0
  243. package/src/runtimes/node/net_info.ts +10 -0
  244. package/src/runtimes/node/runtime.ts +68 -0
  245. package/src/runtimes/react-native/net_info.ts +42 -0
  246. package/src/runtimes/react-native/runtime.ts +65 -0
  247. package/src/runtimes/web/auth/jsonp_auth.ts +51 -0
  248. package/src/runtimes/web/browser.ts +24 -0
  249. package/src/runtimes/web/default_strategy.ts +201 -0
  250. package/src/runtimes/web/dom/dependencies.ts +16 -0
  251. package/src/runtimes/web/dom/dependency_loader.ts +93 -0
  252. package/src/runtimes/web/dom/json2.js +486 -0
  253. package/src/runtimes/web/dom/jsonp_request.ts +52 -0
  254. package/src/runtimes/web/dom/script_receiver.ts +8 -0
  255. package/src/runtimes/web/dom/script_receiver_factory.ts +57 -0
  256. package/src/runtimes/web/dom/script_request.ts +85 -0
  257. package/src/runtimes/web/dom/sockjs/COPYING +11 -0
  258. package/src/runtimes/web/dom/sockjs/Changelog +147 -0
  259. package/src/runtimes/web/dom/sockjs/LICENSE-MIT-SockJS +19 -0
  260. package/src/runtimes/web/dom/sockjs/Makefile +109 -0
  261. package/src/runtimes/web/dom/sockjs/README.md +388 -0
  262. package/src/runtimes/web/dom/sockjs/VERSION-GEN +17 -0
  263. package/src/runtimes/web/dom/sockjs/bin/render.coffee +111 -0
  264. package/src/runtimes/web/dom/sockjs/bin/run_testling.sh +135 -0
  265. package/src/runtimes/web/dom/sockjs/lib/all.js +9 -0
  266. package/src/runtimes/web/dom/sockjs/lib/dom.js +185 -0
  267. package/src/runtimes/web/dom/sockjs/lib/dom2.js +280 -0
  268. package/src/runtimes/web/dom/sockjs/lib/eventemitter.js +57 -0
  269. package/src/runtimes/web/dom/sockjs/lib/heartbeater.js +70 -0
  270. package/src/runtimes/web/dom/sockjs/lib/index.js +41 -0
  271. package/src/runtimes/web/dom/sockjs/lib/info.js +117 -0
  272. package/src/runtimes/web/dom/sockjs/lib/json2.min.js +1 -0
  273. package/src/runtimes/web/dom/sockjs/lib/reventtarget.js +55 -0
  274. package/src/runtimes/web/dom/sockjs/lib/simpleevent.js +28 -0
  275. package/src/runtimes/web/dom/sockjs/lib/sockjs.js +288 -0
  276. package/src/runtimes/web/dom/sockjs/lib/test-hooks.js +16 -0
  277. package/src/runtimes/web/dom/sockjs/lib/trans-iframe-eventsource.js +29 -0
  278. package/src/runtimes/web/dom/sockjs/lib/trans-iframe-htmlfile.js +35 -0
  279. package/src/runtimes/web/dom/sockjs/lib/trans-iframe-within.js +100 -0
  280. package/src/runtimes/web/dom/sockjs/lib/trans-iframe-xhr-polling.js +30 -0
  281. package/src/runtimes/web/dom/sockjs/lib/trans-iframe.js +103 -0
  282. package/src/runtimes/web/dom/sockjs/lib/trans-jsonp-polling.js +106 -0
  283. package/src/runtimes/web/dom/sockjs/lib/trans-jsonp-receiver.js +116 -0
  284. package/src/runtimes/web/dom/sockjs/lib/trans-polling.js +44 -0
  285. package/src/runtimes/web/dom/sockjs/lib/trans-receiver-eventsource.js +41 -0
  286. package/src/runtimes/web/dom/sockjs/lib/trans-receiver-htmlfile.js +65 -0
  287. package/src/runtimes/web/dom/sockjs/lib/trans-receiver-xhr.js +42 -0
  288. package/src/runtimes/web/dom/sockjs/lib/trans-sender.js +138 -0
  289. package/src/runtimes/web/dom/sockjs/lib/trans-xhr.js +29 -0
  290. package/src/runtimes/web/dom/sockjs/lib/utils.js +297 -0
  291. package/src/runtimes/web/dom/sockjs/package.json +18 -0
  292. package/src/runtimes/web/dom/sockjs/version +1 -0
  293. package/src/runtimes/web/http/http.ts +8 -0
  294. package/src/runtimes/web/http/http_xdomain_request.ts +37 -0
  295. package/src/runtimes/web/net_info.ts +50 -0
  296. package/src/runtimes/web/runtime.ts +174 -0
  297. package/src/runtimes/web/timeline/jsonp_timeline.ts +34 -0
  298. package/src/runtimes/web/transports/transport_connection_initializer.ts +39 -0
  299. package/src/runtimes/web/transports/transports.ts +65 -0
  300. package/src/runtimes/worker/auth/fetch_auth.ts +69 -0
  301. package/src/runtimes/worker/net_info.ts +10 -0
  302. package/src/runtimes/worker/runtime.ts +75 -0
  303. package/src/runtimes/worker/timeline/fetch_timeline.ts +39 -0
  304. package/tsconfig.json +26 -0
  305. package/types/spec/javascripts/helpers/node/mock-dom-dependencies.d.ts +1 -0
  306. package/types/spec/javascripts/helpers/pusher_integration_class.d.ts +4 -0
  307. package/types/src/core/auth/auth_transports.d.ts +9 -0
  308. package/types/src/core/auth/channel_authorizer.d.ts +3 -0
  309. package/types/src/core/auth/deprecated_channel_authorizer.d.ts +18 -0
  310. package/types/src/core/auth/options.d.ts +48 -0
  311. package/types/src/core/auth/user_authenticator.d.ts +3 -0
  312. package/types/src/core/base64.d.ts +1 -0
  313. package/types/src/core/channels/channel.d.ts +23 -0
  314. package/types/src/core/channels/channel_table.d.ts +5 -0
  315. package/types/src/core/channels/channels.d.ts +12 -0
  316. package/types/src/core/channels/encrypted_channel.d.ts +15 -0
  317. package/types/src/core/channels/members.d.ts +14 -0
  318. package/types/src/core/channels/metadata.d.ts +4 -0
  319. package/types/src/core/channels/presence_channel.d.ts +13 -0
  320. package/types/src/core/channels/private_channel.d.ts +5 -0
  321. package/types/src/core/config.d.ts +31 -0
  322. package/types/src/core/connection/callbacks.d.ts +18 -0
  323. package/types/src/core/connection/connection.d.ts +16 -0
  324. package/types/src/core/connection/connection_manager.d.ts +50 -0
  325. package/types/src/core/connection/connection_manager_options.d.ts +11 -0
  326. package/types/src/core/connection/handshake/handshake_payload.d.ts +8 -0
  327. package/types/src/core/connection/handshake/index.d.ts +12 -0
  328. package/types/src/core/connection/protocol/action.d.ts +7 -0
  329. package/types/src/core/connection/protocol/message-types.d.ts +7 -0
  330. package/types/src/core/connection/protocol/protocol.d.ts +10 -0
  331. package/types/src/core/defaults.d.ts +26 -0
  332. package/types/src/core/errors.d.ts +28 -0
  333. package/types/src/core/events/callback.d.ts +5 -0
  334. package/types/src/core/events/callback_registry.d.ts +11 -0
  335. package/types/src/core/events/callback_table.d.ts +5 -0
  336. package/types/src/core/events/dispatcher.d.ts +14 -0
  337. package/types/src/core/http/ajax.d.ts +16 -0
  338. package/types/src/core/http/http_factory.d.ts +13 -0
  339. package/types/src/core/http/http_polling_socket.d.ts +3 -0
  340. package/types/src/core/http/http_request.d.ts +17 -0
  341. package/types/src/core/http/http_socket.d.ts +32 -0
  342. package/types/src/core/http/http_streaming_socket.d.ts +3 -0
  343. package/types/src/core/http/request_hooks.d.ts +6 -0
  344. package/types/src/core/http/socket_hooks.d.ts +8 -0
  345. package/types/src/core/http/state.d.ts +6 -0
  346. package/types/src/core/http/url_location.d.ts +5 -0
  347. package/types/src/core/logger.d.ts +11 -0
  348. package/types/src/core/options.d.ts +34 -0
  349. package/types/src/core/pusher-with-encryption.d.ts +5 -0
  350. package/types/src/core/pusher.d.ts +49 -0
  351. package/types/src/core/reachability.d.ts +5 -0
  352. package/types/src/core/socket.d.ts +12 -0
  353. package/types/src/core/strategies/best_connected_ever_strategy.d.ts +10 -0
  354. package/types/src/core/strategies/delayed_strategy.d.ts +15 -0
  355. package/types/src/core/strategies/first_connected_strategy.d.ts +8 -0
  356. package/types/src/core/strategies/if_strategy.d.ts +10 -0
  357. package/types/src/core/strategies/sequential_strategy.d.ts +16 -0
  358. package/types/src/core/strategies/strategy.d.ts +6 -0
  359. package/types/src/core/strategies/strategy_builder.d.ts +5 -0
  360. package/types/src/core/strategies/strategy_options.d.ts +16 -0
  361. package/types/src/core/strategies/strategy_runner.d.ts +5 -0
  362. package/types/src/core/strategies/transport_strategy.d.ts +15 -0
  363. package/types/src/core/strategies/websocket_prioritized_cached_strategy.d.ts +20 -0
  364. package/types/src/core/timeline/level.d.ts +6 -0
  365. package/types/src/core/timeline/timeline.d.ts +25 -0
  366. package/types/src/core/timeline/timeline_sender.d.ts +13 -0
  367. package/types/src/core/timeline/timeline_transport.d.ts +6 -0
  368. package/types/src/core/transports/assistant_to_the_transport_manager.d.ts +14 -0
  369. package/types/src/core/transports/ping_delay_options.d.ts +6 -0
  370. package/types/src/core/transports/transport.d.ts +8 -0
  371. package/types/src/core/transports/transport_connection.d.ts +35 -0
  372. package/types/src/core/transports/transport_connection_options.d.ts +6 -0
  373. package/types/src/core/transports/transport_hooks.d.ts +13 -0
  374. package/types/src/core/transports/transport_manager.d.ts +14 -0
  375. package/types/src/core/transports/transports_table.d.ts +10 -0
  376. package/types/src/core/transports/url_scheme.d.ts +11 -0
  377. package/types/src/core/transports/url_schemes.d.ts +4 -0
  378. package/types/src/core/user.d.ts +21 -0
  379. package/types/src/core/util.d.ts +8 -0
  380. package/types/src/core/utils/collections.d.ts +18 -0
  381. package/types/src/core/utils/factory.d.ts +29 -0
  382. package/types/src/core/utils/flat_promise.d.ts +6 -0
  383. package/types/src/core/utils/timers/abstract_timer.d.ts +10 -0
  384. package/types/src/core/utils/timers/index.d.ts +9 -0
  385. package/types/src/core/utils/timers/scheduling.d.ts +8 -0
  386. package/types/src/core/utils/timers/timed_callback.d.ts +4 -0
  387. package/types/src/core/utils/url_store.d.ts +4 -0
  388. package/types/src/core/watchlist.d.ts +8 -0
  389. package/types/src/runtimes/interface.d.ts +43 -0
  390. package/types/src/runtimes/isomorphic/auth/xhr_auth.d.ts +3 -0
  391. package/types/src/runtimes/isomorphic/default_strategy.d.ts +5 -0
  392. package/types/src/runtimes/isomorphic/http/http.d.ts +3 -0
  393. package/types/src/runtimes/isomorphic/http/http_xhr_request.d.ts +3 -0
  394. package/types/src/runtimes/isomorphic/runtime.d.ts +2 -0
  395. package/types/src/runtimes/isomorphic/timeline/xhr_timeline.d.ts +6 -0
  396. package/types/src/runtimes/isomorphic/transports/transport_connection_initializer.d.ts +1 -0
  397. package/types/src/runtimes/isomorphic/transports/transports.d.ts +5 -0
  398. package/types/src/runtimes/node/net_info.d.ts +6 -0
  399. package/types/src/runtimes/node/runtime.d.ts +3 -0
  400. package/types/src/runtimes/react-native/net_info.d.ts +8 -0
  401. package/types/src/runtimes/react-native/runtime.d.ts +3 -0
  402. package/types/src/runtimes/web/auth/jsonp_auth.d.ts +3 -0
  403. package/types/src/runtimes/web/browser.d.ts +19 -0
  404. package/types/src/runtimes/web/default_strategy.d.ts +5 -0
  405. package/types/src/runtimes/web/dom/dependencies.d.ts +4 -0
  406. package/types/src/runtimes/web/dom/dependency_loader.d.ts +10 -0
  407. package/types/src/runtimes/web/dom/jsonp_request.d.ts +10 -0
  408. package/types/src/runtimes/web/dom/script_receiver.d.ts +7 -0
  409. package/types/src/runtimes/web/dom/script_receiver_factory.d.ts +10 -0
  410. package/types/src/runtimes/web/dom/script_request.d.ts +9 -0
  411. package/types/src/runtimes/web/http/http.d.ts +2 -0
  412. package/types/src/runtimes/web/http/http_xdomain_request.d.ts +3 -0
  413. package/types/src/runtimes/web/net_info.d.ts +7 -0
  414. package/types/src/runtimes/web/runtime.d.ts +3 -0
  415. package/types/src/runtimes/web/timeline/jsonp_timeline.d.ts +6 -0
  416. package/types/src/runtimes/web/transports/transport_connection_initializer.d.ts +1 -0
  417. package/types/src/runtimes/web/transports/transports.d.ts +2 -0
  418. package/types/src/runtimes/worker/auth/fetch_auth.d.ts +3 -0
  419. package/types/src/runtimes/worker/net_info.d.ts +6 -0
  420. package/types/src/runtimes/worker/runtime.d.ts +3 -0
  421. package/types/src/runtimes/worker/timeline/fetch_timeline.d.ts +6 -0
  422. package/webpack/config.node.js +26 -0
  423. package/webpack/config.react-native.js +35 -0
  424. package/webpack/config.shared.js +50 -0
  425. package/webpack/config.web.js +36 -0
  426. package/webpack/config.worker.js +42 -0
  427. package/webpack/dev.server.js +17 -0
  428. package/webpack/hosting_config.js +6 -0
  429. package/with-encryption/index.d.ts +29 -0
  430. package/with-encryption/index.js +4 -0
  431. package/worker/index.d.ts +29 -0
  432. package/worker/index.js +1 -0
  433. package/worker/with-encryption/index.d.ts +29 -0
  434. package/worker/with-encryption/index.js +1 -0
@@ -0,0 +1,2435 @@
1
+ /* SockJS client, http://sockjs.org, MIT License
2
+ *
3
+ * Copyright (c) 2011-2012 VMware, Inc.
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ * of this software and associated documentation files (the "Software"), to deal
7
+ * in the Software without restriction, including without limitation the rights
8
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ * copies of the Software, and to permit persons to whom the Software is
10
+ * furnished to do so, subject to the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be included in
13
+ * all copies or substantial portions of the Software.
14
+ *
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ * THE SOFTWARE.
22
+ */
23
+
24
+ /* SockJS client, version 0.3.4.72.g5b91, http://sockjs.org, MIT License
25
+
26
+ Copyright (c) 2011-2012 VMware, Inc.
27
+
28
+ Permission is hereby granted, free of charge, to any person obtaining a copy
29
+ of this software and associated documentation files (the "Software"), to deal
30
+ in the Software without restriction, including without limitation the rights
31
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
32
+ copies of the Software, and to permit persons to whom the Software is
33
+ furnished to do so, subject to the following conditions:
34
+
35
+ The above copyright notice and this permission notice shall be included in
36
+ all copies or substantial portions of the Software.
37
+
38
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
39
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
40
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
41
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
42
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
43
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
44
+ THE SOFTWARE.
45
+ */
46
+
47
+ // JSON2 by Douglas Crockford (minified).
48
+ var JSON;JSON||(JSON={}),function(){function str(a,b){var c,d,e,f,g=gap,h,i=b[a];i&&typeof i=="object"&&typeof i.toJSON=="function"&&(i=i.toJSON(a)),typeof rep=="function"&&(i=rep.call(b,a,i));switch(typeof i){case"string":return quote(i);case"number":return isFinite(i)?String(i):"null";case"boolean":case"null":return String(i);case"object":if(!i)return"null";gap+=indent,h=[];if(Object.prototype.toString.apply(i)==="[object Array]"){f=i.length;for(c=0;c<f;c+=1)h[c]=str(c,i)||"null";e=h.length===0?"[]":gap?"[\n"+gap+h.join(",\n"+gap)+"\n"+g+"]":"["+h.join(",")+"]",gap=g;return e}if(rep&&typeof rep=="object"){f=rep.length;for(c=0;c<f;c+=1)typeof rep[c]=="string"&&(d=rep[c],e=str(d,i),e&&h.push(quote(d)+(gap?": ":":")+e))}else for(d in i)Object.prototype.hasOwnProperty.call(i,d)&&(e=str(d,i),e&&h.push(quote(d)+(gap?": ":":")+e));e=h.length===0?"{}":gap?"{\n"+gap+h.join(",\n"+gap)+"\n"+g+"}":"{"+h.join(",")+"}",gap=g;return e}}function quote(a){escapable.lastIndex=0;return escapable.test(a)?'"'+a.replace(escapable,function(a){var b=meta[a];return typeof b=="string"?b:"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+a+'"'}function f(a){return a<10?"0"+a:a}"use strict",typeof Date.prototype.toJSON!="function"&&(Date.prototype.toJSON=function(a){return isFinite(this.valueOf())?this.getUTCFullYear()+"-"+f(this.getUTCMonth()+1)+"-"+f(this.getUTCDate())+"T"+f(this.getUTCHours())+":"+f(this.getUTCMinutes())+":"+f(this.getUTCSeconds())+"Z":null},String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(a){return this.valueOf()});var cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,escapable=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,gap,indent,meta={"\b":"\\b","\t":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},rep;typeof JSON.stringify!="function"&&(JSON.stringify=function(a,b,c){var d;gap="",indent="";if(typeof c=="number")for(d=0;d<c;d+=1)indent+=" ";else typeof c=="string"&&(indent=c);rep=b;if(!b||typeof b=="function"||typeof b=="object"&&typeof b.length=="number")return str("",{"":a});throw new Error("JSON.stringify")}),typeof JSON.parse!="function"&&(JSON.parse=function(text,reviver){function walk(a,b){var c,d,e=a[b];if(e&&typeof e=="object")for(c in e)Object.prototype.hasOwnProperty.call(e,c)&&(d=walk(e,c),d!==undefined?e[c]=d:delete e[c]);return reviver.call(a,b,e)}var j;text=String(text),cx.lastIndex=0,cx.test(text)&&(text=text.replace(cx,function(a){return"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)}));if(/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,"@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,"]").replace(/(?:^|:|,)(?:\s*\[)+/g,""))){j=eval("("+text+")");return typeof reviver=="function"?walk({"":j},""):j}throw new SyntaxError("JSON.parse")})}()
49
+
50
+
51
+ // [*] Including lib/index.js
52
+ // Public object
53
+ var SockJS = (function(){
54
+ var _document = document;
55
+ var _window = window;
56
+ var utils = {};
57
+
58
+
59
+ // [*] Including lib/reventtarget.js
60
+ /*
61
+ * ***** BEGIN LICENSE BLOCK *****
62
+ * Copyright (c) 2011-2012 VMware, Inc.
63
+ *
64
+ * For the license see COPYING.
65
+ * ***** END LICENSE BLOCK *****
66
+ */
67
+
68
+ /* Simplified implementation of DOM2 EventTarget.
69
+ * http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-EventTarget
70
+ */
71
+ var REventTarget = function() {};
72
+ REventTarget.prototype.addEventListener = function (eventType, listener) {
73
+ if(!this._listeners) {
74
+ this._listeners = {};
75
+ }
76
+ if(!(eventType in this._listeners)) {
77
+ this._listeners[eventType] = [];
78
+ }
79
+ var arr = this._listeners[eventType];
80
+ if(utils.arrIndexOf(arr, listener) === -1) {
81
+ arr.push(listener);
82
+ }
83
+ return;
84
+ };
85
+
86
+ REventTarget.prototype.removeEventListener = function (eventType, listener) {
87
+ if(!(this._listeners && (eventType in this._listeners))) {
88
+ return;
89
+ }
90
+ var arr = this._listeners[eventType];
91
+ var idx = utils.arrIndexOf(arr, listener);
92
+ if (idx !== -1) {
93
+ if(arr.length > 1) {
94
+ this._listeners[eventType] = arr.slice(0, idx).concat( arr.slice(idx+1) );
95
+ } else {
96
+ delete this._listeners[eventType];
97
+ }
98
+ return;
99
+ }
100
+ return;
101
+ };
102
+
103
+ REventTarget.prototype.dispatchEvent = function (event) {
104
+ var t = event.type;
105
+ var args = Array.prototype.slice.call(arguments, 0);
106
+ if (this['on'+t]) {
107
+ this['on'+t].apply(this, args);
108
+ }
109
+ if (this._listeners && t in this._listeners) {
110
+ for(var i=0; i < this._listeners[t].length; i++) {
111
+ this._listeners[t][i].apply(this, args);
112
+ }
113
+ }
114
+ };
115
+ // [*] End of lib/reventtarget.js
116
+
117
+
118
+ // [*] Including lib/simpleevent.js
119
+ /*
120
+ * ***** BEGIN LICENSE BLOCK *****
121
+ * Copyright (c) 2011-2012 VMware, Inc.
122
+ *
123
+ * For the license see COPYING.
124
+ * ***** END LICENSE BLOCK *****
125
+ */
126
+
127
+ var SimpleEvent = function(type, obj) {
128
+ this.type = type;
129
+ if (typeof obj !== 'undefined') {
130
+ for(var k in obj) {
131
+ if (!obj.hasOwnProperty(k)) continue;
132
+ this[k] = obj[k];
133
+ }
134
+ }
135
+ };
136
+
137
+ SimpleEvent.prototype.toString = function() {
138
+ var r = [];
139
+ for(var k in this) {
140
+ if (!this.hasOwnProperty(k)) continue;
141
+ var v = this[k];
142
+ if (typeof v === 'function') v = '[function]';
143
+ r.push(k + '=' + v);
144
+ }
145
+ return 'SimpleEvent(' + r.join(', ') + ')';
146
+ };
147
+ // [*] End of lib/simpleevent.js
148
+
149
+
150
+ // [*] Including lib/eventemitter.js
151
+ /*
152
+ * ***** BEGIN LICENSE BLOCK *****
153
+ * Copyright (c) 2011-2012 VMware, Inc.
154
+ *
155
+ * For the license see COPYING.
156
+ * ***** END LICENSE BLOCK *****
157
+ */
158
+
159
+ var EventEmitter = function(events) {
160
+ var that = this;
161
+ that._events = events || [];
162
+ that._listeners = {};
163
+ };
164
+ EventEmitter.prototype.emit = function(type) {
165
+ var that = this;
166
+ that._verifyType(type);
167
+ if (that._nuked) return;
168
+
169
+ var args = Array.prototype.slice.call(arguments, 1);
170
+ if (that['on'+type]) {
171
+ that['on'+type].apply(that, args);
172
+ }
173
+ if (type in that._listeners) {
174
+ for(var i = 0; i < that._listeners[type].length; i++) {
175
+ that._listeners[type][i].apply(that, args);
176
+ }
177
+ }
178
+ };
179
+
180
+ EventEmitter.prototype.on = function(type, callback) {
181
+ var that = this;
182
+ that._verifyType(type);
183
+ if (that._nuked) return;
184
+
185
+ if (!(type in that._listeners)) {
186
+ that._listeners[type] = [];
187
+ }
188
+ that._listeners[type].push(callback);
189
+ };
190
+
191
+ EventEmitter.prototype._verifyType = function(type) {
192
+ var that = this;
193
+ if (utils.arrIndexOf(that._events, type) === -1) {
194
+ utils.log('Event ' + JSON.stringify(type) +
195
+ ' not listed ' + JSON.stringify(that._events) +
196
+ ' in ' + that);
197
+ }
198
+ };
199
+
200
+ EventEmitter.prototype.nuke = function() {
201
+ var that = this;
202
+ that._nuked = true;
203
+ for(var i=0; i<that._events.length; i++) {
204
+ delete that[that._events[i]];
205
+ }
206
+ that._listeners = {};
207
+ };
208
+ // [*] End of lib/eventemitter.js
209
+
210
+
211
+ // [*] Including lib/utils.js
212
+ /*
213
+ * ***** BEGIN LICENSE BLOCK *****
214
+ * Copyright (c) 2011-2012 VMware, Inc.
215
+ *
216
+ * For the license see COPYING.
217
+ * ***** END LICENSE BLOCK *****
218
+ */
219
+
220
+ var random_string_chars = 'abcdefghijklmnopqrstuvwxyz0123456789_';
221
+
222
+ utils.random_string = function(length, max) {
223
+ max = max || random_string_chars.length;
224
+ var i, ret = [];
225
+ for(i=0; i < length; i++) {
226
+ ret.push( random_string_chars.substr(Math.floor(Math.random() * max),1) );
227
+ }
228
+ return ret.join('');
229
+ };
230
+
231
+ utils.random_number = function(max) {
232
+ return Math.floor(Math.random() * max);
233
+ };
234
+
235
+ utils.random_number_string = function(max) {
236
+ var t = (''+(max - 1)).length;
237
+ var p = Array(t+1).join('0');
238
+ return (p + utils.random_number(max)).slice(-t);
239
+ };
240
+
241
+ utils.getOrigin = function(url) {
242
+ if (url.match(/^file:\/\//)) {
243
+ // no origin when using file protocol
244
+ return null;
245
+ }
246
+
247
+ var parts = url.match(/^(https?):\/\/([^\/:]+)(:([0-9]+))?/);
248
+ var protocol = parts[1];
249
+ var hostname = parts[2];
250
+ var port = parts[4];
251
+
252
+ if (!port) {
253
+ port = (protocol === "https") ? 443 : 80;
254
+ }
255
+
256
+ return protocol + "://" + hostname + ":" + port;
257
+ };
258
+
259
+ utils.isSameOriginUrl = function(url_a, url_b) {
260
+ // location.origin would do, but it's not always available.
261
+ if (!url_b) url_b = _window.location.href;
262
+
263
+ return utils.getOrigin(url_a) === utils.getOrigin(url_b);
264
+ };
265
+
266
+ utils.objectExtend = function(dst, src) {
267
+ for(var k in src) {
268
+ if (src.hasOwnProperty(k)) {
269
+ dst[k] = src[k];
270
+ }
271
+ }
272
+ return dst;
273
+ };
274
+
275
+ var WPrefix = '_jp';
276
+
277
+ utils.polluteGlobalNamespace = function() {
278
+ if (!(WPrefix in _window)) {
279
+ _window[WPrefix] = {};
280
+ }
281
+ };
282
+
283
+ utils.closeFrame = function (code, reason) {
284
+ return 'c'+JSON.stringify([code, reason]);
285
+ };
286
+
287
+ utils.userSetCode = function (code) {
288
+ return code === 1000 || (code >= 3000 && code <= 4999);
289
+ };
290
+
291
+ // See: http://www.erg.abdn.ac.uk/~gerrit/dccp/notes/ccid2/rto_estimator/
292
+ // and RFC 2988.
293
+ utils.countRTO = function (rtt) {
294
+ var rto;
295
+ if (rtt > 100) {
296
+ rto = 3 * rtt; // rto > 300msec
297
+ } else {
298
+ rto = rtt + 200; // 200msec < rto <= 300msec
299
+ }
300
+ return rto;
301
+ }
302
+
303
+ utils.log = function() {
304
+ if (_window.console && console.log && console.log.apply) {
305
+ console.log.apply(console, arguments);
306
+ }
307
+ };
308
+
309
+ utils.bind = function(fun, that) {
310
+ if (fun.bind) {
311
+ return fun.bind(that);
312
+ } else {
313
+ return function() {
314
+ return fun.apply(that, arguments);
315
+ };
316
+ }
317
+ };
318
+
319
+ utils.flatUrl = function(url) {
320
+ return url.indexOf('?') === -1 && url.indexOf('#') === -1;
321
+ };
322
+
323
+ utils.amendUrl = function(url) {
324
+ var dl = _document.location;
325
+ if (!url) {
326
+ throw new Error('Wrong url for SockJS');
327
+ }
328
+ if (!utils.flatUrl(url)) {
329
+ throw new Error('Only basic urls are supported in SockJS');
330
+ }
331
+
332
+ // '//abc' --> 'http://abc'
333
+ if (url.indexOf('//') === 0) {
334
+ url = dl.protocol + url;
335
+ }
336
+ // '/abc' --> 'http://localhost:80/abc'
337
+ if (url.indexOf('/') === 0) {
338
+ url = dl.protocol + '//' + dl.host + url;
339
+ }
340
+ // strip trailing slashes
341
+ url = url.replace(/[/]+$/,'');
342
+ return url;
343
+ };
344
+
345
+ // IE doesn't support [].indexOf.
346
+ utils.arrIndexOf = function(arr, obj){
347
+ for(var i=0; i < arr.length; i++){
348
+ if(arr[i] === obj){
349
+ return i;
350
+ }
351
+ }
352
+ return -1;
353
+ };
354
+
355
+ utils.arrSkip = function(arr, obj) {
356
+ var idx = utils.arrIndexOf(arr, obj);
357
+ if (idx === -1) {
358
+ return arr.slice();
359
+ } else {
360
+ var dst = arr.slice(0, idx);
361
+ return dst.concat(arr.slice(idx+1));
362
+ }
363
+ };
364
+
365
+ // Via: https://gist.github.com/1133122/2121c601c5549155483f50be3da5305e83b8c5df
366
+ utils.isArray = Array.isArray || function(value) {
367
+ return {}.toString.call(value).indexOf('Array') >= 0
368
+ };
369
+
370
+ utils.delay = function(t, fun) {
371
+ if(typeof t === 'function') {
372
+ fun = t;
373
+ t = 0;
374
+ }
375
+ return setTimeout(fun, t);
376
+ };
377
+
378
+
379
+ // Chars worth escaping, as defined by Douglas Crockford:
380
+ // https://github.com/douglascrockford/JSON-js/blob/47a9882cddeb1e8529e07af9736218075372b8ac/json2.js#L196
381
+ var json_escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
382
+ json_lookup = {
383
+ "\u0000":"\\u0000","\u0001":"\\u0001","\u0002":"\\u0002","\u0003":"\\u0003",
384
+ "\u0004":"\\u0004","\u0005":"\\u0005","\u0006":"\\u0006","\u0007":"\\u0007",
385
+ "\b":"\\b","\t":"\\t","\n":"\\n","\u000b":"\\u000b","\f":"\\f","\r":"\\r",
386
+ "\u000e":"\\u000e","\u000f":"\\u000f","\u0010":"\\u0010","\u0011":"\\u0011",
387
+ "\u0012":"\\u0012","\u0013":"\\u0013","\u0014":"\\u0014","\u0015":"\\u0015",
388
+ "\u0016":"\\u0016","\u0017":"\\u0017","\u0018":"\\u0018","\u0019":"\\u0019",
389
+ "\u001a":"\\u001a","\u001b":"\\u001b","\u001c":"\\u001c","\u001d":"\\u001d",
390
+ "\u001e":"\\u001e","\u001f":"\\u001f","\"":"\\\"","\\":"\\\\",
391
+ "\u007f":"\\u007f","\u0080":"\\u0080","\u0081":"\\u0081","\u0082":"\\u0082",
392
+ "\u0083":"\\u0083","\u0084":"\\u0084","\u0085":"\\u0085","\u0086":"\\u0086",
393
+ "\u0087":"\\u0087","\u0088":"\\u0088","\u0089":"\\u0089","\u008a":"\\u008a",
394
+ "\u008b":"\\u008b","\u008c":"\\u008c","\u008d":"\\u008d","\u008e":"\\u008e",
395
+ "\u008f":"\\u008f","\u0090":"\\u0090","\u0091":"\\u0091","\u0092":"\\u0092",
396
+ "\u0093":"\\u0093","\u0094":"\\u0094","\u0095":"\\u0095","\u0096":"\\u0096",
397
+ "\u0097":"\\u0097","\u0098":"\\u0098","\u0099":"\\u0099","\u009a":"\\u009a",
398
+ "\u009b":"\\u009b","\u009c":"\\u009c","\u009d":"\\u009d","\u009e":"\\u009e",
399
+ "\u009f":"\\u009f","\u00ad":"\\u00ad","\u0600":"\\u0600","\u0601":"\\u0601",
400
+ "\u0602":"\\u0602","\u0603":"\\u0603","\u0604":"\\u0604","\u070f":"\\u070f",
401
+ "\u17b4":"\\u17b4","\u17b5":"\\u17b5","\u200c":"\\u200c","\u200d":"\\u200d",
402
+ "\u200e":"\\u200e","\u200f":"\\u200f","\u2028":"\\u2028","\u2029":"\\u2029",
403
+ "\u202a":"\\u202a","\u202b":"\\u202b","\u202c":"\\u202c","\u202d":"\\u202d",
404
+ "\u202e":"\\u202e","\u202f":"\\u202f","\u2060":"\\u2060","\u2061":"\\u2061",
405
+ "\u2062":"\\u2062","\u2063":"\\u2063","\u2064":"\\u2064","\u2065":"\\u2065",
406
+ "\u2066":"\\u2066","\u2067":"\\u2067","\u2068":"\\u2068","\u2069":"\\u2069",
407
+ "\u206a":"\\u206a","\u206b":"\\u206b","\u206c":"\\u206c","\u206d":"\\u206d",
408
+ "\u206e":"\\u206e","\u206f":"\\u206f","\ufeff":"\\ufeff","\ufff0":"\\ufff0",
409
+ "\ufff1":"\\ufff1","\ufff2":"\\ufff2","\ufff3":"\\ufff3","\ufff4":"\\ufff4",
410
+ "\ufff5":"\\ufff5","\ufff6":"\\ufff6","\ufff7":"\\ufff7","\ufff8":"\\ufff8",
411
+ "\ufff9":"\\ufff9","\ufffa":"\\ufffa","\ufffb":"\\ufffb","\ufffc":"\\ufffc",
412
+ "\ufffd":"\\ufffd","\ufffe":"\\ufffe","\uffff":"\\uffff"};
413
+
414
+ // Some extra characters that Chrome gets wrong, and substitutes with
415
+ // something else on the wire.
416
+ var extra_escapable = /[\x00-\x1f\ud800-\udfff\ufffe\uffff\u0300-\u0333\u033d-\u0346\u034a-\u034c\u0350-\u0352\u0357-\u0358\u035c-\u0362\u0374\u037e\u0387\u0591-\u05af\u05c4\u0610-\u0617\u0653-\u0654\u0657-\u065b\u065d-\u065e\u06df-\u06e2\u06eb-\u06ec\u0730\u0732-\u0733\u0735-\u0736\u073a\u073d\u073f-\u0741\u0743\u0745\u0747\u07eb-\u07f1\u0951\u0958-\u095f\u09dc-\u09dd\u09df\u0a33\u0a36\u0a59-\u0a5b\u0a5e\u0b5c-\u0b5d\u0e38-\u0e39\u0f43\u0f4d\u0f52\u0f57\u0f5c\u0f69\u0f72-\u0f76\u0f78\u0f80-\u0f83\u0f93\u0f9d\u0fa2\u0fa7\u0fac\u0fb9\u1939-\u193a\u1a17\u1b6b\u1cda-\u1cdb\u1dc0-\u1dcf\u1dfc\u1dfe\u1f71\u1f73\u1f75\u1f77\u1f79\u1f7b\u1f7d\u1fbb\u1fbe\u1fc9\u1fcb\u1fd3\u1fdb\u1fe3\u1feb\u1fee-\u1fef\u1ff9\u1ffb\u1ffd\u2000-\u2001\u20d0-\u20d1\u20d4-\u20d7\u20e7-\u20e9\u2126\u212a-\u212b\u2329-\u232a\u2adc\u302b-\u302c\uaab2-\uaab3\uf900-\ufa0d\ufa10\ufa12\ufa15-\ufa1e\ufa20\ufa22\ufa25-\ufa26\ufa2a-\ufa2d\ufa30-\ufa6d\ufa70-\ufad9\ufb1d\ufb1f\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40-\ufb41\ufb43-\ufb44\ufb46-\ufb4e\ufff0-\uffff]/g,
417
+ extra_lookup;
418
+
419
+ // JSON Quote string. Use native implementation when possible.
420
+ var JSONQuote = (JSON && JSON.stringify) || function(string) {
421
+ json_escapable.lastIndex = 0;
422
+ if (json_escapable.test(string)) {
423
+ string = string.replace(json_escapable, function(a) {
424
+ return json_lookup[a];
425
+ });
426
+ }
427
+ return '"' + string + '"';
428
+ };
429
+
430
+ // This may be quite slow, so let's delay until user actually uses bad
431
+ // characters.
432
+ var unroll_lookup = function(escapable) {
433
+ var i;
434
+ var unrolled = {}
435
+ var c = []
436
+ for(i=0; i<65536; i++) {
437
+ c.push( String.fromCharCode(i) );
438
+ }
439
+ escapable.lastIndex = 0;
440
+ c.join('').replace(escapable, function (a) {
441
+ unrolled[ a ] = '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
442
+ return '';
443
+ });
444
+ escapable.lastIndex = 0;
445
+ return unrolled;
446
+ };
447
+
448
+ // Quote string, also taking care of unicode characters that browsers
449
+ // often break. Especially, take care of unicode surrogates:
450
+ // http://en.wikipedia.org/wiki/Mapping_of_Unicode_characters#Surrogates
451
+ utils.quote = function(string) {
452
+ var quoted = JSONQuote(string);
453
+
454
+ // In most cases this should be very fast and good enough.
455
+ extra_escapable.lastIndex = 0;
456
+ if(!extra_escapable.test(quoted)) {
457
+ return quoted;
458
+ }
459
+
460
+ if(!extra_lookup) extra_lookup = unroll_lookup(extra_escapable);
461
+
462
+ return quoted.replace(extra_escapable, function(a) {
463
+ return extra_lookup[a];
464
+ });
465
+ }
466
+
467
+ var _all_protocols = [
468
+ 'iframe-eventsource',
469
+ 'iframe-htmlfile',
470
+ 'iframe-xhr-polling',
471
+ 'jsonp-polling'
472
+ ];
473
+
474
+ utils.probeProtocols = function(url) {
475
+ var probed = {};
476
+ for(var i=0; i<_all_protocols.length; i++) {
477
+ var protocol = _all_protocols[i];
478
+ // User can have a typo in protocol name.
479
+ probed[protocol] = SockJS[protocol] &&
480
+ SockJS[protocol].enabled(url);
481
+ }
482
+ return probed;
483
+ };
484
+
485
+ utils.detectProtocols = function(protocols_probed, protocols_whitelist, info) {
486
+ protocols_whitelist = protocols_whitelist || _all_protocols;
487
+
488
+ var protocols = [];
489
+ for (var i = 0; i < protocols_whitelist.length; i++) {
490
+ var protocol = protocols_whitelist[i];
491
+ if (protocols_probed[protocol]) {
492
+ protocols.push(protocol);
493
+ }
494
+ }
495
+ return protocols;
496
+ }
497
+
498
+ utils.defaultOptions = function(){
499
+ return {
500
+ devel: false,
501
+ debug: false,
502
+ protocols_whitelist: [],
503
+ info: undefined,
504
+ rtt: undefined,
505
+ max_window_time: 4000,
506
+ init_window_size: 4096
507
+ };
508
+ }
509
+ // [*] End of lib/utils.js
510
+
511
+
512
+ // [*] Including lib/dom.js
513
+ /*
514
+ * ***** BEGIN LICENSE BLOCK *****
515
+ * Copyright (c) 2011-2012 VMware, Inc.
516
+ *
517
+ * For the license see COPYING.
518
+ * ***** END LICENSE BLOCK *****
519
+ */
520
+
521
+ utils.attachMessage = function(listener) {
522
+ utils.attachEvent('message', listener);
523
+ };
524
+
525
+ utils.attachEvent = function(event, listener) {
526
+ if (typeof _window.addEventListener !== 'undefined') {
527
+ _window.addEventListener(event, listener, false);
528
+ } else {
529
+ // IE quirks.
530
+ // According to: http://stevesouders.com/misc/test-postmessage.php
531
+ // the message gets delivered only to 'document', not 'window'.
532
+ _document.attachEvent("on" + event, listener);
533
+ // I get 'window' for ie8.
534
+ _window.attachEvent("on" + event, listener);
535
+ }
536
+ };
537
+
538
+ utils.detachMessage = function(listener) {
539
+ utils.detachEvent('message', listener);
540
+ };
541
+
542
+ utils.detachEvent = function(event, listener) {
543
+ if (typeof _window.addEventListener !== 'undefined') {
544
+ _window.removeEventListener(event, listener, false);
545
+ } else {
546
+ _document.detachEvent("on" + event, listener);
547
+ _window.detachEvent("on" + event, listener);
548
+ }
549
+ };
550
+
551
+
552
+ var on_unload = {};
553
+ // Things registered after beforeunload are to be called immediately.
554
+ var after_unload = false;
555
+
556
+ var trigger_unload_callbacks = function() {
557
+ for(var ref in on_unload) {
558
+ on_unload[ref]();
559
+ delete on_unload[ref];
560
+ };
561
+ };
562
+
563
+ var unload_triggered = function() {
564
+ if(after_unload) return;
565
+ after_unload = true;
566
+ trigger_unload_callbacks();
567
+ };
568
+
569
+ // 'unload' alone is not reliable in opera within an iframe, but we
570
+ // can't use `beforeunload` as IE fires it on javascript: links.
571
+ utils.attachEvent('unload', unload_triggered);
572
+
573
+ utils.unload_add = function(listener) {
574
+ var ref = utils.random_string(8);
575
+ on_unload[ref] = listener;
576
+ if (after_unload) {
577
+ utils.delay(trigger_unload_callbacks);
578
+ }
579
+ return ref;
580
+ };
581
+
582
+ utils.unload_del = function(ref) {
583
+ if (ref in on_unload)
584
+ delete on_unload[ref];
585
+ };
586
+
587
+ utils.createIframe = function (iframe_url, error_callback) {
588
+ var iframe = _document.createElement('iframe');
589
+ var tref, unload_ref;
590
+ var unattach = function() {
591
+ clearTimeout(tref);
592
+ // Explorer had problems with that.
593
+ try {iframe.onload = null;} catch (x) {}
594
+ iframe.onerror = null;
595
+ };
596
+ var cleanup = function() {
597
+ if (iframe) {
598
+ unattach();
599
+ // This timeout makes chrome fire onbeforeunload event
600
+ // within iframe. Without the timeout it goes straight to
601
+ // onunload.
602
+ setTimeout(function() {
603
+ if(iframe) {
604
+ iframe.parentNode.removeChild(iframe);
605
+ }
606
+ iframe = null;
607
+ }, 0);
608
+ utils.unload_del(unload_ref);
609
+ }
610
+ };
611
+ var onerror = function(r) {
612
+ if (iframe) {
613
+ cleanup();
614
+ error_callback(r);
615
+ }
616
+ };
617
+ var post = function(msg, origin) {
618
+ try {
619
+ // When the iframe is not loaded, IE raises an exception
620
+ // on 'contentWindow'.
621
+ if (iframe && iframe.contentWindow) {
622
+ iframe.contentWindow.postMessage(msg, origin);
623
+ }
624
+ } catch (x) {};
625
+ };
626
+
627
+ iframe.src = iframe_url;
628
+ iframe.style.display = 'none';
629
+ iframe.style.position = 'absolute';
630
+ iframe.onerror = function(){onerror('onerror');};
631
+ iframe.onload = function() {
632
+ // `onload` is triggered before scripts on the iframe are
633
+ // executed. Give it few seconds to actually load stuff.
634
+ clearTimeout(tref);
635
+ tref = setTimeout(function(){onerror('onload timeout');}, 2000);
636
+ };
637
+ _document.body.appendChild(iframe);
638
+ tref = setTimeout(function(){onerror('timeout');}, 15000);
639
+ unload_ref = utils.unload_add(cleanup);
640
+ return {
641
+ post: post,
642
+ cleanup: cleanup,
643
+ loaded: unattach
644
+ };
645
+ };
646
+
647
+ utils.createHtmlfile = function (iframe_url, error_callback) {
648
+ var doc = new ActiveXObject('htmlfile');
649
+ var tref, unload_ref;
650
+ var iframe;
651
+ var unattach = function() {
652
+ clearTimeout(tref);
653
+ };
654
+ var cleanup = function() {
655
+ if (doc) {
656
+ unattach();
657
+ utils.unload_del(unload_ref);
658
+ iframe.parentNode.removeChild(iframe);
659
+ iframe = doc = null;
660
+ CollectGarbage();
661
+ }
662
+ };
663
+ var onerror = function(r) {
664
+ if (doc) {
665
+ cleanup();
666
+ error_callback(r);
667
+ }
668
+ };
669
+ var post = function(msg, origin) {
670
+ try {
671
+ // When the iframe is not loaded, IE raises an exception
672
+ // on 'contentWindow'.
673
+ if (iframe && iframe.contentWindow) {
674
+ iframe.contentWindow.postMessage(msg, origin);
675
+ }
676
+ } catch (x) {};
677
+ };
678
+
679
+ doc.open();
680
+ doc.write('<html><s' + 'cript>' +
681
+ 'document.domain="' + document.domain + '";' +
682
+ '</s' + 'cript></html>');
683
+ doc.close();
684
+ doc.parentWindow[WPrefix] = _window[WPrefix];
685
+ var c = doc.createElement('div');
686
+ doc.body.appendChild(c);
687
+ iframe = doc.createElement('iframe');
688
+ c.appendChild(iframe);
689
+ iframe.src = iframe_url;
690
+ tref = setTimeout(function(){onerror('timeout');}, 15000);
691
+ unload_ref = utils.unload_add(cleanup);
692
+ return {
693
+ post: post,
694
+ cleanup: cleanup,
695
+ loaded: unattach
696
+ };
697
+ };
698
+ // [*] End of lib/dom.js
699
+
700
+
701
+ // [*] Including lib/dom2.js
702
+ /*
703
+ * ***** BEGIN LICENSE BLOCK *****
704
+ * Copyright (c) 2011-2012 VMware, Inc.
705
+ *
706
+ * For the license see COPYING.
707
+ * ***** END LICENSE BLOCK *****
708
+ */
709
+
710
+ var AbstractXHRObject = function(){};
711
+ AbstractXHRObject.prototype = new EventEmitter(['chunk', 'finish']);
712
+
713
+ AbstractXHRObject.prototype._start = function(method, url, payload, opts) {
714
+ var that = this;
715
+
716
+ try {
717
+ that.xhr = new XMLHttpRequest();
718
+ } catch(x) {};
719
+
720
+ if (!that.xhr) {
721
+ try {
722
+ that.xhr = new _window.ActiveXObject('Microsoft.XMLHTTP');
723
+ } catch(x) {};
724
+ }
725
+ if (_window.ActiveXObject || _window.XDomainRequest) {
726
+ // IE8 caches even POSTs
727
+ url += ((url.indexOf('?') === -1) ? '?' : '&') + 't='+(+new Date);
728
+ }
729
+
730
+ // Explorer tends to keep connection open, even after the
731
+ // tab gets closed: http://bugs.jquery.com/ticket/5280
732
+ that.unload_ref = utils.unload_add(function(){that._cleanup(true);});
733
+ try {
734
+ that.xhr.open(method, url, true);
735
+ } catch(e) {
736
+ // IE raises an exception on wrong port.
737
+ that.emit('finish', 0, '');
738
+ that._cleanup();
739
+ return;
740
+ };
741
+
742
+ if (!opts || !opts.no_credentials) {
743
+ // Mozilla docs says https://developer.mozilla.org/en/XMLHttpRequest :
744
+ // "This never affects same-site requests."
745
+ that.xhr.withCredentials = 'true';
746
+ }
747
+ if (opts && opts.headers) {
748
+ for(var key in opts.headers) {
749
+ that.xhr.setRequestHeader(key, opts.headers[key]);
750
+ }
751
+ }
752
+
753
+ that.xhr.onreadystatechange = function() {
754
+ if (that.xhr) {
755
+ var x = that.xhr;
756
+ switch (x.readyState) {
757
+ case 3:
758
+ // IE doesn't like peeking into responseText or status
759
+ // on Microsoft.XMLHTTP and readystate=3
760
+ try {
761
+ var status = x.status;
762
+ var text = x.responseText;
763
+ } catch (x) {};
764
+ // IE returns 1223 for 204: http://bugs.jquery.com/ticket/1450
765
+ if (status === 1223) status = 204;
766
+
767
+ // IE does return readystate == 3 for 404 answers.
768
+ if (text && text.length > 0) {
769
+ that.emit('chunk', status, text);
770
+ }
771
+ break;
772
+ case 4:
773
+ var status = x.status;
774
+ // IE returns 1223 for 204: http://bugs.jquery.com/ticket/1450
775
+ if (status === 1223) status = 204;
776
+
777
+ that.emit('finish', status, x.responseText);
778
+ that._cleanup(false);
779
+ break;
780
+ }
781
+ }
782
+ };
783
+ that.xhr.send(payload);
784
+ };
785
+
786
+ AbstractXHRObject.prototype._cleanup = function(abort) {
787
+ var that = this;
788
+ if (!that.xhr) return;
789
+ utils.unload_del(that.unload_ref);
790
+
791
+ // IE needs this field to be a function
792
+ that.xhr.onreadystatechange = function(){};
793
+
794
+ if (abort) {
795
+ try {
796
+ that.xhr.abort();
797
+ } catch(x) {};
798
+ }
799
+ that.unload_ref = that.xhr = null;
800
+ };
801
+
802
+ AbstractXHRObject.prototype.close = function() {
803
+ var that = this;
804
+ that.nuke();
805
+ that._cleanup(true);
806
+ };
807
+
808
+ var XHRCorsObject = utils.XHRCorsObject = function() {
809
+ var that = this, args = arguments;
810
+ utils.delay(function(){that._start.apply(that, args);});
811
+ };
812
+ XHRCorsObject.prototype = new AbstractXHRObject();
813
+
814
+ var XHRLocalObject = utils.XHRLocalObject = function(method, url, payload) {
815
+ var that = this;
816
+ utils.delay(function(){
817
+ that._start(method, url, payload, {
818
+ no_credentials: true
819
+ });
820
+ });
821
+ };
822
+ XHRLocalObject.prototype = new AbstractXHRObject();
823
+
824
+
825
+
826
+ // References:
827
+ // http://ajaxian.com/archives/100-line-ajax-wrapper
828
+ // http://msdn.microsoft.com/en-us/library/cc288060(v=VS.85).aspx
829
+ var XDRObject = utils.XDRObject = function(method, url, payload) {
830
+ var that = this;
831
+ utils.delay(function(){that._start(method, url, payload);});
832
+ };
833
+ XDRObject.prototype = new EventEmitter(['chunk', 'finish']);
834
+ XDRObject.prototype._start = function(method, url, payload) {
835
+ var that = this;
836
+ var xdr = new XDomainRequest();
837
+ // IE caches even POSTs
838
+ url += ((url.indexOf('?') === -1) ? '?' : '&') + 't='+(+new Date);
839
+
840
+ var onerror = xdr.ontimeout = xdr.onerror = function() {
841
+ that.emit('finish', 0, '');
842
+ that._cleanup(false);
843
+ };
844
+ xdr.onprogress = function() {
845
+ that.emit('chunk', 200, xdr.responseText);
846
+ };
847
+ xdr.onload = function() {
848
+ that.emit('finish', 200, xdr.responseText);
849
+ that._cleanup(false);
850
+ };
851
+ that.xdr = xdr;
852
+ that.unload_ref = utils.unload_add(function(){that._cleanup(true);});
853
+ try {
854
+ // Fails with AccessDenied if port number is bogus
855
+ that.xdr.open(method, url);
856
+ that.xdr.send(payload);
857
+ } catch(x) {
858
+ onerror();
859
+ }
860
+ };
861
+
862
+ XDRObject.prototype._cleanup = function(abort) {
863
+ var that = this;
864
+ if (!that.xdr) return;
865
+ utils.unload_del(that.unload_ref);
866
+
867
+ that.xdr.ontimeout = that.xdr.onerror = that.xdr.onprogress =
868
+ that.xdr.onload = null;
869
+ if (abort) {
870
+ try {
871
+ that.xdr.abort();
872
+ } catch(x) {};
873
+ }
874
+ that.unload_ref = that.xdr = null;
875
+ };
876
+
877
+ XDRObject.prototype.close = function() {
878
+ var that = this;
879
+ that.nuke();
880
+ that._cleanup(true);
881
+ };
882
+
883
+ // 1. Is natively via XHR
884
+ // 2. Is natively via XDR
885
+ // 3. Nope, but postMessage is there so it should work via the Iframe.
886
+ // 4. Nope, sorry.
887
+ utils.isXHRCorsCapable = function(url) {
888
+ var protocol = url.match(/^(https?:)/)[0];
889
+ if (_window.XMLHttpRequest && 'withCredentials' in new XMLHttpRequest()) {
890
+ return 1;
891
+ }
892
+ // XDomainRequest doesn't work if page is served from file://
893
+ if (_window.XDomainRequest && _document.domain &&
894
+ _document.location.protocol == protocol) {
895
+ return 2;
896
+ }
897
+ if (IframeTransport.enabled()) {
898
+ return 3;
899
+ }
900
+ return 4;
901
+ };
902
+
903
+
904
+ var JsonpSender = function(url, payload, cache){
905
+ var that = this;
906
+ utils.delay(function(){that._start(url, payload, cache);});
907
+ };
908
+ JsonpSender.prototype = new EventEmitter(['finish']);
909
+ JsonpSender.prototype._start = function(url, payload, cache){
910
+ var that = this;
911
+
912
+ if (!('_send_form' in cache)) {
913
+ var form = cache._send_form = _document.createElement('form');
914
+ var area = cache._send_area = _document.createElement('textarea');
915
+ area.name = 'd';
916
+ form.style.display = 'none';
917
+ form.style.position = 'absolute';
918
+ form.method = 'POST';
919
+ form.enctype = 'application/x-www-form-urlencoded';
920
+ form.acceptCharset = "UTF-8";
921
+ form.appendChild(area);
922
+ _document.body.appendChild(form);
923
+ }
924
+ var form = cache._send_form;
925
+ var area = cache._send_area;
926
+ var id = 'a' + utils.random_string(8);
927
+ that.area = area;
928
+ form.target = id;
929
+ form.action = url + '/jsonp_send?i=' + id;
930
+
931
+ var iframe;
932
+ try {
933
+ // ie6 dynamic iframes with target="" support (thanks Chris Lambacher)
934
+ iframe = _document.createElement('<iframe name="'+ id +'">');
935
+ } catch(x) {
936
+ iframe = _document.createElement('iframe');
937
+ iframe.name = id;
938
+ }
939
+ that.iframe = iframe;
940
+ iframe.id = id;
941
+ form.appendChild(iframe);
942
+ iframe.style.display = 'none';
943
+
944
+ try {
945
+ area.value = payload;
946
+ } catch(e) {
947
+ utils.log('Your browser is seriously broken. Go home! ' + e.message);
948
+ }
949
+ form.submit();
950
+ var completed = function(e) {
951
+ if (!that.iframe) return;
952
+ that._cleanup();
953
+ // It is not possible to detect if the iframe succeeded or
954
+ // failed to submit our form.
955
+ that.emit('finish');
956
+ };
957
+ iframe.onerror = iframe.onload = completed;
958
+ iframe.onreadystatechange = function(e) {
959
+ if (iframe.readyState == 'complete') completed();
960
+ };
961
+ };
962
+
963
+ JsonpSender.prototype._cleanup = function(){
964
+ var that = this;
965
+ if (!that.iframe) return;
966
+ var iframe = that.iframe;
967
+ that.area.value = '';
968
+ that.iframe.onreadystatechange = that.iframe.onerror = that.iframe.onload = that.area = null;
969
+ that.iframe = '';
970
+ // Opera mini doesn't like if we GC iframe
971
+ // immediately, thus this timeout.
972
+ utils.delay(500, function() {
973
+ iframe.parentNode.removeChild(iframe);
974
+ iframe = null;
975
+ });
976
+ };
977
+ JsonpSender.prototype.close = function(){
978
+ var that = this;
979
+ that.nuke();
980
+ that._cleanup();
981
+ };
982
+ // [*] End of lib/dom2.js
983
+
984
+
985
+ // [*] Including lib/sockjs.js
986
+ /*
987
+ * ***** BEGIN LICENSE BLOCK *****
988
+ * Copyright (c) 2011-2012 VMware, Inc.
989
+ *
990
+ * For the license see COPYING.
991
+ * ***** END LICENSE BLOCK *****
992
+ */
993
+
994
+ var SockJS = function(url, dep_protocols_whitelist, options) {
995
+ if (this === _window) {
996
+ // makes `new` optional
997
+ return new SockJS(url, dep_protocols_whitelist, options);
998
+ }
999
+
1000
+ var that = this, protocols_whitelist;
1001
+ that._options = utils.defaultOptions();
1002
+ if (options) {
1003
+ utils.objectExtend(that._options, options);
1004
+ }
1005
+ that._base_url = utils.amendUrl(url);
1006
+ that._server = that._options.server || utils.random_number_string(1000);
1007
+ that._bus = new EventEmitter(['close', 'heartbeat', 'message']);
1008
+ if (that._options.protocols_whitelist &&
1009
+ that._options.protocols_whitelist.length) {
1010
+ protocols_whitelist = that._options.protocols_whitelist;
1011
+ } else {
1012
+ // Deprecated API
1013
+ if (typeof dep_protocols_whitelist === 'string' &&
1014
+ dep_protocols_whitelist.length > 0) {
1015
+ protocols_whitelist = [dep_protocols_whitelist];
1016
+ } else if (utils.isArray(dep_protocols_whitelist)) {
1017
+ protocols_whitelist = dep_protocols_whitelist
1018
+ } else {
1019
+ protocols_whitelist = null;
1020
+ }
1021
+ if (protocols_whitelist) {
1022
+ that._debug('Deprecated API: Use "protocols_whitelist" option ' +
1023
+ 'instead of supplying protocol list as a second ' +
1024
+ 'parameter to SockJS constructor.');
1025
+ }
1026
+ }
1027
+ that._protocols = [];
1028
+ that.protocol = null;
1029
+ that.readyState = SockJS.CONNECTING;
1030
+ that._ir = createInfoReceiver(that, that._base_url);
1031
+ that._ir.onfinish = function(info, rtt) {
1032
+ that._ir = null;
1033
+ if (info) {
1034
+ if (that._options.info) {
1035
+ // Override if user supplies the option
1036
+ info = utils.objectExtend(info, that._options.info);
1037
+ }
1038
+ if (that._options.rtt) {
1039
+ rtt = that._options.rtt;
1040
+ }
1041
+ that._applyInfo(info, rtt, protocols_whitelist);
1042
+ that._didClose(undefined, undefined, undefined, "info-onfinish");
1043
+ } else {
1044
+ that._didClose(1002, 'Can\'t connect to server', true, "info-failed");
1045
+ }
1046
+ };
1047
+ };
1048
+ // Inheritance
1049
+ SockJS.prototype = new REventTarget();
1050
+
1051
+ SockJS.version = "0.3.4.72.g5b91";
1052
+
1053
+ SockJS.CONNECTING = 0;
1054
+ SockJS.OPEN = 1;
1055
+ SockJS.CLOSING = 2;
1056
+ SockJS.CLOSED = 3;
1057
+
1058
+ SockJS.prototype._debug = function() {
1059
+ if (this._options.debug)
1060
+ utils.log.apply(utils, arguments);
1061
+ };
1062
+
1063
+ SockJS.prototype._dispatchOpen = function() {
1064
+ var that = this;
1065
+ if (that.readyState === SockJS.CONNECTING) {
1066
+ if (that._transport_tref) {
1067
+ clearTimeout(that._transport_tref);
1068
+ that._transport_tref = null;
1069
+ }
1070
+ that.readyState = SockJS.OPEN;
1071
+ var shi = that._options.info.server_heartbeat_interval;
1072
+ if (shi) that._startHeartbeats(shi);
1073
+ that.dispatchEvent(new SimpleEvent("open"));
1074
+ } else {
1075
+ // The server might have been restarted, and lost track of our
1076
+ // connection.
1077
+ that._didClose(1006, "Server lost session", undefined, "_dispatchOpen");
1078
+ }
1079
+ };
1080
+
1081
+ SockJS.prototype._dispatchMessage = function(data) {
1082
+ var that = this;
1083
+ if (that.readyState !== SockJS.OPEN)
1084
+ return;
1085
+ that._bus.emit('message', data);
1086
+ that.dispatchEvent(new SimpleEvent("message", {data: data}));
1087
+ };
1088
+
1089
+ SockJS.prototype._dispatchHeartbeat = function(flavour) {
1090
+ var that = this;
1091
+ // Ignore heartbeats before "o" frame - prelude.
1092
+ if (that.readyState !== SockJS.OPEN)
1093
+ return;
1094
+ that._bus.emit('heartbeat', flavour);
1095
+ that.dispatchEvent(new SimpleEvent('heartbeat', {flavour: flavour}));
1096
+ };
1097
+
1098
+ SockJS.prototype._didClose = function(code, reason, force, debug) {
1099
+ var that = this;
1100
+ if (that.readyState !== SockJS.CONNECTING &&
1101
+ that.readyState !== SockJS.OPEN &&
1102
+ that.readyState !== SockJS.CLOSING) {
1103
+ // Temporarily disabled below exception until we find the issue
1104
+ // https://github.com/pusher/pusher-js/issues/35
1105
+ // throw new Error('INVALID_STATE_ERR (' + code + ',' + reason + ',' + force + ',' + debug + ')');
1106
+ return;
1107
+ }
1108
+ if (that._ir) {
1109
+ that._ir.nuke();
1110
+ that._ir = null;
1111
+ }
1112
+
1113
+ if (that._transport) {
1114
+ that._transport.doCleanup();
1115
+ that._transport = null;
1116
+ }
1117
+
1118
+ var close_event = new SimpleEvent("close", {
1119
+ code: code,
1120
+ reason: reason,
1121
+ wasClean: utils.userSetCode(code)});
1122
+
1123
+ if (!utils.userSetCode(code) &&
1124
+ that.readyState === SockJS.CONNECTING && !force) {
1125
+ if (that._try_next_protocol(close_event)) {
1126
+ return;
1127
+ }
1128
+ close_event = new SimpleEvent("close", {code: 2000,
1129
+ reason: "All transports failed",
1130
+ wasClean: false,
1131
+ last_event: close_event});
1132
+ }
1133
+ that.readyState = SockJS.CLOSED;
1134
+
1135
+ that._bus.emit('close');
1136
+ utils.delay(function() {
1137
+ that.dispatchEvent(close_event);
1138
+ });
1139
+ };
1140
+
1141
+ SockJS.prototype._didMessage = function(data) {
1142
+ var that = this;
1143
+ var type = data.slice(0, 1);
1144
+ switch(type) {
1145
+ case 'o':
1146
+ that._dispatchOpen();
1147
+ break;
1148
+ case 'a':
1149
+ var payload = JSON.parse(data.slice(1) || '[]');
1150
+ for(var i=0; i < payload.length; i++){
1151
+ that._dispatchMessage(payload[i]);
1152
+ }
1153
+ if (payload.length === 0) {
1154
+ that._dispatchHeartbeat('recv');
1155
+ }
1156
+ break;
1157
+ case 'm':
1158
+ var payload = JSON.parse(data.slice(1) || 'null');
1159
+ that._dispatchMessage(payload);
1160
+ break;
1161
+ case 'c':
1162
+ var payload = JSON.parse(data.slice(1) || '[]');
1163
+ that._didClose(payload[0], payload[1], undefined, "_didMessage");
1164
+ break;
1165
+ case 'h':
1166
+ that._dispatchHeartbeat('send');
1167
+ break;
1168
+ }
1169
+ };
1170
+
1171
+ SockJS.prototype._try_next_protocol = function(close_event) {
1172
+ var that = this;
1173
+ if (that.protocol) {
1174
+ that._debug('Closed transport:', that.protocol, ''+close_event);
1175
+ that.protocol = null;
1176
+ }
1177
+ if (that._transport_tref) {
1178
+ clearTimeout(that._transport_tref);
1179
+ that._transport_tref = null;
1180
+ }
1181
+
1182
+ while(1) {
1183
+ var protocol = that.protocol = that._protocols.shift();
1184
+ if (!protocol) {
1185
+ return false;
1186
+ }
1187
+ // Some protocols require access to `body`, what if were in
1188
+ // the `head`?
1189
+ if (SockJS[protocol] &&
1190
+ SockJS[protocol].need_body === true &&
1191
+ (!_document.body ||
1192
+ (typeof _document.readyState !== 'undefined'
1193
+ && _document.readyState !== 'complete'))) {
1194
+ that._protocols.unshift(protocol);
1195
+ that.protocol = 'waiting-for-load';
1196
+ utils.attachEvent('load', function(){
1197
+ that._try_next_protocol();
1198
+ });
1199
+ return true;
1200
+ }
1201
+
1202
+ if (!SockJS[protocol] || !SockJS[protocol].enabled(that._base_url)) {
1203
+ that._debug('Skipping transport:', protocol);
1204
+ } else {
1205
+ var roundTrips = SockJS[protocol].roundTrips || 1;
1206
+ var to = ((that._options.rto || 0) * roundTrips) || 5000;
1207
+ that._transport_tref = utils.delay(to, function() {
1208
+ if (that.readyState === SockJS.CONNECTING) {
1209
+ // I can't understand how it is possible to run
1210
+ // this timer, when the state is CLOSED, but
1211
+ // apparently in IE everythin is possible.
1212
+ that._didClose(2007, "Transport timeouted");
1213
+ }
1214
+ });
1215
+
1216
+ var connid = utils.random_string(8);
1217
+ var trans_url = that._base_url + '/' + that._server + '/' + connid;
1218
+ that._debug('Opening transport:', protocol, ' url:'+trans_url,
1219
+ ' RTO:'+that._options.rto);
1220
+ that._transport = new SockJS[protocol](that, trans_url,
1221
+ that._base_url);
1222
+ return true;
1223
+ }
1224
+ }
1225
+ };
1226
+
1227
+ SockJS.prototype.close = function(code, reason) {
1228
+ var that = this;
1229
+ if (code && !utils.userSetCode(code))
1230
+ throw new Error("INVALID_ACCESS_ERR");
1231
+ if(that.readyState !== SockJS.CONNECTING &&
1232
+ that.readyState !== SockJS.OPEN) {
1233
+ return false;
1234
+ }
1235
+ that.readyState = SockJS.CLOSING;
1236
+ that._didClose(code || 1000, reason || "Normal closure", undefined, "close");
1237
+ return true;
1238
+ };
1239
+
1240
+ SockJS.prototype.send = function(data) {
1241
+ var that = this;
1242
+ if (that.readyState === SockJS.CONNECTING)
1243
+ throw new Error('INVALID_STATE_ERR');
1244
+ if (that.readyState === SockJS.OPEN) {
1245
+ that._transport.doSend(utils.quote('' + data));
1246
+ }
1247
+ return true;
1248
+ };
1249
+
1250
+ SockJS.prototype._sendEmpty = function() {
1251
+ var that = this;
1252
+ if (that.readyState === SockJS.OPEN) {
1253
+ that._transport.doSend('');
1254
+ }
1255
+ return true;
1256
+ };
1257
+
1258
+ SockJS.prototype._applyInfo = function(info, rtt, protocols_whitelist) {
1259
+ var that = this;
1260
+ that._options.info = info;
1261
+ that._options.rtt = rtt;
1262
+ that._options.rto = utils.countRTO(rtt);
1263
+ that._options.info.null_origin = Boolean(
1264
+ that._options.ignore_null_origin || !_document.domain
1265
+ );
1266
+ var probed = utils.probeProtocols(that._base_url);
1267
+ that._protocols = utils.detectProtocols(probed, protocols_whitelist, info);
1268
+ // Replace the hostname part of URL if supplied by the server
1269
+ if (info.hostname) {
1270
+ var url = /(https?:\/\/)([^\/:]+)((\/|:)?.*)/.exec(that._base_url);
1271
+ that._base_url = url[1] + info.hostname + url[3];
1272
+ }
1273
+ };
1274
+ // [*] End of lib/sockjs.js
1275
+
1276
+
1277
+ // [*] Including lib/trans-sender.js
1278
+ /*
1279
+ * ***** BEGIN LICENSE BLOCK *****
1280
+ * Copyright (c) 2011-2012 VMware, Inc.
1281
+ *
1282
+ * For the license see COPYING.
1283
+ * ***** END LICENSE BLOCK *****
1284
+ */
1285
+
1286
+ var BufferedSender = function() {};
1287
+ BufferedSender.prototype.send_constructor = function(sender) {
1288
+ var that = this;
1289
+ that.send_buffer = [];
1290
+ that.sender = sender;
1291
+ that.init_window_size = that.ri._options.init_window_size;
1292
+ that.window_size = that.init_window_size;
1293
+ that.max_window_time = that.ri._options.max_window_time;
1294
+ };
1295
+ BufferedSender.prototype.doSend = function(message) {
1296
+ var that = this;
1297
+ if (message.length > 0) {
1298
+ that.send_buffer.push(message);
1299
+ }
1300
+
1301
+ if (that.send_stop && message.length == 0) {
1302
+ that.ri._debug('Attempting to send a heartbeat, but sending previous messages is still in progress.');
1303
+ }
1304
+
1305
+ if (!that.send_stop) {
1306
+ that.send_schedule();
1307
+ }
1308
+
1309
+ };
1310
+
1311
+ BufferedSender.prototype.adjustWindow = function(td, full_window) {
1312
+ var that = this;
1313
+ if (td > that.max_window_time) {
1314
+ // Over time, reduce window
1315
+ that.window_size = Math.max(that.window_size / 2,
1316
+ that.init_window_size);
1317
+ return true;
1318
+ } else {
1319
+ if (full_window) {
1320
+ if (td*2 < that.max_window_time) {
1321
+ // A lot time left
1322
+ that.window_size *= 2;
1323
+ } else {
1324
+ // Not so much time left...
1325
+ that.window_size *= 1.1;
1326
+ }
1327
+ return true;
1328
+ }
1329
+ }
1330
+ return false;
1331
+ }
1332
+
1333
+ // For polling transports in a situation when in the message callback,
1334
+ // new message is being send. If the sending connection was started
1335
+ // before receiving one, it is possible to saturate the network and
1336
+ // timeout due to the lack of receiving socket. To avoid that we delay
1337
+ // sending messages by some small time, in order to let receiving
1338
+ // connection be started beforehand. This is only a halfmeasure and
1339
+ // does not fix the big problem, but it does make the tests go more
1340
+ // stable on slow networks.
1341
+ BufferedSender.prototype.send_schedule_wait = function() {
1342
+ var that = this;
1343
+ var tref;
1344
+ that.send_stop = function() {
1345
+ that.send_stop = null;
1346
+ clearTimeout(tref);
1347
+ };
1348
+ tref = utils.delay(25, function() {
1349
+ that.send_stop = null;
1350
+ if (that.send_buffer.length > 0) {
1351
+ that.send_schedule();
1352
+ }
1353
+ });
1354
+ };
1355
+
1356
+ BufferedSender.prototype.send_schedule = function() {
1357
+ var that = this;
1358
+ var t0 = +new Date();
1359
+ var i, serialized = 2, full_window = false;
1360
+ for (i=0; i < that.send_buffer.length; i++) {
1361
+ serialized += that.send_buffer[i].length + 1;
1362
+ if (serialized > that.window_size) {
1363
+ full_window = true;
1364
+ break;
1365
+ }
1366
+ }
1367
+ // Splice removes messages from the array.
1368
+ var messages = that.send_buffer.splice(0, i);
1369
+
1370
+ var payload = '[' + messages.join(',') + ']';
1371
+ that.send_stop = that.sender(that.trans_url, payload, function(success, abort_reason) {
1372
+ that.send_stop = null;
1373
+ if (success === false) {
1374
+ that.ri._didClose(1006, 'Sending error ' + abort_reason);
1375
+ } else {
1376
+ var td = (+new Date()) - t0;
1377
+ if (that.adjustWindow(td, full_window)) {
1378
+ that.ri._debug('window_size adjusted: ' + that.window_size);
1379
+ }
1380
+ that.send_schedule_wait();
1381
+ }
1382
+ });
1383
+ };
1384
+
1385
+ BufferedSender.prototype.send_destructor = function() {
1386
+ var that = this;
1387
+ if (that.send_stop) {
1388
+ that.send_stop();
1389
+ }
1390
+ that.send_stop = null;
1391
+ };
1392
+
1393
+ var jsonPGenericSender = function(url, payload, callback) {
1394
+ var that = this;
1395
+ var js = new JsonpSender(url, payload, that);
1396
+ js.onfinish = function(){
1397
+ callback(true);
1398
+ };
1399
+ return function(){
1400
+ js.close();
1401
+ };
1402
+ };
1403
+
1404
+ var createAjaxSender = function(AjaxObject) {
1405
+ return function(url, payload, callback) {
1406
+ var xo = new AjaxObject('POST', url + '/xhr_send', payload);
1407
+ xo.onfinish = function(status, text) {
1408
+ callback(status === 200 || status === 204,
1409
+ 'http status ' + status);
1410
+ };
1411
+ return function(abort_reason) {
1412
+ xo.close();
1413
+ };
1414
+ };
1415
+ };
1416
+ // [*] End of lib/trans-sender.js
1417
+
1418
+
1419
+ // [*] Including lib/trans-jsonp-receiver.js
1420
+ /*
1421
+ * ***** BEGIN LICENSE BLOCK *****
1422
+ * Copyright (c) 2011-2012 VMware, Inc.
1423
+ *
1424
+ * For the license see COPYING.
1425
+ * ***** END LICENSE BLOCK *****
1426
+ */
1427
+
1428
+ // Parts derived from Socket.io:
1429
+ // https://github.com/LearnBoost/socket.io/blob/0.6.17/lib/socket.io/transports/jsonp-polling.js
1430
+ // and jQuery-JSONP:
1431
+ // https://code.google.com/p/jquery-jsonp/source/browse/trunk/core/jquery.jsonp.js
1432
+ var jsonPGenericReceiver = function(url, callback) {
1433
+ var tref;
1434
+ var script = _document.createElement('script');
1435
+ var script2; // Opera synchronous load trick.
1436
+ var close_script = function(frame) {
1437
+ if (script2) {
1438
+ script2.parentNode.removeChild(script2);
1439
+ script2 = null;
1440
+ }
1441
+ if (script) {
1442
+ clearTimeout(tref);
1443
+ // Unfortunately, you can't really abort script loading of
1444
+ // the script.
1445
+ script.parentNode.removeChild(script);
1446
+ script.onreadystatechange = script.onerror =
1447
+ script.onload = script.onclick = null;
1448
+ script = null;
1449
+ callback(frame);
1450
+ callback = null;
1451
+ }
1452
+ };
1453
+
1454
+ // IE9 fires 'error' event after orsc or before, in random order.
1455
+ var loaded_okay = false;
1456
+ var error_timer = null;
1457
+
1458
+ script.id = 'a' + utils.random_string(8);
1459
+ script.src = url;
1460
+ script.type = 'text/javascript';
1461
+ script.charset = 'UTF-8';
1462
+ script.onerror = function(e) {
1463
+ if (!error_timer) {
1464
+ // Delay firing close_script.
1465
+ error_timer = setTimeout(function() {
1466
+ if (!loaded_okay) {
1467
+ close_script(utils.closeFrame(
1468
+ 1006,
1469
+ "JSONP script loaded abnormally (onerror)"));
1470
+ }
1471
+ }, 1000);
1472
+ }
1473
+ };
1474
+ script.onload = function(e) {
1475
+ close_script(utils.closeFrame(1006, "JSONP script loaded abnormally (onload)"));
1476
+ };
1477
+
1478
+ script.onreadystatechange = function(e) {
1479
+ if (/loaded|closed/.test(script.readyState)) {
1480
+ if (script && script.htmlFor && script.onclick) {
1481
+ loaded_okay = true;
1482
+ try {
1483
+ // In IE, actually execute the script.
1484
+ script.onclick();
1485
+ } catch (x) {}
1486
+ }
1487
+ if (script) {
1488
+ close_script(utils.closeFrame(1006, "JSONP script loaded abnormally (onreadystatechange)"));
1489
+ }
1490
+ }
1491
+ };
1492
+ // IE: event/htmlFor/onclick trick.
1493
+ // One can't rely on proper order for onreadystatechange. In order to
1494
+ // make sure, set a 'htmlFor' and 'event' properties, so that
1495
+ // script code will be installed as 'onclick' handler for the
1496
+ // script object. Later, onreadystatechange, manually execute this
1497
+ // code. FF and Chrome doesn't work with 'event' and 'htmlFor'
1498
+ // set. For reference see:
1499
+ // http://jaubourg.net/2010/07/loading-script-as-onclick-handler-of.html
1500
+ // Also, read on that about script ordering:
1501
+ // http://wiki.whatwg.org/wiki/Dynamic_Script_Execution_Order
1502
+ if (typeof script.async === 'undefined' && _document.attachEvent) {
1503
+ // According to mozilla docs, in recent browsers script.async defaults
1504
+ // to 'true', so we may use it to detect a good browser:
1505
+ // https://developer.mozilla.org/en/HTML/Element/script
1506
+ if (!/opera/i.test(navigator.userAgent)) {
1507
+ // Naively assume we're in IE
1508
+ try {
1509
+ script.htmlFor = script.id;
1510
+ script.event = "onclick";
1511
+ } catch (x) {}
1512
+ script.async = true;
1513
+ } else {
1514
+ // Opera, second sync script hack
1515
+ script2 = _document.createElement('script');
1516
+ script2.text = "try{var a = document.getElementById('"+script.id+"'); if(a)a.onerror();}catch(x){};";
1517
+ script.async = script2.async = false;
1518
+ }
1519
+ }
1520
+ if (typeof script.async !== 'undefined') {
1521
+ script.async = true;
1522
+ }
1523
+
1524
+ // Fallback mostly for Konqueror - stupid timer, 35 seconds shall be plenty.
1525
+ tref = setTimeout(function() {
1526
+ close_script(utils.closeFrame(1006, "JSONP script loaded abnormally (timeout)"));
1527
+ }, 35000);
1528
+
1529
+ var head = _document.getElementsByTagName('head')[0];
1530
+ head.insertBefore(script, head.firstChild);
1531
+ if (script2) {
1532
+ head.insertBefore(script2, head.firstChild);
1533
+ }
1534
+ return close_script;
1535
+ };
1536
+ // [*] End of lib/trans-jsonp-receiver.js
1537
+
1538
+
1539
+ // [*] Including lib/trans-jsonp-polling.js
1540
+ /*
1541
+ * ***** BEGIN LICENSE BLOCK *****
1542
+ * Copyright (c) 2011-2012 VMware, Inc.
1543
+ *
1544
+ * For the license see COPYING.
1545
+ * ***** END LICENSE BLOCK *****
1546
+ */
1547
+
1548
+ // The simplest and most robust transport, using the well-know cross
1549
+ // domain hack - JSONP. This transport is quite inefficient - one
1550
+ // mssage could use up to one http request. But at least it works almost
1551
+ // everywhere.
1552
+ // Known limitations:
1553
+ // o you will get a spinning cursor
1554
+ // o for Konqueror a dumb timer is needed to detect errors
1555
+
1556
+
1557
+ var JsonPTransport = SockJS['jsonp-polling'] = function(ri, trans_url) {
1558
+ utils.polluteGlobalNamespace();
1559
+ var that = this;
1560
+ that.ri = ri;
1561
+ that.trans_url = trans_url;
1562
+ that.send_constructor(jsonPGenericSender);
1563
+ that._schedule_recv();
1564
+ };
1565
+
1566
+ // Inheritnace
1567
+ JsonPTransport.prototype = new BufferedSender();
1568
+
1569
+ JsonPTransport.prototype._schedule_recv = function() {
1570
+ var that = this;
1571
+ var callback = function(data) {
1572
+ that._recv_stop = null;
1573
+ if (data) {
1574
+ // no data - heartbeat;
1575
+ if (!that._is_closing) {
1576
+ that.ri._didMessage(data);
1577
+ }
1578
+ }
1579
+ // The message can be a close message, and change is_closing state.
1580
+ if (!that._is_closing) {
1581
+ that._schedule_recv();
1582
+ }
1583
+ };
1584
+ that._recv_stop = jsonPReceiverWrapper(that.trans_url + '/jsonp',
1585
+ jsonPGenericReceiver, callback);
1586
+ };
1587
+
1588
+ JsonPTransport.enabled = function() {
1589
+ return true;
1590
+ };
1591
+
1592
+ JsonPTransport.need_body = true;
1593
+ JsonPTransport.polling = true;
1594
+
1595
+
1596
+ JsonPTransport.prototype.doCleanup = function() {
1597
+ var that = this;
1598
+ that._is_closing = true;
1599
+ if (that._recv_stop) {
1600
+ that._recv_stop();
1601
+ }
1602
+ that.ri = that._recv_stop = null;
1603
+ that.send_destructor();
1604
+ };
1605
+
1606
+
1607
+ // Abstract away code that handles global namespace pollution.
1608
+ var jsonPReceiverWrapper = function(url, constructReceiver, user_callback) {
1609
+ var id = 'a' + utils.random_string(6);
1610
+ var url_id = url + '?c=' + escape(WPrefix + '.' + id);
1611
+
1612
+ // Unfortunately it is not possible to abort loading of the
1613
+ // script. We need to keep track of frake close frames.
1614
+ var aborting = 0;
1615
+
1616
+ // Callback will be called exactly once.
1617
+ var callback = function(frame) {
1618
+ switch(aborting) {
1619
+ case 0:
1620
+ // Normal behaviour - delete hook _and_ emit message.
1621
+ delete _window[WPrefix][id];
1622
+ user_callback(frame);
1623
+ break;
1624
+ case 1:
1625
+ // Fake close frame - emit but don't delete hook.
1626
+ user_callback(frame);
1627
+ aborting = 2;
1628
+ break;
1629
+ case 2:
1630
+ // Got frame after connection was closed, delete hook, don't emit.
1631
+ delete _window[WPrefix][id];
1632
+ break;
1633
+ }
1634
+ };
1635
+
1636
+ var close_script = constructReceiver(url_id, callback);
1637
+ _window[WPrefix][id] = close_script;
1638
+ var stop = function() {
1639
+ if (_window[WPrefix][id]) {
1640
+ aborting = 1;
1641
+ _window[WPrefix][id](utils.closeFrame(1000, "JSONP user aborted read"));
1642
+ }
1643
+ };
1644
+ return stop;
1645
+ };
1646
+ // [*] End of lib/trans-jsonp-polling.js
1647
+
1648
+
1649
+ // [*] Including lib/trans-xhr.js
1650
+ /*
1651
+ * ***** BEGIN LICENSE BLOCK *****
1652
+ * Copyright (c) 2011-2012 VMware, Inc.
1653
+ *
1654
+ * For the license see COPYING.
1655
+ * ***** END LICENSE BLOCK *****
1656
+ */
1657
+
1658
+ var AjaxBasedTransport = function() {};
1659
+ AjaxBasedTransport.prototype = new BufferedSender();
1660
+
1661
+ AjaxBasedTransport.prototype.run = function(ri, trans_url,
1662
+ url_suffix, Receiver, AjaxObject) {
1663
+ var that = this;
1664
+ that.ri = ri;
1665
+ that.trans_url = trans_url;
1666
+ that.send_constructor(createAjaxSender(AjaxObject));
1667
+ that.poll = new Polling(ri, Receiver,
1668
+ trans_url + url_suffix, AjaxObject);
1669
+ };
1670
+
1671
+ AjaxBasedTransport.prototype.doCleanup = function() {
1672
+ var that = this;
1673
+ if (that.poll) {
1674
+ that.poll.abort();
1675
+ that.poll = null;
1676
+ }
1677
+ that.send_destructor();
1678
+ };
1679
+ // [*] End of lib/trans-xhr.js
1680
+
1681
+
1682
+ // [*] Including lib/trans-iframe.js
1683
+ /*
1684
+ * ***** BEGIN LICENSE BLOCK *****
1685
+ * Copyright (c) 2011-2012 VMware, Inc.
1686
+ *
1687
+ * For the license see COPYING.
1688
+ * ***** END LICENSE BLOCK *****
1689
+ */
1690
+
1691
+ // Few cool transports do work only for same-origin. In order to make
1692
+ // them working cross-domain we shall use iframe, served form the
1693
+ // remote domain. New browsers, have capabilities to communicate with
1694
+ // cross domain iframe, using postMessage(). In IE it was implemented
1695
+ // from IE 8+, but of course, IE got some details wrong:
1696
+ // http://msdn.microsoft.com/en-us/library/cc197015(v=VS.85).aspx
1697
+ // http://stevesouders.com/misc/test-postmessage.php
1698
+
1699
+ var IframeTransport = function() {};
1700
+
1701
+ IframeTransport.prototype.i_constructor = function(ri, trans_url, base_url) {
1702
+ var that = this;
1703
+ that.ri = ri;
1704
+ that.origin = utils.getOrigin(base_url);
1705
+ that.base_url = base_url;
1706
+ that.trans_url = trans_url;
1707
+
1708
+ var iframe_url = base_url + '/iframe.html';
1709
+ var query = [];
1710
+
1711
+ if (that.ri._options.devel) {
1712
+ query.push('t=' + (+new Date));
1713
+ }
1714
+ if (that.ri._options.js_path) {
1715
+ query.push('js_path=' + encodeURIComponent(that.ri._options.js_path));
1716
+ }
1717
+ if (query.length > 0) {
1718
+ iframe_url += ("?" + query.join("&"));
1719
+ }
1720
+
1721
+ that.window_id = utils.random_string(8);
1722
+ iframe_url += '#' + that.window_id;
1723
+
1724
+ that.iframeObj = utils.createIframe(iframe_url, function(r) {
1725
+ that.ri._didClose(1006, "Unable to load an iframe (" + r + ")");
1726
+ });
1727
+
1728
+ that.onmessage_cb = utils.bind(that.onmessage, that);
1729
+ utils.attachMessage(that.onmessage_cb);
1730
+ };
1731
+
1732
+ IframeTransport.prototype.doCleanup = function() {
1733
+ var that = this;
1734
+ if (that.iframeObj) {
1735
+ utils.detachMessage(that.onmessage_cb);
1736
+ try {
1737
+ // When the iframe is not loaded, IE raises an exception
1738
+ // on 'contentWindow'.
1739
+ if (that.iframeObj.iframe.contentWindow) {
1740
+ that.postMessage('c');
1741
+ }
1742
+ } catch (x) {}
1743
+ that.iframeObj.cleanup();
1744
+ that.iframeObj = null;
1745
+ that.onmessage_cb = that.iframeObj = null;
1746
+ }
1747
+ };
1748
+
1749
+ IframeTransport.prototype.onmessage = function(e) {
1750
+ var that = this;
1751
+
1752
+ if (utils.getOrigin(e.origin) !== utils.getOrigin(that.origin)) return;
1753
+ var window_id = e.data.slice(0, 8);
1754
+ var type = e.data.slice(8, 9);
1755
+ var data = e.data.slice(9);
1756
+
1757
+ if (window_id !== that.window_id) return;
1758
+
1759
+ switch(type) {
1760
+ case 's':
1761
+ that.iframeObj.loaded();
1762
+ that.postMessage('s', JSON.stringify([SockJS.version, that.protocol, that.trans_url, that.base_url, that.ri._options]));
1763
+ break;
1764
+ case 't':
1765
+ that.ri._didMessage(data);
1766
+ break;
1767
+ }
1768
+ };
1769
+
1770
+ IframeTransport.prototype.postMessage = function(type, data) {
1771
+ var that = this;
1772
+ that.iframeObj.post(that.window_id + type + (data || ''), that.origin);
1773
+ };
1774
+
1775
+ IframeTransport.prototype.doSend = function (message) {
1776
+ this.postMessage('m', message);
1777
+ };
1778
+
1779
+ IframeTransport.enabled = function() {
1780
+ // postMessage misbehaves in konqueror 4.6.5 - the messages are delivered with
1781
+ // huge delay, or not at all.
1782
+ var konqueror = navigator && navigator.userAgent && navigator.userAgent.indexOf('Konqueror') !== -1;
1783
+ return ((typeof _window.postMessage === 'function' ||
1784
+ typeof _window.postMessage === 'object') && (!konqueror));
1785
+ };
1786
+ // [*] End of lib/trans-iframe.js
1787
+
1788
+
1789
+ // [*] Including lib/trans-iframe-within.js
1790
+ /*
1791
+ * ***** BEGIN LICENSE BLOCK *****
1792
+ * Copyright (c) 2011-2012 VMware, Inc.
1793
+ *
1794
+ * For the license see COPYING.
1795
+ * ***** END LICENSE BLOCK *****
1796
+ */
1797
+
1798
+ var curr_window_id;
1799
+
1800
+ var postMessage = function (type, data) {
1801
+ if(parent !== _window) {
1802
+ parent.postMessage(curr_window_id + type + (data || ''), '*');
1803
+ } else {
1804
+ utils.log("Can't postMessage, no parent window.", type, data);
1805
+ }
1806
+ };
1807
+
1808
+ var FacadeJS = function(options) {
1809
+ this._options = options || utils.defaultOptions();
1810
+ };
1811
+ FacadeJS.prototype._didClose = function (code, reason) {
1812
+ postMessage('t', utils.closeFrame(code, reason));
1813
+ };
1814
+ FacadeJS.prototype._didMessage = function (frame) {
1815
+ postMessage('t', frame);
1816
+ };
1817
+ FacadeJS.prototype._doSend = function (data) {
1818
+ this._transport.doSend(data);
1819
+ };
1820
+ FacadeJS.prototype._doCleanup = function () {
1821
+ this._transport.doCleanup();
1822
+ };
1823
+ FacadeJS.prototype._debug = function () {
1824
+ utils.log.apply(utils, arguments);
1825
+ }
1826
+ utils.parent_origin = undefined;
1827
+
1828
+ SockJS.bootstrap_iframe = function() {
1829
+ var facade;
1830
+ curr_window_id = _document.location.hash.slice(1);
1831
+ var onMessage = function(e) {
1832
+ if(e.source !== parent) return;
1833
+ if(typeof utils.parent_origin === 'undefined')
1834
+ utils.parent_origin = e.origin;
1835
+ if (e.origin !== utils.parent_origin) return;
1836
+
1837
+ var window_id = e.data.slice(0, 8);
1838
+ var type = e.data.slice(8, 9);
1839
+ var data = e.data.slice(9);
1840
+ if (window_id !== curr_window_id) return;
1841
+ switch(type) {
1842
+ case 's':
1843
+ var p = JSON.parse(data);
1844
+ var version = p[0];
1845
+ var protocol = p[1];
1846
+ var trans_url = p[2];
1847
+ var base_url = p[3];
1848
+ var options = p[4];
1849
+ if (version !== SockJS.version) {
1850
+ utils.log("Incompatibile SockJS! Main site uses: " +
1851
+ version + ", the iframe: " +
1852
+ SockJS.version + ". " +
1853
+ "Double check SockJS urls and flush browser cache.");
1854
+ }
1855
+ if (!utils.flatUrl(trans_url) || !utils.flatUrl(base_url)) {
1856
+ utils.log("Only basic urls are supported in SockJS");
1857
+ return;
1858
+ }
1859
+
1860
+ if (!utils.isSameOriginUrl(trans_url) ||
1861
+ !utils.isSameOriginUrl(base_url)) {
1862
+ utils.log("Can't connect to different domain from within an " +
1863
+ "iframe. (" + JSON.stringify([_window.location.href, trans_url, base_url]) +
1864
+ ")");
1865
+ return;
1866
+ }
1867
+ facade = new FacadeJS(options);
1868
+ facade._transport = new FacadeJS[protocol](facade, trans_url, base_url);
1869
+ break;
1870
+ case 'm':
1871
+ facade._doSend(data);
1872
+ break;
1873
+ case 'c':
1874
+ if (facade)
1875
+ facade._doCleanup();
1876
+ facade = null;
1877
+ break;
1878
+ }
1879
+ };
1880
+
1881
+ // alert('test ticker');
1882
+ // facade = new FacadeJS();
1883
+ // facade._transport = new FacadeJS['w-iframe-xhr-polling'](facade, 'http://host.com:9999/ticker/12/basd');
1884
+
1885
+ utils.attachMessage(onMessage);
1886
+
1887
+ // Start
1888
+ postMessage('s');
1889
+ };
1890
+ // [*] End of lib/trans-iframe-within.js
1891
+
1892
+
1893
+ // [*] Including lib/info.js
1894
+ /*
1895
+ * ***** BEGIN LICENSE BLOCK *****
1896
+ * Copyright (c) 2011-2012 VMware, Inc.
1897
+ *
1898
+ * For the license see COPYING.
1899
+ * ***** END LICENSE BLOCK *****
1900
+ */
1901
+
1902
+ var InfoReceiver = function(base_url, AjaxObject) {
1903
+ var that = this;
1904
+ utils.delay(function(){that.doXhr(base_url, AjaxObject);});
1905
+ };
1906
+
1907
+ InfoReceiver.prototype = new EventEmitter(['finish']);
1908
+
1909
+ InfoReceiver.prototype.doXhr = function(base_url, AjaxObject) {
1910
+ var that = this;
1911
+ var t0 = (new Date()).getTime();
1912
+ var xo = new AjaxObject('GET', base_url + '/info');
1913
+
1914
+ var tref = utils.delay(8000,
1915
+ function(){xo.ontimeout();});
1916
+
1917
+ xo.onfinish = function(status, text) {
1918
+ clearTimeout(tref);
1919
+ tref = null;
1920
+ if (status === 200) {
1921
+ var rtt = (new Date()).getTime() - t0;
1922
+ var info = JSON.parse(text);
1923
+ if (typeof info !== 'object') info = {};
1924
+ that.emit('finish', info, rtt);
1925
+ } else {
1926
+ that.emit('finish');
1927
+ }
1928
+ };
1929
+ xo.ontimeout = function() {
1930
+ xo.close();
1931
+ that.emit('finish');
1932
+ };
1933
+ };
1934
+
1935
+ var InfoReceiverIframe = function(ri, base_url) {
1936
+ var that = this;
1937
+ var go = function() {
1938
+ var ifr = new IframeTransport();
1939
+ ifr.protocol = 'w-iframe-info-receiver';
1940
+ var fun = function(r) {
1941
+ if (typeof r === 'string' && r.substr(0,1) === 'm') {
1942
+ var d = JSON.parse(r.substr(1));
1943
+ var info = d[0], rtt = d[1];
1944
+ that.emit('finish', info, rtt);
1945
+ } else {
1946
+ that.emit('finish');
1947
+ }
1948
+ ifr.doCleanup();
1949
+ ifr = null;
1950
+ };
1951
+ var mock_ri = {
1952
+ _options: {
1953
+ js_path: ri._options.js_path
1954
+ },
1955
+ _didClose: fun,
1956
+ _didMessage: fun
1957
+ };
1958
+ ifr.i_constructor(mock_ri, base_url, base_url);
1959
+ }
1960
+ if(!_document.body) {
1961
+ utils.attachEvent('load', go);
1962
+ } else {
1963
+ go();
1964
+ }
1965
+ };
1966
+ InfoReceiverIframe.prototype = new EventEmitter(['finish']);
1967
+
1968
+
1969
+ var InfoReceiverFake = function() {
1970
+ // It may not be possible to do cross domain AJAX to get the info
1971
+ // data, for example for IE7. But we want to run JSONP, so let's
1972
+ // fake the response, with rtt=2s (rto=6s).
1973
+ var that = this;
1974
+ utils.delay(function() {
1975
+ that.emit('finish', {}, 2000);
1976
+ });
1977
+ };
1978
+ InfoReceiverFake.prototype = new EventEmitter(['finish']);
1979
+
1980
+ var createInfoReceiver = function(connection, base_url) {
1981
+ if (utils.isSameOriginUrl(base_url)) {
1982
+ // If, for some reason, we have SockJS locally - there's no
1983
+ // need to start up the complex machinery. Just use ajax.
1984
+ return new InfoReceiver(base_url, utils.XHRLocalObject);
1985
+ }
1986
+ switch (utils.isXHRCorsCapable(base_url)) {
1987
+ case 1:
1988
+ // XHRLocalObject -> no_credentials=true
1989
+ return new InfoReceiver(base_url, utils.XHRLocalObject);
1990
+ case 2:
1991
+ return new InfoReceiver(base_url, utils.XDRObject);
1992
+ case 3:
1993
+ // Opera
1994
+ return new InfoReceiverIframe(connection, base_url);
1995
+ default:
1996
+ // IE 7
1997
+ return new InfoReceiverFake();
1998
+ };
1999
+ };
2000
+
2001
+
2002
+ var WInfoReceiverIframe = FacadeJS['w-iframe-info-receiver'] = function(ri, _trans_url, base_url) {
2003
+ var ir = new InfoReceiver(base_url, utils.XHRLocalObject);
2004
+ ir.onfinish = function(info, rtt) {
2005
+ ri._didMessage('m'+JSON.stringify([info, rtt]));
2006
+ ri._didClose(undefined, undefined, undefined, "w-iframe-info-receiver");
2007
+ }
2008
+ };
2009
+ WInfoReceiverIframe.prototype.doCleanup = function() {};
2010
+ // [*] End of lib/info.js
2011
+
2012
+
2013
+ // [*] Including lib/trans-iframe-eventsource.js
2014
+ /*
2015
+ * ***** BEGIN LICENSE BLOCK *****
2016
+ * Copyright (c) 2011-2012 VMware, Inc.
2017
+ *
2018
+ * For the license see COPYING.
2019
+ * ***** END LICENSE BLOCK *****
2020
+ */
2021
+
2022
+ var EventSourceIframeTransport = SockJS['iframe-eventsource'] = function () {
2023
+ var that = this;
2024
+ that.protocol = 'w-iframe-eventsource';
2025
+ that.i_constructor.apply(that, arguments);
2026
+ };
2027
+
2028
+ EventSourceIframeTransport.prototype = new IframeTransport();
2029
+
2030
+ EventSourceIframeTransport.enabled = function () {
2031
+ return ('EventSource' in _window) && IframeTransport.enabled();
2032
+ };
2033
+
2034
+ EventSourceIframeTransport.need_body = true;
2035
+ EventSourceIframeTransport.roundTrips = 3; // html, javascript, eventsource
2036
+
2037
+
2038
+ // w-iframe-eventsource
2039
+ var EventSourceTransport = FacadeJS['w-iframe-eventsource'] = function(ri, trans_url) {
2040
+ this.run(ri, trans_url, '/eventsource', EventSourceReceiver, utils.XHRLocalObject);
2041
+ }
2042
+ EventSourceTransport.prototype = new AjaxBasedTransport();
2043
+ // [*] End of lib/trans-iframe-eventsource.js
2044
+
2045
+
2046
+ // [*] Including lib/trans-iframe-xhr-polling.js
2047
+ /*
2048
+ * ***** BEGIN LICENSE BLOCK *****
2049
+ * Copyright (c) 2011-2012 VMware, Inc.
2050
+ *
2051
+ * For the license see COPYING.
2052
+ * ***** END LICENSE BLOCK *****
2053
+ */
2054
+
2055
+ var XhrPollingIframeTransport = SockJS['iframe-xhr-polling'] = function () {
2056
+ var that = this;
2057
+ that.protocol = 'w-iframe-xhr-polling';
2058
+ that.i_constructor.apply(that, arguments);
2059
+ };
2060
+
2061
+ XhrPollingIframeTransport.prototype = new IframeTransport();
2062
+
2063
+ XhrPollingIframeTransport.enabled = function () {
2064
+ return _window.XMLHttpRequest && IframeTransport.enabled();
2065
+ };
2066
+
2067
+ XhrPollingIframeTransport.need_body = true;
2068
+ XhrPollingIframeTransport.roundTrips = 3; // html, javascript, xhr
2069
+
2070
+
2071
+ // w-iframe-xhr-polling
2072
+ var XhrPollingITransport = FacadeJS['w-iframe-xhr-polling'] = function(ri, trans_url) {
2073
+ this.run(ri, trans_url, '/xhr', XhrReceiver, utils.XHRLocalObject);
2074
+ };
2075
+
2076
+ XhrPollingITransport.prototype = new AjaxBasedTransport();
2077
+ // [*] End of lib/trans-iframe-xhr-polling.js
2078
+
2079
+
2080
+ // [*] Including lib/trans-iframe-htmlfile.js
2081
+ /*
2082
+ * ***** BEGIN LICENSE BLOCK *****
2083
+ * Copyright (c) 2011-2012 VMware, Inc.
2084
+ *
2085
+ * For the license see COPYING.
2086
+ * ***** END LICENSE BLOCK *****
2087
+ */
2088
+
2089
+ // This transport generally works in any browser, but will cause a
2090
+ // spinning cursor to appear in any browser other than IE.
2091
+ // We may test this transport in all browsers - why not, but in
2092
+ // production it should be only run in IE.
2093
+
2094
+ var HtmlFileIframeTransport = SockJS['iframe-htmlfile'] = function () {
2095
+ var that = this;
2096
+ that.protocol = 'w-iframe-htmlfile';
2097
+ that.i_constructor.apply(that, arguments);
2098
+ };
2099
+
2100
+ // Inheritance.
2101
+ HtmlFileIframeTransport.prototype = new IframeTransport();
2102
+
2103
+ HtmlFileIframeTransport.enabled = function() {
2104
+ return IframeTransport.enabled();
2105
+ };
2106
+
2107
+ HtmlFileIframeTransport.need_body = true;
2108
+ HtmlFileIframeTransport.roundTrips = 3; // html, javascript, htmlfile
2109
+
2110
+
2111
+ // w-iframe-htmlfile
2112
+ var HtmlFileTransport = FacadeJS['w-iframe-htmlfile'] = function(ri, trans_url) {
2113
+ this.run(ri, trans_url, '/htmlfile', HtmlfileReceiver, utils.XHRLocalObject);
2114
+ };
2115
+ HtmlFileTransport.prototype = new AjaxBasedTransport();
2116
+ // [*] End of lib/trans-iframe-htmlfile.js
2117
+
2118
+
2119
+ // [*] Including lib/trans-polling.js
2120
+ /*
2121
+ * ***** BEGIN LICENSE BLOCK *****
2122
+ * Copyright (c) 2011-2012 VMware, Inc.
2123
+ *
2124
+ * For the license see COPYING.
2125
+ * ***** END LICENSE BLOCK *****
2126
+ */
2127
+
2128
+ var Polling = function(ri, Receiver, recv_url, AjaxObject) {
2129
+ var that = this;
2130
+ that.ri = ri;
2131
+ that.Receiver = Receiver;
2132
+ that.recv_url = recv_url;
2133
+ that.AjaxObject = AjaxObject;
2134
+ that._scheduleRecv();
2135
+ };
2136
+
2137
+ Polling.prototype._scheduleRecv = function() {
2138
+ var that = this;
2139
+ var poll = that.poll = new that.Receiver(that.recv_url, that.AjaxObject);
2140
+ var msg_counter = 0;
2141
+ poll.onmessage = function(e) {
2142
+ msg_counter += 1;
2143
+ that.ri._didMessage(e.data);
2144
+ };
2145
+ poll.onclose = function(e) {
2146
+ that.poll = poll = poll.onmessage = poll.onclose = null;
2147
+ if (!that.poll_is_closing) {
2148
+ if (e.reason === 'permanent') {
2149
+ that.ri._didClose(1006, 'Polling error (' + e.reason + ')');
2150
+ } else {
2151
+ that._scheduleRecv();
2152
+ }
2153
+ }
2154
+ };
2155
+ };
2156
+
2157
+ Polling.prototype.abort = function() {
2158
+ var that = this;
2159
+ that.poll_is_closing = true;
2160
+ if (that.poll) {
2161
+ that.poll.abort();
2162
+ }
2163
+ };
2164
+ // [*] End of lib/trans-polling.js
2165
+
2166
+
2167
+ // [*] Including lib/trans-receiver-eventsource.js
2168
+ /*
2169
+ * ***** BEGIN LICENSE BLOCK *****
2170
+ * Copyright (c) 2011-2012 VMware, Inc.
2171
+ *
2172
+ * For the license see COPYING.
2173
+ * ***** END LICENSE BLOCK *****
2174
+ */
2175
+
2176
+ var EventSourceReceiver = function(url) {
2177
+ var that = this;
2178
+ var es = new EventSource(url);
2179
+ es.onmessage = function(e) {
2180
+ that.dispatchEvent(new SimpleEvent('message',
2181
+ {'data': unescape(e.data)}));
2182
+ };
2183
+ that.es_close = es.onerror = function(e, abort_reason) {
2184
+ // ES on reconnection has readyState = 0 or 1.
2185
+ // on network error it's CLOSED = 2
2186
+ var reason = abort_reason ? 'user' :
2187
+ (es.readyState !== 2 ? 'network' : 'permanent');
2188
+ that.es_close = es.onmessage = es.onerror = null;
2189
+ // EventSource reconnects automatically.
2190
+ es.close();
2191
+ es = null;
2192
+ // Safari and chrome < 15 crash if we close window before
2193
+ // waiting for ES cleanup. See:
2194
+ // https://code.google.com/p/chromium/issues/detail?id=89155
2195
+ utils.delay(200, function() {
2196
+ that.dispatchEvent(new SimpleEvent('close', {reason: reason}));
2197
+ });
2198
+ };
2199
+ };
2200
+
2201
+ EventSourceReceiver.prototype = new REventTarget();
2202
+
2203
+ EventSourceReceiver.prototype.abort = function() {
2204
+ var that = this;
2205
+ if (that.es_close) {
2206
+ that.es_close({}, true);
2207
+ }
2208
+ };
2209
+ // [*] End of lib/trans-receiver-eventsource.js
2210
+
2211
+
2212
+ // [*] Including lib/trans-receiver-htmlfile.js
2213
+ /*
2214
+ * ***** BEGIN LICENSE BLOCK *****
2215
+ * Copyright (c) 2011-2012 VMware, Inc.
2216
+ *
2217
+ * For the license see COPYING.
2218
+ * ***** END LICENSE BLOCK *****
2219
+ */
2220
+
2221
+ var _is_ie_htmlfile_capable;
2222
+ var isIeHtmlfileCapable = function() {
2223
+ if (_is_ie_htmlfile_capable === undefined) {
2224
+ if ('ActiveXObject' in _window) {
2225
+ try {
2226
+ _is_ie_htmlfile_capable = !!new ActiveXObject('htmlfile');
2227
+ } catch (x) {}
2228
+ } else {
2229
+ _is_ie_htmlfile_capable = false;
2230
+ }
2231
+ }
2232
+ return _is_ie_htmlfile_capable;
2233
+ };
2234
+
2235
+
2236
+ var HtmlfileReceiver = function(url) {
2237
+ var that = this;
2238
+ utils.polluteGlobalNamespace();
2239
+
2240
+ that.id = 'a' + utils.random_string(6, 26);
2241
+ url += ((url.indexOf('?') === -1) ? '?' : '&') +
2242
+ 'c=' + escape(WPrefix + '.' + that.id);
2243
+
2244
+ var constructor = isIeHtmlfileCapable() ?
2245
+ utils.createHtmlfile : utils.createIframe;
2246
+
2247
+ var iframeObj;
2248
+ _window[WPrefix][that.id] = {
2249
+ start: function () {
2250
+ iframeObj.loaded();
2251
+ },
2252
+ message: function (data) {
2253
+ that.dispatchEvent(new SimpleEvent('message', {'data': data}));
2254
+ },
2255
+ stop: function () {
2256
+ that.iframe_close({}, 'network');
2257
+ }
2258
+ };
2259
+ that.iframe_close = function(e, abort_reason) {
2260
+ iframeObj.cleanup();
2261
+ that.iframe_close = iframeObj = null;
2262
+ delete _window[WPrefix][that.id];
2263
+ that.dispatchEvent(new SimpleEvent('close', {reason: abort_reason}));
2264
+ };
2265
+ iframeObj = constructor(url, function(e) {
2266
+ that.iframe_close({}, 'permanent');
2267
+ });
2268
+ };
2269
+
2270
+ HtmlfileReceiver.prototype = new REventTarget();
2271
+
2272
+ HtmlfileReceiver.prototype.abort = function() {
2273
+ var that = this;
2274
+ if (that.iframe_close) {
2275
+ that.iframe_close({}, 'user');
2276
+ }
2277
+ };
2278
+ // [*] End of lib/trans-receiver-htmlfile.js
2279
+
2280
+
2281
+ // [*] Including lib/trans-receiver-xhr.js
2282
+ /*
2283
+ * ***** BEGIN LICENSE BLOCK *****
2284
+ * Copyright (c) 2011-2012 VMware, Inc.
2285
+ *
2286
+ * For the license see COPYING.
2287
+ * ***** END LICENSE BLOCK *****
2288
+ */
2289
+
2290
+ var XhrReceiver = function(url, AjaxObject) {
2291
+ var that = this;
2292
+ var buf_pos = 0;
2293
+
2294
+ that.xo = new AjaxObject('POST', url, null);
2295
+ that.xo.onchunk = function(status, text) {
2296
+ if (status !== 200) return;
2297
+ while (1) {
2298
+ var buf = text.slice(buf_pos);
2299
+ var p = buf.indexOf('\n');
2300
+ if (p === -1) break;
2301
+ buf_pos += p+1;
2302
+ var msg = buf.slice(0, p);
2303
+ that.dispatchEvent(new SimpleEvent('message', {data: msg}));
2304
+ }
2305
+ };
2306
+ that.xo.onfinish = function(status, text) {
2307
+ that.xo.onchunk(status, text);
2308
+ that.xo = null;
2309
+ var reason = status === 200 ? 'network' : 'permanent';
2310
+ that.dispatchEvent(new SimpleEvent('close', {reason: reason}));
2311
+ }
2312
+ };
2313
+
2314
+ XhrReceiver.prototype = new REventTarget();
2315
+
2316
+ XhrReceiver.prototype.abort = function() {
2317
+ var that = this;
2318
+ if (that.xo) {
2319
+ that.xo.close();
2320
+ that.dispatchEvent(new SimpleEvent('close', {reason: 'user'}));
2321
+ that.xo = null;
2322
+ }
2323
+ };
2324
+ // [*] End of lib/trans-receiver-xhr.js
2325
+
2326
+
2327
+ // [*] Including lib/test-hooks.js
2328
+ /*
2329
+ * ***** BEGIN LICENSE BLOCK *****
2330
+ * Copyright (c) 2011-2012 VMware, Inc.
2331
+ *
2332
+ * For the license see COPYING.
2333
+ * ***** END LICENSE BLOCK *****
2334
+ */
2335
+
2336
+ // For testing
2337
+ SockJS.getUtils = function(){
2338
+ return utils;
2339
+ };
2340
+
2341
+ SockJS.getIframeTransport = function(){
2342
+ return IframeTransport;
2343
+ };
2344
+ // [*] End of lib/test-hooks.js
2345
+
2346
+
2347
+ // [*] Including lib/heartbeater.js
2348
+ /*
2349
+ * ***** BEGIN LICENSE BLOCK *****
2350
+ * Copyright (c) 2011-2012 VMware, Inc.
2351
+ *
2352
+ * For the license see COPYING.
2353
+ * ***** END LICENSE BLOCK *****
2354
+ */
2355
+
2356
+ var Heartbeater = function(timeout, how_many_intervals){
2357
+ var that = this;
2358
+
2359
+ that.timeout = timeout;
2360
+ that.not_poked = 0;
2361
+
2362
+ that._onTimeout = function(){
2363
+ that.not_poked += 1;
2364
+ if (that.not_poked === how_many_intervals) {
2365
+ that.emit('timeout');
2366
+ }
2367
+ that._restartTimeout();
2368
+ };
2369
+ that._restartTimeout();
2370
+ };
2371
+
2372
+ Heartbeater.prototype = new EventEmitter(['first', 'second', 'timeout']);
2373
+ Heartbeater.prototype.poke = function(){
2374
+ this.not_poked = 0;
2375
+ this._restartTimeout();
2376
+ };
2377
+
2378
+ Heartbeater.prototype.close = function(){
2379
+ clearTimeout(this.tref);
2380
+ };
2381
+
2382
+ Heartbeater.prototype._restartTimeout = function(){
2383
+ if (this.tref) {
2384
+ clearTimeout(this.tref);
2385
+ }
2386
+ this.tref = setTimeout(this._onTimeout, this.timeout);
2387
+ };
2388
+
2389
+
2390
+ SockJS.prototype._startHeartbeats = function(server_heartbeat_interval){
2391
+ var that = this;
2392
+
2393
+ that._heartbeater = new Heartbeater(server_heartbeat_interval, 2);
2394
+
2395
+ // 1. Answer server pings
2396
+ that._bus.on('heartbeat', function(){
2397
+ if (!SockJS[that.protocol].polling) {
2398
+ // Polling transports need to reconnect on every delivery,
2399
+ // there is no need to send anything.
2400
+ that._sendEmpty();
2401
+ }
2402
+ });
2403
+
2404
+ // 2. Expect traffic between (2*interval...3*interval)
2405
+ that._heartbeater.ontimeout = function(){
2406
+ that._didClose(1007, 'Server heartbeat missed');
2407
+ };
2408
+ var poke = function(){
2409
+ that._heartbeater.poke();
2410
+ };
2411
+ that._bus.on('heartbeat', poke);
2412
+ that._bus.on('message', poke);
2413
+ that._bus.on('close', function(){
2414
+ that._heartbeater.nuke();
2415
+ that._heartbeater.close();
2416
+ });
2417
+ };
2418
+ // [*] End of lib/heartbeater.js
2419
+
2420
+ return SockJS;
2421
+ })();
2422
+ if ('_sockjs_onload' in window) setTimeout(_sockjs_onload, 1);
2423
+
2424
+ // AMD compliance
2425
+ if (typeof define === 'function' && define.amd) {
2426
+ define('sockjs', [], function(){return SockJS;});
2427
+ }
2428
+
2429
+ if (typeof module === 'object' && module && module.exports) {
2430
+ module.exports = SockJS;
2431
+ }
2432
+ // [*] End of lib/index.js
2433
+
2434
+ // [*] End of lib/all.js
2435
+