pusher-fake 1.9.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +5 -5
  2. data/bin/pusher-fake +5 -1
  3. data/lib/pusher-fake.rb +2 -2
  4. data/lib/pusher-fake/channel.rb +9 -8
  5. data/lib/pusher-fake/channel/presence.rb +2 -0
  6. data/lib/pusher-fake/channel/private.rb +3 -1
  7. data/lib/pusher-fake/channel/public.rb +2 -0
  8. data/lib/pusher-fake/configuration.rb +20 -5
  9. data/lib/pusher-fake/connection.rb +10 -7
  10. data/lib/pusher-fake/server.rb +2 -0
  11. data/lib/pusher-fake/server/application.rb +14 -11
  12. data/lib/pusher-fake/support/base.rb +2 -0
  13. data/lib/pusher-fake/support/cucumber.rb +2 -0
  14. data/lib/pusher-fake/support/rspec.rb +2 -0
  15. data/lib/pusher-fake/webhook.rb +3 -1
  16. data/spec/features/api/channels_spec.rb +2 -0
  17. data/spec/features/api/users_spec.rb +2 -0
  18. data/spec/features/client/connect_spec.rb +2 -0
  19. data/spec/features/client/event_spec.rb +2 -0
  20. data/spec/features/client/presence_spec.rb +2 -0
  21. data/spec/features/client/subscribe_spec.rb +9 -5
  22. data/spec/features/server/event_spec.rb +2 -0
  23. data/spec/features/server/webhooks_spec.rb +25 -13
  24. data/spec/lib/pusher-fake/channel/presence_spec.rb +2 -0
  25. data/spec/lib/pusher-fake/channel/private_spec.rb +4 -2
  26. data/spec/lib/pusher-fake/channel/public_spec.rb +2 -0
  27. data/spec/lib/pusher-fake/channel_spec.rb +5 -3
  28. data/spec/lib/pusher-fake/configuration_spec.rb +36 -7
  29. data/spec/lib/pusher-fake/connection_spec.rb +4 -2
  30. data/spec/lib/pusher-fake/server/application_spec.rb +21 -2
  31. data/spec/lib/pusher-fake/server_spec.rb +2 -0
  32. data/spec/lib/pusher-fake/webhook_spec.rb +3 -1
  33. data/spec/lib/pusher_fake_spec.rb +2 -0
  34. data/spec/spec_helper.rb +3 -1
  35. data/spec/support/application.rb +3 -1
  36. data/spec/support/application/public/javascripts/vendor/polyfill.min.js +1 -0
  37. data/spec/support/application/public/javascripts/vendor/pusher-7.0.0.js +4565 -0
  38. data/spec/support/application/views/index.erb +2 -1
  39. data/spec/support/capybara.rb +3 -0
  40. data/spec/support/coveralls.rb +2 -0
  41. data/spec/support/helpers/connect.rb +2 -0
  42. data/spec/support/helpers/event.rb +2 -0
  43. data/spec/support/helpers/subscription.rb +2 -0
  44. data/spec/support/helpers/user.rb +2 -0
  45. data/spec/support/matchers/have_configuration_option.rb +2 -0
  46. data/spec/support/pusher_fake.rb +2 -0
  47. data/spec/support/webhooks.rb +14 -10
  48. metadata +41 -27
  49. data/lib/pusher-fake/cucumber.rb +0 -4
  50. data/spec/support/application/public/javascripts/vendor/pusher-4.2.1.js +0 -4179
@@ -13,7 +13,8 @@
13
13
  <ul></ul>
14
14
  </section>
15
15
 
16
- <script src="/javascripts/vendor/pusher-4.2.1.js"></script>
16
+ <script src="/javascripts/vendor/polyfill.min.js"></script>
17
+ <script src="/javascripts/vendor/pusher-7.0.0.js"></script>
17
18
  <script>
18
19
  Pusher.instance = <%= PusherFake.javascript %>;
