diff --git a/packages/livedata/stream_client_sockjs.js b/packages/livedata/stream_client_sockjs.js index 607b3c37b20..3e7d4ed80de 100644 --- a/packages/livedata/stream_client_sockjs.js +++ b/packages/livedata/stream_client_sockjs.js @@ -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; @@ -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();