pusher_rails 0.2.3 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/README.md +2 -2
- data/pusher_rails.gemspec +1 -1
- data/vendor/assets/javascripts/pusher.js +93 -81
- metadata +2 -2
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
|
4
4
|
Adds:
|
5
5
|
- [pusher-gem v0.9.3](https://github.com/pusher/pusher-gem/tree/v0.9.3)
|
6
|
-
- [pusher.js v1.12.
|
6
|
+
- [pusher.js v1.12.2](https://github.com/pusher/pusher-js/tree/v1.12.2)
|
7
7
|
- [backpusher.js](https://github.com/pusher/backpusher)
|
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.12.
|
24
|
+
* Pusher JavaScript Library v1.12.2
|
25
25
|
* http://pusherapp.com/
|
26
26
|
*
|
27
27
|
* Copyright 2011, Pusher
|
data/pusher_rails.gemspec
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
/*!
|
2
|
-
* Pusher JavaScript Library v1.12.
|
2
|
+
* Pusher JavaScript Library v1.12.2
|
3
3
|
* http://pusherapp.com/
|
4
4
|
*
|
5
5
|
* Copyright 2011, Pusher
|
@@ -183,7 +183,7 @@
|
|
183
183
|
};
|
184
184
|
|
185
185
|
// Pusher defaults
|
186
|
-
Pusher.VERSION = '1.12.
|
186
|
+
Pusher.VERSION = '1.12.2';
|
187
187
|
|
188
188
|
Pusher.host = 'ws.pusherapp.com';
|
189
189
|
Pusher.ws_port = 80;
|
@@ -220,44 +220,67 @@ Example:
|
|
220
220
|
emitter.bind('foo_event', function(data){ alert(data)} );
|
221
221
|
|
222
222
|
// Bind to all
|
223
|
-
emitter.bind_all(function(
|
223
|
+
emitter.bind_all(function(eventName, data){ alert(data) });
|
224
224
|
|
225
225
|
--------------------------------------------------------*/
|
226
|
+
|
227
|
+
function CallbackRegistry() {
|
228
|
+
this._callbacks = {};
|
229
|
+
};
|
230
|
+
|
231
|
+
CallbackRegistry.prototype.get = function(eventName) {
|
232
|
+
return this._callbacks[this._prefix(eventName)];
|
233
|
+
};
|
234
|
+
|
235
|
+
CallbackRegistry.prototype.add = function(eventName, callback) {
|
236
|
+
var prefixedEventName = this._prefix(eventName);
|
237
|
+
this._callbacks[prefixedEventName] = this._callbacks[prefixedEventName] || [];
|
238
|
+
this._callbacks[prefixedEventName].push(callback);
|
239
|
+
};
|
240
|
+
|
241
|
+
CallbackRegistry.prototype.remove = function(eventName, callback) {
|
242
|
+
if(this.get(eventName)) {
|
243
|
+
var index = Pusher.Util.arrayIndexOf(this.get(eventName), callback);
|
244
|
+
this._callbacks[this._prefix(eventName)].splice(index, 1);
|
245
|
+
}
|
246
|
+
};
|
247
|
+
|
248
|
+
CallbackRegistry.prototype._prefix = function(eventName) {
|
249
|
+
return "_" + eventName;
|
250
|
+
};
|
251
|
+
|
252
|
+
|
226
253
|
function EventsDispatcher(failThrough) {
|
227
|
-
this.callbacks =
|
254
|
+
this.callbacks = new CallbackRegistry();
|
228
255
|
this.global_callbacks = [];
|
229
256
|
// Run this function when dispatching an event when no callbacks defined
|
230
257
|
this.failThrough = failThrough;
|
231
258
|
}
|
232
259
|
|
233
|
-
EventsDispatcher.prototype.bind = function(
|
234
|
-
this.callbacks
|
235
|
-
this.callbacks[event_name].push(callback);
|
260
|
+
EventsDispatcher.prototype.bind = function(eventName, callback) {
|
261
|
+
this.callbacks.add(eventName, callback);
|
236
262
|
return this;// chainable
|
237
263
|
};
|
238
264
|
|
239
265
|
EventsDispatcher.prototype.unbind = function(eventName, callback) {
|
240
|
-
|
241
|
-
var index = Pusher.Util.arrayIndexOf(this.callbacks[eventName], callback);
|
242
|
-
this.callbacks[eventName].splice(index, 1);
|
243
|
-
}
|
266
|
+
this.callbacks.remove(eventName, callback);
|
244
267
|
return this;
|
245
268
|
};
|
246
269
|
|
247
|
-
EventsDispatcher.prototype.emit = function(
|
270
|
+
EventsDispatcher.prototype.emit = function(eventName, data) {
|
248
271
|
// Global callbacks
|
249
272
|
for (var i = 0; i < this.global_callbacks.length; i++) {
|
250
|
-
this.global_callbacks[i](
|
273
|
+
this.global_callbacks[i](eventName, data);
|
251
274
|
}
|
252
275
|
|
253
276
|
// Event callbacks
|
254
|
-
var callbacks = this.callbacks
|
277
|
+
var callbacks = this.callbacks.get(eventName);
|
255
278
|
if (callbacks) {
|
256
279
|
for (var i = 0; i < callbacks.length; i++) {
|
257
280
|
callbacks[i](data);
|
258
281
|
}
|
259
282
|
} else if (this.failThrough) {
|
260
|
-
this.failThrough(
|
283
|
+
this.failThrough(eventName, data)
|
261
284
|
}
|
262
285
|
|
263
286
|
return this;
|
@@ -402,7 +425,7 @@ Example:
|
|
402
425
|
'connected': ['permanentlyClosing', 'waiting'],
|
403
426
|
'impermanentlyClosing': ['waiting', 'permanentlyClosing'],
|
404
427
|
'permanentlyClosing': ['permanentlyClosed'],
|
405
|
-
'permanentlyClosed': ['waiting'],
|
428
|
+
'permanentlyClosed': ['waiting', 'failed'],
|
406
429
|
'failed': ['permanentlyClosed']
|
407
430
|
};
|
408
431
|
|
@@ -819,7 +842,7 @@ Example:
|
|
819
842
|
|
820
843
|
Connection.prototype.connect = function() {
|
821
844
|
// no WebSockets
|
822
|
-
if (
|
845
|
+
if (!this._machine.is('failed') && !Pusher.Transport) {
|
823
846
|
this._machine.transition('failed');
|
824
847
|
}
|
825
848
|
// initial open of connection
|
@@ -840,17 +863,12 @@ Example:
|
|
840
863
|
|
841
864
|
Connection.prototype.send = function(data) {
|
842
865
|
if (this._machine.is('connected')) {
|
843
|
-
//
|
844
|
-
// 1. Open page/tab, connect WS, get some data.
|
845
|
-
// 2. Switch tab or close Mobile Safari and wait for WS connection to get closed (probably by server).
|
846
|
-
// 3. Switch back to tab or open Mobile Safari and Mobile Safari crashes.
|
847
|
-
// The problem is that WS tries to send data on closed WS connection before it realises it is closed.
|
848
|
-
// The timeout means that by the time the send happens, the WS readyState correctly reflects closed state.
|
866
|
+
// Workaround for MobileSafari bug (see https://gist.github.com/2052006)
|
849
867
|
var self = this;
|
850
868
|
setTimeout(function() {
|
851
869
|
self.socket.send(data);
|
852
870
|
}, 0);
|
853
|
-
return true;
|
871
|
+
return true;
|
854
872
|
} else {
|
855
873
|
return false;
|
856
874
|
}
|
@@ -1145,73 +1163,82 @@ Example:
|
|
1145
1163
|
}
|
1146
1164
|
};
|
1147
1165
|
}).call(this);
|
1148
|
-
|
1149
|
-
|
1150
|
-
|
1151
|
-
|
1152
|
-
|
1153
|
-
elem.addEventListener('load', callback, false)
|
1154
|
-
}
|
1155
|
-
} else {
|
1156
|
-
handleScriptLoaded = function(elem, callback) {
|
1166
|
+
// _require(dependencies, callback) takes an array of dependency urls and a
|
1167
|
+
// callback to call when all the dependecies have finished loading
|
1168
|
+
var _require = (function() {
|
1169
|
+
function handleScriptLoaded(elem, callback) {
|
1170
|
+
if (document.addEventListener) {
|
1171
|
+
elem.addEventListener('load', callback, false);
|
1172
|
+
} else {
|
1157
1173
|
elem.attachEvent('onreadystatechange', function () {
|
1158
|
-
if(elem.readyState == 'loaded' || elem.readyState == 'complete')
|
1159
|
-
|
1174
|
+
if (elem.readyState == 'loaded' || elem.readyState == 'complete') {
|
1175
|
+
callback();
|
1176
|
+
}
|
1177
|
+
});
|
1160
1178
|
}
|
1161
1179
|
}
|
1162
1180
|
|
1163
|
-
|
1164
|
-
var
|
1165
|
-
|
1181
|
+
function addScript(src, callback) {
|
1182
|
+
var head = document.getElementsByTagName('head')[0];
|
1183
|
+
var script = document.createElement('script');
|
1184
|
+
script.setAttribute('src', src);
|
1185
|
+
script.setAttribute("type","text/javascript");
|
1186
|
+
script.setAttribute('async', true);
|
1166
1187
|
|
1167
|
-
function
|
1168
|
-
|
1169
|
-
|
1170
|
-
// Opera needs the timeout for page initialization weirdness
|
1171
|
-
setTimeout(callback, 0);
|
1172
|
-
}
|
1173
|
-
}
|
1188
|
+
handleScriptLoaded(script, function() {
|
1189
|
+
callback();
|
1190
|
+
});
|
1174
1191
|
|
1175
|
-
|
1176
|
-
|
1177
|
-
var head = document.getElementsByTagName('head')[0];
|
1178
|
-
var script = document.createElement('script');
|
1179
|
-
script.setAttribute('src', src);
|
1180
|
-
script.setAttribute("type","text/javascript");
|
1181
|
-
script.setAttribute('async', true);
|
1192
|
+
head.appendChild(script);
|
1193
|
+
}
|
1182
1194
|
|
1183
|
-
|
1184
|
-
|
1195
|
+
return function(deps, callback) {
|
1196
|
+
var deps_loaded = 0;
|
1197
|
+
for (var i = 0; i < deps.length; i++) {
|
1198
|
+
addScript(deps[i], function() {
|
1199
|
+
if (deps.length == ++deps_loaded) {
|
1200
|
+
// This setTimeout is a workaround for an Opera issue
|
1201
|
+
setTimeout(callback, 0);
|
1202
|
+
}
|
1185
1203
|
});
|
1186
|
-
|
1187
|
-
head.appendChild(script);
|
1188
|
-
}
|
1189
|
-
|
1190
|
-
for(var i = 0; i < dep_length; i++) {
|
1191
|
-
addScript(deps[i], callback);
|
1192
1204
|
}
|
1193
1205
|
}
|
1194
1206
|
})();
|
1195
1207
|
|
1196
1208
|
;(function() {
|
1209
|
+
// Support Firefox versions which prefix WebSocket
|
1210
|
+
if (!window['WebSocket'] && window['MozWebSocket']) {
|
1211
|
+
window['WebSocket'] = window['MozWebSocket']
|
1212
|
+
}
|
1213
|
+
|
1214
|
+
if (window['WebSocket']) {
|
1215
|
+
Pusher.Transport = window['WebSocket'];
|
1216
|
+
Pusher.TransportType = 'native';
|
1217
|
+
}
|
1218
|
+
|
1197
1219
|
var cdn = (document.location.protocol == 'http:') ? Pusher.cdn_http : Pusher.cdn_https;
|
1198
1220
|
var root = cdn + Pusher.VERSION;
|
1199
1221
|
var deps = [];
|
1200
1222
|
|
1201
|
-
if (window['JSON']
|
1223
|
+
if (!window['JSON']) {
|
1202
1224
|
deps.push(root + '/json2' + Pusher.dependency_suffix + '.js');
|
1203
1225
|
}
|
1204
|
-
if (window['WebSocket']
|
1226
|
+
if (!window['WebSocket']) {
|
1205
1227
|
// We manually initialize web-socket-js to iron out cross browser issues
|
1206
1228
|
window.WEB_SOCKET_DISABLE_AUTO_INITIALIZATION = true;
|
1207
1229
|
deps.push(root + '/flashfallback' + Pusher.dependency_suffix + '.js');
|
1208
1230
|
}
|
1209
1231
|
|
1210
1232
|
var initialize = function() {
|
1211
|
-
if (window['WebSocket']
|
1233
|
+
if (window['WebSocket']) {
|
1234
|
+
// Initialize function in the case that we have native WebSocket support
|
1212
1235
|
return function() {
|
1213
|
-
|
1214
|
-
|
1236
|
+
Pusher.ready();
|
1237
|
+
}
|
1238
|
+
} else {
|
1239
|
+
// Initialize function for fallback case
|
1240
|
+
return function() {
|
1241
|
+
if (window['WebSocket']) {
|
1215
1242
|
// window['WebSocket'] is a flash emulation of WebSocket
|
1216
1243
|
Pusher.Transport = window['WebSocket'];
|
1217
1244
|
Pusher.TransportType = 'flash';
|
@@ -1228,25 +1255,10 @@ var _require = (function () {
|
|
1228
1255
|
Pusher.ready();
|
1229
1256
|
}
|
1230
1257
|
}
|
1231
|
-
} else {
|
1232
|
-
return function() {
|
1233
|
-
// This is because Mozilla have decided to
|
1234
|
-
// prefix the WebSocket constructor with "Moz".
|
1235
|
-
if (window['MozWebSocket'] !== undefined) {
|
1236
|
-
Pusher.Transport = window['MozWebSocket'];
|
1237
|
-
} else {
|
1238
|
-
Pusher.Transport = window['WebSocket'];
|
1239
|
-
}
|
1240
|
-
// We have some form of a native websocket,
|
1241
|
-
// even if the constructor is prefixed:
|
1242
|
-
Pusher.TransportType = 'native';
|
1243
|
-
|
1244
|
-
// Initialise Pusher.
|
1245
|
-
Pusher.ready();
|
1246
|
-
}
|
1247
1258
|
}
|
1248
1259
|
}();
|
1249
1260
|
|
1261
|
+
// Allows calling a function when the document body is available
|
1250
1262
|
var ondocumentbody = function(callback) {
|
1251
1263
|
var load_body = function() {
|
1252
1264
|
document.body ? callback() : setTimeout(load_body, 0);
|
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.2.
|
4
|
+
version: 0.2.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-08-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: pusher
|