19
20
  Pusher.instance.connection.bind("state_change", function(states) {
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "capybara/poltergeist"
2
4
  require "capybara/rspec"
3
5
 
@@ -6,4 +8,5 @@ Capybara.register_driver :poltergeist do |app|
6
8
  end
7
9
 
8
10
  Capybara.app = Sinatra::Application
11
+ Capybara.server = :webrick
9
12
  Capybara.default_driver = :poltergeist
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  if ENV["CI"]
2
4
  require "coveralls"
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ConnectHelpers
2
4
  def connect(options = {})
3
5
  visit "/"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module EventHelpers
2
4
  def have_event(event, options = {})
3
5
  have_css("li", text: "Channel #{options[:on]} received #{event} event.")
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SubscriptionHelpers
2
4
  def subscribe_to(channel)
3
5
  page.execute_script("Helpers.subscribe(#{MultiJson.dump(channel)})")
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module UserHelpers
2
4
  def user_id(name = nil)
3
5
  using_session(name) do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec::Matchers.define :have_configuration_option do |option|
2
4
  match do |configuration|
3
5
  configuration.respond_to?(option) &&
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "thin/server"
2
4
 
3
5
  RSpec.configure do |config|
@@ -1,4 +1,14 @@
1
- # rubocop:disable Style/GlobalVars
1
+ # frozen_string_literal: true
2
+
3
+ class WebhookHelper
4
+ def self.events
5
+ @events ||= []
6
+ end
7
+
8
+ def self.mutex
9
+ @mutex ||= Mutex.new
10
+ end
11
+ end
2
12
 
3
13
  thread = Thread.new do
4
14
  # Not explicitly requiring Thin::Server occasionally results in
@@ -12,7 +22,9 @@ thread = Thread.new do
12
22
  webhook = Pusher::WebHook.new(request)
13
23
 
14
24
  if webhook.valid?
15
- $events.concat(webhook.events)
25
+ WebhookHelper.mutex.synchronize do
26
+ WebhookHelper.events.concat(webhook.events)
27
+ end
16
28
  end
17
29
 
18
30
  Rack::Response.new.finish
@@ -26,11 +38,3 @@ thread = Thread.new do
26
38
  end
27
39
 
28
40
  at_exit { thread.exit }
29
-
30
- RSpec.configure do |config|
31
- config.before do
32
- $events = []
33
-
34
- PusherFake.configuration.webhooks = ["http://127.0.0.1:8082"]
35
- end
36
- end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pusher-fake
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tristan Dunn
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-02 00:00:00.000000000 Z
11
+ date: 2020-09-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: em-http-request
@@ -72,112 +72,126 @@ dependencies:
72
72
  requirements:
73
73
  - - '='
74
74
  - !ruby/object:Gem::Version
75
- version: 1.16.0
75
+ version: 1.18.1
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - '='
81
81
  - !ruby/object:Gem::Version
82
- version: 1.16.0
82
+ version: 1.18.1
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: pusher
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - '='
88
88
  - !ruby/object:Gem::Version
89
- version: 1.3.1
89
+ version: 1.3.3
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - '='
95
95
  - !ruby/object:Gem::Version
96
- version: 1.3.1
96
+ version: 1.3.3
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rake
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - '='
102
102
  - !ruby/object:Gem::Version
103
- version: 12.2.1
103
+ version: 13.0.1
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - '='
109
109
  - !ruby/object:Gem::Version
110
- version: 12.2.1
110
+ version: 13.0.1
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: rspec
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - '='
116
116
  - !ruby/object:Gem::Version
117
- version: 3.7.0
117
+ version: 3.9.0
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - '='
123
123
  - !ruby/object:Gem::Version
124
- version: 3.7.0
124
+ version: 3.9.0
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: rubocop
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - '='
130
130
  - !ruby/object:Gem::Version
131
- version: 0.51.0
131
+ version: 0.90.0
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - '='
137
137
  - !ruby/object:Gem::Version
138
- version: 0.51.0
138
+ version: 0.90.0
139
+ - !ruby/object:Gem::Dependency
140
+ name: rubocop-performance
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - '='
144
+ - !ruby/object:Gem::Version
145
+ version: 1.8.0
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - '='
151
+ - !ruby/object:Gem::Version
152
+ version: 1.8.0
139
153
  - !ruby/object:Gem::Dependency
140
154
  name: rubocop-rspec
141
155
  requirement: !ruby/object:Gem::Requirement
142
156
  requirements:
143
157
  - - '='
144
158
  - !ruby/object:Gem::Version
145
- version: 1.19.0
159
+ version: 1.43.2
146
160
  type: :development
147
161
  prerelease: false
148
162
  version_requirements: !ruby/object:Gem::Requirement
149
163
  requirements:
150
164
  - - '='
151
165
  - !ruby/object:Gem::Version
152
- version: 1.19.0
166
+ version: 1.43.2
153
167
  - !ruby/object:Gem::Dependency
154
168
  name: sinatra
155
169
  requirement: !ruby/object:Gem::Requirement
156
170
  requirements:
157
171
  - - '='
158
172
  - !ruby/object:Gem::Version
159
- version: 2.0.0
173
+ version: 2.1.0
160
174
  type: :development
161
175
  prerelease: false
162
176
  version_requirements: !ruby/object:Gem::Requirement
163
177
  requirements:
164
178
  - - '='
165
179
  - !ruby/object:Gem::Version
166
- version: 2.0.0
180
+ version: 2.1.0
167
181
  - !ruby/object:Gem::Dependency
168
182
  name: yard
169
183
  requirement: !ruby/object:Gem::Requirement
170
184
  requirements:
171
185
  - - '='
172
186
  - !ruby/object:Gem::Version
173
- version: 0.9.9
187
+ version: 0.9.25
174
188
  type: :development
175
189
  prerelease: false
176
190
  version_requirements: !ruby/object:Gem::Requirement
177
191
  requirements:
178
192
  - - '='
179
193
  - !ruby/object:Gem::Version
180
- version: 0.9.9
194
+ version: 0.9.25
181
195
  description: A fake Pusher server for development and testing.
182
196
  email: hello@tristandunn.com
183
197
  executables:
@@ -193,7 +207,6 @@ files:
193
207
  - lib/pusher-fake/channel/public.rb
194
208
  - lib/pusher-fake/configuration.rb
195
209
  - lib/pusher-fake/connection.rb
196
- - lib/pusher-fake/cucumber.rb
197
210
  - lib/pusher-fake/server.rb
198
211
  - lib/pusher-fake/server/application.rb
199
212
  - lib/pusher-fake/support/base.rb
@@ -220,7 +233,8 @@ files:
220
233
  - spec/lib/pusher_fake_spec.rb
221
234
  - spec/spec_helper.rb
222
235
  - spec/support/application.rb
223
- - spec/support/application/public/javascripts/vendor/pusher-4.2.1.js
236
+ - spec/support/application/public/javascripts/vendor/polyfill.min.js
237
+ - spec/support/application/public/javascripts/vendor/pusher-7.0.0.js
224
238
  - spec/support/application/views/index.erb
225
239
  - spec/support/capybara.rb
226
240
  - spec/support/coveralls.rb
@@ -235,7 +249,7 @@ homepage: https://github.com/tristandunn/pusher-fake
235
249
  licenses:
236
250
  - MIT
237
251
  metadata: {}
238
- post_install_message:
252
+ post_install_message:
239
253
  rdoc_options: []
240
254
  require_paths:
241
255
  - lib
@@ -243,16 +257,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
243
257
  requirements:
244
258
  - - ">="
245
259
  - !ruby/object:Gem::Version
246
- version: '0'
260
+ version: '2.4'
247
261
  required_rubygems_version: !ruby/object:Gem::Requirement
248
262
  requirements:
249
263
  - - ">="
250
264
  - !ruby/object:Gem::Version
251
265
  version: '0'
252
266
  requirements: []
253
- rubyforge_project:
254
- rubygems_version: 2.6.13
255
- signing_key:
267
+ rubygems_version: 3.0.3
268
+ signing_key:
256
269
  specification_version: 4
257
270
  summary: A fake Pusher server for development and testing.
258
271
  test_files:
@@ -270,7 +283,8 @@ test_files:
270
283
  - spec/support/application.rb
271
284
  - spec/support/pusher_fake.rb
272
285
  - spec/support/matchers/have_configuration_option.rb
273
- - spec/support/application/public/javascripts/vendor/pusher-4.2.1.js
286
+ - spec/support/application/public/javascripts/vendor/pusher-7.0.0.js
287
+ - spec/support/application/public/javascripts/vendor/polyfill.min.js
274
288
  - spec/support/application/views/index.erb
275
289
  - spec/support/coveralls.rb
276
290
  - spec/support/helpers/connect.rb
@@ -1,4 +0,0 @@
1
- require "pusher-fake/support/cucumber"
2
-
3
- warn %([DEPRECATION] "pusher-fake/cucumber" is deprecated.) +
4
- %(Please use "pusher-fake/support/cucumber" instead.)
@@ -1,4179 +0,0 @@
1
- /*!
2
- * Pusher JavaScript Library v4.2.1
3
- * https://pusher.com/
4
- *
5
- * Copyright 2017, Pusher
6
- * Released under the MIT licence.
7
- */
8
-
9
- (function webpackUniversalModuleDefinition(root, factory) {
10
- if(typeof exports === 'object' && typeof module === 'object')
11
- module.exports = factory();
12
- else if(typeof define === 'function' && define.amd)
13
- define([], factory);
14
- else if(typeof exports === 'object')
15
- exports["Pusher"] = factory();
16
- else
17
- root["Pusher"] = factory();
18
- })(this, function() {
19
- return /******/ (function(modules) { // webpackBootstrap
20
- /******/ // The module cache
21
- /******/ var installedModules = {};
22
-
23
- /******/ // The require function
24
- /******/ function __webpack_require__(moduleId) {
25
-
26
- /******/ // Check if module is in cache
27
- /******/ if(installedModules[moduleId])
28
- /******/ return installedModules[moduleId].exports;
29
-
30
- /******/ // Create a new module (and put it into the cache)
31
- /******/ var module = installedModules[moduleId] = {
32
- /******/ exports: {},
33
- /******/ id: moduleId,
34
- /******/ loaded: false
35
- /******/ };
36
-
37
- /******/ // Execute the module function
38
- /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
39
-
40
- /******/ // Flag the module as loaded
41
- /******/ module.loaded = true;
42
-
43
- /******/ // Return the exports of the module
44
- /******/ return module.exports;
45
- /******/ }
46
-
47
-
48
- /******/ // expose the modules object (__webpack_modules__)
49
- /******/ __webpack_require__.m = modules;
50
-
51
- /******/ // expose the module cache
52
- /******/ __webpack_require__.c = installedModules;
53
-
54
- /******/ // __webpack_public_path__
55
- /******/ __webpack_require__.p = "";
56
-
57
- /******/ // Load entry module and return exports
58
- /******/ return __webpack_require__(0);
59
- /******/ })
60
- /************************************************************************/
61
- /******/ ([
62
- /* 0 */
63
- /***/ (function(module, exports, __webpack_require__) {
64
-
65
- "use strict";
66
- var pusher_1 = __webpack_require__(1);
67
- module.exports = pusher_1["default"];
68
-
69
-
70
- /***/ }),
71
- /* 1 */
72
- /***/ (function(module, exports, __webpack_require__) {
73
-
74
- "use strict";
75
- var runtime_1 = __webpack_require__(2);
76
- var Collections = __webpack_require__(9);
77
- var dispatcher_1 = __webpack_require__(24);
78
- var timeline_1 = __webpack_require__(39);
79
- var level_1 = __webpack_require__(40);
80
- var StrategyBuilder = __webpack_require__(41);
81
- var timers_1 = __webpack_require__(12);
82
- var defaults_1 = __webpack_require__(5);
83
- var DefaultConfig = __webpack_require__(63);
84
- var logger_1 = __webpack_require__(8);
85
- var factory_1 = __webpack_require__(43);
86
- var url_store_1 = __webpack_require__(14);
87
- var Pusher = (function () {
88
- function Pusher(app_key, options) {
89
- var _this = this;
90
- checkAppKey(app_key);
91
- options = options || {};
92
- if (!options.cluster) {
93
- var suffix = url_store_1["default"].buildLogSuffix("javascriptQuickStart");
94
- logger_1["default"].warn("You should always specify a cluster when connecting. " + suffix);
95
- }
96
- this.key = app_key;
97
- this.config = Collections.extend(DefaultConfig.getGlobalConfig(), options.cluster ? DefaultConfig.getClusterConfig(options.cluster) : {}, options);
98
- this.channels = factory_1["default"].createChannels();
99
- this.global_emitter = new dispatcher_1["default"]();
100
- this.sessionID = Math.floor(Math.random() * 1000000000);
101
- this.timeline = new timeline_1["default"](this.key, this.sessionID, {
102
- cluster: this.config.cluster,
103
- features: Pusher.getClientFeatures(),
104
- params: this.config.timelineParams || {},
105
- limit: 50,
106
- level: level_1["default"].INFO,
107
- version: defaults_1["default"].VERSION
108
- });
109
- if (!this.config.disableStats) {
110
- this.timelineSender = factory_1["default"].createTimelineSender(this.timeline, {
111
- host: this.config.statsHost,
112
- path: "/timeline/v2/" + runtime_1["default"].TimelineTransport.name
113
- });
114
- }
115
- var getStrategy = function (options) {
116
- var config = Collections.extend({}, _this.config, options);
117
- return StrategyBuilder.build(runtime_1["default"].getDefaultStrategy(config), config);
118
- };
119
- this.connection = factory_1["default"].createConnectionManager(this.key, Collections.extend({ getStrategy: getStrategy,
120
- timeline: this.timeline,
121
- activityTimeout: this.config.activity_timeout,
122
- pongTimeout: this.config.pong_timeout,
123
- unavailableTimeout: this.config.unavailable_timeout
124
- }, this.config, { encrypted: this.isEncrypted() }));
125
- this.connection.bind('connected', function () {
126
- _this.subscribeAll();
127
- if (_this.timelineSender) {
128
- _this.timelineSender.send(_this.connection.isEncrypted());
129
- }
130
- });
131
- this.connection.bind('message', function (params) {
132
- var internal = (params.event.indexOf('pusher_internal:') === 0);
133
- if (params.channel) {
134
- var channel = _this.channel(params.channel);
135
- if (channel) {
136
- channel.handleEvent(params.event, params.data);
137
- }
138
- }
139
- if (!internal) {
140
- _this.global_emitter.emit(params.event, params.data);
141
- }
142
- });
143
- this.connection.bind('connecting', function () {
144
- _this.channels.disconnect();
145
- });
146
- this.connection.bind('disconnected', function () {
147
- _this.channels.disconnect();
148
- });
149
- this.connection.bind('error', function (err) {
150
- logger_1["default"].warn('Error', err);
151
- });
152
- Pusher.instances.push(this);
153
- this.timeline.info({ instances: Pusher.instances.length });
154
- if (Pusher.isReady) {
155
- this.connect();
156
- }
157
- }
158
- Pusher.ready = function () {
159
- Pusher.isReady = true;
160
- for (var i = 0, l = Pusher.instances.length; i < l; i++) {
161
- Pusher.instances[i].connect();
162
- }
163
- };
164
- Pusher.log = function (message) {
165
- if (Pusher.logToConsole && (window).console && (window).console.log) {
166
- (window).console.log(message);
167
- }
168
- };
169
- Pusher.getClientFeatures = function () {
170
- return Collections.keys(Collections.filterObject({ "ws": runtime_1["default"].Transports.ws }, function (t) { return t.isSupported({}); }));
171
- };
172
- Pusher.prototype.channel = function (name) {
173
- return this.channels.find(name);
174
- };
175
- Pusher.prototype.allChannels = function () {
176
- return this.channels.all();
177
- };
178
- Pusher.prototype.connect = function () {
179
- this.connection.connect();
180
- if (this.timelineSender) {
181
- if (!this.timelineSenderTimer) {
182
- var encrypted = this.connection.isEncrypted();
183
- var timelineSender = this.timelineSender;
184
- this.timelineSenderTimer = new timers_1.PeriodicTimer(60000, function () {
185
- timelineSender.send(encrypted);
186
- });
187
- }
188
- }
189
- };
190
- Pusher.prototype.disconnect = function () {
191
- this.connection.disconnect();
192
- if (this.timelineSenderTimer) {
193
- this.timelineSenderTimer.ensureAborted();
194
- this.timelineSenderTimer = null;
195
- }
196
- };
197
- Pusher.prototype.bind = function (event_name, callback, context) {
198
- this.global_emitter.bind(event_name, callback, context);
199
- return this;
200
- };
201
- Pusher.prototype.unbind = function (event_name, callback, context) {
202
- this.global_emitter.unbind(event_name, callback, context);
203
- return this;
204
- };
205
- Pusher.prototype.bind_global = function (callback) {
206
- this.global_emitter.bind_global(callback);
207
- return this;
208
- };
209
- Pusher.prototype.unbind_global = function (callback) {
210
- this.global_emitter.unbind_global(callback);
211
- return this;
212
- };
213
- Pusher.prototype.unbind_all = function (callback) {
214
- this.global_emitter.unbind_all();
215
- return this;
216
- };
217
- Pusher.prototype.subscribeAll = function () {
218
- var channelName;
219
- for (channelName in this.channels.channels) {
220
- if (this.channels.channels.hasOwnProperty(channelName)) {
221
- this.subscribe(channelName);
222
- }
223
- }
224
- };
225
- Pusher.prototype.subscribe = function (channel_name) {
226
- var channel = this.channels.add(channel_name, this);
227
- if (channel.subscriptionPending && channel.subscriptionCancelled) {
228
- channel.reinstateSubscription();
229
- }
230
- else if (!channel.subscriptionPending && this.connection.state === "connected") {
231
- channel.subscribe();
232
- }
233
- return channel;
234
- };
235
- Pusher.prototype.unsubscribe = function (channel_name) {
236
- var channel = this.channels.find(channel_name);
237
- if (channel && channel.subscriptionPending) {
238
- channel.cancelSubscription();
239
- }
240
- else {
241
- channel = this.channels.remove(channel_name);
242
- if (channel && this.connection.state === "connected") {
243
- channel.unsubscribe();
244
- }
245
- }
246
- };
247
- Pusher.prototype.send_event = function (event_name, data, channel) {
248
- return this.connection.send_event(event_name, data, channel);
249
- };
250
- Pusher.prototype.isEncrypted = function () {
251
- if (runtime_1["default"].getProtocol() === "https:") {
252
- return true;
253
- }
254
- else {
255
- return Boolean(this.config.encrypted);
256
- }
257
- };
258
- Pusher.instances = [];
259
- Pusher.isReady = false;
260
- Pusher.logToConsole = false;
261
- Pusher.Runtime = runtime_1["default"];
262
- Pusher.ScriptReceivers = runtime_1["default"].ScriptReceivers;
263
- Pusher.DependenciesReceivers = runtime_1["default"].DependenciesReceivers;
264
- Pusher.auth_callbacks = runtime_1["default"].auth_callbacks;
265
- return Pusher;
266
- }());
267
- exports.__esModule = true;
268
- exports["default"] = Pusher;
269
- function checkAppKey(key) {
270
- if (key === null || key === undefined) {
271
- throw "You must pass your app key when you instantiate Pusher.";
272
- }
273
- }
274
- runtime_1["default"].setup(Pusher);
275
-
276
-
277
- /***/ }),
278
- /* 2 */
279
- /***/ (function(module, exports, __webpack_require__) {
280
-
281
- "use strict";
282
- var dependencies_1 = __webpack_require__(3);
283
- var xhr_auth_1 = __webpack_require__(7);
284
- var jsonp_auth_1 = __webpack_require__(15);
285
- var script_request_1 = __webpack_require__(16);
286
- var jsonp_request_1 = __webpack_require__(17);
287
- var script_receiver_factory_1 = __webpack_require__(4);
288
- var jsonp_timeline_1 = __webpack_require__(18);
289
- var transports_1 = __webpack_require__(19);
290
- var net_info_1 = __webpack_require__(26);
291
- var default_strategy_1 = __webpack_require__(27);
292
- var transport_connection_initializer_1 = __webpack_require__(28);
293
- var http_1 = __webpack_require__(29);
294
- var Runtime = {
295
- nextAuthCallbackID: 1,
296
- auth_callbacks: {},
297
- ScriptReceivers: script_receiver_factory_1.ScriptReceivers,
298
- DependenciesReceivers: dependencies_1.DependenciesReceivers,
299
- getDefaultStrategy: default_strategy_1["default"],
300
- Transports: transports_1["default"],
301
- transportConnectionInitializer: transport_connection_initializer_1["default"],
302
- HTTPFactory: http_1["default"],
303
- TimelineTransport: jsonp_timeline_1["default"],
304
- getXHRAPI: function () {
305
- return window.XMLHttpRequest;
306
- },
307
- getWebSocketAPI: function () {
308
- return window.WebSocket || window.MozWebSocket;
309
- },
310
- setup: function (PusherClass) {
311
- var _this = this;
312
- window.Pusher = PusherClass;
313
- var initializeOnDocumentBody = function () {
314
- _this.onDocumentBody(PusherClass.ready);
315
- };
316
- if (!window.JSON) {
317
- dependencies_1.Dependencies.load("json2", {}, initializeOnDocumentBody);
318
- }
319
- else {
320
- initializeOnDocumentBody();
321
- }
322
- },
323
- getDocument: function () {
324
- return document;
325
- },
326
- getProtocol: function () {
327
- return this.getDocument().location.protocol;
328
- },
329
- getAuthorizers: function () {
330
- return { ajax: xhr_auth_1["default"], jsonp: jsonp_auth_1["default"] };
331
- },
332
- onDocumentBody: function (callback) {
333
- var _this = this;
334
- if (document.body) {
335
- callback();
336
- }
337
- else {
338
- setTimeout(function () {
339
- _this.onDocumentBody(callback);
340
- }, 0);
341
- }
342
- },
343
- createJSONPRequest: function (url, data) {
344
- return new jsonp_request_1["default"](url, data);
345
- },
346
- createScriptRequest: function (src) {
347
- return new script_request_1["default"](src);
348
- },
349
- getLocalStorage: function () {
350
- try {
351
- return window.localStorage;
352
- }
353
- catch (e) {
354
- return undefined;
355
- }
356
- },
357
- createXHR: function () {
358
- if (this.getXHRAPI()) {
359
- return this.createXMLHttpRequest();
360
- }
361
- else {
362
- return this.createMicrosoftXHR();
363
- }
364
- },
365
- createXMLHttpRequest: function () {
366
- var Constructor = this.getXHRAPI();
367
- return new Constructor();
368
- },
369
- createMicrosoftXHR: function () {
370
- return new ActiveXObject("Microsoft.XMLHTTP");
371
- },
372
- getNetwork: function () {
373
- return net_info_1.Network;
374
- },
375
- createWebSocket: function (url) {
376
- var Constructor = this.getWebSocketAPI();
377
- return new Constructor(url);
378
- },
379
- createSocketRequest: function (method, url) {
380
- if (this.isXHRSupported()) {
381
- return this.HTTPFactory.createXHR(method, url);
382
- }
383
- else if (this.isXDRSupported(url.indexOf("https:") === 0)) {
384
- return this.HTTPFactory.createXDR(method, url);
385
- }
386
- else {
387
- throw "Cross-origin HTTP requests are not supported";
388
- }
389
- },
390
- isXHRSupported: function () {
391
- var Constructor = this.getXHRAPI();
392
- return Boolean(Constructor) && (new Constructor()).withCredentials !== undefined;
393
- },
394
- isXDRSupported: function (encrypted) {
395
- var protocol = encrypted ? "https:" : "http:";
396
- var documentProtocol = this.getProtocol();
397
- return Boolean((window['XDomainRequest'])) && documentProtocol === protocol;
398
- },
399
- addUnloadListener: function (listener) {
400
- if (window.addEventListener !== undefined) {
401
- window.addEventListener("unload", listener, false);
402
- }
403
- else if (window.attachEvent !== undefined) {
404
- window.attachEvent("onunload", listener);
405
- }
406
- },
407
- removeUnloadListener: function (listener) {
408
- if (window.addEventListener !== undefined) {
409
- window.removeEventListener("unload", listener, false);
410
- }
411
- else if (window.detachEvent !== undefined) {
412
- window.detachEvent("onunload", listener);
413
- }
414
- }
415
- };
416
- exports.__esModule = true;
417
- exports["default"] = Runtime;
418
-
419
-
420
- /***/ }),
421
- /* 3 */
422
- /***/ (function(module, exports, __webpack_require__) {
423
-
424
- "use strict";
425
- var script_receiver_factory_1 = __webpack_require__(4);
426
- var defaults_1 = __webpack_require__(5);
427
- var dependency_loader_1 = __webpack_require__(6);
428
- exports.DependenciesReceivers = new script_receiver_factory_1.ScriptReceiverFactory("_pusher_dependencies", "Pusher.DependenciesReceivers");
429
- exports.Dependencies = new dependency_loader_1["default"]({
430
- cdn_http: defaults_1["default"].cdn_http,
431
- cdn_https: defaults_1["default"].cdn_https,
432
- version: defaults_1["default"].VERSION,
433
- suffix: defaults_1["default"].dependency_suffix,
434
- receivers: exports.DependenciesReceivers
435
- });
436
-
437
-
438
- /***/ }),
439
- /* 4 */
440
- /***/ (function(module, exports) {
441
-
442
- "use strict";
443
- var ScriptReceiverFactory = (function () {
444
- function ScriptReceiverFactory(prefix, name) {
445
- this.lastId = 0;
446
- this.prefix = prefix;
447
- this.name = name;
448
- }
449
- ScriptReceiverFactory.prototype.create = function (callback) {
450
- this.lastId++;
451
- var number = this.lastId;
452
- var id = this.prefix + number;
453
- var name = this.name + "[" + number + "]";
454
- var called = false;
455
- var callbackWrapper = function () {
456
- if (!called) {
457
- callback.apply(null, arguments);
458
- called = true;
459
- }
460
- };
461
- this[number] = callbackWrapper;
462
- return { number: number, id: id, name: name, callback: callbackWrapper };
463
- };
464
- ScriptReceiverFactory.prototype.remove = function (receiver) {
465
- delete this[receiver.number];
466
- };
467
- return ScriptReceiverFactory;
468
- }());
469
- exports.ScriptReceiverFactory = ScriptReceiverFactory;
470
- exports.ScriptReceivers = new ScriptReceiverFactory("_pusher_script_", "Pusher.ScriptReceivers");
471
-
472
-
473
- /***/ }),
474
- /* 5 */
475
- /***/ (function(module, exports) {
476
-
477
- "use strict";
478
- var Defaults = {
479
- VERSION: "4.2.1",
480
- PROTOCOL: 7,
481
- host: 'ws.pusherapp.com',
482
- ws_port: 80,
483
- wss_port: 443,
484
- sockjs_host: 'sockjs.pusher.com',
485
- sockjs_http_port: 80,
486
- sockjs_https_port: 443,
487
- sockjs_path: "/pusher",
488
- stats_host: 'stats.pusher.com',
489
- channel_auth_endpoint: '/pusher/auth',
490
- channel_auth_transport: 'ajax',
491
- activity_timeout: 120000,
492
- pong_timeout: 30000,
493
- unavailable_timeout: 10000,
494
- cdn_http: 'http://js.pusher.com',
495
- cdn_https: 'https://js.pusher.com',
496
- dependency_suffix: ''
497
- };
498
- exports.__esModule = true;
499
- exports["default"] = Defaults;
500
-
501
-
502
- /***/ }),
503
- /* 6 */
504
- /***/ (function(module, exports, __webpack_require__) {
505
-
506
- "use strict";
507
- var script_receiver_factory_1 = __webpack_require__(4);
508
- var runtime_1 = __webpack_require__(2);
509
- var DependencyLoader = (function () {
510
- function DependencyLoader(options) {
511
- this.options = options;
512
- this.receivers = options.receivers || script_receiver_factory_1.ScriptReceivers;
513
- this.loading = {};
514
- }
515
- DependencyLoader.prototype.load = function (name, options, callback) {
516
- var self = this;
517
- if (self.loading[name] && self.loading[name].length > 0) {
518
- self.loading[name].push(callback);
519
- }
520
- else {
521
- self.loading[name] = [callback];
522
- var request = runtime_1["default"].createScriptRequest(self.getPath(name, options));
523
- var receiver = self.receivers.create(function (error) {
524
- self.receivers.remove(receiver);
525
- if (self.loading[name]) {
526
- var callbacks = self.loading[name];
527
- delete self.loading[name];
528
- var successCallback = function (wasSuccessful) {
529
- if (!wasSuccessful) {
530
- request.cleanup();
531
- }
532
- };
533
- for (var i = 0; i < callbacks.length; i++) {
534
- callbacks[i](error, successCallback);
535
- }
536
- }
537
- });
538
- request.send(receiver);
539
- }
540
- };
541
- DependencyLoader.prototype.getRoot = function (options) {
542
- var cdn;
543
- var protocol = runtime_1["default"].getDocument().location.protocol;
544
- if ((options && options.encrypted) || protocol === "https:") {
545
- cdn = this.options.cdn_https;
546
- }
547
- else {
548
- cdn = this.options.cdn_http;
549
- }
550
- return cdn.replace(/\/*$/, "") + "/" + this.options.version;
551
- };
552
- DependencyLoader.prototype.getPath = function (name, options) {
553
- return this.getRoot(options) + '/' + name + this.options.suffix + '.js';
554
- };
555
- ;
556
- return DependencyLoader;
557
- }());
558
- exports.__esModule = true;
559
- exports["default"] = DependencyLoader;
560
-
561
-
562
- /***/ }),
563
- /* 7 */
564
- /***/ (function(module, exports, __webpack_require__) {
565
-
566
- "use strict";
567
- var logger_1 = __webpack_require__(8);
568
- var runtime_1 = __webpack_require__(2);
569
- var url_store_1 = __webpack_require__(14);
570
- var ajax = function (context, socketId, callback) {
571
- var self = this, xhr;
572
- xhr = runtime_1["default"].createXHR();
573
- xhr.open("POST", self.options.authEndpoint, true);
574
- xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
575
- for (var headerName in this.authOptions.headers) {
576
- xhr.setRequestHeader(headerName, this.authOptions.headers[headerName]);
577
- }
578
- xhr.onreadystatechange = function () {
579
- if (xhr.readyState === 4) {
580
- if (xhr.status === 200) {
581
- var data, parsed = false;
582
- try {
583
- data = JSON.parse(xhr.responseText);
584
- parsed = true;
585
- }
586
- catch (e) {
587
- callback(true, 'JSON returned from webapp was invalid, yet status code was 200. Data was: ' + xhr.responseText);
588
- }
589
- if (parsed) {
590
- callback(false, data);
591
- }
592
- }
593
- else {
594
- var suffix = url_store_1["default"].buildLogSuffix("authenticationEndpoint");
595
- logger_1["default"].warn(("Couldn't retrieve authentication info. " + xhr.status) +
596
- ("Clients must be authenticated to join private or presence channels. " + suffix));
597
- callback(true, xhr.status);
598
- }
599
- }
600
- };
601
- xhr.send(this.composeQuery(socketId));
602
- return xhr;
603
- };
604
- exports.__esModule = true;
605
- exports["default"] = ajax;
606
-
607
-
608
- /***/ }),
609
- /* 8 */
610
- /***/ (function(module, exports, __webpack_require__) {
611
-
612
- "use strict";
613
- var collections_1 = __webpack_require__(9);
614
- var pusher_1 = __webpack_require__(1);
615
- var Logger = {
616
- debug: function () {
617
- var args = [];
618
- for (var _i = 0; _i < arguments.length; _i++) {
619
- args[_i - 0] = arguments[_i];
620
- }
621
- if (!pusher_1["default"].log) {
622
- return;
623
- }
624
- pusher_1["default"].log(collections_1.stringify.apply(this, arguments));
625
- },
626
- warn: function () {
627
- var args = [];
628
- for (var _i = 0; _i < arguments.length; _i++) {
629
- args[_i - 0] = arguments[_i];
630
- }
631
- var message = collections_1.stringify.apply(this, arguments);
632
- if ((window).console) {
633
- if ((window).console.warn) {
634
- (window).console.warn(message);
635
- }
636
- else if ((window).console.log) {
637
- (window).console.log(message);
638
- }
639
- }
640
- if (pusher_1["default"].log) {
641
- pusher_1["default"].log(message);
642
- }
643
- }
644
- };
645
- exports.__esModule = true;
646
- exports["default"] = Logger;
647
-
648
-
649
- /***/ }),
650
- /* 9 */
651
- /***/ (function(module, exports, __webpack_require__) {
652
-
653
- "use strict";
654
- var base64_1 = __webpack_require__(10);
655
- var util_1 = __webpack_require__(11);
656
- function extend(target) {
657
- var sources = [];
658
- for (var _i = 1; _i < arguments.length; _i++) {
659
- sources[_i - 1] = arguments[_i];
660
- }
661
- for (var i = 0; i < sources.length; i++) {
662
- var extensions = sources[i];
663
- for (var property in extensions) {
664
- if (extensions[property] && extensions[property].constructor &&
665
- extensions[property].constructor === Object) {
666
- target[property] = extend(target[property] || {}, extensions[property]);
667
- }
668
- else {
669
- target[property] = extensions[property];
670
- }
671
- }
672
- }
673
- return target;
674
- }
675
- exports.extend = extend;
676
- function stringify() {
677
- var m = ["Pusher"];
678
- for (var i = 0; i < arguments.length; i++) {
679
- if (typeof arguments[i] === "string") {
680
- m.push(arguments[i]);
681
- }
682
- else {
683
- m.push(safeJSONStringify(arguments[i]));
684
- }
685
- }
686
- return m.join(" : ");
687
- }
688
- exports.stringify = stringify;
689
- function arrayIndexOf(array, item) {
690
- var nativeIndexOf = Array.prototype.indexOf;
691
- if (array === null) {
692
- return -1;
693
- }
694
- if (nativeIndexOf && array.indexOf === nativeIndexOf) {
695
- return array.indexOf(item);
696
- }
697
- for (var i = 0, l = array.length; i < l; i++) {
698
- if (array[i] === item) {
699
- return i;
700
- }
701
- }
702
- return -1;
703
- }
704
- exports.arrayIndexOf = arrayIndexOf;
705
- function objectApply(object, f) {
706
- for (var key in object) {
707
- if (Object.prototype.hasOwnProperty.call(object, key)) {
708
- f(object[key], key, object);
709
- }
710
- }
711
- }
712
- exports.objectApply = objectApply;
713
- function keys(object) {
714
- var keys = [];
715
- objectApply(object, function (_, key) {
716
- keys.push(key);
717
- });
718
- return keys;
719
- }
720
- exports.keys = keys;
721
- function values(object) {
722
- var values = [];
723
- objectApply(object, function (value) {
724
- values.push(value);
725
- });
726
- return values;
727
- }
728
- exports.values = values;
729
- function apply(array, f, context) {
730
- for (var i = 0; i < array.length; i++) {
731
- f.call(context || (window), array[i], i, array);
732
- }
733
- }
734
- exports.apply = apply;
735
- function map(array, f) {
736
- var result = [];
737
- for (var i = 0; i < array.length; i++) {
738
- result.push(f(array[i], i, array, result));
739
- }
740
- return result;
741
- }
742
- exports.map = map;
743
- function mapObject(object, f) {
744
- var result = {};
745
- objectApply(object, function (value, key) {
746
- result[key] = f(value);
747
- });
748
- return result;
749
- }
750
- exports.mapObject = mapObject;
751
- function filter(array, test) {
752
- test = test || function (value) { return !!value; };
753
- var result = [];
754
- for (var i = 0; i < array.length; i++) {
755
- if (test(array[i], i, array, result)) {
756
- result.push(array[i]);
757
- }
758
- }
759
- return result;
760
- }
761
- exports.filter = filter;
762
- function filterObject(object, test) {
763
- var result = {};
764
- objectApply(object, function (value, key) {
765
- if ((test && test(value, key, object, result)) || Boolean(value)) {
766
- result[key] = value;
767
- }
768
- });
769
- return result;
770
- }
771
- exports.filterObject = filterObject;
772
- function flatten(object) {
773
- var result = [];
774
- objectApply(object, function (value, key) {
775
- result.push([key, value]);
776
- });
777
- return result;
778
- }
779
- exports.flatten = flatten;
780
- function any(array, test) {
781
- for (var i = 0; i < array.length; i++) {
782
- if (test(array[i], i, array)) {
783
- return true;
784
- }
785
- }
786
- return false;
787
- }
788
- exports.any = any;
789
- function all(array, test) {
790
- for (var i = 0; i < array.length; i++) {
791
- if (!test(array[i], i, array)) {
792
- return false;
793
- }
794
- }
795
- return true;
796
- }
797
- exports.all = all;
798
- function encodeParamsObject(data) {
799
- return mapObject(data, function (value) {
800
- if (typeof value === "object") {
801
- value = safeJSONStringify(value);
802
- }
803
- return encodeURIComponent(base64_1["default"](value.toString()));
804
- });
805
- }
806
- exports.encodeParamsObject = encodeParamsObject;
807
- function buildQueryString(data) {
808
- var params = filterObject(data, function (value) {
809
- return value !== undefined;
810
- });
811
- var query = map(flatten(encodeParamsObject(params)), util_1["default"].method("join", "=")).join("&");
812
- return query;
813
- }
814
- exports.buildQueryString = buildQueryString;
815
- function decycleObject(object) {
816
- var objects = [], paths = [];
817
- return (function derez(value, path) {
818
- var i, name, nu;
819
- switch (typeof value) {
820
- case 'object':
821
- if (!value) {
822
- return null;
823
- }
824
- for (i = 0; i < objects.length; i += 1) {
825
- if (objects[i] === value) {
826
- return { $ref: paths[i] };
827
- }
828
- }
829
- objects.push(value);
830
- paths.push(path);
831
- if (Object.prototype.toString.apply(value) === '[object Array]') {
832
- nu = [];
833
- for (i = 0; i < value.length; i += 1) {
834
- nu[i] = derez(value[i], path + '[' + i + ']');
835
- }
836
- }
837
- else {
838
- nu = {};
839
- for (name in value) {
840
- if (Object.prototype.hasOwnProperty.call(value, name)) {
841
- nu[name] = derez(value[name], path + '[' + JSON.stringify(name) + ']');
842
- }
843
- }
844
- }
845
- return nu;
846
- case 'number':
847
- case 'string':
848
- case 'boolean':
849
- return value;
850
- }
851
- }(object, '$'));
852
- }
853
- exports.decycleObject = decycleObject;
854
- function safeJSONStringify(source) {
855
- try {
856
- return JSON.stringify(source);
857
- }
858
- catch (e) {
859
- return JSON.stringify(decycleObject(source));
860
- }
861
- }
862
- exports.safeJSONStringify = safeJSONStringify;
863
-
864
-
865
- /***/ }),
866
- /* 10 */
867
- /***/ (function(module, exports, __webpack_require__) {
868
-
869
- "use strict";
870
- function encode(s) {
871
- return btoa(utob(s));
872
- }
873
- exports.__esModule = true;
874
- exports["default"] = encode;
875
- var fromCharCode = String.fromCharCode;
876
- var b64chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
877
- var b64tab = {};
878
- for (var i = 0, l = b64chars.length; i < l; i++) {
879
- b64tab[b64chars.charAt(i)] = i;
880
- }
881
- var cb_utob = function (c) {
882
- var cc = c.charCodeAt(0);
883
- return cc < 0x80 ? c
884
- : cc < 0x800 ? fromCharCode(0xc0 | (cc >>> 6)) +
885
- fromCharCode(0x80 | (cc & 0x3f))
886
- : fromCharCode(0xe0 | ((cc >>> 12) & 0x0f)) +
887
- fromCharCode(0x80 | ((cc >>> 6) & 0x3f)) +
888
- fromCharCode(0x80 | (cc & 0x3f));
889
- };
890
- var utob = function (u) {
891
- return u.replace(/[^\x00-\x7F]/g, cb_utob);
892
- };
893
- var cb_encode = function (ccc) {
894
- var padlen = [0, 2, 1][ccc.length % 3];
895
- var ord = ccc.charCodeAt(0) << 16
896
- | ((ccc.length > 1 ? ccc.charCodeAt(1) : 0) << 8)
897
- | ((ccc.length > 2 ? ccc.charCodeAt(2) : 0));
898
- var chars = [
899
- b64chars.charAt(ord >>> 18),
900
- b64chars.charAt((ord >>> 12) & 63),
901
- padlen >= 2 ? '=' : b64chars.charAt((ord >>> 6) & 63),
902
- padlen >= 1 ? '=' : b64chars.charAt(ord & 63)
903
- ];
904
- return chars.join('');
905
- };
906
- var btoa = (window).btoa || function (b) {
907
- return b.replace(/[\s\S]{1,3}/g, cb_encode);
908
- };
909
-
910
-
911
- /***/ }),
912
- /* 11 */
913
- /***/ (function(module, exports, __webpack_require__) {
914
-
915
- "use strict";
916
- var timers_1 = __webpack_require__(12);
917
- var Util = {
918
- now: function () {
919
- if (Date.now) {
920
- return Date.now();
921
- }
922
- else {
923
- return new Date().valueOf();
924
- }
925
- },
926
- defer: function (callback) {
927
- return new timers_1.OneOffTimer(0, callback);
928
- },
929
- method: function (name) {
930
- var args = [];
931
- for (var _i = 1; _i < arguments.length; _i++) {
932
- args[_i - 1] = arguments[_i];
933
- }
934
- var boundArguments = Array.prototype.slice.call(arguments, 1);
935
- return function (object) {
936
- return object[name].apply(object, boundArguments.concat(arguments));
937
- };
938
- }
939
- };
940
- exports.__esModule = true;
941
- exports["default"] = Util;
942
-
943
-
944
- /***/ }),
945
- /* 12 */
946
- /***/ (function(module, exports, __webpack_require__) {
947
-
948
- "use strict";
949
- var __extends = (this && this.__extends) || function (d, b) {
950
- for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
951
- function __() { this.constructor = d; }
952
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
953
- };
954
- var abstract_timer_1 = __webpack_require__(13);
955
- function clearTimeout(timer) {
956
- (window).clearTimeout(timer);
957
- }
958
- function clearInterval(timer) {
959
- (window).clearInterval(timer);
960
- }
961
- var OneOffTimer = (function (_super) {
962
- __extends(OneOffTimer, _super);
963
- function OneOffTimer(delay, callback) {
964
- _super.call(this, setTimeout, clearTimeout, delay, function (timer) {
965
- callback();
966
- return null;
967
- });
968
- }
969
- return OneOffTimer;
970
- }(abstract_timer_1["default"]));
971
- exports.OneOffTimer = OneOffTimer;
972
- var PeriodicTimer = (function (_super) {
973
- __extends(PeriodicTimer, _super);
974
- function PeriodicTimer(delay, callback) {
975
- _super.call(this, setInterval, clearInterval, delay, function (timer) {
976
- callback();
977
- return timer;
978
- });
979
- }
980
- return PeriodicTimer;
981
- }(abstract_timer_1["default"]));
982
- exports.PeriodicTimer = PeriodicTimer;
983
-
984
-
985
- /***/ }),
986
- /* 13 */
987
- /***/ (function(module, exports) {
988
-
989
- "use strict";
990
- var Timer = (function () {
991
- function Timer(set, clear, delay, callback) {
992
- var _this = this;
993
- this.clear = clear;
994
- this.timer = set(function () {
995
- if (_this.timer) {
996
- _this.timer = callback(_this.timer);
997
- }
998
- }, delay);
999
- }
1000
- Timer.prototype.isRunning = function () {
1001
- return this.timer !== null;
1002
- };
1003
- Timer.prototype.ensureAborted = function () {
1004
- if (this.timer) {
1005
- this.clear(this.timer);
1006
- this.timer = null;
1007
- }
1008
- };
1009
- return Timer;
1010
- }());
1011
- exports.__esModule = true;
1012
- exports["default"] = Timer;
1013
-
1014
-
1015
- /***/ }),
1016
- /* 14 */
1017
- /***/ (function(module, exports) {
1018
-
1019
- "use strict";
1020
- var urlStore = {
1021
- baseUrl: "https://pusher.com",
1022
- urls: {
1023
- authenticationEndpoint: {
1024
- path: "/docs/authenticating_users"
1025
- },
1026
- javascriptQuickStart: {
1027
- path: "/docs/javascript_quick_start"
1028
- }
1029
- }
1030
- };
1031
- var buildLogSuffix = function (key) {
1032
- var urlPrefix = "See:";
1033
- var urlObj = urlStore.urls[key];
1034
- if (!urlObj)
1035
- return "";
1036
- var url;
1037
- if (urlObj.fullUrl) {
1038
- url = urlObj.fullUrl;
1039
- }
1040
- else if (urlObj.path) {
1041
- url = urlStore.baseUrl + urlObj.path;
1042
- }
1043
- if (!url)
1044
- return "";
1045
- return urlPrefix + " " + url;
1046
- };
1047
- exports.__esModule = true;
1048
- exports["default"] = { buildLogSuffix: buildLogSuffix };
1049
-
1050
-
1051
- /***/ }),
1052
- /* 15 */
1053
- /***/ (function(module, exports, __webpack_require__) {
1054
-
1055
- "use strict";
1056
- var logger_1 = __webpack_require__(8);
1057
- var jsonp = function (context, socketId, callback) {
1058
- if (this.authOptions.headers !== undefined) {
1059
- logger_1["default"].warn("Warn", "To send headers with the auth request, you must use AJAX, rather than JSONP.");
1060
- }
1061
- var callbackName = context.nextAuthCallbackID.toString();
1062
- context.nextAuthCallbackID++;
1063
- var document = context.getDocument();
1064
- var script = document.createElement("script");
1065
- context.auth_callbacks[callbackName] = function (data) {
1066
- callback(false, data);
1067
- };
1068
- var callback_name = "Pusher.auth_callbacks['" + callbackName + "']";
1069
- script.src = this.options.authEndpoint +
1070
- '?callback=' +
1071
- encodeURIComponent(callback_name) +
1072
- '&' +
1073
- this.composeQuery(socketId);
1074
- var head = document.getElementsByTagName("head")[0] || document.documentElement;
1075
- head.insertBefore(script, head.firstChild);
1076
- };
1077
- exports.__esModule = true;
1078
- exports["default"] = jsonp;
1079
-
1080
-
1081
- /***/ }),
1082
- /* 16 */
1083
- /***/ (function(module, exports) {
1084
-
1085
- "use strict";
1086
- var ScriptRequest = (function () {
1087
- function ScriptRequest(src) {
1088
- this.src = src;
1089
- }
1090
- ScriptRequest.prototype.send = function (receiver) {
1091
- var self = this;
1092
- var errorString = "Error loading " + self.src;
1093
- self.script = document.createElement("script");
1094
- self.script.id = receiver.id;
1095
- self.script.src = self.src;
1096
- self.script.type = "text/javascript";
1097
- self.script.charset = "UTF-8";
1098
- if (self.script.addEventListener) {
1099
- self.script.onerror = function () {
1100
- receiver.callback(errorString);
1101
- };
1102
- self.script.onload = function () {
1103
- receiver.callback(null);
1104
- };
1105
- }
1106
- else {
1107
- self.script.onreadystatechange = function () {
1108
- if (self.script.readyState === 'loaded' ||
1109
- self.script.readyState === 'complete') {
1110
- receiver.callback(null);
1111
- }
1112
- };
1113
- }
1114
- if (self.script.async === undefined && document.attachEvent &&
1115
- /opera/i.test(navigator.userAgent)) {
1116
- self.errorScript = document.createElement("script");
1117
- self.errorScript.id = receiver.id + "_error";
1118
- self.errorScript.text = receiver.name + "('" + errorString + "');";
1119
- self.script.async = self.errorScript.async = false;
1120
- }
1121
- else {
1122
- self.script.async = true;
1123
- }
1124
- var head = document.getElementsByTagName('head')[0];
1125
- head.insertBefore(self.script, head.firstChild);
1126
- if (self.errorScript) {
1127
- head.insertBefore(self.errorScript, self.script.nextSibling);
1128
- }
1129
- };
1130
- ScriptRequest.prototype.cleanup = function () {
1131
- if (this.script) {
1132
- this.script.onload = this.script.onerror = null;
1133
- this.script.onreadystatechange = null;
1134
- }
1135
- if (this.script && this.script.parentNode) {
1136
- this.script.parentNode.removeChild(this.script);
1137
- }
1138
- if (this.errorScript && this.errorScript.parentNode) {
1139
- this.errorScript.parentNode.removeChild(this.errorScript);
1140
- }
1141
- this.script = null;
1142
- this.errorScript = null;
1143
- };
1144
- return ScriptRequest;
1145
- }());
1146
- exports.__esModule = true;
1147
- exports["default"] = ScriptRequest;
1148
-
1149
-
1150
- /***/ }),
1151
- /* 17 */
1152
- /***/ (function(module, exports, __webpack_require__) {
1153
-
1154
- "use strict";
1155
- var Collections = __webpack_require__(9);
1156
- var runtime_1 = __webpack_require__(2);
1157
- var JSONPRequest = (function () {
1158
- function JSONPRequest(url, data) {
1159
- this.url = url;
1160
- this.data = data;
1161
- }
1162
- JSONPRequest.prototype.send = function (receiver) {
1163
- if (this.request) {
1164
- return;
1165
- }
1166
- var query = Collections.buildQueryString(this.data);
1167
- var url = this.url + "/" + receiver.number + "?" + query;
1168
- this.request = runtime_1["default"].createScriptRequest(url);
1169
- this.request.send(receiver);
1170
- };
1171
- JSONPRequest.prototype.cleanup = function () {
1172
- if (this.request) {
1173
- this.request.cleanup();
1174
- }
1175
- };
1176
- return JSONPRequest;
1177
- }());
1178
- exports.__esModule = true;
1179
- exports["default"] = JSONPRequest;
1180
-
1181
-
1182
- /***/ }),
1183
- /* 18 */
1184
- /***/ (function(module, exports, __webpack_require__) {
1185
-
1186
- "use strict";
1187
- var runtime_1 = __webpack_require__(2);
1188
- var script_receiver_factory_1 = __webpack_require__(4);
1189
- var getAgent = function (sender, encrypted) {
1190
- return function (data, callback) {
1191
- var scheme = "http" + (encrypted ? "s" : "") + "://";
1192
- var url = scheme + (sender.host || sender.options.host) + sender.options.path;
1193
- var request = runtime_1["default"].createJSONPRequest(url, data);
1194
- var receiver = runtime_1["default"].ScriptReceivers.create(function (error, result) {
1195
- script_receiver_factory_1.ScriptReceivers.remove(receiver);
1196
- request.cleanup();
1197
- if (result && result.host) {
1198
- sender.host = result.host;
1199
- }
1200
- if (callback) {
1201
- callback(error, result);
1202
- }
1203
- });
1204
- request.send(receiver);
1205
- };
1206
- };
1207
- var jsonp = {
1208
- name: 'jsonp',
1209
- getAgent: getAgent
1210
- };
1211
- exports.__esModule = true;
1212
- exports["default"] = jsonp;
1213
-
1214
-
1215
- /***/ }),
1216
- /* 19 */
1217
- /***/ (function(module, exports, __webpack_require__) {
1218
-
1219
- "use strict";
1220
- var transports_1 = __webpack_require__(20);
1221
- var transport_1 = __webpack_require__(22);
1222
- var URLSchemes = __webpack_require__(21);
1223
- var runtime_1 = __webpack_require__(2);
1224
- var dependencies_1 = __webpack_require__(3);
1225
- var Collections = __webpack_require__(9);
1226
- var SockJSTransport = new transport_1["default"]({
1227
- file: "sockjs",
1228
- urls: URLSchemes.sockjs,
1229
- handlesActivityChecks: true,
1230
- supportsPing: false,
1231
- isSupported: function () {
1232
- return true;
1233
- },
1234
- isInitialized: function () {
1235
- return window.SockJS !== undefined;
1236
- },
1237
- getSocket: function (url, options) {
1238
- return new window.SockJS(url, null, {
1239
- js_path: dependencies_1.Dependencies.getPath("sockjs", {
1240
- encrypted: options.encrypted
1241
- }),
1242
- ignore_null_origin: options.ignoreNullOrigin
1243
- });
1244
- },
1245
- beforeOpen: function (socket, path) {
1246
- socket.send(JSON.stringify({
1247
- path: path
1248
- }));
1249
- }
1250
- });
1251
- var xdrConfiguration = {
1252
- isSupported: function (environment) {
1253
- var yes = runtime_1["default"].isXDRSupported(environment.encrypted);
1254
- return yes;
1255
- }
1256
- };
1257
- var XDRStreamingTransport = new transport_1["default"](Collections.extend({}, transports_1.streamingConfiguration, xdrConfiguration));
1258
- var XDRPollingTransport = new transport_1["default"](Collections.extend({}, transports_1.pollingConfiguration, xdrConfiguration));
1259
- transports_1["default"].xdr_streaming = XDRStreamingTransport;
1260
- transports_1["default"].xdr_polling = XDRPollingTransport;
1261
- transports_1["default"].sockjs = SockJSTransport;
1262
- exports.__esModule = true;
1263
- exports["default"] = transports_1["default"];
1264
-
1265
-
1266
- /***/ }),
1267
- /* 20 */
1268
- /***/ (function(module, exports, __webpack_require__) {
1269
-
1270
- "use strict";
1271
- var URLSchemes = __webpack_require__(21);
1272
- var transport_1 = __webpack_require__(22);
1273
- var Collections = __webpack_require__(9);
1274
- var runtime_1 = __webpack_require__(2);
1275
- var WSTransport = new transport_1["default"]({
1276
- urls: URLSchemes.ws,
1277
- handlesActivityChecks: false,
1278
- supportsPing: false,
1279
- isInitialized: function () {
1280
- return Boolean(runtime_1["default"].getWebSocketAPI());
1281
- },
1282
- isSupported: function () {
1283
- return Boolean(runtime_1["default"].getWebSocketAPI());
1284
- },
1285
- getSocket: function (url) {
1286
- return runtime_1["default"].createWebSocket(url);
1287
- }
1288
- });
1289
- var httpConfiguration = {
1290
- urls: URLSchemes.http,
1291
- handlesActivityChecks: false,
1292
- supportsPing: true,
1293
- isInitialized: function () {
1294
- return true;
1295
- }
1296
- };
1297
- exports.streamingConfiguration = Collections.extend({ getSocket: function (url) {
1298
- return runtime_1["default"].HTTPFactory.createStreamingSocket(url);
1299
- }
1300
- }, httpConfiguration);
1301
- exports.pollingConfiguration = Collections.extend({ getSocket: function (url) {
1302
- return runtime_1["default"].HTTPFactory.createPollingSocket(url);
1303
- }
1304
- }, httpConfiguration);
1305
- var xhrConfiguration = {
1306
- isSupported: function () {
1307
- return runtime_1["default"].isXHRSupported();
1308
- }
1309
- };
1310
- var XHRStreamingTransport = new transport_1["default"](Collections.extend({}, exports.streamingConfiguration, xhrConfiguration));
1311
- var XHRPollingTransport = new transport_1["default"](Collections.extend({}, exports.pollingConfiguration, xhrConfiguration));
1312
- var Transports = {
1313
- ws: WSTransport,
1314
- xhr_streaming: XHRStreamingTransport,
1315
- xhr_polling: XHRPollingTransport
1316
- };
1317
- exports.__esModule = true;
1318
- exports["default"] = Transports;
1319
-
1320
-
1321
- /***/ }),
1322
- /* 21 */
1323
- /***/ (function(module, exports, __webpack_require__) {
1324
-
1325
- "use strict";
1326
- var defaults_1 = __webpack_require__(5);
1327
- function getGenericURL(baseScheme, params, path) {
1328
- var scheme = baseScheme + (params.encrypted ? "s" : "");
1329
- var host = params.encrypted ? params.hostEncrypted : params.hostUnencrypted;
1330
- return scheme + "://" + host + path;
1331
- }
1332
- function getGenericPath(key, queryString) {
1333
- var path = "/app/" + key;
1334
- var query = "?protocol=" + defaults_1["default"].PROTOCOL +
1335
- "&client=js" +
1336
- "&version=" + defaults_1["default"].VERSION +
1337
- (queryString ? ("&" + queryString) : "");
1338
- return path + query;
1339
- }
1340
- exports.ws = {
1341
- getInitial: function (key, params) {
1342
- return getGenericURL("ws", params, getGenericPath(key, "flash=false"));
1343
- }
1344
- };
1345
- exports.http = {
1346
- getInitial: function (key, params) {
1347
- var path = (params.httpPath || "/pusher") + getGenericPath(key);
1348
- return getGenericURL("http", params, path);
1349
- }
1350
- };
1351
- exports.sockjs = {
1352
- getInitial: function (key, params) {
1353
- return getGenericURL("http", params, params.httpPath || "/pusher");
1354
- },
1355
- getPath: function (key, params) {
1356
- return getGenericPath(key);
1357
- }
1358
- };
1359
-
1360
-
1361
- /***/ }),
1362
- /* 22 */
1363
- /***/ (function(module, exports, __webpack_require__) {
1364
-
1365
- "use strict";
1366
- var transport_connection_1 = __webpack_require__(23);
1367
- var Transport = (function () {
1368
- function Transport(hooks) {
1369
- this.hooks = hooks;
1370
- }
1371
- Transport.prototype.isSupported = function (environment) {
1372
- return this.hooks.isSupported(environment);
1373
- };
1374
- Transport.prototype.createConnection = function (name, priority, key, options) {
1375
- return new transport_connection_1["default"](this.hooks, name, priority, key, options);
1376
- };
1377
- return Transport;
1378
- }());
1379
- exports.__esModule = true;
1380
- exports["default"] = Transport;
1381
-
1382
-
1383
- /***/ }),
1384
- /* 23 */
1385
- /***/ (function(module, exports, __webpack_require__) {
1386
-
1387
- "use strict";
1388
- var __extends = (this && this.__extends) || function (d, b) {
1389
- for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
1390
- function __() { this.constructor = d; }
1391
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
1392
- };
1393
- var util_1 = __webpack_require__(11);
1394
- var Collections = __webpack_require__(9);
1395
- var dispatcher_1 = __webpack_require__(24);
1396
- var logger_1 = __webpack_require__(8);
1397
- var runtime_1 = __webpack_require__(2);
1398
- var TransportConnection = (function (_super) {
1399
- __extends(TransportConnection, _super);
1400
- function TransportConnection(hooks, name, priority, key, options) {
1401
- _super.call(this);
1402
- this.initialize = runtime_1["default"].transportConnectionInitializer;
1403
- this.hooks = hooks;
1404
- this.name = name;
1405
- this.priority = priority;
1406
- this.key = key;
1407
- this.options = options;
1408
- this.state = "new";
1409
- this.timeline = options.timeline;
1410
- this.activityTimeout = options.activityTimeout;
1411
- this.id = this.timeline.generateUniqueID();
1412
- }
1413
- TransportConnection.prototype.handlesActivityChecks = function () {
1414
- return Boolean(this.hooks.handlesActivityChecks);
1415
- };
1416
- TransportConnection.prototype.supportsPing = function () {
1417
- return Boolean(this.hooks.supportsPing);
1418
- };
1419
- TransportConnection.prototype.connect = function () {
1420
- var _this = this;
1421
- if (this.socket || this.state !== "initialized") {
1422
- return false;
1423
- }
1424
- var url = this.hooks.urls.getInitial(this.key, this.options);
1425
- try {
1426
- this.socket = this.hooks.getSocket(url, this.options);
1427
- }
1428
- catch (e) {
1429
- util_1["default"].defer(function () {
1430
- _this.onError(e);
1431
- _this.changeState("closed");
1432
- });
1433
- return false;
1434
- }
1435
- this.bindListeners();
1436
- logger_1["default"].debug("Connecting", { transport: this.name, url: url });
1437
- this.changeState("connecting");
1438
- return true;
1439
- };
1440
- TransportConnection.prototype.close = function () {
1441
- if (this.socket) {
1442
- this.socket.close();
1443
- return true;
1444
- }
1445
- else {
1446
- return false;
1447
- }
1448
- };
1449
- TransportConnection.prototype.send = function (data) {
1450
- var _this = this;
1451
- if (this.state === "open") {
1452
- util_1["default"].defer(function () {
1453
- if (_this.socket) {
1454
- _this.socket.send(data);
1455
- }
1456
- });
1457
- return true;
1458
- }
1459
- else {
1460
- return false;
1461
- }
1462
- };
1463
- TransportConnection.prototype.ping = function () {
1464
- if (this.state === "open" && this.supportsPing()) {
1465
- this.socket.ping();
1466
- }
1467
- };
1468
- TransportConnection.prototype.onOpen = function () {
1469
- if (this.hooks.beforeOpen) {
1470
- this.hooks.beforeOpen(this.socket, this.hooks.urls.getPath(this.key, this.options));
1471
- }
1472
- this.changeState("open");
1473
- this.socket.onopen = undefined;
1474
- };
1475
- TransportConnection.prototype.onError = function (error) {
1476
- this.emit("error", { type: 'WebSocketError', error: error });
1477
- this.timeline.error(this.buildTimelineMessage({ error: error.toString() }));
1478
- };
1479
- TransportConnection.prototype.onClose = function (closeEvent) {
1480
- if (closeEvent) {
1481
- this.changeState("closed", {
1482
- code: closeEvent.code,
1483
- reason: closeEvent.reason,
1484
- wasClean: closeEvent.wasClean
1485
- });
1486
- }
1487
- else {
1488
- this.changeState("closed");
1489
- }
1490
- this.unbindListeners();
1491
- this.socket = undefined;
1492
- };
1493
- TransportConnection.prototype.onMessage = function (message) {
1494
- this.emit("message", message);
1495
- };
1496
- TransportConnection.prototype.onActivity = function () {
1497
- this.emit("activity");
1498
- };
1499
- TransportConnection.prototype.bindListeners = function () {
1500
- var _this = this;
1501
- this.socket.onopen = function () {
1502
- _this.onOpen();
1503
- };
1504
- this.socket.onerror = function (error) {
1505
- _this.onError(error);
1506
- };
1507
- this.socket.onclose = function (closeEvent) {
1508
- _this.onClose(closeEvent);
1509
- };
1510
- this.socket.onmessage = function (message) {
1511
- _this.onMessage(message);
1512
- };
1513
- if (this.supportsPing()) {
1514
- this.socket.onactivity = function () { _this.onActivity(); };
1515
- }
1516
- };
1517
- TransportConnection.prototype.unbindListeners = function () {
1518
- if (this.socket) {
1519
- this.socket.onopen = undefined;
1520
- this.socket.onerror = undefined;
1521
- this.socket.onclose = undefined;
1522
- this.socket.onmessage = undefined;
1523
- if (this.supportsPing()) {
1524
- this.socket.onactivity = undefined;
1525
- }
1526
- }
1527
- };
1528
- TransportConnection.prototype.changeState = function (state, params) {
1529
- this.state = state;
1530
- this.timeline.info(this.buildTimelineMessage({
1531
- state: state,
1532
- params: params
1533
- }));
1534
- this.emit(state, params);
1535
- };
1536
- TransportConnection.prototype.buildTimelineMessage = function (message) {
1537
- return Collections.extend({ cid: this.id }, message);
1538
- };
1539
- return TransportConnection;
1540
- }(dispatcher_1["default"]));
1541
- exports.__esModule = true;
1542
- exports["default"] = TransportConnection;
1543
-
1544
-
1545
- /***/ }),
1546
- /* 24 */
1547
- /***/ (function(module, exports, __webpack_require__) {
1548
-
1549
- "use strict";
1550
- var Collections = __webpack_require__(9);
1551
- var callback_registry_1 = __webpack_require__(25);
1552
- var Dispatcher = (function () {
1553
- function Dispatcher(failThrough) {
1554
- this.callbacks = new callback_registry_1["default"]();
1555
- this.global_callbacks = [];
1556
- this.failThrough = failThrough;
1557
- }
1558
- Dispatcher.prototype.bind = function (eventName, callback, context) {
1559
- this.callbacks.add(eventName, callback, context);
1560
- return this;
1561
- };
1562
- Dispatcher.prototype.bind_global = function (callback) {
1563
- this.global_callbacks.push(callback);
1564
- return this;
1565
- };
1566
- Dispatcher.prototype.unbind = function (eventName, callback, context) {
1567
- this.callbacks.remove(eventName, callback, context);
1568
- return this;
1569
- };
1570
- Dispatcher.prototype.unbind_global = function (callback) {
1571
- if (!callback) {
1572
- this.global_callbacks = [];
1573
- return this;
1574
- }
1575
- this.global_callbacks = Collections.filter(this.global_callbacks || [], function (c) { return c !== callback; });
1576
- return this;
1577
- };
1578
- Dispatcher.prototype.unbind_all = function () {
1579
- this.unbind();
1580
- this.unbind_global();
1581
- return this;
1582
- };
1583
- Dispatcher.prototype.emit = function (eventName, data) {
1584
- var i;
1585
- for (i = 0; i < this.global_callbacks.length; i++) {
1586
- this.global_callbacks[i](eventName, data);
1587
- }
1588
- var callbacks = this.callbacks.get(eventName);
1589
- if (callbacks && callbacks.length > 0) {
1590
- for (i = 0; i < callbacks.length; i++) {
1591
- callbacks[i].fn.call(callbacks[i].context || (window), data);
1592
- }
1593
- }
1594
- else if (this.failThrough) {
1595
- this.failThrough(eventName, data);
1596
- }
1597
- return this;
1598
- };
1599
- return Dispatcher;
1600
- }());
1601
- exports.__esModule = true;
1602
- exports["default"] = Dispatcher;
1603
-
1604
-
1605
- /***/ }),
1606
- /* 25 */
1607
- /***/ (function(module, exports, __webpack_require__) {
1608
-
1609
- "use strict";
1610
- var Collections = __webpack_require__(9);
1611
- var CallbackRegistry = (function () {
1612
- function CallbackRegistry() {
1613
- this._callbacks = {};
1614
- }
1615
- CallbackRegistry.prototype.get = function (name) {
1616
- return this._callbacks[prefix(name)];
1617
- };
1618
- CallbackRegistry.prototype.add = function (name, callback, context) {
1619
- var prefixedEventName = prefix(name);
1620
- this._callbacks[prefixedEventName] = this._callbacks[prefixedEventName] || [];
1621
- this._callbacks[prefixedEventName].push({
1622
- fn: callback,
1623
- context: context
1624
- });
1625
- };
1626
- CallbackRegistry.prototype.remove = function (name, callback, context) {
1627
- if (!name && !callback && !context) {
1628
- this._callbacks = {};
1629
- return;
1630
- }
1631
- var names = name ? [prefix(name)] : Collections.keys(this._callbacks);
1632
- if (callback || context) {
1633
- this.removeCallback(names, callback, context);
1634
- }
1635
- else {
1636
- this.removeAllCallbacks(names);
1637
- }
1638
- };
1639
- CallbackRegistry.prototype.removeCallback = function (names, callback, context) {
1640
- Collections.apply(names, function (name) {
1641
- this._callbacks[name] = Collections.filter(this._callbacks[name] || [], function (binding) {
1642
- return (callback && callback !== binding.fn) ||
1643
- (context && context !== binding.context);
1644
- });
1645
- if (this._callbacks[name].length === 0) {
1646
- delete this._callbacks[name];
1647
- }
1648
- }, this);
1649
- };
1650
- CallbackRegistry.prototype.removeAllCallbacks = function (names) {
1651
- Collections.apply(names, function (name) {
1652
- delete this._callbacks[name];
1653
- }, this);
1654
- };
1655
- return CallbackRegistry;
1656
- }());
1657
- exports.__esModule = true;
1658
- exports["default"] = CallbackRegistry;
1659
- function prefix(name) {
1660
- return "_" + name;
1661
- }
1662
-
1663
-
1664
- /***/ }),
1665
- /* 26 */
1666
- /***/ (function(module, exports, __webpack_require__) {
1667
-
1668
- "use strict";
1669
- var __extends = (this && this.__extends) || function (d, b) {
1670
- for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
1671
- function __() { this.constructor = d; }
1672
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
1673
- };
1674
- var dispatcher_1 = __webpack_require__(24);
1675
- var NetInfo = (function (_super) {
1676
- __extends(NetInfo, _super);
1677
- function NetInfo() {
1678
- _super.call(this);
1679
- var self = this;
1680
- if (window.addEventListener !== undefined) {
1681
- window.addEventListener("online", function () {
1682
- self.emit('online');
1683
- }, false);
1684
- window.addEventListener("offline", function () {
1685
- self.emit('offline');
1686
- }, false);
1687
- }
1688
- }
1689
- NetInfo.prototype.isOnline = function () {
1690
- if (window.navigator.onLine === undefined) {
1691
- return true;
1692
- }
1693
- else {
1694
- return window.navigator.onLine;
1695
- }
1696
- };
1697
- return NetInfo;
1698
- }(dispatcher_1["default"]));
1699
- exports.NetInfo = NetInfo;
1700
- exports.Network = new NetInfo();
1701
-
1702
-
1703
- /***/ }),
1704
- /* 27 */
1705
- /***/ (function(module, exports) {
1706
-
1707
- "use strict";
1708
- var getDefaultStrategy = function (config) {
1709
- var wsStrategy;
1710
- if (config.encrypted) {
1711
- wsStrategy = [
1712
- ":best_connected_ever",
1713
- ":ws_loop",
1714
- [":delayed", 2000, [":http_fallback_loop"]]
1715
- ];
1716
- }
1717
- else {
1718
- wsStrategy = [
1719
- ":best_connected_ever",
1720
- ":ws_loop",
1721
- [":delayed", 2000, [":wss_loop"]],
1722
- [":delayed", 5000, [":http_fallback_loop"]]
1723
- ];
1724
- }
1725
- return [
1726
- [":def", "ws_options", {
1727
- hostUnencrypted: config.wsHost + ":" + config.wsPort,
1728
- hostEncrypted: config.wsHost + ":" + config.wssPort
1729
- }],
1730
- [":def", "wss_options", [":extend", ":ws_options", {
1731
- encrypted: true
1732
- }]],
1733
- [":def", "sockjs_options", {
1734
- hostUnencrypted: config.httpHost + ":" + config.httpPort,
1735
- hostEncrypted: config.httpHost + ":" + config.httpsPort,
1736
- httpPath: config.httpPath
1737
- }],
1738
- [":def", "timeouts", {
1739
- loop: true,
1740
- timeout: 15000,
1741
- timeoutLimit: 60000
1742
- }],
1743
- [":def", "ws_manager", [":transport_manager", {
1744
- lives: 2,
1745
- minPingDelay: 10000,
1746
- maxPingDelay: config.activity_timeout
1747
- }]],
1748
- [":def", "streaming_manager", [":transport_manager", {
1749
- lives: 2,
1750
- minPingDelay: 10000,
1751
- maxPingDelay: config.activity_timeout
1752
- }]],
1753
- [":def_transport", "ws", "ws", 3, ":ws_options", ":ws_manager"],
1754
- [":def_transport", "wss", "ws", 3, ":wss_options", ":ws_manager"],
1755
- [":def_transport", "sockjs", "sockjs", 1, ":sockjs_options"],
1756
- [":def_transport", "xhr_streaming", "xhr_streaming", 1, ":sockjs_options", ":streaming_manager"],
1757
- [":def_transport", "xdr_streaming", "xdr_streaming", 1, ":sockjs_options", ":streaming_manager"],
1758
- [":def_transport", "xhr_polling", "xhr_polling", 1, ":sockjs_options"],
1759
- [":def_transport", "xdr_polling", "xdr_polling", 1, ":sockjs_options"],
1760
- [":def", "ws_loop", [":sequential", ":timeouts", ":ws"]],
1761
- [":def", "wss_loop", [":sequential", ":timeouts", ":wss"]],
1762
- [":def", "sockjs_loop", [":sequential", ":timeouts", ":sockjs"]],
1763
- [":def", "streaming_loop", [":sequential", ":timeouts",
1764
- [":if", [":is_supported", ":xhr_streaming"],
1765
- ":xhr_streaming",
1766
- ":xdr_streaming"
1767
- ]
1768
- ]],
1769
- [":def", "polling_loop", [":sequential", ":timeouts",
1770
- [":if", [":is_supported", ":xhr_polling"],
1771
- ":xhr_polling",
1772
- ":xdr_polling"
1773
- ]
1774
- ]],
1775
- [":def", "http_loop", [":if", [":is_supported", ":streaming_loop"], [
1776
- ":best_connected_ever",
1777
- ":streaming_loop",
1778
- [":delayed", 4000, [":polling_loop"]]
1779
- ], [
1780
- ":polling_loop"
1781
- ]]],
1782
- [":def", "http_fallback_loop",
1783
- [":if", [":is_supported", ":http_loop"], [
1784
- ":http_loop"
1785
- ], [
1786
- ":sockjs_loop"
1787
- ]]
1788
- ],
1789
- [":def", "strategy",
1790
- [":cached", 1800000,
1791
- [":first_connected",
1792
- [":if", [":is_supported", ":ws"],
1793
- wsStrategy,
1794
- ":http_fallback_loop"
1795
- ]
1796
- ]
1797
- ]
1798
- ]
1799
- ];
1800
- };
1801
- exports.__esModule = true;
1802
- exports["default"] = getDefaultStrategy;
1803
-
1804
-
1805
- /***/ }),
1806
- /* 28 */
1807
- /***/ (function(module, exports, __webpack_require__) {
1808
-
1809
- "use strict";
1810
- var dependencies_1 = __webpack_require__(3);
1811
- function default_1() {
1812
- var self = this;
1813
- self.timeline.info(self.buildTimelineMessage({
1814
- transport: self.name + (self.options.encrypted ? "s" : "")
1815
- }));
1816
- if (self.hooks.isInitialized()) {
1817
- self.changeState("initialized");
1818
- }
1819
- else if (self.hooks.file) {
1820
- self.changeState("initializing");
1821
- dependencies_1.Dependencies.load(self.hooks.file, { encrypted: self.options.encrypted }, function (error, callback) {
1822
- if (self.hooks.isInitialized()) {
1823
- self.changeState("initialized");
1824
- callback(true);
1825
- }
1826
- else {
1827
- if (error) {
1828
- self.onError(error);
1829
- }
1830
- self.onClose();
1831
- callback(false);
1832
- }
1833
- });
1834
- }
1835
- else {
1836
- self.onClose();
1837
- }
1838
- }
1839
- exports.__esModule = true;
1840
- exports["default"] = default_1;
1841
-
1842
-
1843
- /***/ }),
1844
- /* 29 */
1845
- /***/ (function(module, exports, __webpack_require__) {
1846
-
1847
- "use strict";
1848
- var http_xdomain_request_1 = __webpack_require__(30);
1849
- var http_1 = __webpack_require__(32);
1850
- http_1["default"].createXDR = function (method, url) {
1851
- return this.createRequest(http_xdomain_request_1["default"], method, url);
1852
- };
1853
- exports.__esModule = true;
1854
- exports["default"] = http_1["default"];
1855
-
1856
-
1857
- /***/ }),
1858
- /* 30 */
1859
- /***/ (function(module, exports, __webpack_require__) {
1860
-
1861
- "use strict";
1862
- var Errors = __webpack_require__(31);
1863
- var hooks = {
1864
- getRequest: function (socket) {
1865
- var xdr = new window.XDomainRequest();
1866
- xdr.ontimeout = function () {
1867
- socket.emit("error", new Errors.RequestTimedOut());
1868
- socket.close();
1869
- };
1870
- xdr.onerror = function (e) {
1871
- socket.emit("error", e);
1872
- socket.close();
1873
- };
1874
- xdr.onprogress = function () {
1875
- if (xdr.responseText && xdr.responseText.length > 0) {
1876
- socket.onChunk(200, xdr.responseText);
1877
- }
1878
- };
1879
- xdr.onload = function () {
1880
- if (xdr.responseText && xdr.responseText.length > 0) {
1881
- socket.onChunk(200, xdr.responseText);
1882
- }
1883
- socket.emit("finished", 200);
1884
- socket.close();
1885
- };
1886
- return xdr;
1887
- },
1888
- abortRequest: function (xdr) {
1889
- xdr.ontimeout = xdr.onerror = xdr.onprogress = xdr.onload = null;
1890
- xdr.abort();
1891
- }
1892
- };
1893
- exports.__esModule = true;
1894
- exports["default"] = hooks;
1895
-
1896
-
1897
- /***/ }),
1898
- /* 31 */
1899
- /***/ (function(module, exports) {
1900
-
1901
- "use strict";
1902
- var __extends = (this && this.__extends) || function (d, b) {
1903
- for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
1904
- function __() { this.constructor = d; }
1905
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
1906
- };
1907
- var BadEventName = (function (_super) {
1908
- __extends(BadEventName, _super);
1909
- function BadEventName() {
1910
- _super.apply(this, arguments);
1911
- }
1912
- return BadEventName;
1913
- }(Error));
1914
- exports.BadEventName = BadEventName;
1915
- var RequestTimedOut = (function (_super) {
1916
- __extends(RequestTimedOut, _super);
1917
- function RequestTimedOut() {
1918
- _super.apply(this, arguments);
1919
- }
1920
- return RequestTimedOut;
1921
- }(Error));
1922
- exports.RequestTimedOut = RequestTimedOut;
1923
- var TransportPriorityTooLow = (function (_super) {
1924
- __extends(TransportPriorityTooLow, _super);
1925
- function TransportPriorityTooLow() {
1926
- _super.apply(this, arguments);
1927
- }
1928
- return TransportPriorityTooLow;
1929
- }(Error));
1930
- exports.TransportPriorityTooLow = TransportPriorityTooLow;
1931
- var TransportClosed = (function (_super) {
1932
- __extends(TransportClosed, _super);
1933
- function TransportClosed() {
1934
- _super.apply(this, arguments);
1935
- }
1936
- return TransportClosed;
1937
- }(Error));
1938
- exports.TransportClosed = TransportClosed;
1939
- var UnsupportedTransport = (function (_super) {
1940
- __extends(UnsupportedTransport, _super);
1941
- function UnsupportedTransport() {
1942
- _super.apply(this, arguments);
1943
- }
1944
- return UnsupportedTransport;
1945
- }(Error));
1946
- exports.UnsupportedTransport = UnsupportedTransport;
1947
- var UnsupportedStrategy = (function (_super) {
1948
- __extends(UnsupportedStrategy, _super);
1949
- function UnsupportedStrategy() {
1950
- _super.apply(this, arguments);
1951
- }
1952
- return UnsupportedStrategy;
1953
- }(Error));
1954
- exports.UnsupportedStrategy = UnsupportedStrategy;
1955
-
1956
-
1957
- /***/ }),
1958
- /* 32 */
1959
- /***/ (function(module, exports, __webpack_require__) {
1960
-
1961
- "use strict";
1962
- var http_request_1 = __webpack_require__(33);
1963
- var http_socket_1 = __webpack_require__(34);
1964
- var http_streaming_socket_1 = __webpack_require__(36);
1965
- var http_polling_socket_1 = __webpack_require__(37);
1966
- var http_xhr_request_1 = __webpack_require__(38);
1967
- var HTTP = {
1968
- createStreamingSocket: function (url) {
1969
- return this.createSocket(http_streaming_socket_1["default"], url);
1970
- },
1971
- createPollingSocket: function (url) {
1972
- return this.createSocket(http_polling_socket_1["default"], url);
1973
- },
1974
- createSocket: function (hooks, url) {
1975
- return new http_socket_1["default"](hooks, url);
1976
- },
1977
- createXHR: function (method, url) {
1978
- return this.createRequest(http_xhr_request_1["default"], method, url);
1979
- },
1980
- createRequest: function (hooks, method, url) {
1981
- return new http_request_1["default"](hooks, method, url);
1982
- }
1983
- };
1984
- exports.__esModule = true;
1985
- exports["default"] = HTTP;
1986
-
1987
-
1988
- /***/ }),
1989
- /* 33 */
1990
- /***/ (function(module, exports, __webpack_require__) {
1991
-
1992
- "use strict";
1993
- var __extends = (this && this.__extends) || function (d, b) {
1994
- for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
1995
- function __() { this.constructor = d; }
1996
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
1997
- };
1998
- var runtime_1 = __webpack_require__(2);
1999
- var dispatcher_1 = __webpack_require__(24);
2000
- var MAX_BUFFER_LENGTH = 256 * 1024;
2001
- var HTTPRequest = (function (_super) {
2002
- __extends(HTTPRequest, _super);
2003
- function HTTPRequest(hooks, method, url) {
2004
- _super.call(this);
2005
- this.hooks = hooks;
2006
- this.method = method;
2007
- this.url = url;
2008
- }
2009
- HTTPRequest.prototype.start = function (payload) {
2010
- var _this = this;
2011
- this.position = 0;
2012
- this.xhr = this.hooks.getRequest(this);
2013
- this.unloader = function () {
2014
- _this.close();
2015
- };
2016
- runtime_1["default"].addUnloadListener(this.unloader);
2017
- this.xhr.open(this.method, this.url, true);
2018
- if (this.xhr.setRequestHeader) {
2019
- this.xhr.setRequestHeader("Content-Type", "application/json");
2020
- }
2021
- this.xhr.send(payload);
2022
- };
2023
- HTTPRequest.prototype.close = function () {
2024
- if (this.unloader) {
2025
- runtime_1["default"].removeUnloadListener(this.unloader);
2026
- this.unloader = null;
2027
- }
2028
- if (this.xhr) {
2029
- this.hooks.abortRequest(this.xhr);
2030
- this.xhr = null;
2031
- }
2032
- };
2033
- HTTPRequest.prototype.onChunk = function (status, data) {
2034
- while (true) {
2035
- var chunk = this.advanceBuffer(data);
2036
- if (chunk) {
2037
- this.emit("chunk", { status: status, data: chunk });
2038
- }
2039
- else {
2040
- break;
2041
- }
2042
- }
2043
- if (this.isBufferTooLong(data)) {
2044
- this.emit("buffer_too_long");
2045
- }
2046
- };
2047
- HTTPRequest.prototype.advanceBuffer = function (buffer) {
2048
- var unreadData = buffer.slice(this.position);
2049
- var endOfLinePosition = unreadData.indexOf("\n");
2050
- if (endOfLinePosition !== -1) {
2051
- this.position += endOfLinePosition + 1;
2052
- return unreadData.slice(0, endOfLinePosition);
2053
- }
2054
- else {
2055
- return null;
2056
- }
2057
- };
2058
- HTTPRequest.prototype.isBufferTooLong = function (buffer) {
2059
- return this.position === buffer.length && buffer.length > MAX_BUFFER_LENGTH;
2060
- };
2061
- return HTTPRequest;
2062
- }(dispatcher_1["default"]));
2063
- exports.__esModule = true;
2064
- exports["default"] = HTTPRequest;
2065
-
2066
-
2067
- /***/ }),
2068
- /* 34 */
2069
- /***/ (function(module, exports, __webpack_require__) {
2070
-
2071
- "use strict";
2072
- var state_1 = __webpack_require__(35);
2073
- var util_1 = __webpack_require__(11);
2074
- var runtime_1 = __webpack_require__(2);
2075
- var autoIncrement = 1;
2076
- var HTTPSocket = (function () {
2077
- function HTTPSocket(hooks, url) {
2078
- this.hooks = hooks;
2079
- this.session = randomNumber(1000) + "/" + randomString(8);
2080
- this.location = getLocation(url);
2081
- this.readyState = state_1["default"].CONNECTING;
2082
- this.openStream();
2083
- }
2084
- HTTPSocket.prototype.send = function (payload) {
2085
- return this.sendRaw(JSON.stringify([payload]));
2086
- };
2087
- HTTPSocket.prototype.ping = function () {
2088
- this.hooks.sendHeartbeat(this);
2089
- };
2090
- HTTPSocket.prototype.close = function (code, reason) {
2091
- this.onClose(code, reason, true);
2092
- };
2093
- HTTPSocket.prototype.sendRaw = function (payload) {
2094
- if (this.readyState === state_1["default"].OPEN) {
2095
- try {
2096
- runtime_1["default"].createSocketRequest("POST", getUniqueURL(getSendURL(this.location, this.session))).start(payload);
2097
- return true;
2098
- }
2099
- catch (e) {
2100
- return false;
2101
- }
2102
- }
2103
- else {
2104
- return false;
2105
- }
2106
- };
2107
- HTTPSocket.prototype.reconnect = function () {
2108
- this.closeStream();
2109
- this.openStream();
2110
- };
2111
- ;
2112
- HTTPSocket.prototype.onClose = function (code, reason, wasClean) {
2113
- this.closeStream();
2114
- this.readyState = state_1["default"].CLOSED;
2115
- if (this.onclose) {
2116
- this.onclose({
2117
- code: code,
2118
- reason: reason,
2119
- wasClean: wasClean
2120
- });
2121
- }
2122
- };
2123
- HTTPSocket.prototype.onChunk = function (chunk) {
2124
- if (chunk.status !== 200) {
2125
- return;
2126
- }
2127
- if (this.readyState === state_1["default"].OPEN) {
2128
- this.onActivity();
2129
- }
2130
- var payload;
2131
- var type = chunk.data.slice(0, 1);
2132
- switch (type) {
2133
- case 'o':
2134
- payload = JSON.parse(chunk.data.slice(1) || '{}');
2135
- this.onOpen(payload);
2136
- break;
2137
- case 'a':
2138
- payload = JSON.parse(chunk.data.slice(1) || '[]');
2139
- for (var i = 0; i < payload.length; i++) {
2140
- this.onEvent(payload[i]);
2141
- }
2142
- break;
2143
- case 'm':
2144
- payload = JSON.parse(chunk.data.slice(1) || 'null');
2145
- this.onEvent(payload);
2146
- break;
2147
- case 'h':
2148
- this.hooks.onHeartbeat(this);
2149
- break;
2150
- case 'c':
2151
- payload = JSON.parse(chunk.data.slice(1) || '[]');
2152
- this.onClose(payload[0], payload[1], true);
2153
- break;
2154
- }
2155
- };
2156
- HTTPSocket.prototype.onOpen = function (options) {
2157
- if (this.readyState === state_1["default"].CONNECTING) {
2158
- if (options && options.hostname) {
2159
- this.location.base = replaceHost(this.location.base, options.hostname);
2160
- }
2161
- this.readyState = state_1["default"].OPEN;
2162
- if (this.onopen) {
2163
- this.onopen();
2164
- }
2165
- }
2166
- else {
2167
- this.onClose(1006, "Server lost session", true);
2168
- }
2169
- };
2170
- HTTPSocket.prototype.onEvent = function (event) {
2171
- if (this.readyState === state_1["default"].OPEN && this.onmessage) {
2172
- this.onmessage({ data: event });
2173
- }
2174
- };
2175
- HTTPSocket.prototype.onActivity = function () {
2176
- if (this.onactivity) {
2177
- this.onactivity();
2178
- }
2179
- };
2180
- HTTPSocket.prototype.onError = function (error) {
2181
- if (this.onerror) {
2182
- this.onerror(error);
2183
- }
2184
- };
2185
- HTTPSocket.prototype.openStream = function () {
2186
- var _this = this;
2187
- this.stream = runtime_1["default"].createSocketRequest("POST", getUniqueURL(this.hooks.getReceiveURL(this.location, this.session)));
2188
- this.stream.bind("chunk", function (chunk) {
2189
- _this.onChunk(chunk);
2190
- });
2191
- this.stream.bind("finished", function (status) {
2192
- _this.hooks.onFinished(_this, status);
2193
- });
2194
- this.stream.bind("buffer_too_long", function () {
2195
- _this.reconnect();
2196
- });
2197
- try {
2198
- this.stream.start();
2199
- }
2200
- catch (error) {
2201
- util_1["default"].defer(function () {
2202
- _this.onError(error);
2203
- _this.onClose(1006, "Could not start streaming", false);
2204
- });
2205
- }
2206
- };
2207
- HTTPSocket.prototype.closeStream = function () {
2208
- if (this.stream) {
2209
- this.stream.unbind_all();
2210
- this.stream.close();
2211
- this.stream = null;
2212
- }
2213
- };
2214
- return HTTPSocket;
2215
- }());
2216
- function getLocation(url) {
2217
- var parts = /([^\?]*)\/*(\??.*)/.exec(url);
2218
- return {
2219
- base: parts[1],
2220
- queryString: parts[2]
2221
- };
2222
- }
2223
- function getSendURL(url, session) {
2224
- return url.base + "/" + session + "/xhr_send";
2225
- }
2226
- function getUniqueURL(url) {
2227
- var separator = (url.indexOf('?') === -1) ? "?" : "&";
2228
- return url + separator + "t=" + (+new Date()) + "&n=" + autoIncrement++;
2229
- }
2230
- function replaceHost(url, hostname) {
2231
- var urlParts = /(https?:\/\/)([^\/:]+)((\/|:)?.*)/.exec(url);
2232
- return urlParts[1] + hostname + urlParts[3];
2233
- }
2234
- function randomNumber(max) {
2235
- return Math.floor(Math.random() * max);
2236
- }
2237
- function randomString(length) {
2238
- var result = [];
2239
- for (var i = 0; i < length; i++) {
2240
- result.push(randomNumber(32).toString(32));
2241
- }
2242
- return result.join('');
2243
- }
2244
- exports.__esModule = true;
2245
- exports["default"] = HTTPSocket;
2246
-
2247
-
2248
- /***/ }),
2249
- /* 35 */
2250
- /***/ (function(module, exports) {
2251
-
2252
- "use strict";
2253
- var State;
2254
- (function (State) {
2255
- State[State["CONNECTING"] = 0] = "CONNECTING";
2256
- State[State["OPEN"] = 1] = "OPEN";
2257
- State[State["CLOSED"] = 3] = "CLOSED";
2258
- })(State || (State = {}));
2259
- exports.__esModule = true;
2260
- exports["default"] = State;
2261
-
2262
-
2263
- /***/ }),
2264
- /* 36 */
2265
- /***/ (function(module, exports) {
2266
-
2267
- "use strict";
2268
- var hooks = {
2269
- getReceiveURL: function (url, session) {
2270
- return url.base + "/" + session + "/xhr_streaming" + url.queryString;
2271
- },
2272
- onHeartbeat: function (socket) {
2273
- socket.sendRaw("[]");
2274
- },
2275
- sendHeartbeat: function (socket) {
2276
- socket.sendRaw("[]");
2277
- },
2278
- onFinished: function (socket, status) {
2279
- socket.onClose(1006, "Connection interrupted (" + status + ")", false);
2280
- }
2281
- };
2282
- exports.__esModule = true;
2283
- exports["default"] = hooks;
2284
-
2285
-
2286
- /***/ }),
2287
- /* 37 */
2288
- /***/ (function(module, exports) {
2289
-
2290
- "use strict";
2291
- var hooks = {
2292
- getReceiveURL: function (url, session) {
2293
- return url.base + "/" + session + "/xhr" + url.queryString;
2294
- },
2295
- onHeartbeat: function () {
2296
- },
2297
- sendHeartbeat: function (socket) {
2298
- socket.sendRaw("[]");
2299
- },
2300
- onFinished: function (socket, status) {
2301
- if (status === 200) {
2302
- socket.reconnect();
2303
- }
2304
- else {
2305
- socket.onClose(1006, "Connection interrupted (" + status + ")", false);
2306
- }
2307
- }
2308
- };
2309
- exports.__esModule = true;
2310
- exports["default"] = hooks;
2311
-
2312
-
2313
- /***/ }),
2314
- /* 38 */
2315
- /***/ (function(module, exports, __webpack_require__) {
2316
-
2317
- "use strict";
2318
- var runtime_1 = __webpack_require__(2);
2319
- var hooks = {
2320
- getRequest: function (socket) {
2321
- var Constructor = runtime_1["default"].getXHRAPI();
2322
- var xhr = new Constructor();
2323
- xhr.onreadystatechange = xhr.onprogress = function () {
2324
- switch (xhr.readyState) {
2325
- case 3:
2326
- if (xhr.responseText && xhr.responseText.length > 0) {
2327
- socket.onChunk(xhr.status, xhr.responseText);
2328
- }
2329
- break;
2330
- case 4:
2331
- if (xhr.responseText && xhr.responseText.length > 0) {
2332
- socket.onChunk(xhr.status, xhr.responseText);
2333
- }
2334
- socket.emit("finished", xhr.status);
2335
- socket.close();
2336
- break;
2337
- }
2338
- };
2339
- return xhr;
2340
- },
2341
- abortRequest: function (xhr) {
2342
- xhr.onreadystatechange = null;
2343
- xhr.abort();
2344
- }
2345
- };
2346
- exports.__esModule = true;
2347
- exports["default"] = hooks;
2348
-
2349
-
2350
- /***/ }),
2351
- /* 39 */
2352
- /***/ (function(module, exports, __webpack_require__) {
2353
-
2354
- "use strict";
2355
- var Collections = __webpack_require__(9);
2356
- var util_1 = __webpack_require__(11);
2357
- var level_1 = __webpack_require__(40);
2358
- var Timeline = (function () {
2359
- function Timeline(key, session, options) {
2360
- this.key = key;
2361
- this.session = session;
2362
- this.events = [];
2363
- this.options = options || {};
2364
- this.sent = 0;
2365
- this.uniqueID = 0;
2366
- }
2367
- Timeline.prototype.log = function (level, event) {
2368
- if (level <= this.options.level) {
2369
- this.events.push(Collections.extend({}, event, { timestamp: util_1["default"].now() }));
2370
- if (this.options.limit && this.events.length > this.options.limit) {
2371
- this.events.shift();
2372
- }
2373
- }
2374
- };
2375
- Timeline.prototype.error = function (event) {
2376
- this.log(level_1["default"].ERROR, event);
2377
- };
2378
- Timeline.prototype.info = function (event) {
2379
- this.log(level_1["default"].INFO, event);
2380
- };
2381
- Timeline.prototype.debug = function (event) {
2382
- this.log(level_1["default"].DEBUG, event);
2383
- };
2384
- Timeline.prototype.isEmpty = function () {
2385
- return this.events.length === 0;
2386
- };
2387
- Timeline.prototype.send = function (sendfn, callback) {
2388
- var _this = this;
2389
- var data = Collections.extend({
2390
- session: this.session,
2391
- bundle: this.sent + 1,
2392
- key: this.key,
2393
- lib: "js",
2394
- version: this.options.version,
2395
- cluster: this.options.cluster,
2396
- features: this.options.features,
2397
- timeline: this.events
2398
- }, this.options.params);
2399
- this.events = [];
2400
- sendfn(data, function (error, result) {
2401
- if (!error) {
2402
- _this.sent++;
2403
- }
2404
- if (callback) {
2405
- callback(error, result);
2406
- }
2407
- });
2408
- return true;
2409
- };
2410
- Timeline.prototype.generateUniqueID = function () {
2411
- this.uniqueID++;
2412
- return this.uniqueID;
2413
- };
2414
- return Timeline;
2415
- }());
2416
- exports.__esModule = true;
2417
- exports["default"] = Timeline;
2418
-
2419
-
2420
- /***/ }),
2421
- /* 40 */
2422
- /***/ (function(module, exports) {
2423
-
2424
- "use strict";
2425
- var TimelineLevel;
2426
- (function (TimelineLevel) {
2427
- TimelineLevel[TimelineLevel["ERROR"] = 3] = "ERROR";
2428
- TimelineLevel[TimelineLevel["INFO"] = 6] = "INFO";
2429
- TimelineLevel[TimelineLevel["DEBUG"] = 7] = "DEBUG";
2430
- })(TimelineLevel || (TimelineLevel = {}));
2431
- exports.__esModule = true;
2432
- exports["default"] = TimelineLevel;
2433
-
2434
-
2435
- /***/ }),
2436
- /* 41 */
2437
- /***/ (function(module, exports, __webpack_require__) {
2438
-
2439
- "use strict";
2440
- var Collections = __webpack_require__(9);
2441
- var util_1 = __webpack_require__(11);
2442
- var transport_manager_1 = __webpack_require__(42);
2443
- var Errors = __webpack_require__(31);
2444
- var transport_strategy_1 = __webpack_require__(56);
2445
- var sequential_strategy_1 = __webpack_require__(57);
2446
- var best_connected_ever_strategy_1 = __webpack_require__(58);
2447
- var cached_strategy_1 = __webpack_require__(59);
2448
- var delayed_strategy_1 = __webpack_require__(60);
2449
- var if_strategy_1 = __webpack_require__(61);
2450
- var first_connected_strategy_1 = __webpack_require__(62);
2451
- var runtime_1 = __webpack_require__(2);
2452
- var Transports = runtime_1["default"].Transports;
2453
- exports.build = function (scheme, options) {
2454
- var context = Collections.extend({}, globalContext, options);
2455
- return evaluate(scheme, context)[1].strategy;
2456
- };
2457
- var UnsupportedStrategy = {
2458
- isSupported: function () {
2459
- return false;
2460
- },
2461
- connect: function (_, callback) {
2462
- var deferred = util_1["default"].defer(function () {
2463
- callback(new Errors.UnsupportedStrategy());
2464
- });
2465
- return {
2466
- abort: function () {
2467
- deferred.ensureAborted();
2468
- },
2469
- forceMinPriority: function () { }
2470
- };
2471
- }
2472
- };
2473
- function returnWithOriginalContext(f) {
2474
- return function (context) {
2475
- return [f.apply(this, arguments), context];
2476
- };
2477
- }
2478
- var globalContext = {
2479
- extend: function (context, first, second) {
2480
- return [Collections.extend({}, first, second), context];
2481
- },
2482
- def: function (context, name, value) {
2483
- if (context[name] !== undefined) {
2484
- throw "Redefining symbol " + name;
2485
- }
2486
- context[name] = value;
2487
- return [undefined, context];
2488
- },
2489
- def_transport: function (context, name, type, priority, options, manager) {
2490
- var transportClass = Transports[type];
2491
- if (!transportClass) {
2492
- throw new Errors.UnsupportedTransport(type);
2493
- }
2494
- var enabled = (!context.enabledTransports ||
2495
- Collections.arrayIndexOf(context.enabledTransports, name) !== -1) &&
2496
- (!context.disabledTransports ||
2497
- Collections.arrayIndexOf(context.disabledTransports, name) === -1);
2498
- var transport;
2499
- if (enabled) {
2500
- transport = new transport_strategy_1["default"](name, priority, manager ? manager.getAssistant(transportClass) : transportClass, Collections.extend({
2501
- key: context.key,
2502
- encrypted: context.encrypted,
2503
- timeline: context.timeline,
2504
- ignoreNullOrigin: context.ignoreNullOrigin
2505
- }, options));
2506
- }
2507
- else {
2508
- transport = UnsupportedStrategy;
2509
- }
2510
- var newContext = context.def(context, name, transport)[1];
2511
- newContext.Transports = context.Transports || {};
2512
- newContext.Transports[name] = transport;
2513
- return [undefined, newContext];
2514
- },
2515
- transport_manager: returnWithOriginalContext(function (_, options) {
2516
- return new transport_manager_1["default"](options);
2517
- }),
2518
- sequential: returnWithOriginalContext(function (_, options) {
2519
- var strategies = Array.prototype.slice.call(arguments, 2);
2520
- return new sequential_strategy_1["default"](strategies, options);
2521
- }),
2522
- cached: returnWithOriginalContext(function (context, ttl, strategy) {
2523
- return new cached_strategy_1["default"](strategy, context.Transports, {
2524
- ttl: ttl,
2525
- timeline: context.timeline,
2526
- encrypted: context.encrypted
2527
- });
2528
- }),
2529
- first_connected: returnWithOriginalContext(function (_, strategy) {
2530
- return new first_connected_strategy_1["default"](strategy);
2531
- }),
2532
- best_connected_ever: returnWithOriginalContext(function () {
2533
- var strategies = Array.prototype.slice.call(arguments, 1);
2534
- return new best_connected_ever_strategy_1["default"](strategies);
2535
- }),
2536
- delayed: returnWithOriginalContext(function (_, delay, strategy) {
2537
- return new delayed_strategy_1["default"](strategy, { delay: delay });
2538
- }),
2539
- "if": returnWithOriginalContext(function (_, test, trueBranch, falseBranch) {
2540
- return new if_strategy_1["default"](test, trueBranch, falseBranch);
2541
- }),
2542
- is_supported: returnWithOriginalContext(function (_, strategy) {
2543
- return function () {
2544
- return strategy.isSupported();
2545
- };
2546
- })
2547
- };
2548
- function isSymbol(expression) {
2549
- return (typeof expression === "string") && expression.charAt(0) === ":";
2550
- }
2551
- function getSymbolValue(expression, context) {
2552
- return context[expression.slice(1)];
2553
- }
2554
- function evaluateListOfExpressions(expressions, context) {
2555
- if (expressions.length === 0) {
2556
- return [[], context];
2557
- }
2558
- var head = evaluate(expressions[0], context);
2559
- var tail = evaluateListOfExpressions(expressions.slice(1), head[1]);
2560
- return [[head[0]].concat(tail[0]), tail[1]];
2561
- }
2562
- function evaluateString(expression, context) {
2563
- if (!isSymbol(expression)) {
2564
- return [expression, context];
2565
- }
2566
- var value = getSymbolValue(expression, context);
2567
- if (value === undefined) {
2568
- throw "Undefined symbol " + expression;
2569
- }
2570
- return [value, context];
2571
- }
2572
- function evaluateArray(expression, context) {
2573
- if (isSymbol(expression[0])) {
2574
- var f = getSymbolValue(expression[0], context);
2575
- if (expression.length > 1) {
2576
- if (typeof f !== "function") {
2577
- throw "Calling non-function " + expression[0];
2578
- }
2579
- var args = [Collections.extend({}, context)].concat(Collections.map(expression.slice(1), function (arg) {
2580
- return evaluate(arg, Collections.extend({}, context))[0];
2581
- }));
2582
- return f.apply(this, args);
2583
- }
2584
- else {
2585
- return [f, context];
2586
- }
2587
- }
2588
- else {
2589
- return evaluateListOfExpressions(expression, context);
2590
- }
2591
- }
2592
- function evaluate(expression, context) {
2593
- if (typeof expression === "string") {
2594
- return evaluateString(expression, context);
2595
- }
2596
- else if (typeof expression === "object") {
2597
- if (expression instanceof Array && expression.length > 0) {
2598
- return evaluateArray(expression, context);
2599
- }
2600
- }
2601
- return [expression, context];
2602
- }
2603
-
2604
-
2605
- /***/ }),
2606
- /* 42 */
2607
- /***/ (function(module, exports, __webpack_require__) {
2608
-
2609
- "use strict";
2610
- var factory_1 = __webpack_require__(43);
2611
- var TransportManager = (function () {
2612
- function TransportManager(options) {
2613
- this.options = options || {};
2614
- this.livesLeft = this.options.lives || Infinity;
2615
- }
2616
- TransportManager.prototype.getAssistant = function (transport) {
2617
- return factory_1["default"].createAssistantToTheTransportManager(this, transport, {
2618
- minPingDelay: this.options.minPingDelay,
2619
- maxPingDelay: this.options.maxPingDelay
2620
- });
2621
- };
2622
- TransportManager.prototype.isAlive = function () {
2623
- return this.livesLeft > 0;
2624
- };
2625
- TransportManager.prototype.reportDeath = function () {
2626
- this.livesLeft -= 1;
2627
- };
2628
- return TransportManager;
2629
- }());
2630
- exports.__esModule = true;
2631
- exports["default"] = TransportManager;
2632
-
2633
-
2634
- /***/ }),
2635
- /* 43 */
2636
- /***/ (function(module, exports, __webpack_require__) {
2637
-
2638
- "use strict";
2639
- var assistant_to_the_transport_manager_1 = __webpack_require__(44);
2640
- var handshake_1 = __webpack_require__(45);
2641
- var pusher_authorizer_1 = __webpack_require__(48);
2642
- var timeline_sender_1 = __webpack_require__(49);
2643
- var presence_channel_1 = __webpack_require__(50);
2644
- var private_channel_1 = __webpack_require__(51);
2645
- var channel_1 = __webpack_require__(52);
2646
- var connection_manager_1 = __webpack_require__(54);
2647
- var channels_1 = __webpack_require__(55);
2648
- var Factory = {
2649
- createChannels: function () {
2650
- return new channels_1["default"]();
2651
- },
2652
- createConnectionManager: function (key, options) {
2653
- return new connection_manager_1["default"](key, options);
2654
- },
2655
- createChannel: function (name, pusher) {
2656
- return new channel_1["default"](name, pusher);
2657
- },
2658
- createPrivateChannel: function (name, pusher) {
2659
- return new private_channel_1["default"](name, pusher);
2660
- },
2661
- createPresenceChannel: function (name, pusher) {
2662
- return new presence_channel_1["default"](name, pusher);
2663
- },
2664
- createTimelineSender: function (timeline, options) {
2665
- return new timeline_sender_1["default"](timeline, options);
2666
- },
2667
- createAuthorizer: function (channel, options) {
2668
- if (options.authorizer) {
2669
- return options.authorizer(channel, options);
2670
- }
2671
- return new pusher_authorizer_1["default"](channel, options);
2672
- },
2673
- createHandshake: function (transport, callback) {
2674
- return new handshake_1["default"](transport, callback);
2675
- },
2676
- createAssistantToTheTransportManager: function (manager, transport, options) {
2677
- return new assistant_to_the_transport_manager_1["default"](manager, transport, options);
2678
- }
2679
- };
2680
- exports.__esModule = true;
2681
- exports["default"] = Factory;
2682
-
2683
-
2684
- /***/ }),
2685
- /* 44 */
2686
- /***/ (function(module, exports, __webpack_require__) {
2687
-
2688
- "use strict";
2689
- var util_1 = __webpack_require__(11);
2690
- var Collections = __webpack_require__(9);
2691
- var AssistantToTheTransportManager = (function () {
2692
- function AssistantToTheTransportManager(manager, transport, options) {
2693
- this.manager = manager;
2694
- this.transport = transport;
2695
- this.minPingDelay = options.minPingDelay;
2696
- this.maxPingDelay = options.maxPingDelay;
2697
- this.pingDelay = undefined;
2698
- }
2699
- AssistantToTheTransportManager.prototype.createConnection = function (name, priority, key, options) {
2700
- var _this = this;
2701
- options = Collections.extend({}, options, {
2702
- activityTimeout: this.pingDelay
2703
- });
2704
- var connection = this.transport.createConnection(name, priority, key, options);
2705
- var openTimestamp = null;
2706
- var onOpen = function () {
2707
- connection.unbind("open", onOpen);
2708
- connection.bind("closed", onClosed);
2709
- openTimestamp = util_1["default"].now();
2710
- };
2711
- var onClosed = function (closeEvent) {
2712
- connection.unbind("closed", onClosed);
2713
- if (closeEvent.code === 1002 || closeEvent.code === 1003) {
2714
- _this.manager.reportDeath();
2715
- }
2716
- else if (!closeEvent.wasClean && openTimestamp) {
2717
- var lifespan = util_1["default"].now() - openTimestamp;
2718
- if (lifespan < 2 * _this.maxPingDelay) {
2719
- _this.manager.reportDeath();
2720
- _this.pingDelay = Math.max(lifespan / 2, _this.minPingDelay);
2721
- }
2722
- }
2723
- };
2724
- connection.bind("open", onOpen);
2725
- return connection;
2726
- };
2727
- AssistantToTheTransportManager.prototype.isSupported = function (environment) {
2728
- return this.manager.isAlive() && this.transport.isSupported(environment);
2729
- };
2730
- return AssistantToTheTransportManager;
2731
- }());
2732
- exports.__esModule = true;
2733
- exports["default"] = AssistantToTheTransportManager;
2734
-
2735
-
2736
- /***/ }),
2737
- /* 45 */
2738
- /***/ (function(module, exports, __webpack_require__) {
2739
-
2740
- "use strict";
2741
- var Collections = __webpack_require__(9);
2742
- var Protocol = __webpack_require__(46);
2743
- var connection_1 = __webpack_require__(47);
2744
- var Handshake = (function () {
2745
- function Handshake(transport, callback) {
2746
- this.transport = transport;
2747
- this.callback = callback;
2748
- this.bindListeners();
2749
- }
2750
- Handshake.prototype.close = function () {
2751
- this.unbindListeners();
2752
- this.transport.close();
2753
- };
2754
- Handshake.prototype.bindListeners = function () {
2755
- var _this = this;
2756
- this.onMessage = function (m) {
2757
- _this.unbindListeners();
2758
- var result;
2759
- try {
2760
- result = Protocol.processHandshake(m);
2761
- }
2762
- catch (e) {
2763
- _this.finish("error", { error: e });
2764
- _this.transport.close();
2765
- return;
2766
- }
2767
- if (result.action === "connected") {
2768
- _this.finish("connected", {
2769
- connection: new connection_1["default"](result.id, _this.transport),
2770
- activityTimeout: result.activityTimeout
2771
- });
2772
- }
2773
- else {
2774
- _this.finish(result.action, { error: result.error });
2775
- _this.transport.close();
2776
- }
2777
- };
2778
- this.onClosed = function (closeEvent) {
2779
- _this.unbindListeners();
2780
- var action = Protocol.getCloseAction(closeEvent) || "backoff";
2781
- var error = Protocol.getCloseError(closeEvent);
2782
- _this.finish(action, { error: error });
2783
- };
2784
- this.transport.bind("message", this.onMessage);
2785
- this.transport.bind("closed", this.onClosed);
2786
- };
2787
- Handshake.prototype.unbindListeners = function () {
2788
- this.transport.unbind("message", this.onMessage);
2789
- this.transport.unbind("closed", this.onClosed);
2790
- };
2791
- Handshake.prototype.finish = function (action, params) {
2792
- this.callback(Collections.extend({ transport: this.transport, action: action }, params));
2793
- };
2794
- return Handshake;
2795
- }());
2796
- exports.__esModule = true;
2797
- exports["default"] = Handshake;
2798
-
2799
-
2800
- /***/ }),
2801
- /* 46 */
2802
- /***/ (function(module, exports) {
2803
-
2804
- "use strict";
2805
- exports.decodeMessage = function (message) {
2806
- try {
2807
- var params = JSON.parse(message.data);
2808
- if (typeof params.data === 'string') {
2809
- try {
2810
- params.data = JSON.parse(params.data);
2811
- }
2812
- catch (e) {
2813
- if (!(e instanceof SyntaxError)) {
2814
- throw e;
2815
- }
2816
- }
2817
- }
2818
- return params;
2819
- }
2820
- catch (e) {
2821
- throw { type: 'MessageParseError', error: e, data: message.data };
2822
- }
2823
- };
2824
- exports.encodeMessage = function (message) {
2825
- return JSON.stringify(message);
2826
- };
2827
- exports.processHandshake = function (message) {
2828
- message = exports.decodeMessage(message);
2829
- if (message.event === "pusher:connection_established") {
2830
- if (!message.data.activity_timeout) {
2831
- throw "No activity timeout specified in handshake";
2832
- }
2833
- return {
2834
- action: "connected",
2835
- id: message.data.socket_id,
2836
- activityTimeout: message.data.activity_timeout * 1000
2837
- };
2838
- }
2839
- else if (message.event === "pusher:error") {
2840
- return {
2841
- action: this.getCloseAction(message.data),
2842
- error: this.getCloseError(message.data)
2843
- };
2844
- }
2845
- else {
2846
- throw "Invalid handshake";
2847
- }
2848
- };
2849
- exports.getCloseAction = function (closeEvent) {
2850
- if (closeEvent.code < 4000) {
2851
- if (closeEvent.code >= 1002 && closeEvent.code <= 1004) {
2852
- return "backoff";
2853
- }
2854
- else {
2855
- return null;
2856
- }
2857
- }
2858
- else if (closeEvent.code === 4000) {
2859
- return "ssl_only";
2860
- }
2861
- else if (closeEvent.code < 4100) {
2862
- return "refused";
2863
- }
2864
- else if (closeEvent.code < 4200) {
2865
- return "backoff";
2866
- }
2867
- else if (closeEvent.code < 4300) {
2868
- return "retry";
2869
- }
2870
- else {
2871
- return "refused";
2872
- }
2873
- };
2874
- exports.getCloseError = function (closeEvent) {
2875
- if (closeEvent.code !== 1000 && closeEvent.code !== 1001) {
2876
- return {
2877
- type: 'PusherError',
2878
- data: {
2879
- code: closeEvent.code,
2880
- message: closeEvent.reason || closeEvent.message
2881
- }
2882
- };
2883
- }
2884
- else {
2885
- return null;
2886
- }
2887
- };
2888
-
2889
-
2890
- /***/ }),
2891
- /* 47 */
2892
- /***/ (function(module, exports, __webpack_require__) {
2893
-
2894
- "use strict";
2895
- var __extends = (this && this.__extends) || function (d, b) {
2896
- for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
2897
- function __() { this.constructor = d; }
2898
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
2899
- };
2900
- var Collections = __webpack_require__(9);
2901
- var dispatcher_1 = __webpack_require__(24);
2902
- var Protocol = __webpack_require__(46);
2903
- var logger_1 = __webpack_require__(8);
2904
- var Connection = (function (_super) {
2905
- __extends(Connection, _super);
2906
- function Connection(id, transport) {
2907
- _super.call(this);
2908
- this.id = id;
2909
- this.transport = transport;
2910
- this.activityTimeout = transport.activityTimeout;
2911
- this.bindListeners();
2912
- }
2913
- Connection.prototype.handlesActivityChecks = function () {
2914
- return this.transport.handlesActivityChecks();
2915
- };
2916
- Connection.prototype.send = function (data) {
2917
- return this.transport.send(data);
2918
- };
2919
- Connection.prototype.send_event = function (name, data, channel) {
2920
- var message = { event: name, data: data };
2921
- if (channel) {
2922
- message.channel = channel;
2923
- }
2924
- logger_1["default"].debug('Event sent', message);
2925
- return this.send(Protocol.encodeMessage(message));
2926
- };
2927
- Connection.prototype.ping = function () {
2928
- if (this.transport.supportsPing()) {
2929
- this.transport.ping();
2930
- }
2931
- else {
2932
- this.send_event('pusher:ping', {});
2933
- }
2934
- };
2935
- Connection.prototype.close = function () {
2936
- this.transport.close();
2937
- };
2938
- Connection.prototype.bindListeners = function () {
2939
- var _this = this;
2940
- var listeners = {
2941
- message: function (m) {
2942
- var message;
2943
- try {
2944
- message = Protocol.decodeMessage(m);
2945
- }
2946
- catch (e) {
2947
- _this.emit('error', {
2948
- type: 'MessageParseError',
2949
- error: e,
2950
- data: m.data
2951
- });
2952
- }
2953
- if (message !== undefined) {
2954
- logger_1["default"].debug('Event recd', message);
2955
- switch (message.event) {
2956
- case 'pusher:error':
2957
- _this.emit('error', { type: 'PusherError', data: message.data });
2958
- break;
2959
- case 'pusher:ping':
2960
- _this.emit("ping");
2961
- break;
2962
- case 'pusher:pong':
2963
- _this.emit("pong");
2964
- break;
2965
- }
2966
- _this.emit('message', message);
2967
- }
2968
- },
2969
- activity: function () {
2970
- _this.emit("activity");
2971
- },
2972
- error: function (error) {
2973
- _this.emit("error", { type: "WebSocketError", error: error });
2974
- },
2975
- closed: function (closeEvent) {
2976
- unbindListeners();
2977
- if (closeEvent && closeEvent.code) {
2978
- _this.handleCloseEvent(closeEvent);
2979
- }
2980
- _this.transport = null;
2981
- _this.emit("closed");
2982
- }
2983
- };
2984
- var unbindListeners = function () {
2985
- Collections.objectApply(listeners, function (listener, event) {
2986
- _this.transport.unbind(event, listener);
2987
- });
2988
- };
2989
- Collections.objectApply(listeners, function (listener, event) {
2990
- _this.transport.bind(event, listener);
2991
- });
2992
- };
2993
- Connection.prototype.handleCloseEvent = function (closeEvent) {
2994
- var action = Protocol.getCloseAction(closeEvent);
2995
- var error = Protocol.getCloseError(closeEvent);
2996
- if (error) {
2997
- this.emit('error', error);
2998
- }
2999
- if (action) {
3000
- this.emit(action);
3001
- }
3002
- };
3003
- return Connection;
3004
- }(dispatcher_1["default"]));
3005
- exports.__esModule = true;
3006
- exports["default"] = Connection;
3007
-
3008
-
3009
- /***/ }),
3010
- /* 48 */
3011
- /***/ (function(module, exports, __webpack_require__) {
3012
-
3013
- "use strict";
3014
- var runtime_1 = __webpack_require__(2);
3015
- var PusherAuthorizer = (function () {
3016
- function PusherAuthorizer(channel, options) {
3017
- this.channel = channel;
3018
- var authTransport = options.authTransport;
3019
- if (typeof runtime_1["default"].getAuthorizers()[authTransport] === "undefined") {
3020
- throw "'" + authTransport + "' is not a recognized auth transport";
3021
- }
3022
- this.type = authTransport;
3023
- this.options = options;
3024
- this.authOptions = (options || {}).auth || {};
3025
- }
3026
- PusherAuthorizer.prototype.composeQuery = function (socketId) {
3027
- var query = 'socket_id=' + encodeURIComponent(socketId) +
3028
- '&channel_name=' + encodeURIComponent(this.channel.name);
3029
- for (var i in this.authOptions.params) {
3030
- query += "&" + encodeURIComponent(i) + "=" + encodeURIComponent(this.authOptions.params[i]);
3031
- }
3032
- return query;
3033
- };
3034
- PusherAuthorizer.prototype.authorize = function (socketId, callback) {
3035
- PusherAuthorizer.authorizers = PusherAuthorizer.authorizers || runtime_1["default"].getAuthorizers();
3036
- return PusherAuthorizer.authorizers[this.type].call(this, runtime_1["default"], socketId, callback);
3037
- };
3038
- return PusherAuthorizer;
3039
- }());
3040
- exports.__esModule = true;
3041
- exports["default"] = PusherAuthorizer;
3042
-
3043
-
3044
- /***/ }),
3045
- /* 49 */
3046
- /***/ (function(module, exports, __webpack_require__) {
3047
-
3048
- "use strict";
3049
- var runtime_1 = __webpack_require__(2);
3050
- var TimelineSender = (function () {
3051
- function TimelineSender(timeline, options) {
3052
- this.timeline = timeline;
3053
- this.options = options || {};
3054
- }
3055
- TimelineSender.prototype.send = function (encrypted, callback) {
3056
- if (this.timeline.isEmpty()) {
3057
- return;
3058
- }
3059
- this.timeline.send(runtime_1["default"].TimelineTransport.getAgent(this, encrypted), callback);
3060
- };
3061
- return TimelineSender;
3062
- }());
3063
- exports.__esModule = true;
3064
- exports["default"] = TimelineSender;
3065
-
3066
-
3067
- /***/ }),
3068
- /* 50 */
3069
- /***/ (function(module, exports, __webpack_require__) {
3070
-
3071
- "use strict";
3072
- var __extends = (this && this.__extends) || function (d, b) {
3073
- for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
3074
- function __() { this.constructor = d; }
3075
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
3076
- };
3077
- var private_channel_1 = __webpack_require__(51);
3078
- var logger_1 = __webpack_require__(8);
3079
- var members_1 = __webpack_require__(53);
3080
- var url_store_1 = __webpack_require__(14);
3081
- var PresenceChannel = (function (_super) {
3082
- __extends(PresenceChannel, _super);
3083
- function PresenceChannel(name, pusher) {
3084
- _super.call(this, name, pusher);
3085
- this.members = new members_1["default"]();
3086
- }
3087
- PresenceChannel.prototype.authorize = function (socketId, callback) {
3088
- var _this = this;
3089
- _super.prototype.authorize.call(this, socketId, function (error, authData) {
3090
- if (!error) {
3091
- if (authData.channel_data === undefined) {
3092
- var suffix = url_store_1["default"].buildLogSuffix("authenticationEndpoint");
3093
- logger_1["default"].warn(("Invalid auth response for channel '" + _this.name + "',") +
3094
- ("expected 'channel_data' field. " + suffix));
3095
- callback("Invalid auth response");
3096
- return;
3097
- }
3098
- var channelData = JSON.parse(authData.channel_data);
3099
- _this.members.setMyID(channelData.user_id);
3100
- }
3101
- callback(error, authData);
3102
- });
3103
- };
3104
- PresenceChannel.prototype.handleEvent = function (event, data) {
3105
- switch (event) {
3106
- case "pusher_internal:subscription_succeeded":
3107
- this.subscriptionPending = false;
3108
- this.subscribed = true;
3109
- if (this.subscriptionCancelled) {
3110
- this.pusher.unsubscribe(this.name);
3111
- }
3112
- else {
3113
- this.members.onSubscription(data);
3114
- this.emit("pusher:subscription_succeeded", this.members);
3115
- }
3116
- break;
3117
- case "pusher_internal:member_added":
3118
- var addedMember = this.members.addMember(data);
3119
- this.emit('pusher:member_added', addedMember);
3120
- break;
3121
- case "pusher_internal:member_removed":
3122
- var removedMember = this.members.removeMember(data);
3123
- if (removedMember) {
3124
- this.emit('pusher:member_removed', removedMember);
3125
- }
3126
- break;
3127
- default:
3128
- private_channel_1["default"].prototype.handleEvent.call(this, event, data);
3129
- }
3130
- };
3131
- PresenceChannel.prototype.disconnect = function () {
3132
- this.members.reset();
3133
- _super.prototype.disconnect.call(this);
3134
- };
3135
- return PresenceChannel;
3136
- }(private_channel_1["default"]));
3137
- exports.__esModule = true;
3138
- exports["default"] = PresenceChannel;
3139
-
3140
-
3141
- /***/ }),
3142
- /* 51 */
3143
- /***/ (function(module, exports, __webpack_require__) {
3144
-
3145
- "use strict";
3146
- var __extends = (this && this.__extends) || function (d, b) {
3147
- for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
3148
- function __() { this.constructor = d; }
3149
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
3150
- };
3151
- var factory_1 = __webpack_require__(43);
3152
- var channel_1 = __webpack_require__(52);
3153
- var PrivateChannel = (function (_super) {
3154
- __extends(PrivateChannel, _super);
3155
- function PrivateChannel() {
3156
- _super.apply(this, arguments);
3157
- }
3158
- PrivateChannel.prototype.authorize = function (socketId, callback) {
3159
- var authorizer = factory_1["default"].createAuthorizer(this, this.pusher.config);
3160
- return authorizer.authorize(socketId, callback);
3161
- };
3162
- return PrivateChannel;
3163
- }(channel_1["default"]));
3164
- exports.__esModule = true;
3165
- exports["default"] = PrivateChannel;
3166
-
3167
-
3168
- /***/ }),
3169
- /* 52 */
3170
- /***/ (function(module, exports, __webpack_require__) {
3171
-
3172
- "use strict";
3173
- var __extends = (this && this.__extends) || function (d, b) {
3174
- for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
3175
- function __() { this.constructor = d; }
3176
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
3177
- };
3178
- var dispatcher_1 = __webpack_require__(24);
3179
- var Errors = __webpack_require__(31);
3180
- var logger_1 = __webpack_require__(8);
3181
- var Channel = (function (_super) {
3182
- __extends(Channel, _super);
3183
- function Channel(name, pusher) {
3184
- _super.call(this, function (event, data) {
3185
- logger_1["default"].debug('No callbacks on ' + name + ' for ' + event);
3186
- });
3187
- this.name = name;
3188
- this.pusher = pusher;
3189
- this.subscribed = false;
3190
- this.subscriptionPending = false;
3191
- this.subscriptionCancelled = false;
3192
- }
3193
- Channel.prototype.authorize = function (socketId, callback) {
3194
- return callback(false, {});
3195
- };
3196
- Channel.prototype.trigger = function (event, data) {
3197
- if (event.indexOf("client-") !== 0) {
3198
- throw new Errors.BadEventName("Event '" + event + "' does not start with 'client-'");
3199
- }
3200
- return this.pusher.send_event(event, data, this.name);
3201
- };
3202
- Channel.prototype.disconnect = function () {
3203
- this.subscribed = false;
3204
- this.subscriptionPending = false;
3205
- };
3206
- Channel.prototype.handleEvent = function (event, data) {
3207
- if (event.indexOf("pusher_internal:") === 0) {
3208
- if (event === "pusher_internal:subscription_succeeded") {
3209
- this.subscriptionPending = false;
3210
- this.subscribed = true;
3211
- if (this.subscriptionCancelled) {
3212
- this.pusher.unsubscribe(this.name);
3213
- }
3214
- else {
3215
- this.emit("pusher:subscription_succeeded", data);
3216
- }
3217
- }
3218
- }
3219
- else {
3220
- this.emit(event, data);
3221
- }
3222
- };
3223
- Channel.prototype.subscribe = function () {
3224
- var _this = this;
3225
- if (this.subscribed) {
3226
- return;
3227
- }
3228
- this.subscriptionPending = true;
3229
- this.subscriptionCancelled = false;
3230
- this.authorize(this.pusher.connection.socket_id, function (error, data) {
3231
- if (error) {
3232
- _this.handleEvent('pusher:subscription_error', data);
3233
- }
3234
- else {
3235
- _this.pusher.send_event('pusher:subscribe', {
3236
- auth: data.auth,
3237
- channel_data: data.channel_data,
3238
- channel: _this.name
3239
- });
3240
- }
3241
- });
3242
- };
3243
- Channel.prototype.unsubscribe = function () {
3244
- this.subscribed = false;
3245
- this.pusher.send_event('pusher:unsubscribe', {
3246
- channel: this.name
3247
- });
3248
- };
3249
- Channel.prototype.cancelSubscription = function () {
3250
- this.subscriptionCancelled = true;
3251
- };
3252
- Channel.prototype.reinstateSubscription = function () {
3253
- this.subscriptionCancelled = false;
3254
- };
3255
- return Channel;
3256
- }(dispatcher_1["default"]));
3257
- exports.__esModule = true;
3258
- exports["default"] = Channel;
3259
-
3260
-
3261
- /***/ }),
3262
- /* 53 */
3263
- /***/ (function(module, exports, __webpack_require__) {
3264
-
3265
- "use strict";
3266
- var Collections = __webpack_require__(9);
3267
- var Members = (function () {
3268
- function Members() {
3269
- this.reset();
3270
- }
3271
- Members.prototype.get = function (id) {
3272
- if (Object.prototype.hasOwnProperty.call(this.members, id)) {
3273
- return {
3274
- id: id,
3275
- info: this.members[id]
3276
- };
3277
- }
3278
- else {
3279
- return null;
3280
- }
3281
- };
3282
- Members.prototype.each = function (callback) {
3283
- var _this = this;
3284
- Collections.objectApply(this.members, function (member, id) {
3285
- callback(_this.get(id));
3286
- });
3287
- };
3288
- Members.prototype.setMyID = function (id) {
3289
- this.myID = id;
3290
- };
3291
- Members.prototype.onSubscription = function (subscriptionData) {
3292
- this.members = subscriptionData.presence.hash;
3293
- this.count = subscriptionData.presence.count;
3294
- this.me = this.get(this.myID);
3295
- };
3296
- Members.prototype.addMember = function (memberData) {
3297
- if (this.get(memberData.user_id) === null) {
3298
- this.count++;
3299
- }
3300
- this.members[memberData.user_id] = memberData.user_info;
3301
- return this.get(memberData.user_id);
3302
- };
3303
- Members.prototype.removeMember = function (memberData) {
3304
- var member = this.get(memberData.user_id);
3305
- if (member) {
3306
- delete this.members[memberData.user_id];
3307
- this.count--;
3308
- }
3309
- return member;
3310
- };
3311
- Members.prototype.reset = function () {
3312
- this.members = {};
3313
- this.count = 0;
3314
- this.myID = null;
3315
- this.me = null;
3316
- };
3317
- return Members;
3318
- }());
3319
- exports.__esModule = true;
3320
- exports["default"] = Members;
3321
-
3322
-
3323
- /***/ }),
3324
- /* 54 */
3325
- /***/ (function(module, exports, __webpack_require__) {
3326
-
3327
- "use strict";
3328
- var __extends = (this && this.__extends) || function (d, b) {
3329
- for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
3330
- function __() { this.constructor = d; }
3331
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
3332
- };
3333
- var dispatcher_1 = __webpack_require__(24);
3334
- var timers_1 = __webpack_require__(12);
3335
- var logger_1 = __webpack_require__(8);
3336
- var Collections = __webpack_require__(9);
3337
- var runtime_1 = __webpack_require__(2);
3338
- var ConnectionManager = (function (_super) {
3339
- __extends(ConnectionManager, _super);
3340
- function ConnectionManager(key, options) {
3341
- var _this = this;
3342
- _super.call(this);
3343
- this.key = key;
3344
- this.options = options || {};
3345
- this.state = "initialized";
3346
- this.connection = null;
3347
- this.encrypted = !!options.encrypted;
3348
- this.timeline = this.options.timeline;
3349
- this.connectionCallbacks = this.buildConnectionCallbacks();
3350
- this.errorCallbacks = this.buildErrorCallbacks();
3351
- this.handshakeCallbacks = this.buildHandshakeCallbacks(this.errorCallbacks);
3352
- var Network = runtime_1["default"].getNetwork();
3353
- Network.bind("online", function () {
3354
- _this.timeline.info({ netinfo: "online" });
3355
- if (_this.state === "connecting" || _this.state === "unavailable") {
3356
- _this.retryIn(0);
3357
- }
3358
- });
3359
- Network.bind("offline", function () {
3360
- _this.timeline.info({ netinfo: "offline" });
3361
- if (_this.connection) {
3362
- _this.sendActivityCheck();
3363
- }
3364
- });
3365
- this.updateStrategy();
3366
- }
3367
- ConnectionManager.prototype.connect = function () {
3368
- if (this.connection || this.runner) {
3369
- return;
3370
- }
3371
- if (!this.strategy.isSupported()) {
3372
- this.updateState("failed");
3373
- return;
3374
- }
3375
- this.updateState("connecting");
3376
- this.startConnecting();
3377
- this.setUnavailableTimer();
3378
- };
3379
- ;
3380
- ConnectionManager.prototype.send = function (data) {
3381
- if (this.connection) {
3382
- return this.connection.send(data);
3383
- }
3384
- else {
3385
- return false;
3386
- }
3387
- };
3388
- ;
3389
- ConnectionManager.prototype.send_event = function (name, data, channel) {
3390
- if (this.connection) {
3391
- return this.connection.send_event(name, data, channel);
3392
- }
3393
- else {
3394
- return false;
3395
- }
3396
- };
3397
- ;
3398
- ConnectionManager.prototype.disconnect = function () {
3399
- this.disconnectInternally();
3400
- this.updateState("disconnected");
3401
- };
3402
- ;
3403
- ConnectionManager.prototype.isEncrypted = function () {
3404
- return this.encrypted;
3405
- };
3406
- ;
3407
- ConnectionManager.prototype.startConnecting = function () {
3408
- var _this = this;
3409
- var callback = function (error, handshake) {
3410
- if (error) {
3411
- _this.runner = _this.strategy.connect(0, callback);
3412
- }
3413
- else {
3414
- if (handshake.action === "error") {
3415
- _this.emit("error", { type: "HandshakeError", error: handshake.error });
3416
- _this.timeline.error({ handshakeError: handshake.error });
3417
- }
3418
- else {
3419
- _this.abortConnecting();
3420
- _this.handshakeCallbacks[handshake.action](handshake);
3421
- }
3422
- }
3423
- };
3424
- this.runner = this.strategy.connect(0, callback);
3425
- };
3426
- ;
3427
- ConnectionManager.prototype.abortConnecting = function () {
3428
- if (this.runner) {
3429
- this.runner.abort();
3430
- this.runner = null;
3431
- }
3432
- };
3433
- ;
3434
- ConnectionManager.prototype.disconnectInternally = function () {
3435
- this.abortConnecting();
3436
- this.clearRetryTimer();
3437
- this.clearUnavailableTimer();
3438
- if (this.connection) {
3439
- var connection = this.abandonConnection();
3440
- connection.close();
3441
- }
3442
- };
3443
- ;
3444
- ConnectionManager.prototype.updateStrategy = function () {
3445
- this.strategy = this.options.getStrategy({
3446
- key: this.key,
3447
- timeline: this.timeline,
3448
- encrypted: this.encrypted
3449
- });
3450
- };
3451
- ;
3452
- ConnectionManager.prototype.retryIn = function (delay) {
3453
- var _this = this;
3454
- this.timeline.info({ action: "retry", delay: delay });
3455
- if (delay > 0) {
3456
- this.emit("connecting_in", Math.round(delay / 1000));
3457
- }
3458
- this.retryTimer = new timers_1.OneOffTimer(delay || 0, function () {
3459
- _this.disconnectInternally();
3460
- _this.connect();
3461
- });
3462
- };
3463
- ;
3464
- ConnectionManager.prototype.clearRetryTimer = function () {
3465
- if (this.retryTimer) {
3466
- this.retryTimer.ensureAborted();
3467
- this.retryTimer = null;
3468
- }
3469
- };
3470
- ;
3471
- ConnectionManager.prototype.setUnavailableTimer = function () {
3472
- var _this = this;
3473
- this.unavailableTimer = new timers_1.OneOffTimer(this.options.unavailableTimeout, function () {
3474
- _this.updateState("unavailable");
3475
- });
3476
- };
3477
- ;
3478
- ConnectionManager.prototype.clearUnavailableTimer = function () {
3479
- if (this.unavailableTimer) {
3480
- this.unavailableTimer.ensureAborted();
3481
- }
3482
- };
3483
- ;
3484
- ConnectionManager.prototype.sendActivityCheck = function () {
3485
- var _this = this;
3486
- this.stopActivityCheck();
3487
- this.connection.ping();
3488
- this.activityTimer = new timers_1.OneOffTimer(this.options.pongTimeout, function () {
3489
- _this.timeline.error({ pong_timed_out: _this.options.pongTimeout });
3490
- _this.retryIn(0);
3491
- });
3492
- };
3493
- ;
3494
- ConnectionManager.prototype.resetActivityCheck = function () {
3495
- var _this = this;
3496
- this.stopActivityCheck();
3497
- if (this.connection && !this.connection.handlesActivityChecks()) {
3498
- this.activityTimer = new timers_1.OneOffTimer(this.activityTimeout, function () {
3499
- _this.sendActivityCheck();
3500
- });
3501
- }
3502
- };
3503
- ;
3504
- ConnectionManager.prototype.stopActivityCheck = function () {
3505
- if (this.activityTimer) {
3506
- this.activityTimer.ensureAborted();
3507
- }
3508
- };
3509
- ;
3510
- ConnectionManager.prototype.buildConnectionCallbacks = function () {
3511
- var _this = this;
3512
- return {
3513
- message: function (message) {
3514
- _this.resetActivityCheck();
3515
- _this.emit('message', message);
3516
- },
3517
- ping: function () {
3518
- _this.send_event('pusher:pong', {});
3519
- },
3520
- activity: function () {
3521
- _this.resetActivityCheck();
3522
- },
3523
- error: function (error) {
3524
- _this.emit("error", { type: "WebSocketError", error: error });
3525
- },
3526
- closed: function () {
3527
- _this.abandonConnection();
3528
- if (_this.shouldRetry()) {
3529
- _this.retryIn(1000);
3530
- }
3531
- }
3532
- };
3533
- };
3534
- ;
3535
- ConnectionManager.prototype.buildHandshakeCallbacks = function (errorCallbacks) {
3536
- var _this = this;
3537
- return Collections.extend({}, errorCallbacks, {
3538
- connected: function (handshake) {
3539
- _this.activityTimeout = Math.min(_this.options.activityTimeout, handshake.activityTimeout, handshake.connection.activityTimeout || Infinity);
3540
- _this.clearUnavailableTimer();
3541
- _this.setConnection(handshake.connection);
3542
- _this.socket_id = _this.connection.id;
3543
- _this.updateState("connected", { socket_id: _this.socket_id });
3544
- }
3545
- });
3546
- };
3547
- ;
3548
- ConnectionManager.prototype.buildErrorCallbacks = function () {
3549
- var _this = this;
3550
- var withErrorEmitted = function (callback) {
3551
- return function (result) {
3552
- if (result.error) {
3553
- _this.emit("error", { type: "WebSocketError", error: result.error });
3554
- }
3555
- callback(result);
3556
- };
3557
- };
3558
- return {
3559
- ssl_only: withErrorEmitted(function () {
3560
- _this.encrypted = true;
3561
- _this.updateStrategy();
3562
- _this.retryIn(0);
3563
- }),
3564
- refused: withErrorEmitted(function () {
3565
- _this.disconnect();
3566
- }),
3567
- backoff: withErrorEmitted(function () {
3568
- _this.retryIn(1000);
3569
- }),
3570
- retry: withErrorEmitted(function () {
3571
- _this.retryIn(0);
3572
- })
3573
- };
3574
- };
3575
- ;
3576
- ConnectionManager.prototype.setConnection = function (connection) {
3577
- this.connection = connection;
3578
- for (var event in this.connectionCallbacks) {
3579
- this.connection.bind(event, this.connectionCallbacks[event]);
3580
- }
3581
- this.resetActivityCheck();
3582
- };
3583
- ;
3584
- ConnectionManager.prototype.abandonConnection = function () {
3585
- if (!this.connection) {
3586
- return;
3587
- }
3588
- this.stopActivityCheck();
3589
- for (var event in this.connectionCallbacks) {
3590
- this.connection.unbind(event, this.connectionCallbacks[event]);
3591
- }
3592
- var connection = this.connection;
3593
- this.connection = null;
3594
- return connection;
3595
- };
3596
- ConnectionManager.prototype.updateState = function (newState, data) {
3597
- var previousState = this.state;
3598
- this.state = newState;
3599
- if (previousState !== newState) {
3600
- var newStateDescription = newState;
3601
- if (newStateDescription === "connected") {
3602
- newStateDescription += " with new socket ID " + data.socket_id;
3603
- }
3604
- logger_1["default"].debug('State changed', previousState + ' -> ' + newStateDescription);
3605
- this.timeline.info({ state: newState, params: data });
3606
- this.emit('state_change', { previous: previousState, current: newState });
3607
- this.emit(newState, data);
3608
- }
3609
- };
3610
- ConnectionManager.prototype.shouldRetry = function () {
3611
- return this.state === "connecting" || this.state === "connected";
3612
- };
3613
- return ConnectionManager;
3614
- }(dispatcher_1["default"]));
3615
- exports.__esModule = true;
3616
- exports["default"] = ConnectionManager;
3617
-
3618
-
3619
- /***/ }),
3620
- /* 55 */
3621
- /***/ (function(module, exports, __webpack_require__) {
3622
-
3623
- "use strict";
3624
- var Collections = __webpack_require__(9);
3625
- var factory_1 = __webpack_require__(43);
3626
- var Channels = (function () {
3627
- function Channels() {
3628
- this.channels = {};
3629
- }
3630
- Channels.prototype.add = function (name, pusher) {
3631
- if (!this.channels[name]) {
3632
- this.channels[name] = createChannel(name, pusher);
3633
- }
3634
- return this.channels[name];
3635
- };
3636
- Channels.prototype.all = function () {
3637
- return Collections.values(this.channels);
3638
- };
3639
- Channels.prototype.find = function (name) {
3640
- return this.channels[name];
3641
- };
3642
- Channels.prototype.remove = function (name) {
3643
- var channel = this.channels[name];
3644
- delete this.channels[name];
3645
- return channel;
3646
- };
3647
- Channels.prototype.disconnect = function () {
3648
- Collections.objectApply(this.channels, function (channel) {
3649
- channel.disconnect();
3650
- });
3651
- };
3652
- return Channels;
3653
- }());
3654
- exports.__esModule = true;
3655
- exports["default"] = Channels;
3656
- function createChannel(name, pusher) {
3657
- if (name.indexOf('private-') === 0) {
3658
- return factory_1["default"].createPrivateChannel(name, pusher);
3659
- }
3660
- else if (name.indexOf('presence-') === 0) {
3661
- return factory_1["default"].createPresenceChannel(name, pusher);
3662
- }
3663
- else {
3664
- return factory_1["default"].createChannel(name, pusher);
3665
- }
3666
- }
3667
-
3668
-
3669
- /***/ }),
3670
- /* 56 */
3671
- /***/ (function(module, exports, __webpack_require__) {
3672
-
3673
- "use strict";
3674
- var factory_1 = __webpack_require__(43);
3675
- var util_1 = __webpack_require__(11);
3676
- var Errors = __webpack_require__(31);
3677
- var Collections = __webpack_require__(9);
3678
- var TransportStrategy = (function () {
3679
- function TransportStrategy(name, priority, transport, options) {
3680
- this.name = name;
3681
- this.priority = priority;
3682
- this.transport = transport;
3683
- this.options = options || {};
3684
- }
3685
- TransportStrategy.prototype.isSupported = function () {
3686
- return this.transport.isSupported({
3687
- encrypted: this.options.encrypted
3688
- });
3689
- };
3690
- TransportStrategy.prototype.connect = function (minPriority, callback) {
3691
- var _this = this;
3692
- if (!this.isSupported()) {
3693
- return failAttempt(new Errors.UnsupportedStrategy(), callback);
3694
- }
3695
- else if (this.priority < minPriority) {
3696
- return failAttempt(new Errors.TransportPriorityTooLow(), callback);
3697
- }
3698
- var connected = false;
3699
- var transport = this.transport.createConnection(this.name, this.priority, this.options.key, this.options);
3700
- var handshake = null;
3701
- var onInitialized = function () {
3702
- transport.unbind("initialized", onInitialized);
3703
- transport.connect();
3704
- };
3705
- var onOpen = function () {
3706
- handshake = factory_1["default"].createHandshake(transport, function (result) {
3707
- connected = true;
3708
- unbindListeners();
3709
- callback(null, result);
3710
- });
3711
- };
3712
- var onError = function (error) {
3713
- unbindListeners();
3714
- callback(error);
3715
- };
3716
- var onClosed = function () {
3717
- unbindListeners();
3718
- var serializedTransport;
3719
- serializedTransport = Collections.safeJSONStringify(transport);
3720
- callback(new Errors.TransportClosed(serializedTransport));
3721
- };
3722
- var unbindListeners = function () {
3723
- transport.unbind("initialized", onInitialized);
3724
- transport.unbind("open", onOpen);
3725
- transport.unbind("error", onError);
3726
- transport.unbind("closed", onClosed);
3727
- };
3728
- transport.bind("initialized", onInitialized);
3729
- transport.bind("open", onOpen);
3730
- transport.bind("error", onError);
3731
- transport.bind("closed", onClosed);
3732
- transport.initialize();
3733
- return {
3734
- abort: function () {
3735
- if (connected) {
3736
- return;
3737
- }
3738
- unbindListeners();
3739
- if (handshake) {
3740
- handshake.close();
3741
- }
3742
- else {
3743
- transport.close();
3744
- }
3745
- },
3746
- forceMinPriority: function (p) {
3747
- if (connected) {
3748
- return;
3749
- }
3750
- if (_this.priority < p) {
3751
- if (handshake) {
3752
- handshake.close();
3753
- }
3754
- else {
3755
- transport.close();
3756
- }
3757
- }
3758
- }
3759
- };
3760
- };
3761
- return TransportStrategy;
3762
- }());
3763
- exports.__esModule = true;
3764
- exports["default"] = TransportStrategy;
3765
- function failAttempt(error, callback) {
3766
- util_1["default"].defer(function () {
3767
- callback(error);
3768
- });
3769
- return {
3770
- abort: function () { },
3771
- forceMinPriority: function () { }
3772
- };
3773
- }
3774
-
3775
-
3776
- /***/ }),
3777
- /* 57 */
3778
- /***/ (function(module, exports, __webpack_require__) {
3779
-
3780
- "use strict";
3781
- var Collections = __webpack_require__(9);
3782
- var util_1 = __webpack_require__(11);
3783
- var timers_1 = __webpack_require__(12);
3784
- var SequentialStrategy = (function () {
3785
- function SequentialStrategy(strategies, options) {
3786
- this.strategies = strategies;
3787
- this.loop = Boolean(options.loop);
3788
- this.failFast = Boolean(options.failFast);
3789
- this.timeout = options.timeout;
3790
- this.timeoutLimit = options.timeoutLimit;
3791
- }
3792
- SequentialStrategy.prototype.isSupported = function () {
3793
- return Collections.any(this.strategies, util_1["default"].method("isSupported"));
3794
- };
3795
- SequentialStrategy.prototype.connect = function (minPriority, callback) {
3796
- var _this = this;
3797
- var strategies = this.strategies;
3798
- var current = 0;
3799
- var timeout = this.timeout;
3800
- var runner = null;
3801
- var tryNextStrategy = function (error, handshake) {
3802
- if (handshake) {
3803
- callback(null, handshake);
3804
- }
3805
- else {
3806
- current = current + 1;
3807
- if (_this.loop) {
3808
- current = current % strategies.length;
3809
- }
3810
- if (current < strategies.length) {
3811
- if (timeout) {
3812
- timeout = timeout * 2;
3813
- if (_this.timeoutLimit) {
3814
- timeout = Math.min(timeout, _this.timeoutLimit);
3815
- }
3816
- }
3817
- runner = _this.tryStrategy(strategies[current], minPriority, { timeout: timeout, failFast: _this.failFast }, tryNextStrategy);
3818
- }
3819
- else {
3820
- callback(true);
3821
- }
3822
- }
3823
- };
3824
- runner = this.tryStrategy(strategies[current], minPriority, { timeout: timeout, failFast: this.failFast }, tryNextStrategy);
3825
- return {
3826
- abort: function () {
3827
- runner.abort();
3828
- },
3829
- forceMinPriority: function (p) {
3830
- minPriority = p;
3831
- if (runner) {
3832
- runner.forceMinPriority(p);
3833
- }
3834
- }
3835
- };
3836
- };
3837
- SequentialStrategy.prototype.tryStrategy = function (strategy, minPriority, options, callback) {
3838
- var timer = null;
3839
- var runner = null;
3840
- if (options.timeout > 0) {
3841
- timer = new timers_1.OneOffTimer(options.timeout, function () {
3842
- runner.abort();
3843
- callback(true);
3844
- });
3845
- }
3846
- runner = strategy.connect(minPriority, function (error, handshake) {
3847
- if (error && timer && timer.isRunning() && !options.failFast) {
3848
- return;
3849
- }
3850
- if (timer) {
3851
- timer.ensureAborted();
3852
- }
3853
- callback(error, handshake);
3854
- });
3855
- return {
3856
- abort: function () {
3857
- if (timer) {
3858
- timer.ensureAborted();
3859
- }
3860
- runner.abort();
3861
- },
3862
- forceMinPriority: function (p) {
3863
- runner.forceMinPriority(p);
3864
- }
3865
- };
3866
- };
3867
- return SequentialStrategy;
3868
- }());
3869
- exports.__esModule = true;
3870
- exports["default"] = SequentialStrategy;
3871
-
3872
-
3873
- /***/ }),
3874
- /* 58 */
3875
- /***/ (function(module, exports, __webpack_require__) {
3876
-
3877
- "use strict";
3878
- var Collections = __webpack_require__(9);
3879
- var util_1 = __webpack_require__(11);
3880
- var BestConnectedEverStrategy = (function () {
3881
- function BestConnectedEverStrategy(strategies) {
3882
- this.strategies = strategies;
3883
- }
3884
- BestConnectedEverStrategy.prototype.isSupported = function () {
3885
- return Collections.any(this.strategies, util_1["default"].method("isSupported"));
3886
- };
3887
- BestConnectedEverStrategy.prototype.connect = function (minPriority, callback) {
3888
- return connect(this.strategies, minPriority, function (i, runners) {
3889
- return function (error, handshake) {
3890
- runners[i].error = error;
3891
- if (error) {
3892
- if (allRunnersFailed(runners)) {
3893
- callback(true);
3894
- }
3895
- return;
3896
- }
3897
- Collections.apply(runners, function (runner) {
3898
- runner.forceMinPriority(handshake.transport.priority);
3899
- });
3900
- callback(null, handshake);
3901
- };
3902
- });
3903
- };
3904
- return BestConnectedEverStrategy;
3905
- }());
3906
- exports.__esModule = true;
3907
- exports["default"] = BestConnectedEverStrategy;
3908
- function connect(strategies, minPriority, callbackBuilder) {
3909
- var runners = Collections.map(strategies, function (strategy, i, _, rs) {
3910
- return strategy.connect(minPriority, callbackBuilder(i, rs));
3911
- });
3912
- return {
3913
- abort: function () {
3914
- Collections.apply(runners, abortRunner);
3915
- },
3916
- forceMinPriority: function (p) {
3917
- Collections.apply(runners, function (runner) {
3918
- runner.forceMinPriority(p);
3919
- });
3920
- }
3921
- };
3922
- }
3923
- function allRunnersFailed(runners) {
3924
- return Collections.all(runners, function (runner) {
3925
- return Boolean(runner.error);
3926
- });
3927
- }
3928
- function abortRunner(runner) {
3929
- if (!runner.error && !runner.aborted) {
3930
- runner.abort();
3931
- runner.aborted = true;
3932
- }
3933
- }
3934
-
3935
-
3936
- /***/ }),
3937
- /* 59 */
3938
- /***/ (function(module, exports, __webpack_require__) {
3939
-
3940
- "use strict";
3941
- var util_1 = __webpack_require__(11);
3942
- var runtime_1 = __webpack_require__(2);
3943
- var sequential_strategy_1 = __webpack_require__(57);
3944
- var Collections = __webpack_require__(9);
3945
- var CachedStrategy = (function () {
3946
- function CachedStrategy(strategy, transports, options) {
3947
- this.strategy = strategy;
3948
- this.transports = transports;
3949
- this.ttl = options.ttl || 1800 * 1000;
3950
- this.encrypted = options.encrypted;
3951
- this.timeline = options.timeline;
3952
- }
3953
- CachedStrategy.prototype.isSupported = function () {
3954
- return this.strategy.isSupported();
3955
- };
3956
- CachedStrategy.prototype.connect = function (minPriority, callback) {
3957
- var encrypted = this.encrypted;
3958
- var info = fetchTransportCache(encrypted);
3959
- var strategies = [this.strategy];
3960
- if (info && info.timestamp + this.ttl >= util_1["default"].now()) {
3961
- var transport = this.transports[info.transport];
3962
- if (transport) {
3963
- this.timeline.info({
3964
- cached: true,
3965
- transport: info.transport,
3966
- latency: info.latency
3967
- });
3968
- strategies.push(new sequential_strategy_1["default"]([transport], {
3969
- timeout: info.latency * 2 + 1000,
3970
- failFast: true
3971
- }));
3972
- }
3973
- }
3974
- var startTimestamp = util_1["default"].now();
3975
- var runner = strategies.pop().connect(minPriority, function cb(error, handshake) {
3976
- if (error) {
3977
- flushTransportCache(encrypted);
3978
- if (strategies.length > 0) {
3979
- startTimestamp = util_1["default"].now();
3980
- runner = strategies.pop().connect(minPriority, cb);
3981
- }
3982
- else {
3983
- callback(error);
3984
- }
3985
- }
3986
- else {
3987
- storeTransportCache(encrypted, handshake.transport.name, util_1["default"].now() - startTimestamp);
3988
- callback(null, handshake);
3989
- }
3990
- });
3991
- return {
3992
- abort: function () {
3993
- runner.abort();
3994
- },
3995
- forceMinPriority: function (p) {
3996
- minPriority = p;
3997
- if (runner) {
3998
- runner.forceMinPriority(p);
3999
- }
4000
- }
4001
- };
4002
- };
4003
- return CachedStrategy;
4004
- }());
4005
- exports.__esModule = true;
4006
- exports["default"] = CachedStrategy;
4007
- function getTransportCacheKey(encrypted) {
4008
- return "pusherTransport" + (encrypted ? "Encrypted" : "Unencrypted");
4009
- }
4010
- function fetchTransportCache(encrypted) {
4011
- var storage = runtime_1["default"].getLocalStorage();
4012
- if (storage) {
4013
- try {
4014
- var serializedCache = storage[getTransportCacheKey(encrypted)];
4015
- if (serializedCache) {
4016
- return JSON.parse(serializedCache);
4017
- }
4018
- }
4019
- catch (e) {
4020
- flushTransportCache(encrypted);
4021
- }
4022
- }
4023
- return null;
4024
- }
4025
- function storeTransportCache(encrypted, transport, latency) {
4026
- var storage = runtime_1["default"].getLocalStorage();
4027
- if (storage) {
4028
- try {
4029
- storage[getTransportCacheKey(encrypted)] = Collections.safeJSONStringify({
4030
- timestamp: util_1["default"].now(),
4031
- transport: transport,
4032
- latency: latency
4033
- });
4034
- }
4035
- catch (e) {
4036
- }
4037
- }
4038
- }
4039
- function flushTransportCache(encrypted) {
4040
- var storage = runtime_1["default"].getLocalStorage();
4041
- if (storage) {
4042
- try {
4043
- delete storage[getTransportCacheKey(encrypted)];
4044
- }
4045
- catch (e) {
4046
- }
4047
- }
4048
- }
4049
-
4050
-
4051
- /***/ }),
4052
- /* 60 */
4053
- /***/ (function(module, exports, __webpack_require__) {
4054
-
4055
- "use strict";
4056
- var timers_1 = __webpack_require__(12);
4057
- var DelayedStrategy = (function () {
4058
- function DelayedStrategy(strategy, _a) {
4059
- var number = _a.delay;
4060
- this.strategy = strategy;
4061
- this.options = { delay: number };
4062
- }
4063
- DelayedStrategy.prototype.isSupported = function () {
4064
- return this.strategy.isSupported();
4065
- };
4066
- DelayedStrategy.prototype.connect = function (minPriority, callback) {
4067
- var strategy = this.strategy;
4068
- var runner;
4069
- var timer = new timers_1.OneOffTimer(this.options.delay, function () {
4070
- runner = strategy.connect(minPriority, callback);
4071
- });
4072
- return {
4073
- abort: function () {
4074
- timer.ensureAborted();
4075
- if (runner) {
4076
- runner.abort();
4077
- }
4078
- },
4079
- forceMinPriority: function (p) {
4080
- minPriority = p;
4081
- if (runner) {
4082
- runner.forceMinPriority(p);
4083
- }
4084
- }
4085
- };
4086
- };
4087
- return DelayedStrategy;
4088
- }());
4089
- exports.__esModule = true;
4090
- exports["default"] = DelayedStrategy;
4091
-
4092
-
4093
- /***/ }),
4094
- /* 61 */
4095
- /***/ (function(module, exports) {
4096
-
4097
- "use strict";
4098
- var IfStrategy = (function () {
4099
- function IfStrategy(test, trueBranch, falseBranch) {
4100
- this.test = test;
4101
- this.trueBranch = trueBranch;
4102
- this.falseBranch = falseBranch;
4103
- }
4104
- IfStrategy.prototype.isSupported = function () {
4105
- var branch = this.test() ? this.trueBranch : this.falseBranch;
4106
- return branch.isSupported();
4107
- };
4108
- IfStrategy.prototype.connect = function (minPriority, callback) {
4109
- var branch = this.test() ? this.trueBranch : this.falseBranch;
4110
- return branch.connect(minPriority, callback);
4111
- };
4112
- return IfStrategy;
4113
- }());
4114
- exports.__esModule = true;
4115
- exports["default"] = IfStrategy;
4116
-
4117
-
4118
- /***/ }),
4119
- /* 62 */
4120
- /***/ (function(module, exports) {
4121
-
4122
- "use strict";
4123
- var FirstConnectedStrategy = (function () {
4124
- function FirstConnectedStrategy(strategy) {
4125
- this.strategy = strategy;
4126
- }
4127
- FirstConnectedStrategy.prototype.isSupported = function () {
4128
- return this.strategy.isSupported();
4129
- };
4130
- FirstConnectedStrategy.prototype.connect = function (minPriority, callback) {
4131
- var runner = this.strategy.connect(minPriority, function (error, handshake) {
4132
- if (handshake) {
4133
- runner.abort();
4134
- }
4135
- callback(error, handshake);
4136
- });
4137
- return runner;
4138
- };
4139
- return FirstConnectedStrategy;
4140
- }());
4141
- exports.__esModule = true;
4142
- exports["default"] = FirstConnectedStrategy;
4143
-
4144
-
4145
- /***/ }),
4146
- /* 63 */
4147
- /***/ (function(module, exports, __webpack_require__) {
4148
-
4149
- "use strict";
4150
- var defaults_1 = __webpack_require__(5);
4151
- exports.getGlobalConfig = function () {
4152
- return {
4153
- wsHost: defaults_1["default"].host,
4154
- wsPort: defaults_1["default"].ws_port,
4155
- wssPort: defaults_1["default"].wss_port,
4156
- httpHost: defaults_1["default"].sockjs_host,
4157
- httpPort: defaults_1["default"].sockjs_http_port,
4158
- httpsPort: defaults_1["default"].sockjs_https_port,
4159
- httpPath: defaults_1["default"].sockjs_path,
4160
- statsHost: defaults_1["default"].stats_host,
4161
- authEndpoint: defaults_1["default"].channel_auth_endpoint,
4162
- authTransport: defaults_1["default"].channel_auth_transport,
4163
- activity_timeout: defaults_1["default"].activity_timeout,
4164
- pong_timeout: defaults_1["default"].pong_timeout,
4165
- unavailable_timeout: defaults_1["default"].unavailable_timeout
4166
- };
4167
- };
4168
- exports.getClusterConfig = function (clusterName) {
4169
- return {
4170
- wsHost: "ws-" + clusterName + ".pusher.com",
4171
- httpHost: "sockjs-" + clusterName + ".pusher.com"
4172
- };
4173
- };
4174
-
4175
-
4176
- /***/ })
4177
- /******/ ])
4178
- });
4179
- ;