diff --git a/src/js/common_shim.js b/src/js/common_shim.js index 96d7c8e0..d188c152 100644 --- a/src/js/common_shim.js +++ b/src/js/common_shim.js @@ -353,7 +353,7 @@ export function removeExtmapAllowMixed(window, browserDetails) { if (browserDetails.browser === 'chrome' && browserDetails.version >= 71) { return; } - if (browserDetails.browser === 'safari' && browserDetails.version >= 605) { + if (browserDetails.browser === 'safari' && browserDetails.version >= 13.1) { return; } const nativeSRD = window.RTCPeerConnection.prototype.setRemoteDescription; diff --git a/src/js/utils.js b/src/js/utils.js index f7b64187..5492b886 100644 --- a/src/js/utils.js +++ b/src/js/utils.js @@ -21,7 +21,7 @@ let deprecationWarnings_ = true; */ export function extractVersion(uastring, expr, pos) { const match = uastring.match(expr); - return match && match.length >= pos && parseInt(match[pos], 10); + return match && match.length >= pos && parseFloat(match[pos], 10); } // Wraps the peerconnection event eventNameToWrap in a function @@ -177,7 +177,7 @@ export function detectBrowser(window) { navigator.userAgent.match(/AppleWebKit\/(\d+)\./)) { // Safari. result.browser = 'safari'; result.version = extractVersion(navigator.userAgent, - /AppleWebKit\/(\d+)\./, 1); + /version\/(\d+(\.?\d+))/i, 1); result.supportsUnifiedPlan = window.RTCRtpTransceiver && 'currentDirection' in window.RTCRtpTransceiver.prototype; } else { // Default fallthrough: not supported. diff --git a/test/unit/detectBrowser.js b/test/unit/detectBrowser.js index c6a5266c..5f3c49f5 100644 --- a/test/unit/detectBrowser.js +++ b/test/unit/detectBrowser.js @@ -60,6 +60,6 @@ describe('detectBrowser', () => { const browserDetails = detectBrowser(window); expect(browserDetails.browser).to.equal('safari'); - expect(browserDetails.version).to.equal(604); + expect(browserDetails.version).to.equal(10.2); }); }); diff --git a/test/unit/extmap-allow-mixed.js b/test/unit/extmap-allow-mixed.js index 1a724bc3..fe6a2350 100644 --- a/test/unit/extmap-allow-mixed.js +++ b/test/unit/extmap-allow-mixed.js @@ -70,11 +70,11 @@ describe('removal of extmap-allow-mixed', () => { window.RTCPeerConnection.prototype.setRemoteDescription = function() { return origSetRemoteDescription.apply(this, arguments); }; - browserDetails = {browser: 'safari', version: '605'}; + browserDetails = {browser: 'safari', version: 13.1}; }); - it('does not remove the extmap-allow-mixed line after 605', () => { - browserDetails.version = 605; + it('does not remove the extmap-allow-mixed line after 13.1', () => { + browserDetails.version = 13.1; shim.removeExtmapAllowMixed(window, browserDetails); const pc = new window.RTCPeerConnection(); @@ -83,8 +83,8 @@ describe('removal of extmap-allow-mixed', () => { .to.equal('\n' + sdp); }); - it('does remove the extmap-allow-mixed line before 605', () => { - browserDetails.version = 604; + it('does remove the extmap-allow-mixed line before 13.1', () => { + browserDetails.version = 13.0; shim.removeExtmapAllowMixed(window, browserDetails); const pc = new window.RTCPeerConnection(); diff --git a/test/unit/extractVersion.js b/test/unit/extractVersion.js index fcbd2099..b90444af 100644 --- a/test/unit/extractVersion.js +++ b/test/unit/extractVersion.js @@ -116,30 +116,37 @@ describe('extractVersion', () => { }); describe('Safari regular expression', () => { - const expr = /AppleWebKit\/(\d+)/; - it('matches the webkit version', () => { + const expr = /version\/(\d+(\.?\d+))/i; + it('matches the Safari version', () => { ua = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) ' + 'AppleWebKit/604.1.6 (KHTML, like Gecko) Version/10.2 Safari/604.1.6'; - expect(extractVersion(ua, expr, 1)).to.equal(604); + expect(extractVersion(ua, expr, 1)).to.equal(10.2); + }); + + it('drops patch version numbers', () => { + ua = 'Mozilla/5.0 (iPhone; CPU iPhone OS 7_1 like Mac OS X) ' + + 'AppleWebKit/537.51.2 (KHTML, like Gecko) Version/7.0.4 ' + + 'Mobile/11D167 Safari/9537.53'; + expect(extractVersion(ua, expr, 1)).to.equal(7.0); }); it('matches the iphone simulator', () => { ua = 'Mozilla/5.0 (iPhone; CPU iPhone OS 8_0 like Mac OS X) ' + 'AppleWebKit/600.1.3 (KHTML, like Gecko) Version/8.0 ' + 'Mobile/12A4345d Safari/600.1.4'; - expect(extractVersion(ua, expr, 1)).to.equal(600); + expect(extractVersion(ua, expr, 1)).to.equal(8.0); }); - it('matches Chrome (by design, do not use for Chrome)', () => { + it('does not match Chrome', () => { ua = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like ' + 'Gecko) Chrome/45.0.2454.101 Safari/537.36'; - expect(extractVersion(ua, expr, 1)).to.equal(537); + expect(extractVersion(ua, expr, 1)).to.equal(null); }); - it('matches Edge (by design, do not use for Edge', () => { + it('does not match Edge', () => { ua = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 ' + '(KHTML, like Gecko) Chrome/46.0.2486.0 Safari/537.36 Edge/13.10547'; - expect(extractVersion(ua, expr, 1)).to.equal(537); + expect(extractVersion(ua, expr, 1)).to.equal(null); }); it('does not match Firefox', () => {