Skip to content

Commit

Permalink
Use Websockets on all browsers other than iOS <= 5
Browse files Browse the repository at this point in the history
  • Loading branch information
avital committed May 9, 2013
1 parent 99d5be0 commit 5b2240d
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions packages/livedata/stream_client_sockjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,27 @@ _.extend(Meteor._DdpClientStream.prototype, {
self.HEARTBEAT_TIMEOUT);
},

_sockjsProtocolsWhitelist: function () {
// only allow polling protocols. no streaming. streaming
// makes safari spin.
var protocolsWhitelist = [
'xdr-polling', 'xhr-polling', 'iframe-xhr-polling', 'jsonp-polling'];

// iOS 4 and 5 and below crash when using websockets over certain
// proxies. this seems to be resolved with iOS 6. eg
// https://github.com/LearnBoost/socket.io/issues/193#issuecomment-7308865.
//
// iOS <4 doesn't support websockets at all so sockjs will just
// immediately fall back to http
var noWebsockets = navigator &&
/iPhone|iPad|iPod/.test(navigator.userAgent) &&
/OS 4_|OS 5_/.test(navigator.userAgent);

if (!noWebsockets)
protocolsWhitelist = ['websocket'].concat(protocolsWhitelist);

return protocolsWhitelist;
},

_launchConnection: function () {
var self = this;
Expand All @@ -137,11 +158,8 @@ _.extend(Meteor._DdpClientStream.prototype, {
self.socket = new SockJS(
Meteor._DdpClientStream._toSockjsUrl(self.rawUrl),
undefined, {
debug: false, protocols_whitelist: [
// only allow polling protocols. no websockets or streaming.
// streaming makes safari spin, and websockets hurt chrome.
'xdr-polling', 'xhr-polling', 'iframe-xhr-polling', 'jsonp-polling'
]});
debug: false, protocols_whitelist: self._sockjsProtocolsWhitelist()
});
self.socket.onmessage = function (data) {
self._heartbeat_received();

Expand Down

0 comments on commit 5b2240d

Please sign in to comment.