Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ua-parser-js to enable reliable browser name and version parsing #4001

Merged
merged 3 commits into from
Aug 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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