pusher_rails 0.1.4 → 0.1.5

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.5
2
+ ======
3
+ - Upgraded to pusher.js 1.10.1
4
+
1
5
  v0.1.4
2
6
  ======
3
7
  - Upgraded backpusher.js to pusher/backpusher@9caa3ecce01916d8bcb8da1d5997912ec3c60bf9 which fixes a problem with success/error callbacks on create/fetch calls.
data/README.md CHANGED
@@ -3,10 +3,10 @@
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.9.4](https://github.com/pusher/pusher-js/tree/v1.9.4)
6
+ - [pusher.js v1.10.1](https://github.com/pusher/pusher-js/tree/v1.10.1)
7
7
  - [backpusher.js](https://github.com/pusher/backpusher/commit/e61c9d7a761fcb48f312416408d1bf4ed418735b#diff-1)
8
8
 
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.
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.
10
10
 
11
11
  Add this to your app/assets/javascripts/application.js:
12
12
 
@@ -20,17 +20,17 @@ Add this to your app/assets/javascripts/application.js:
20
20
  Licenses
21
21
  ========
22
22
 
23
- /*
24
- * Pusher JavaScript Library v1.9.4
23
+ /*!
24
+ * Pusher JavaScript Library v1.10.1
25
25
  * http://pusherapp.com/
26
26
  *
27
27
  * Copyright 2011, Pusher
28
28
  * Released under the MIT licence.
29
29
  */
30
-
30
+
31
31
  // Backpusher.js 0.0.1
32
32
  // (c) 2011 Pusher.
33
33
  // Backpusher may be freely distributed under the MIT license.
34
34
  // For all details and documentation:
35
35
  // http://github.com/pusher/backpusher
36
-
36
+
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.4'
6
+ s.version = '0.1.5'
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.authors = ["David Grandinetti"]
9
9
  s.email = ["dave@wegoto12.com"]
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Pusher JavaScript Library v1.9.4
2
+ * Pusher JavaScript Library v1.10.1
3
3
  * http://pusherapp.com/
4
4
  *
5
5
  * Copyright 2011, Pusher
@@ -58,7 +58,6 @@ Pusher.prototype = {
58
58
  },
59
59
 
60
60
  disconnect: function() {
61
- Pusher.debug('Disconnecting');
62
61
  this.connection.disconnect();
63
62
  },
64
63
 
@@ -87,7 +86,7 @@ Pusher.prototype = {
87
86
  if (this.connection.state === 'connected') {
88
87
  channel.authorize(this, function(err, data) {
89
88
  if (err) {
90
- channel.emit('subscription_error', data);
89
+ channel.emit('pusher:subscription_error', data);
91
90
  } else {
92
91
  self.send_event('pusher:subscribe', {
93
92
  channel: channel_name,
@@ -118,8 +117,7 @@ Pusher.prototype = {
118
117
  };
119
118
  if (channel) payload['channel'] = channel;
120
119
 
121
- this.connection.send(JSON.stringify(payload));
122
- return this;
120
+ return this.connection.send(JSON.stringify(payload));
123
121
  },
124
122
 
125
123
  send_local_event: function(event_name, event_data, channel_name) {
@@ -172,7 +170,7 @@ Pusher.debug = function() {
172
170
  }
173
171
 
174
172
  // Pusher defaults
175
- Pusher.VERSION = '1.9.4';
173
+ Pusher.VERSION = '1.10.1';
176
174
 
177
175
  Pusher.host = 'ws.pusherapp.com';
178
176
  Pusher.ws_port = 80;
@@ -181,6 +179,7 @@ Pusher.channel_auth_endpoint = '/pusher/auth';
181
179
  Pusher.connection_timeout = 5000;
182
180
  Pusher.cdn_http = 'http://js.pusherapp.com/'
183
181
  Pusher.cdn_https = 'https://d3ds63zw57jt09.cloudfront.net/'
182
+ Pusher.dependency_suffix = '';
184
183
  Pusher.data_decorator = function(event_name, event_data){ return event_data }; // wrap event_data before dispatching
185
184
  Pusher.allow_reconnect = true;
186
185
  Pusher.channel_auth_transport = 'ajax';
@@ -353,6 +352,38 @@ Example:
353
352
  ;(function() {
354
353
  var Pusher = this.Pusher;
355
354
 
355
+ /*
356
+ A little bauble to interface with window.navigator.onLine,
357
+ window.ononline and window.onoffline. Easier to mock.
358
+ */
359
+ var NetInfo = function() {
360
+ var self = this;
361
+ Pusher.EventsDispatcher.call(this);
362
+ // This is okay, as IE doesn't support this stuff anyway.
363
+ if (window.addEventListener !== undefined) {
364
+ window.addEventListener("online", function() {
365
+ self.emit('online', null);
366
+ }, false);
367
+ window.addEventListener("offline", function() {
368
+ self.emit('offline', null);
369
+ }, false);
370
+ }
371
+ };
372
+
373
+ // Offline means definitely offline (no connection to router).
374
+ // Inverse does NOT mean definitely online (only currently supported in Safari
375
+ // and even there only means the device has a connection to the router).
376
+ NetInfo.prototype.isOnLine = function() {
377
+ if (window.navigator.onLine === undefined) {
378
+ return true;
379
+ } else {
380
+ return window.navigator.onLine;
381
+ }
382
+ };
383
+
384
+ Pusher.Util.extend(NetInfo.prototype, Pusher.EventsDispatcher.prototype);
385
+ this.Pusher.NetInfo = Pusher.NetInfo = NetInfo;
386
+
356
387
  var machineTransitions = {
357
388
  'initialized': ['waiting', 'failed'],
358
389
  'waiting': ['connecting', 'permanentlyClosed'],
@@ -361,7 +392,8 @@ Example:
361
392
  'connected': ['permanentlyClosing', 'impermanentlyClosing', 'waiting'],
362
393
  'impermanentlyClosing': ['waiting', 'permanentlyClosing'],
363
394
  'permanentlyClosing': ['permanentlyClosed'],
364
- 'permanentlyClosed': ['waiting']
395
+ 'permanentlyClosed': ['waiting'],
396
+ 'failed': ['permanentlyClosing']
365
397
  };
366
398
 
367
399
 
@@ -396,7 +428,28 @@ Example:
396
428
  this.options = Pusher.Util.extend({encrypted: false}, options || {});
397
429
 
398
430
  this.netInfo = new Pusher.NetInfo();
399
- Pusher.EventsDispatcher.call(this.netInfo);
431
+
432
+ this.netInfo.bind('online', function(){
433
+ if (self._machine.is('waiting')) {
434
+ self._machine.transition('connecting');
435
+ triggerStateChange('connecting');
436
+ }
437
+ });
438
+
439
+ this.netInfo.bind('offline', function() {
440
+ if (self._machine.is('connected')) {
441
+ // These are for Chrome 15, which ends up
442
+ // having two sockets hanging around.
443
+ self.socket.onclose = undefined;
444
+ self.socket.onmessage = undefined;
445
+ self.socket.onerror = undefined;
446
+ self.socket.onopen = undefined;
447
+
448
+ self.socket.close();
449
+ self.socket = undefined;
450
+ self._machine.transition('waiting');
451
+ }
452
+ });
400
453
 
401
454
  // define the state machine that runs the connection
402
455
  this._machine = new Pusher.Machine(self, 'initialized', machineTransitions, {
@@ -413,28 +466,21 @@ Example:
413
466
  },
414
467
 
415
468
  waitingPre: function() {
416
- self._waitingTimer = setTimeout(function() {
417
- self._machine.transition('connecting');
418
- }, self.connectionWait);
419
-
420
469
  if (self.connectionWait > 0) {
421
470
  informUser('connecting_in', self.connectionWait);
422
471
  }
423
472
 
424
- if (netInfoSaysOffline() || self.connectionAttempts > 4) {
425
- if(netInfoSaysOffline())
426
- {
427
- // called by some browsers upon reconnection to router
428
- self.netInfo.bind('online', function() {
429
- if(self._machine.is('waiting'))
430
- self._machine.transition('connecting');
431
- });
432
- }
433
-
473
+ if (self.netInfo.isOnLine() === false || self.connectionAttempts > 4){
434
474
  triggerStateChange('unavailable');
435
475
  } else {
436
476
  triggerStateChange('connecting');
437
477
  }
478
+
479
+ if (self.netInfo.isOnLine() === true) {
480
+ self._waitingTimer = setTimeout(function() {
481
+ self._machine.transition('connecting');
482
+ }, self.connectionWait);
483
+ }
438
484
  },
439
485
 
440
486
  waitingExit: function() {
@@ -442,6 +488,15 @@ Example:
442
488
  },
443
489
 
444
490
  connectingPre: function() {
491
+ // Case that a user manages to get to the connecting
492
+ // state even when offline.
493
+ if (self.netInfo.isOnLine() === false) {
494
+ self._machine.transition('waiting');
495
+ triggerStateChange('unavailable');
496
+
497
+ return;
498
+ }
499
+
445
500
  // removed: if not closed, something is wrong that we should fix
446
501
  // if(self.socket !== undefined) self.socket.close();
447
502
  var url = formatURL(self.key, self.connectionSecure);
@@ -499,14 +554,7 @@ Example:
499
554
 
500
555
  self.socket.onmessage = ws_onMessage;
501
556
  self.socket.onerror = ws_onError;
502
- self.socket.onclose = function() {
503
- self._machine.transition('waiting');
504
- };
505
- // onoffline called by some browsers on loss of connection to router
506
- self.netInfo.bind('offline', function() {
507
- if(self._machine.is('connected'))
508
- self.socket.close();
509
- });
557
+ self.socket.onclose = transitionToWaiting;
510
558
 
511
559
  resetConnectionParameters(self);
512
560
  },
@@ -520,17 +568,24 @@ Example:
520
568
  },
521
569
 
522
570
  impermanentlyClosingPost: function() {
523
- self.socket.onclose = transitionToWaiting;
524
- self.socket.close();
571
+ if (self.socket) {
572
+ self.socket.onclose = transitionToWaiting;
573
+ self.socket.close();
574
+ }
525
575
  },
526
576
 
527
577
  permanentlyClosingPost: function() {
528
- self.socket.onclose = function() {
578
+ if (self.socket) {
579
+ self.socket.onclose = function() {
580
+ resetConnectionParameters(self);
581
+ self._machine.transition('permanentlyClosed');
582
+ };
583
+
584
+ self.socket.close();
585
+ } else {
529
586
  resetConnectionParameters(self);
530
587
  self._machine.transition('permanentlyClosed');
531
- };
532
-
533
- self.socket.close();
588
+ }
534
589
  },
535
590
 
536
591
  failedPre: function() {
@@ -566,7 +621,12 @@ Example:
566
621
  var port = Pusher.ws_port;
567
622
  var protocol = 'ws://';
568
623
 
569
- if (isSecure) {
624
+ // Always connect with SSL if the current page has
625
+ // been loaded via HTTPS.
626
+ //
627
+ // FUTURE: Always connect using SSL.
628
+ //
629
+ if (isSecure || document.location.protocol === 'https:') {
570
630
  port = Pusher.wss_port;
571
631
  protocol = 'wss://';
572
632
  }
@@ -609,6 +669,14 @@ Example:
609
669
  if (params.data.code === 4001) {
610
670
  self._machine.transition('permanentlyClosing');
611
671
  }
672
+
673
+ if (params.data.code === 4000) {
674
+ Pusher.debug(params.data.message);
675
+
676
+ self.compulsorySecure = true;
677
+ self.connectionSecure = true;
678
+ self.options.encrypted = true;
679
+ }
612
680
  } else if (params.event === 'pusher:heartbeat') {
613
681
  } else if (self._machine.is('connected')) {
614
682
  informUser('message', params);
@@ -674,18 +742,11 @@ Example:
674
742
  self.emit('state_change', {previous: prevState, current: newState});
675
743
  self.emit(newState, data);
676
744
  }
677
-
678
- // Offline means definitely offline (no connection to router).
679
- // Inverse does NOT mean definitely online (only currently supported in Safari
680
- // and even there only means the device has a connection to the router).
681
- function netInfoSaysOffline() {
682
- return self.netInfo.isOnLine() === false;
683
- }
684
745
  };
685
746
 
686
747
  Connection.prototype.connect = function() {
687
748
  // no WebSockets
688
- if (Pusher.Transport === null) {
749
+ if (Pusher.Transport === null || typeof Pusher.Transport === 'undefined') {
689
750
  this._machine.transition('failed');
690
751
  }
691
752
  // initial open of connection
@@ -694,7 +755,7 @@ Example:
694
755
  this._machine.transition('waiting');
695
756
  }
696
757
  // user skipping connection wait
697
- else if (this._machine.is('waiting')) {
758
+ else if (this._machine.is('waiting') && this.netInfo.isOnLine() === true) {
698
759
  this._machine.transition('connecting');
699
760
  }
700
761
  // user re-opening connection after closing it
@@ -713,6 +774,12 @@ Example:
713
774
  };
714
775
 
715
776
  Connection.prototype.disconnect = function() {
777
+ if (this._machine.is('permanentlyClosed')) {
778
+ return;
779
+ }
780
+
781
+ Pusher.debug('Disconnecting');
782
+
716
783
  if (this._machine.is('waiting')) {
717
784
  this._machine.transition('permanentlyClosed');
718
785
  } else {
@@ -722,28 +789,6 @@ Example:
722
789
 
723
790
  Pusher.Util.extend(Connection.prototype, Pusher.EventsDispatcher.prototype);
724
791
  this.Pusher.Connection = Connection;
725
-
726
- /*
727
- A little bauble to interface with window.navigator.onLine,
728
- window.ononline and window.onoffline. Easier to mock.
729
- */
730
- var NetInfo = function() {
731
- var self = this;
732
- window.ononline = function() {
733
- self.emit('online', null);
734
- };
735
- window.onoffline = function() {
736
- self.emit('offline', null);
737
- };
738
- };
739
-
740
- NetInfo.prototype.isOnLine = function() {
741
- return window.navigator.onLine;
742
- };
743
-
744
- Pusher.Util.extend(NetInfo.prototype, Pusher.EventsDispatcher.prototype);
745
- this.Pusher.Connection.NetInfo = NetInfo;
746
-
747
792
  }).call(this);
748
793
 
749
794
  Pusher.Channels = function() {
@@ -778,26 +823,27 @@ Pusher.Channels.prototype = {
778
823
  };
779
824
 
780
825
  Pusher.Channel = function(channel_name, pusher) {
826
+ var channel = this;
781
827
  Pusher.EventsDispatcher.call(this);
782
828
 
783
829
  this.pusher = pusher;
784
830
  this.name = channel_name;
785
831
  this.subscribed = false;
832
+
833
+ this.bind('pusher_internal:subscription_succeeded', function(sub_data){
834
+ channel.acknowledge_subscription(sub_data);
835
+ });
786
836
  };
787
837
 
788
838
  Pusher.Channel.prototype = {
789
839
  // inheritable constructor
790
- init: function(){
791
-
792
- },
793
-
794
- disconnect: function(){
795
-
796
- },
840
+ init: function() {},
841
+ disconnect: function() {},
797
842
 
798
843
  // Activate after successful subscription. Called on top-level pusher:subscription_succeeded
799
844
  acknowledge_subscription: function(data){
800
845
  this.subscribed = true;
846
+ this.dispatch_with_all('pusher:subscription_succeeded');
801
847
  },
802
848
 
803
849
  is_private: function(){
@@ -813,8 +859,7 @@ Pusher.Channel.prototype = {
813
859
  },
814
860
 
815
861
  trigger: function(event, data) {
816
- this.pusher.send_event(event, data, this.name);
817
- return this;
862
+ return this.pusher.send_event(event, data, this.name);
818
863
  }
819
864
  };
820
865
 
@@ -826,17 +871,31 @@ Pusher.auth_callbacks = {};
826
871
 
827
872
  Pusher.authorizers = {
828
873
  ajax: function(pusher, callback){
829
- var self = this;
830
- var xhr = window.XMLHttpRequest ?
831
- new XMLHttpRequest() :
832
- new ActiveXObject("Microsoft.XMLHTTP");
874
+ var self = this, xhr;
875
+
876
+ if (Pusher.XHR) {
877
+ xhr = new Pusher.XHR();
878
+ } else {
879
+ xhr = (window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP"));
880
+ }
881
+
833
882
  xhr.open("POST", Pusher.channel_auth_endpoint, true);
834
883
  xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
835
884
  xhr.onreadystatechange = function() {
836
885
  if (xhr.readyState == 4) {
837
886
  if (xhr.status == 200) {
838
- var data = JSON.parse(xhr.responseText);
839
- callback(false, data);
887
+ var data, parsed = false;
888
+
889
+ try {
890
+ data = JSON.parse(xhr.responseText);
891
+ parsed = true;
892
+ } catch (e) {
893
+ callback(true, 'JSON returned from webapp was invalid, yet status code was 200. Data was: ' + xhr.responseText);
894
+ }
895
+
896
+ if (parsed) { // prevents double execution.
897
+ callback(false, data);
898
+ }
840
899
  } else {
841
900
  Pusher.debug("Couldn't get auth info from your webapp", status);
842
901
  callback(true, xhr.status);
@@ -872,11 +931,6 @@ Pusher.Channel.PrivateChannel = {
872
931
  Pusher.Channel.PresenceChannel = {
873
932
 
874
933
  init: function(){
875
- this.bind('pusher_internal:subscription_succeeded', function(sub_data){
876
- this.acknowledge_subscription(sub_data);
877
- this.dispatch_with_all('pusher:subscription_succeeded', this.members);
878
- }.scopedTo(this));
879
-
880
934
  this.bind('pusher_internal:member_added', function(data){
881
935
  var member = this.members.add(data.user_id, data.user_info);
882
936
  this.dispatch_with_all('pusher:member_added', member);
@@ -898,6 +952,8 @@ Pusher.Channel.PresenceChannel = {
898
952
  this.members._members_map = sub_data.presence.hash;
899
953
  this.members.count = sub_data.presence.count;
900
954
  this.subscribed = true;
955
+
956
+ this.dispatch_with_all('pusher:subscription_succeeded', this.members);
901
957
  },
902
958
 
903
959
  is_presence: function(){
@@ -1016,24 +1072,22 @@ var _require = (function () {
1016
1072
  ;(function() {
1017
1073
  var cdn = (document.location.protocol == 'http:') ? Pusher.cdn_http : Pusher.cdn_https;
1018
1074
  var root = cdn + Pusher.VERSION;
1019
-
1020
1075
  var deps = [];
1076
+
1021
1077
  if (typeof window['JSON'] === 'undefined') {
1022
- deps.push(root + '/json2.js');
1078
+ deps.push(root + '/json2' + Pusher.dependency_suffix + '.js');
1023
1079
  }
1024
- if (typeof window['WebSocket'] === 'undefined') {
1080
+ if (typeof window['WebSocket'] === 'undefined' && typeof window['MozWebSocket'] === 'undefined') {
1025
1081
  // We manually initialize web-socket-js to iron out cross browser issues
1026
1082
  window.WEB_SOCKET_DISABLE_AUTO_INITIALIZATION = true;
1027
- deps.push(root + '/flashfallback.js');
1083
+ deps.push(root + '/flashfallback' + Pusher.dependency_suffix + '.js');
1028
1084
  }
1029
1085
 
1030
1086
  var initialize = function() {
1031
- Pusher.NetInfo = Pusher.Connection.NetInfo;
1032
-
1033
1087
  if (typeof window['WebSocket'] === 'undefined' && typeof window['MozWebSocket'] === 'undefined') {
1034
1088
  return function() {
1035
1089
  // This runs after flashfallback.js has loaded
1036
- if (typeof window['WebSocket'] !== 'undefined') {
1090
+ if (typeof window['WebSocket'] !== 'undefined' && typeof window['MozWebSocket'] === 'undefined') {
1037
1091
  // window['WebSocket'] is a flash emulation of WebSocket
1038
1092
  Pusher.Transport = window['WebSocket'];
1039
1093
  Pusher.TransportType = 'flash';
@@ -1086,4 +1140,3 @@ var _require = (function () {
1086
1140
  initializeOnDocumentBody();
1087
1141
  }
1088
1142
  })();
1089
-
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pusher_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-01 00:00:00.000000000 Z
12
+ date: 2012-01-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: pusher
16
- requirement: &70285432931700 !ruby/object:Gem::Requirement
16
+ requirement: &70344468425460 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: 0.8.4
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70285432931700
24
+ version_requirements: *70344468425460
25
25
  description: Adds pusher.js/backpusher.js to the asset pipeline and pusher-gem to
26
26
  to your app.
27
27
  email: