Skip to content

Commit

Permalink
Add ua-parser-js to enable reliable browser name and version parsing (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
dsilhavy authored Aug 9, 2022
1 parent 5ee8bca commit 4534b0f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
15 changes: 10 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@
"fast-deep-equal": "2.0.1",
"html-entities": "^1.2.1",
"imsc": "^1.0.2",
"localforage": "^1.7.1"
"localforage": "^1.7.1",
"ua-parser-js": "^1.0.2"
},
"repository": {
"type": "git",
Expand Down
12 changes: 12 additions & 0 deletions src/core/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
*/

import path from 'path-browserify'
import { UAParser } from 'ua-parser-js'

class Utils {
static mixin(dest, source, copy) {
Expand Down Expand Up @@ -175,6 +176,17 @@ class Utils {
return targetUrl
}
}

static parseUserAgent(ua = null) {
try {
const uaString = ua === null ? typeof navigator !== 'undefined' ? navigator.userAgent.toLowerCase() : '' : '';

return UAParser(uaString);
}
catch(e) {
return {};
}
}
}

export default Utils;
5 changes: 3 additions & 2 deletions src/streaming/controllers/CatchupController.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import Constants from '../constants/Constants';
import MediaPlayerEvents from '../MediaPlayerEvents';
import Events from '../../core/events/Events';
import MetricsConstants from '../constants/MetricsConstants';
import Utils from '../../core/Utils';

function CatchupController() {
const context = this.context;
Expand Down Expand Up @@ -115,8 +116,8 @@ function CatchupController() {
isCatchupSeekInProgress = false;

// Detect safari browser (special behavior for low latency streams)
const ua = typeof navigator !== 'undefined' ? navigator.userAgent.toLowerCase() : '';
const isSafari = /safari/.test(ua) && !/chrome/.test(ua);
const ua = Utils.parseUserAgent();
const isSafari = ua && ua.browser && ua.browser.name && ua.browser.name.toLowerCase() === 'safari';
minPlaybackRateChange = isSafari ? 0.25 : 0.02;
}

Expand Down

0 comments on commit 4534b0f

Please sign in to comment.