Skip to content

Commit 66fefdb

Browse files
committed
[8.x] extract safari version for internal usage
so nobody has to worry about bugs in very old safari versions Fixes #1082 with inspiration from #1127 Cherry-picked from b6095e0 b702d86 and adapted for the 8.x version
1 parent a58e7f5 commit 66fefdb

File tree

5 files changed

+28
-15
lines changed

5 files changed

+28
-15
lines changed

src/js/common_shim.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,8 @@ export function removeExtmapAllowMixed(window, browserDetails) {
353353
if (browserDetails.browser === 'chrome' && browserDetails.version >= 71) {
354354
return;
355355
}
356-
if (browserDetails.browser === 'safari' && browserDetails.version >= 605) {
356+
if (browserDetails.browser === 'safari' &&
357+
browserDetails._safariVersion >= 13.1) {
357358
return;
358359
}
359360
const nativeSRD = window.RTCPeerConnection.prototype.setRemoteDescription;

src/js/utils.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ let deprecationWarnings_ = true;
2121
*/
2222
export function extractVersion(uastring, expr, pos) {
2323
const match = uastring.match(expr);
24-
return match && match.length >= pos && parseInt(match[pos], 10);
24+
return match && match.length >= pos && parseFloat(match[pos], 10);
2525
}
2626

2727
// Wraps the peerconnection event eventNameToWrap in a function
@@ -163,24 +163,27 @@ export function detectBrowser(window) {
163163

164164
if (navigator.mozGetUserMedia) { // Firefox.
165165
result.browser = 'firefox';
166-
result.version = extractVersion(navigator.userAgent,
167-
/Firefox\/(\d+)\./, 1);
166+
result.version = parseInt(extractVersion(navigator.userAgent,
167+
/Firefox\/(\d+)\./, 1));
168168
} else if (navigator.webkitGetUserMedia ||
169169
(window.isSecureContext === false && window.webkitRTCPeerConnection)) {
170170
// Chrome, Chromium, Webview, Opera.
171171
// Version matches Chrome/WebRTC version.
172172
// Chrome 74 removed webkitGetUserMedia on http as well so we need the
173173
// more complicated fallback to webkitRTCPeerConnection.
174174
result.browser = 'chrome';
175-
result.version = extractVersion(navigator.userAgent,
176-
/Chrom(e|ium)\/(\d+)\./, 2);
175+
result.version = parseInt(extractVersion(navigator.userAgent,
176+
/Chrom(e|ium)\/(\d+)\./, 2));
177177
} else if (window.RTCPeerConnection &&
178178
navigator.userAgent.match(/AppleWebKit\/(\d+)\./)) { // Safari.
179179
result.browser = 'safari';
180-
result.version = extractVersion(navigator.userAgent,
181-
/AppleWebKit\/(\d+)\./, 1);
180+
result.version = parseInt(extractVersion(navigator.userAgent,
181+
/AppleWebKit\/(\d+)\./, 1));
182182
result.supportsUnifiedPlan = window.RTCRtpTransceiver &&
183183
'currentDirection' in window.RTCRtpTransceiver.prototype;
184+
// Only for internal usage.
185+
result._safariVersion = extractVersion(navigator.userAgent,
186+
/Version\/(\d+(\.?\d+))/, 1);
184187
} else { // Default fallthrough: not supported.
185188
result.browser = 'Not a supported browser.';
186189
return result;

test/unit/detectBrowser.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,6 @@ describe('detectBrowser', () => {
6161
const browserDetails = detectBrowser(window);
6262
expect(browserDetails.browser).to.equal('safari');
6363
expect(browserDetails.version).to.equal(604);
64+
expect(browserDetails._safariVersion).to.equal(10.2);
6465
});
6566
});

test/unit/extmap-allow-mixed.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ describe('removal of extmap-allow-mixed', () => {
4040
window.RTCPeerConnection.prototype.setRemoteDescription = function() {
4141
return origSetRemoteDescription.apply(this, arguments);
4242
};
43-
browserDetails = {browser: 'chrome', version: '88'};
43+
browserDetails = {browser: 'chrome', version: 88};
4444
});
4545

4646
it('does not remove the extmap-allow-mixed line after Chrome 71', () => {
@@ -70,11 +70,11 @@ describe('removal of extmap-allow-mixed', () => {
7070
window.RTCPeerConnection.prototype.setRemoteDescription = function() {
7171
return origSetRemoteDescription.apply(this, arguments);
7272
};
73-
browserDetails = {browser: 'safari', version: '605'};
73+
browserDetails = {browser: 'safari', version: 605};
7474
});
7575

76-
it('does not remove the extmap-allow-mixed line after 605', () => {
77-
browserDetails.version = 605;
76+
it('does not remove the extmap-allow-mixed line after 13.1', () => {
77+
browserDetails._safariVersion = 13.1;
7878
shim.removeExtmapAllowMixed(window, browserDetails);
7979

8080
const pc = new window.RTCPeerConnection();
@@ -83,8 +83,8 @@ describe('removal of extmap-allow-mixed', () => {
8383
.to.equal('\n' + sdp);
8484
});
8585

86-
it('does remove the extmap-allow-mixed line before 605', () => {
87-
browserDetails.version = 604;
86+
it('does remove the extmap-allow-mixed line before 13.1', () => {
87+
browserDetails._safariVersion = 13.0;
8888
shim.removeExtmapAllowMixed(window, browserDetails);
8989

9090
const pc = new window.RTCPeerConnection();

test/unit/extractVersion.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ describe('extractVersion', () => {
115115
});
116116
});
117117

118-
describe('Safari regular expression', () => {
118+
describe('Webkit regular expression', () => {
119119
const expr = /AppleWebKit\/(\d+)/;
120120
it('matches the webkit version', () => {
121121
ua = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) ' +
@@ -148,5 +148,13 @@ describe('extractVersion', () => {
148148
expect(extractVersion(ua, expr, 1)).to.equal(null);
149149
});
150150
});
151+
describe('Safari regular expression', () => {
152+
const expr = /Version\/(\d+(\.?\d+))/;
153+
it('extracts the Safari version', () => {
154+
ua = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) ' +
155+
'AppleWebKit/604.1.6 (KHTML, like Gecko) Version/10.2 Safari/604.1.6';
156+
expect(extractVersion(ua, expr, 1)).to.equal(10.2);
157+
});
158+
});
151159
});
152160

0 commit comments

Comments
 (0)