pusher_rails 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ v0.1.6
2
+ ======
3
+ - Upgraded to pusher.js 1.11.0
4
+
1
5
  v0.1.5
2
6
  ======
3
7
  - Upgraded to pusher.js 1.10.1
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  Adds:
5
5
  - [pusher-gem v0.8.4](https://github.com/pusher/pusher-gem/tree/v0.8.4)
6
- - [pusher.js v1.10.1](https://github.com/pusher/pusher-js/tree/v1.10.1)
6
+ - [pusher.js v1.11.0](https://github.com/pusher/pusher-js/tree/v1.11.0)
7
7
  - [backpusher.js](https://github.com/pusher/backpusher/commit/e61c9d7a761fcb48f312416408d1bf4ed418735b#diff-1)
8
8
 
9
9
  This pulls in the *pusher-gem* as well as adding *pusher.js* and *backpusher.js* to the assets pipeline of your Rails 3.1+ app.
@@ -21,7 +21,7 @@ Licenses
21
21
  ========
22
22
 
23
23
  /*!
24
- * Pusher JavaScript Library v1.10.1
24
+ * Pusher JavaScript Library v1.11.0
25
25
  * http://pusherapp.com/
26
26
  *
27
27
  * Copyright 2011, Pusher
data/pusher_rails.gemspec CHANGED
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = 'pusher_rails'
6
- s.version = '0.1.5'
6
+ s.version = '0.1.6'
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.authors = ["David Grandinetti"]
9
9
  s.email = ["dave@wegoto12.com"]
@@ -1,12 +1,12 @@
1
1
  /*!
2
- * Pusher JavaScript Library v1.10.1
2
+ * Pusher JavaScript Library v1.11.0
3
3
  * http://pusherapp.com/
4
4
  *
5
5
  * Copyright 2011, Pusher
6
6
  * Released under the MIT licence.
7
7
  */
8
8
 
9
- if (typeof Function.prototype.scopedTo === 'undefined') {
9
+ if (Function.prototype.scopedTo === undefined) {
10
10
  Function.prototype.scopedTo = function(context, args) {
11
11
  var f = this;
12
12
  return function() {
@@ -18,14 +18,14 @@ if (typeof Function.prototype.scopedTo === 'undefined') {
18
18
 
19
19
  var Pusher = function(app_key, options) {
20
20
  this.options = options || {};
21
- this.path = '/app/' + app_key + '?client=js&version=' + Pusher.VERSION;
22
21
  this.key = app_key;
23
22
  this.channels = new Pusher.Channels();
24
- this.global_channel = new Pusher.Channel('pusher_global_channel');
25
- this.global_channel.global = true;
23
+ this.global_emitter = new Pusher.EventsDispatcher()
26
24
 
27
25
  var self = this;
28
26
 
27
+ this.checkAppKey();
28
+
29
29
  this.connection = new Pusher.Connection(this.key, this.options);
30
30
 
31
31
  // Setup / teardown connection
@@ -34,13 +34,21 @@ var Pusher = function(app_key, options) {
34
34
  self.subscribeAll();
35
35
  })
36
36
  .bind('message', function(params) {
37
- self.send_local_event(params.event, params.data, params.channel);
37
+ var internal = (params.event.indexOf('pusher_internal:') === 0);
38
+ if (params.channel) {
39
+ var channel;
40
+ if (channel = self.channel(params.channel)) {
41
+ channel.emit(params.event, params.data);
42
+ }
43
+ }
44
+ // Emit globaly [deprecated]
45
+ if (!internal) self.global_emitter.emit(params.event, params.data);
38
46
  })
39
47
  .bind('disconnected', function() {
40
48
  self.channels.disconnect();
41
49
  })
42
50
  .bind('error', function(err) {
43
- Pusher.debug('Error', err);
51
+ Pusher.warn('Error', err);
44
52
  });
45
53
 
46
54
  Pusher.instances.push(this);
@@ -62,12 +70,12 @@ Pusher.prototype = {
62
70
  },
63
71
 
64
72
  bind: function(event_name, callback) {
65
- this.global_channel.bind(event_name, callback);
73
+ this.global_emitter.bind(event_name, callback);
66
74
  return this;
67
75
  },
68
76
 
69
77
  bind_all: function(callback) {
70
- this.global_channel.bind_all(callback);
78
+ this.global_emitter.bind_all(callback);
71
79
  return this;
72
80
  },
73
81
 
@@ -109,30 +117,13 @@ Pusher.prototype = {
109
117
  },
110
118
 
111
119
  send_event: function(event_name, data, channel) {
112
- Pusher.debug("Event sent (channel,event,data)", channel, event_name, data);
113
-
114
- var payload = {
115
- event: event_name,
116
- data: data
117
- };
118
- if (channel) payload['channel'] = channel;
119
-
120
- return this.connection.send(JSON.stringify(payload));
120
+ return this.connection.send_event(event_name, data, channel);
121
121
  },
122
122
 
123
- send_local_event: function(event_name, event_data, channel_name) {
124
- event_data = Pusher.data_decorator(event_name, event_data);
125
- if (channel_name) {
126
- var channel = this.channel(channel_name);
127
- if (channel) {
128
- channel.dispatch_with_all(event_name, event_data);
129
- }
130
- } else {
131
- // Bit hacky but these events won't get logged otherwise
132
- Pusher.debug("Event recd (event,data)", event_name, event_data);
123
+ checkAppKey: function() {
124
+ if(this.key === null || this.key === undefined) {
125
+ Pusher.warn('Warning', 'You must pass your app key when you instantiate Pusher.');
133
126
  }
134
-
135
- this.global_channel.dispatch_with_all(event_name, event_data);
136
127
  }
137
128
  };
138
129
 
@@ -147,42 +138,61 @@ Pusher.Util = {
147
138
  }
148
139
  }
149
140
  return target;
141
+ },
142
+
143
+ stringify: function stringify() {
144
+ var m = ["Pusher"]
145
+ for (var i = 0; i < arguments.length; i++){
146
+ if (typeof arguments[i] === "string") {
147
+ m.push(arguments[i])
148
+ } else {
149
+ if (window['JSON'] == undefined) {
150
+ m.push(arguments[i].toString());
151
+ } else {
152
+ m.push(JSON.stringify(arguments[i]))
153
+ }
154
+ }
155
+ };
156
+ return m.join(" : ")
157
+ },
158
+
159
+ arrayIndexOf: function(array, item) { // MSIE doesn't have array.indexOf
160
+ var nativeIndexOf = Array.prototype.indexOf;
161
+ if (array == null) return -1;
162
+ if (nativeIndexOf && array.indexOf === nativeIndexOf) return array.indexOf(item);
163
+ for (i = 0, l = array.length; i < l; i++) if (array[i] === item) return i;
164
+ return -1;
150
165
  }
151
166
  };
152
167
 
153
168
  // To receive log output provide a Pusher.log function, for example
154
169
  // Pusher.log = function(m){console.log(m)}
155
170
  Pusher.debug = function() {
156
- if (!Pusher.log) { return }
157
- var m = ["Pusher"]
158
- for (var i = 0; i < arguments.length; i++){
159
- if (typeof arguments[i] === "string") {
160
- m.push(arguments[i])
161
- } else {
162
- if (window['JSON'] == undefined) {
163
- m.push(arguments[i].toString());
164
- } else {
165
- m.push(JSON.stringify(arguments[i]))
166
- }
167
- }
168
- };
169
- Pusher.log(m.join(" : "))
171
+ if (!Pusher.log) return
172
+ Pusher.log(Pusher.Util.stringify.apply(this, arguments))
170
173
  }
174
+ Pusher.warn = function() {
175
+ if (window.console && window.console.warn) {
176
+ window.console.warn(Pusher.Util.stringify.apply(this, arguments));
177
+ } else {
178
+ if (!Pusher.log) return
179
+ Pusher.log(Pusher.Util.stringify.apply(this, arguments));
180
+ }
181
+ };
171
182
 
172
183
  // Pusher defaults
173
- Pusher.VERSION = '1.10.1';
184
+ Pusher.VERSION = '1.11.0';
174
185
 
175
186
  Pusher.host = 'ws.pusherapp.com';
176
187
  Pusher.ws_port = 80;
177
188
  Pusher.wss_port = 443;
178
189
  Pusher.channel_auth_endpoint = '/pusher/auth';
179
- Pusher.connection_timeout = 5000;
180
- Pusher.cdn_http = 'http://js.pusherapp.com/'
181
- Pusher.cdn_https = 'https://d3ds63zw57jt09.cloudfront.net/'
190
+ Pusher.cdn_http = 'http://js.pusher.com/'
191
+ Pusher.cdn_https = 'https://d3dy5gmtp8yhk7.cloudfront.net/'
182
192
  Pusher.dependency_suffix = '';
183
- Pusher.data_decorator = function(event_name, event_data){ return event_data }; // wrap event_data before dispatching
184
- Pusher.allow_reconnect = true;
185
193
  Pusher.channel_auth_transport = 'ajax';
194
+ Pusher.activity_timeout = 120000;
195
+ Pusher.pong_timeout = 30000;
186
196
 
187
197
  Pusher.isReady = false;
188
198
  Pusher.ready = function() {
@@ -208,9 +218,11 @@ Example:
208
218
  emitter.bind_all(function(event_name, data){ alert(data) });
209
219
 
210
220
  --------------------------------------------------------*/
211
- function EventsDispatcher() {
221
+ function EventsDispatcher(failThrough) {
212
222
  this.callbacks = {};
213
223
  this.global_callbacks = [];
224
+ // Run this function when dispatching an event when no callbacks defined
225
+ this.failThrough = failThrough;
214
226
  }
215
227
 
216
228
  EventsDispatcher.prototype.bind = function(event_name, callback) {
@@ -218,42 +230,37 @@ Example:
218
230
  this.callbacks[event_name].push(callback);
219
231
  return this;// chainable
220
232
  };
221
-
222
- EventsDispatcher.prototype.emit = function(event_name, data) {
223
- this.dispatch_global_callbacks(event_name, data);
224
- this.dispatch(event_name, data);
233
+
234
+ EventsDispatcher.prototype.unbind = function(eventName, callback) {
235
+ if(this.callbacks[eventName]) {
236
+ var index = Pusher.Util.arrayIndexOf(this.callbacks[eventName], callback);
237
+ this.callbacks[eventName].splice(index, 1);
238
+ }
225
239
  return this;
226
240
  };
227
241
 
228
- EventsDispatcher.prototype.bind_all = function(callback) {
229
- this.global_callbacks.push(callback);
230
- return this;
231
- };
242
+ EventsDispatcher.prototype.emit = function(event_name, data) {
243
+ // Global callbacks
244
+ for (var i = 0; i < this.global_callbacks.length; i++) {
245
+ this.global_callbacks[i](event_name, data);
246
+ }
232
247
 
233
- EventsDispatcher.prototype.dispatch = function(event_name, event_data) {
248
+ // Event callbacks
234
249
  var callbacks = this.callbacks[event_name];
235
-
236
250
  if (callbacks) {
237
251
  for (var i = 0; i < callbacks.length; i++) {
238
- callbacks[i](event_data);
239
- }
240
- } else {
241
- // Log is un-necessary in case of global channel or connection object
242
- if (!(this.global || this instanceof Pusher.Connection || this instanceof Pusher.Machine)) {
243
- Pusher.debug('No callbacks for ' + event_name, event_data);
252
+ callbacks[i](data);
244
253
  }
254
+ } else if (this.failThrough) {
255
+ this.failThrough(event_name, data)
245
256
  }
246
- };
247
257
 
248
- EventsDispatcher.prototype.dispatch_global_callbacks = function(event_name, data) {
249
- for (var i = 0; i < this.global_callbacks.length; i++) {
250
- this.global_callbacks[i](event_name, data);
251
- }
258
+ return this;
252
259
  };
253
260
 
254
- EventsDispatcher.prototype.dispatch_with_all = function(event_name, data) {
255
- this.dispatch(event_name, data);
256
- this.dispatch_global_callbacks(event_name, data);
261
+ EventsDispatcher.prototype.bind_all = function(callback) {
262
+ this.global_callbacks.push(callback);
263
+ return this;
257
264
  };
258
265
 
259
266
  this.Pusher.EventsDispatcher = EventsDispatcher;
@@ -266,16 +273,6 @@ Example:
266
273
  Helpers:
267
274
  -----------------------------------------------*/
268
275
 
269
- // MSIE doesn't have array.indexOf
270
- var nativeIndexOf = Array.prototype.indexOf;
271
- function indexOf(array, item) {
272
- if (array == null) return -1;
273
- if (nativeIndexOf && array.indexOf === nativeIndexOf) return array.indexOf(item);
274
- for (i = 0, l = array.length; i < l; i++) if (array[i] === item) return i;
275
- return -1;
276
- }
277
-
278
-
279
276
  function capitalize(str) {
280
277
  return str.substr(0, 1).toUpperCase() + str.substr(1);
281
278
  }
@@ -290,10 +287,9 @@ Example:
290
287
  /*-----------------------------------------------
291
288
  The State Machine
292
289
  -----------------------------------------------*/
293
- function Machine(actor, initialState, transitions, stateActions) {
290
+ function Machine(initialState, transitions, stateActions) {
294
291
  Pusher.EventsDispatcher.call(this);
295
292
 
296
- this.actor = actor;
297
293
  this.state = undefined;
298
294
  this.errors = [];
299
295
 
@@ -310,8 +306,8 @@ Example:
310
306
  var prevState = this.state;
311
307
  var stateCallbacks = this.stateActions;
312
308
 
313
- if (prevState && (indexOf(this.transitions[prevState], nextState) == -1)) {
314
- throw new Error(this.actor.key + ': Invalid transition [' + prevState + ' to ' + nextState + ']');
309
+ if (prevState && (Pusher.Util.arrayIndexOf(this.transitions[prevState], nextState) == -1)) {
310
+ throw new Error('Invalid transition [' + prevState + ' to ' + nextState + ']');
315
311
  }
316
312
 
317
313
  // exit
@@ -350,8 +346,6 @@ Example:
350
346
  }).call(this);
351
347
 
352
348
  ;(function() {
353
- var Pusher = this.Pusher;
354
-
355
349
  /*
356
350
  A little bauble to interface with window.navigator.onLine,
357
351
  window.ononline and window.onoffline. Easier to mock.
@@ -382,7 +376,12 @@ Example:
382
376
  };
383
377
 
384
378
  Pusher.Util.extend(NetInfo.prototype, Pusher.EventsDispatcher.prototype);
385
- this.Pusher.NetInfo = Pusher.NetInfo = NetInfo;
379
+
380
+ this.Pusher.NetInfo = NetInfo;
381
+ }).call(this);
382
+
383
+ ;(function() {
384
+ var Pusher = this.Pusher;
386
385
 
387
386
  var machineTransitions = {
388
387
  'initialized': ['waiting', 'failed'],
@@ -425,7 +424,7 @@ Example:
425
424
 
426
425
  Pusher.EventsDispatcher.call(this);
427
426
 
428
- this.options = Pusher.Util.extend({encrypted: false}, options || {});
427
+ this.options = Pusher.Util.extend({encrypted: false}, options);
429
428
 
430
429
  this.netInfo = new Pusher.NetInfo();
431
430
 
@@ -452,7 +451,7 @@ Example:
452
451
  });
453
452
 
454
453
  // define the state machine that runs the connection
455
- this._machine = new Pusher.Machine(self, 'initialized', machineTransitions, {
454
+ this._machine = new Pusher.Machine('initialized', machineTransitions, {
456
455
 
457
456
  // TODO: Use the constructor for this.
458
457
  initializedPre: function() {
@@ -467,7 +466,7 @@ Example:
467
466
 
468
467
  waitingPre: function() {
469
468
  if (self.connectionWait > 0) {
470
- informUser('connecting_in', self.connectionWait);
469
+ self.emit('connecting_in', self.connectionWait);
471
470
  }
472
471
 
473
472
  if (self.netInfo.isOnLine() === false || self.connectionAttempts > 4){
@@ -529,7 +528,7 @@ Example:
529
528
  },
530
529
 
531
530
  openPre: function() {
532
- self.socket.onmessage = ws_onMessage;
531
+ self.socket.onmessage = ws_onMessageOpen;
533
532
  self.socket.onerror = ws_onError;
534
533
  self.socket.onclose = transitionToWaiting;
535
534
 
@@ -552,11 +551,13 @@ Example:
552
551
  connectedPre: function(socket_id) {
553
552
  self.socket_id = socket_id;
554
553
 
555
- self.socket.onmessage = ws_onMessage;
554
+ self.socket.onmessage = ws_onMessageConnected;
556
555
  self.socket.onerror = ws_onError;
557
556
  self.socket.onclose = transitionToWaiting;
558
557
 
559
558
  resetConnectionParameters(self);
559
+
560
+ resetActivityCheck();
560
561
  },
561
562
 
562
563
  connectedPost: function() {
@@ -564,6 +565,7 @@ Example:
564
565
  },
565
566
 
566
567
  connectedExit: function() {
568
+ stopActivityCheck();
567
569
  triggerStateChange('disconnected');
568
570
  },
569
571
 
@@ -639,6 +641,22 @@ Example:
639
641
  self._machine.transition('impermanentlyClosing');
640
642
  }
641
643
 
644
+ function resetActivityCheck() {
645
+ if (self._activityTimer) { clearTimeout(self._activityTimer); }
646
+ // Send ping after inactivity
647
+ self._activityTimer = setTimeout(function() {
648
+ self.send_event('pusher:ping', {})
649
+ // Wait for pong response
650
+ self._activityTimer = setTimeout(function() {
651
+ self.socket.close();
652
+ }, (self.options.pong_timeout || Pusher.pong_timeout))
653
+ }, (self.options.activity_timeout || Pusher.activity_timeout))
654
+ }
655
+
656
+ function stopActivityCheck() {
657
+ if (self._activityTimer) { clearTimeout(self._activityTimer); }
658
+ }
659
+
642
660
  /*-----------------------------------------------
643
661
  WebSocket Callbacks
644
662
  -----------------------------------------------*/
@@ -648,38 +666,49 @@ Example:
648
666
  self._machine.transition('open');
649
667
  };
650
668
 
651
- function ws_onMessage(event) {
669
+ function ws_onMessageOpen(event) {
652
670
  var params = parseWebSocketEvent(event);
653
-
654
- // case of invalid JSON payload sent
655
- // we have to handle the error in the parseWebSocketEvent
656
- // method as JavaScript error objects are kinda icky.
657
- if (typeof params === 'undefined') return;
658
-
659
- Pusher.debug('Event recd (event,data)', params.event, params.data);
660
-
661
- // Continue to work with valid payloads:
662
- if (params.event === 'pusher:connection_established') {
663
- self._machine.transition('connected', params.data.socket_id);
664
- } else if (params.event === 'pusher:error') {
665
- // first inform the end-developer of this error
666
- informUser('error', {type: 'PusherError', data: params.data});
667
-
668
- // App not found by key - close connection
669
- if (params.data.code === 4001) {
670
- self._machine.transition('permanentlyClosing');
671
+ if (params !== undefined) {
672
+ if (params.event === 'pusher:connection_established') {
673
+ self._machine.transition('connected', params.data.socket_id);
674
+ } else if (params.event === 'pusher:error') {
675
+ // first inform the end-developer of this error
676
+ self.emit('error', {type: 'PusherError', data: params.data});
677
+
678
+ switch (params.data.code) {
679
+ case 4000:
680
+ Pusher.warn(params.data.message);
681
+
682
+ self.compulsorySecure = true;
683
+ self.connectionSecure = true;
684
+ self.options.encrypted = true;
685
+ break;
686
+ case 4001:
687
+ // App not found by key - close connection
688
+ self._machine.transition('permanentlyClosing');
689
+ break;
690
+ }
671
691
  }
692
+ }
693
+ }
672
694
 
673
- if (params.data.code === 4000) {
674
- Pusher.debug(params.data.message);
695
+ function ws_onMessageConnected(event) {
696
+ resetActivityCheck();
675
697
 
676
- self.compulsorySecure = true;
677
- self.connectionSecure = true;
678
- self.options.encrypted = true;
698
+ var params = parseWebSocketEvent(event);
699
+ if (params !== undefined) {
700
+ Pusher.debug('Event recd', params);
701
+
702
+ switch (params.event) {
703
+ case 'pusher:error':
704
+ self.emit('error', {type: 'PusherError', data: params.data});
705
+ break;
706
+ case 'pusher:ping':
707
+ self.send_event('pusher:pong', {})
708
+ break;
679
709
  }
680
- } else if (params.event === 'pusher:heartbeat') {
681
- } else if (self._machine.is('connected')) {
682
- informUser('message', params);
710
+
711
+ self.emit('message', params);
683
712
  }
684
713
  }
685
714
 
@@ -706,7 +735,7 @@ Example:
706
735
 
707
736
  return params;
708
737
  } catch (e) {
709
- informUser('error', {type: 'MessageParseError', error: e, data: event.data});
738
+ self.emit('error', {type: 'MessageParseError', error: e, data: event.data});
710
739
  }
711
740
  }
712
741
 
@@ -715,7 +744,7 @@ Example:
715
744
  }
716
745
 
717
746
  function ws_onError() {
718
- informUser('error', {
747
+ self.emit('error', {
719
748
  type: 'WebSocketError'
720
749
  });
721
750
 
@@ -724,10 +753,6 @@ Example:
724
753
  self._machine.transition('impermanentlyClosing');
725
754
  }
726
755
 
727
- function informUser(eventName, data) {
728
- self.emit(eventName, data);
729
- }
730
-
731
756
  function triggerStateChange(newState, data) {
732
757
  // avoid emitting and changing the state
733
758
  // multiple times when it's the same.
@@ -746,7 +771,7 @@ Example:
746
771
 
747
772
  Connection.prototype.connect = function() {
748
773
  // no WebSockets
749
- if (Pusher.Transport === null || typeof Pusher.Transport === 'undefined') {
774
+ if (Pusher.Transport === null || Pusher.Transport === undefined) {
750
775
  this._machine.transition('failed');
751
776
  }
752
777
  // initial open of connection
@@ -773,12 +798,19 @@ Example:
773
798
  }
774
799
  };
775
800
 
776
- Connection.prototype.disconnect = function() {
777
- if (this._machine.is('permanentlyClosed')) {
778
- return;
779
- }
801
+ Connection.prototype.send_event = function(event_name, data, channel) {
802
+ var payload = {
803
+ event: event_name,
804
+ data: data
805
+ };
806
+ if (channel) payload['channel'] = channel;
780
807
 
781
- Pusher.debug('Disconnecting');
808
+ Pusher.debug('Event sent', payload);
809
+ return this.send(JSON.stringify(payload));
810
+ }
811
+
812
+ Connection.prototype.disconnect = function() {
813
+ if (this._machine.is('permanentlyClosed')) return;
782
814
 
783
815
  if (this._machine.is('waiting')) {
784
816
  this._machine.transition('permanentlyClosed');
@@ -823,15 +855,17 @@ Pusher.Channels.prototype = {
823
855
  };
824
856
 
825
857
  Pusher.Channel = function(channel_name, pusher) {
826
- var channel = this;
827
- Pusher.EventsDispatcher.call(this);
858
+ var self = this;
859
+ Pusher.EventsDispatcher.call(this, function(event_name, event_data) {
860
+ Pusher.debug('No callbacks on ' + channel_name + ' for ' + event_name);
861
+ });
828
862
 
829
863
  this.pusher = pusher;
830
864
  this.name = channel_name;
831
865
  this.subscribed = false;
832
866
 
833
- this.bind('pusher_internal:subscription_succeeded', function(sub_data){
834
- channel.acknowledge_subscription(sub_data);
867
+ this.bind('pusher_internal:subscription_succeeded', function(data) {
868
+ self.onSubscriptionSucceeded(data);
835
869
  });
836
870
  };
837
871
 
@@ -840,18 +874,9 @@ Pusher.Channel.prototype = {
840
874
  init: function() {},
841
875
  disconnect: function() {},
842
876
 
843
- // Activate after successful subscription. Called on top-level pusher:subscription_succeeded
844
- acknowledge_subscription: function(data){
877
+ onSubscriptionSucceeded: function(data) {
845
878
  this.subscribed = true;
846
- this.dispatch_with_all('pusher:subscription_succeeded');
847
- },
848
-
849
- is_private: function(){
850
- return false;
851
- },
852
-
853
- is_presence: function(){
854
- return false;
879
+ this.emit('pusher:subscription_succeeded');
855
880
  },
856
881
 
857
882
  authorize: function(pusher, callback){
@@ -897,7 +922,7 @@ Pusher.authorizers = {
897
922
  callback(false, data);
898
923
  }
899
924
  } else {
900
- Pusher.debug("Couldn't get auth info from your webapp", status);
925
+ Pusher.warn("Couldn't get auth info from your webapp", status);
901
926
  callback(true, xhr.status);
902
927
  }
903
928
  }
@@ -919,27 +944,22 @@ Pusher.authorizers = {
919
944
  };
920
945
 
921
946
  Pusher.Channel.PrivateChannel = {
922
- is_private: function(){
923
- return true;
924
- },
925
-
926
947
  authorize: function(pusher, callback){
927
948
  Pusher.authorizers[Pusher.channel_auth_transport].scopedTo(this)(pusher, callback);
928
949
  }
929
950
  };
930
951
 
931
952
  Pusher.Channel.PresenceChannel = {
932
-
933
953
  init: function(){
934
954
  this.bind('pusher_internal:member_added', function(data){
935
955
  var member = this.members.add(data.user_id, data.user_info);
936
- this.dispatch_with_all('pusher:member_added', member);
956
+ this.emit('pusher:member_added', member);
937
957
  }.scopedTo(this))
938
958
 
939
959
  this.bind('pusher_internal:member_removed', function(data){
940
960
  var member = this.members.remove(data.user_id);
941
961
  if (member) {
942
- this.dispatch_with_all('pusher:member_removed', member);
962
+ this.emit('pusher:member_removed', member);
943
963
  }
944
964
  }.scopedTo(this))
945
965
  },
@@ -948,16 +968,12 @@ Pusher.Channel.PresenceChannel = {
948
968
  this.members.clear();
949
969
  },
950
970
 
951
- acknowledge_subscription: function(sub_data){
952
- this.members._members_map = sub_data.presence.hash;
953
- this.members.count = sub_data.presence.count;
971
+ onSubscriptionSucceeded: function(data) {
972
+ this.members._members_map = data.presence.hash;
973
+ this.members.count = data.presence.count;
954
974
  this.subscribed = true;
955
975
 
956
- this.dispatch_with_all('pusher:subscription_succeeded', this.members);
957
- },
958
-
959
- is_presence: function(){
960
- return true;
976
+ this.emit('pusher:subscription_succeeded', this.members);
961
977
  },
962
978
 
963
979
  members: {
@@ -1008,19 +1024,16 @@ Pusher.Channel.PresenceChannel = {
1008
1024
 
1009
1025
  Pusher.Channel.factory = function(channel_name, pusher){
1010
1026
  var channel = new Pusher.Channel(channel_name, pusher);
1011
- if(channel_name.indexOf(Pusher.Channel.private_prefix) === 0) {
1027
+ if (channel_name.indexOf('private-') === 0) {
1012
1028
  Pusher.Util.extend(channel, Pusher.Channel.PrivateChannel);
1013
- } else if(channel_name.indexOf(Pusher.Channel.presence_prefix) === 0) {
1029
+ } else if (channel_name.indexOf('presence-') === 0) {
1014
1030
  Pusher.Util.extend(channel, Pusher.Channel.PrivateChannel);
1015
1031
  Pusher.Util.extend(channel, Pusher.Channel.PresenceChannel);
1016
1032
  };
1017
- channel.init();// inheritable constructor
1033
+ channel.init();
1018
1034
  return channel;
1019
1035
  };
1020
1036
 
1021
- Pusher.Channel.private_prefix = "private-";
1022
- Pusher.Channel.presence_prefix = "presence-";
1023
-
1024
1037
  var _require = (function () {
1025
1038
 
1026
1039
  var handleScriptLoaded;
@@ -1074,20 +1087,20 @@ var _require = (function () {
1074
1087
  var root = cdn + Pusher.VERSION;
1075
1088
  var deps = [];
1076
1089
 
1077
- if (typeof window['JSON'] === 'undefined') {
1090
+ if (window['JSON'] === undefined) {
1078
1091
  deps.push(root + '/json2' + Pusher.dependency_suffix + '.js');
1079
1092
  }
1080
- if (typeof window['WebSocket'] === 'undefined' && typeof window['MozWebSocket'] === 'undefined') {
1093
+ if (window['WebSocket'] === undefined && window['MozWebSocket'] === undefined) {
1081
1094
  // We manually initialize web-socket-js to iron out cross browser issues
1082
1095
  window.WEB_SOCKET_DISABLE_AUTO_INITIALIZATION = true;
1083
1096
  deps.push(root + '/flashfallback' + Pusher.dependency_suffix + '.js');
1084
1097
  }
1085
1098
 
1086
1099
  var initialize = function() {
1087
- if (typeof window['WebSocket'] === 'undefined' && typeof window['MozWebSocket'] === 'undefined') {
1100
+ if (window['WebSocket'] === undefined && window['MozWebSocket'] === undefined) {
1088
1101
  return function() {
1089
1102
  // This runs after flashfallback.js has loaded
1090
- if (typeof window['WebSocket'] !== 'undefined' && typeof window['MozWebSocket'] === 'undefined') {
1103
+ if (window['WebSocket'] !== undefined && window['MozWebSocket'] === undefined) {
1091
1104
  // window['WebSocket'] is a flash emulation of WebSocket
1092
1105
  Pusher.Transport = window['WebSocket'];
1093
1106
  Pusher.TransportType = 'flash';
@@ -1108,7 +1121,7 @@ var _require = (function () {
1108
1121
  return function() {
1109
1122
  // This is because Mozilla have decided to
1110
1123
  // prefix the WebSocket constructor with "Moz".
1111
- if (typeof window['MozWebSocket'] !== 'undefined') {
1124
+ if (window['MozWebSocket'] !== undefined) {
1112
1125
  Pusher.Transport = window['MozWebSocket'];
1113
1126
  } else {
1114
1127
  Pusher.Transport = window['WebSocket'];
metadata CHANGED
@@ -1,35 +1,46 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: pusher_rails
3
- version: !ruby/object:Gem::Version
4
- version: 0.1.5
5
- prerelease:
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 6
9
+ version: 0.1.6
6
10
  platform: ruby
7
- authors:
11
+ authors:
8
12
  - David Grandinetti
9
13
  autorequire:
10
14
  bindir: bin
11
15
  cert_chain: []
12
- date: 2012-01-03 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
16
+
17
+ date: 2012-01-23 00:00:00 +00:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
15
21
  name: pusher
16
- requirement: &70344468425460 !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
19
25
  - - ~>
20
- - !ruby/object:Gem::Version
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ - 8
30
+ - 4
21
31
  version: 0.8.4
22
32
  type: :runtime
23
- prerelease: false
24
- version_requirements: *70344468425460
25
- description: Adds pusher.js/backpusher.js to the asset pipeline and pusher-gem to
26
- to your app.
27
- email:
33
+ version_requirements: *id001
34
+ description: Adds pusher.js/backpusher.js to the asset pipeline and pusher-gem to to your app.
35
+ email:
28
36
  - dave@wegoto12.com
29
37
  executables: []
38
+
30
39
  extensions: []
40
+
31
41
  extra_rdoc_files: []
32
- files:
42
+
43
+ files:
33
44
  - .gitignore
34
45
  - CHANGELOG.md
35
46
  - README.md
@@ -37,28 +48,35 @@ files:
37
48
  - pusher_rails.gemspec
38
49
  - vendor/assets/javascripts/backpusher.js
39
50
  - vendor/assets/javascripts/pusher.js
51
+ has_rdoc: true
40
52
  homepage: https://github.com/dbgrandi/pusher_rails
41
53
  licenses: []
54
+
42
55
  post_install_message:
43
56
  rdoc_options: []
44
- require_paths:
57
+
58
+ require_paths:
45
59
  - lib
46
- required_ruby_version: !ruby/object:Gem::Requirement
47
- none: false
48
- requirements:
49
- - - ! '>='
50
- - !ruby/object:Gem::Version
51
- version: '0'
52
- required_rubygems_version: !ruby/object:Gem::Requirement
53
- none: false
54
- requirements:
55
- - - ! '>='
56
- - !ruby/object:Gem::Version
57
- version: '0'
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ segments:
65
+ - 0
66
+ version: "0"
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ segments:
72
+ - 0
73
+ version: "0"
58
74
  requirements: []
75
+
59
76
  rubyforge_project:
60
- rubygems_version: 1.8.10
77
+ rubygems_version: 1.3.6
61
78
  signing_key:
62
79
  specification_version: 3
63
80
  summary: Pusher integration for Rails 3.1+
64
81
  test_files: []
82
+