pusher_rails 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +5 -0
- data/README.md +4 -4
- data/pusher_rails.gemspec +3 -3
- data/vendor/assets/javascripts/pusher.js +88 -36
- metadata +8 -8
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -2,8 +2,8 @@
|
|
2
2
|
=====================
|
3
3
|
|
4
4
|
Adds:
|
5
|
-
- [pusher-gem v0.8.
|
6
|
-
- [pusher.js v1.9.
|
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)
|
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.9.
|
24
|
+
* Pusher JavaScript Library v1.9.4
|
25
25
|
* http://pusherapp.com/
|
26
26
|
*
|
27
27
|
* Copyright 2011, Pusher
|
@@ -33,4 +33,4 @@ Licenses
|
|
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,15 +3,15 @@ $:.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.
|
6
|
+
s.version = '0.1.3'
|
7
7
|
s.platform = Gem::Platform::RUBY
|
8
8
|
s.authors = ["David Grandinetti"]
|
9
9
|
s.email = ["dave@wegoto12.com"]
|
10
10
|
s.summary = 'Pusher integration for Rails 3.1+'
|
11
|
-
s.description = 'Adds pusher.js/backpusher.js to the asset pipeline and pusher-
|
11
|
+
s.description = 'Adds pusher.js/backpusher.js to the asset pipeline and pusher-gem to to your app.'
|
12
12
|
s.homepage = 'https://github.com/dbgrandi/pusher_rails'
|
13
13
|
|
14
|
-
s.add_dependency "pusher", "~> 0.8.
|
14
|
+
s.add_dependency "pusher", "~> 0.8.4"
|
15
15
|
|
16
16
|
s.files = `git ls-files`.split("\n")
|
17
17
|
s.require_paths = ["lib"]
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/*!
|
2
|
-
* Pusher JavaScript Library v1.9.
|
2
|
+
* Pusher JavaScript Library v1.9.4
|
3
3
|
* http://pusherapp.com/
|
4
4
|
*
|
5
5
|
* Copyright 2011, Pusher
|
@@ -85,12 +85,16 @@ Pusher.prototype = {
|
|
85
85
|
var self = this;
|
86
86
|
var channel = this.channels.add(channel_name, this);
|
87
87
|
if (this.connection.state === 'connected') {
|
88
|
-
channel.authorize(this, function(data) {
|
89
|
-
|
90
|
-
channel
|
91
|
-
|
92
|
-
|
93
|
-
|
88
|
+
channel.authorize(this, function(err, data) {
|
89
|
+
if (err) {
|
90
|
+
channel.emit('subscription_error', data);
|
91
|
+
} else {
|
92
|
+
self.send_event('pusher:subscribe', {
|
93
|
+
channel: channel_name,
|
94
|
+
auth: data.auth,
|
95
|
+
channel_data: data.channel_data
|
96
|
+
});
|
97
|
+
}
|
94
98
|
});
|
95
99
|
}
|
96
100
|
return channel;
|
@@ -168,7 +172,7 @@ Pusher.debug = function() {
|
|
168
172
|
}
|
169
173
|
|
170
174
|
// Pusher defaults
|
171
|
-
Pusher.VERSION = '1.9.
|
175
|
+
Pusher.VERSION = '1.9.4';
|
172
176
|
|
173
177
|
Pusher.host = 'ws.pusherapp.com';
|
174
178
|
Pusher.ws_port = 80;
|
@@ -391,6 +395,9 @@ Example:
|
|
391
395
|
|
392
396
|
this.options = Pusher.Util.extend({encrypted: false}, options || {});
|
393
397
|
|
398
|
+
this.netInfo = new Pusher.NetInfo();
|
399
|
+
Pusher.EventsDispatcher.call(this.netInfo);
|
400
|
+
|
394
401
|
// define the state machine that runs the connection
|
395
402
|
this._machine = new Pusher.Machine(self, 'initialized', machineTransitions, {
|
396
403
|
|
@@ -414,7 +421,16 @@ Example:
|
|
414
421
|
informUser('connecting_in', self.connectionWait);
|
415
422
|
}
|
416
423
|
|
417
|
-
if (self.connectionAttempts > 4) {
|
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
|
+
|
418
434
|
triggerStateChange('unavailable');
|
419
435
|
} else {
|
420
436
|
triggerStateChange('connecting');
|
@@ -460,9 +476,7 @@ Example:
|
|
460
476
|
openPre: function() {
|
461
477
|
self.socket.onmessage = ws_onMessage;
|
462
478
|
self.socket.onerror = ws_onError;
|
463
|
-
self.socket.onclose =
|
464
|
-
self._machine.transition('waiting');
|
465
|
-
};
|
479
|
+
self.socket.onclose = transitionToWaiting;
|
466
480
|
|
467
481
|
// allow time to get connected-to-Pusher message, otherwise close socket, try again
|
468
482
|
self._openTimer = setTimeout(TransitionToImpermanentClosing, self.connectedTimeout);
|
@@ -488,6 +502,11 @@ Example:
|
|
488
502
|
self.socket.onclose = function() {
|
489
503
|
self._machine.transition('waiting');
|
490
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
|
+
});
|
491
510
|
|
492
511
|
resetConnectionParameters(self);
|
493
512
|
},
|
@@ -655,6 +674,13 @@ Example:
|
|
655
674
|
self.emit('state_change', {previous: prevState, current: newState});
|
656
675
|
self.emit(newState, data);
|
657
676
|
}
|
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
|
+
}
|
658
684
|
};
|
659
685
|
|
660
686
|
Connection.prototype.connect = function() {
|
@@ -695,8 +721,29 @@ Example:
|
|
695
721
|
};
|
696
722
|
|
697
723
|
Pusher.Util.extend(Connection.prototype, Pusher.EventsDispatcher.prototype);
|
698
|
-
|
699
724
|
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
|
+
|
700
747
|
}).call(this);
|
701
748
|
|
702
749
|
Pusher.Channels = function() {
|
@@ -741,13 +788,13 @@ Pusher.Channel = function(channel_name, pusher) {
|
|
741
788
|
Pusher.Channel.prototype = {
|
742
789
|
// inheritable constructor
|
743
790
|
init: function(){
|
744
|
-
|
791
|
+
|
745
792
|
},
|
746
|
-
|
793
|
+
|
747
794
|
disconnect: function(){
|
748
|
-
|
795
|
+
|
749
796
|
},
|
750
|
-
|
797
|
+
|
751
798
|
// Activate after successful subscription. Called on top-level pusher:subscription_succeeded
|
752
799
|
acknowledge_subscription: function(data){
|
753
800
|
this.subscribed = true;
|
@@ -756,13 +803,13 @@ Pusher.Channel.prototype = {
|
|
756
803
|
is_private: function(){
|
757
804
|
return false;
|
758
805
|
},
|
759
|
-
|
806
|
+
|
760
807
|
is_presence: function(){
|
761
808
|
return false;
|
762
809
|
},
|
763
|
-
|
810
|
+
|
764
811
|
authorize: function(pusher, callback){
|
765
|
-
callback({}); // normal channels don't require auth
|
812
|
+
callback(false, {}); // normal channels don't require auth
|
766
813
|
},
|
767
814
|
|
768
815
|
trigger: function(event, data) {
|
@@ -789,9 +836,10 @@ Pusher.authorizers = {
|
|
789
836
|
if (xhr.readyState == 4) {
|
790
837
|
if (xhr.status == 200) {
|
791
838
|
var data = JSON.parse(xhr.responseText);
|
792
|
-
callback(data);
|
839
|
+
callback(false, data);
|
793
840
|
} else {
|
794
841
|
Pusher.debug("Couldn't get auth info from your webapp", status);
|
842
|
+
callback(true, xhr.status);
|
795
843
|
}
|
796
844
|
}
|
797
845
|
};
|
@@ -799,8 +847,11 @@ Pusher.authorizers = {
|
|
799
847
|
},
|
800
848
|
jsonp: function(pusher, callback){
|
801
849
|
var qstring = 'socket_id=' + encodeURIComponent(pusher.connection.socket_id) + '&channel_name=' + encodeURIComponent(this.name);
|
802
|
-
var script = document.createElement("script");
|
803
|
-
|
850
|
+
var script = document.createElement("script");
|
851
|
+
// Hacked wrapper.
|
852
|
+
Pusher.auth_callbacks[this.name] = function(data) {
|
853
|
+
callback(false, data);
|
854
|
+
};
|
804
855
|
var callback_name = "Pusher.auth_callbacks['" + this.name + "']";
|
805
856
|
script.src = Pusher.channel_auth_endpoint+'?callback='+encodeURIComponent(callback_name)+'&'+qstring;
|
806
857
|
var head = document.getElementsByTagName("head")[0] || document.documentElement;
|
@@ -812,25 +863,25 @@ Pusher.Channel.PrivateChannel = {
|
|
812
863
|
is_private: function(){
|
813
864
|
return true;
|
814
865
|
},
|
815
|
-
|
866
|
+
|
816
867
|
authorize: function(pusher, callback){
|
817
868
|
Pusher.authorizers[Pusher.channel_auth_transport].scopedTo(this)(pusher, callback);
|
818
869
|
}
|
819
870
|
};
|
820
871
|
|
821
872
|
Pusher.Channel.PresenceChannel = {
|
822
|
-
|
873
|
+
|
823
874
|
init: function(){
|
824
875
|
this.bind('pusher_internal:subscription_succeeded', function(sub_data){
|
825
876
|
this.acknowledge_subscription(sub_data);
|
826
877
|
this.dispatch_with_all('pusher:subscription_succeeded', this.members);
|
827
878
|
}.scopedTo(this));
|
828
|
-
|
879
|
+
|
829
880
|
this.bind('pusher_internal:member_added', function(data){
|
830
881
|
var member = this.members.add(data.user_id, data.user_info);
|
831
882
|
this.dispatch_with_all('pusher:member_added', member);
|
832
883
|
}.scopedTo(this))
|
833
|
-
|
884
|
+
|
834
885
|
this.bind('pusher_internal:member_removed', function(data){
|
835
886
|
var member = this.members.remove(data.user_id);
|
836
887
|
if (member) {
|
@@ -838,21 +889,21 @@ Pusher.Channel.PresenceChannel = {
|
|
838
889
|
}
|
839
890
|
}.scopedTo(this))
|
840
891
|
},
|
841
|
-
|
892
|
+
|
842
893
|
disconnect: function(){
|
843
894
|
this.members.clear();
|
844
895
|
},
|
845
|
-
|
896
|
+
|
846
897
|
acknowledge_subscription: function(sub_data){
|
847
898
|
this.members._members_map = sub_data.presence.hash;
|
848
899
|
this.members.count = sub_data.presence.count;
|
849
900
|
this.subscribed = true;
|
850
901
|
},
|
851
|
-
|
902
|
+
|
852
903
|
is_presence: function(){
|
853
904
|
return true;
|
854
905
|
},
|
855
|
-
|
906
|
+
|
856
907
|
members: {
|
857
908
|
_members_map: {},
|
858
909
|
count: 0,
|
@@ -882,13 +933,12 @@ Pusher.Channel.PresenceChannel = {
|
|
882
933
|
},
|
883
934
|
|
884
935
|
get: function(user_id) {
|
885
|
-
|
886
|
-
if (user_info) {
|
936
|
+
if (this._members_map.hasOwnProperty(user_id)) { // have heard of this user user_id
|
887
937
|
return {
|
888
938
|
id: user_id,
|
889
|
-
info:
|
939
|
+
info: this._members_map[user_id]
|
890
940
|
}
|
891
|
-
} else {
|
941
|
+
} else { // have never heard of this user
|
892
942
|
return null;
|
893
943
|
}
|
894
944
|
},
|
@@ -968,7 +1018,7 @@ var _require = (function () {
|
|
968
1018
|
var root = cdn + Pusher.VERSION;
|
969
1019
|
|
970
1020
|
var deps = [];
|
971
|
-
if (typeof window['JSON'] === undefined) {
|
1021
|
+
if (typeof window['JSON'] === 'undefined') {
|
972
1022
|
deps.push(root + '/json2.js');
|
973
1023
|
}
|
974
1024
|
if (typeof window['WebSocket'] === 'undefined') {
|
@@ -978,6 +1028,8 @@ var _require = (function () {
|
|
978
1028
|
}
|
979
1029
|
|
980
1030
|
var initialize = function() {
|
1031
|
+
Pusher.NetInfo = Pusher.Connection.NetInfo;
|
1032
|
+
|
981
1033
|
if (typeof window['WebSocket'] === 'undefined' && typeof window['MozWebSocket'] === 'undefined') {
|
982
1034
|
return function() {
|
983
1035
|
// This runs after flashfallback.js has loaded
|
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
|
+
version: 0.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,21 +9,21 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
12
|
+
date: 2011-11-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: pusher
|
16
|
-
requirement: &
|
16
|
+
requirement: &70338432315200 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 0.8.
|
21
|
+
version: 0.8.4
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
25
|
-
description: Adds pusher.js/backpusher.js to the asset pipeline and pusher-
|
26
|
-
your app.
|
24
|
+
version_requirements: *70338432315200
|
25
|
+
description: Adds pusher.js/backpusher.js to the asset pipeline and pusher-gem to
|
26
|
+
to your app.
|
27
27
|
email:
|
28
28
|
- dave@wegoto12.com
|
29
29
|
executables: []
|
@@ -57,7 +57,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
57
57
|
version: '0'
|
58
58
|
requirements: []
|
59
59
|
rubyforge_project:
|
60
|
-
rubygems_version: 1.8.
|
60
|
+
rubygems_version: 1.8.10
|
61
61
|
signing_key:
|
62
62
|
specification_version: 3
|
63
63
|
summary: Pusher integration for Rails 3.1+
|