Take control over your live stream video by running it yourself. Streaming + chat out of the box.
HTML activitypubbroadcastingchatdecentralizedfederationfediversegolanghacktoberfesthlslivelivestreamowncastrtmpself-hostedstreaming-videovideo
Replace ua-parser-js with bowser (#4470)
renovate[bot]b19afbd1d461
diff --git a/.github/workflows/chromatic.yml b/.github/workflows/chromatic.ymlindex 530f17d254..a6637cba5b 100644--- a/.github/workflows/chromatic.yml+++ b/.github/workflows/chromatic.yml@@ -85,11 +85,11 @@ jobs:- '**/*.{js,ts,tsx,jsx,md,css,scss,json}'- name: Install dependencies- if: ${{ github.actor != 'renovate[bot]' && github.actor != 'renovate' && steps.changed-files-yaml.outputs.src_any_changed == 'true'}}+ if: ${{ github.actor != 'renovate[bot]' && github.actor != 'renovate' && github.event.pull_request.user.login != 'renovate[bot]' && github.event.pull_request.user.login != 'renovate' && steps.changed-files-yaml.outputs.src_any_changed == 'true' }}run: npm install- name: Publish to Chromatic- if: ${{ github.actor != 'renovate[bot]' && github.actor != 'renovate' && steps.changed-files-yaml.outputs.src_any_changed == 'true' }}+ if: ${{ github.actor != 'renovate[bot]' && github.actor != 'renovate' && github.event.pull_request.user.login != 'renovate[bot]' && github.event.pull_request.user.login != 'renovate' && steps.changed-files-yaml.outputs.src_any_changed == 'true' }}uses: chromaui/action@v17with:workingDir: webdiff --git a/web/package-lock.json b/web/package-lock.jsonindex f5d284712d..601da9e746 100644--- a/web/package-lock.json+++ b/web/package-lock.json@@ -29,6 +29,7 @@"antd": "6.5.0","autoprefixer": "^10.4.14","babel-plugin-dynamic-import-node": "^2.3.3",+ "bowser": "2.14.1","chart.js": "^4.2.0","classnames": "2.5.1","date-fns": "^4.0.0",@@ -54,7 +55,6 @@"sanitize-html": "^2.11.0","semver": "^7.6.3","sharp": "0.34.5",- "ua-parser-js": "1.0.41","video.js": "^8.3.0","xstate": "^5.32.4","yaml": "2.9.0"@@ -78,7 +78,6 @@"@types/react": "18.3.31","@types/react-linkify": "1.0.4","@types/sanitize-html": "^2.9.0",- "@types/ua-parser-js": "0.7.39","@types/video.js": "^7.3.50","@typescript-eslint/eslint-plugin": "8.62.1","@typescript-eslint/parser": "8.62.1",@@ -4270,9 +4269,6 @@"cpu": ["arm"],- "libc": [- "glibc"- ],"license": "LGPL-3.0-or-later","optional": true,"os": [@@ -4289,9 +4285,6 @@"cpu": ["arm64"],- "libc": [- "glibc"- ],"license": "LGPL-3.0-or-later","optional": true,"os": [@@ -4308,9 +4301,6 @@"cpu": ["ppc64"],- "libc": [- "glibc"- ],"license": "LGPL-3.0-or-later","optional": true,"os": [@@ -4327,9 +4317,6 @@"cpu": ["riscv64"],- "libc": [- "glibc"- ],"license": "LGPL-3.0-or-later","optional": true,"os": [@@ -4346,9 +4333,6 @@"cpu": ["s390x"],- "libc": [- "glibc"- ],"license": "LGPL-3.0-or-later","optional": true,"os": [@@ -4365,9 +4349,6 @@"cpu": ["x64"],- "libc": [- "glibc"- ],"license": "LGPL-3.0-or-later","optional": true,"os": [@@ -4384,9 +4365,6 @@"cpu": ["arm64"],- "libc": [- "musl"- ],"license": "LGPL-3.0-or-later","optional": true,"os": [@@ -4403,9 +4381,6 @@"cpu": ["x64"],- "libc": [- "musl"- ],"license": "LGPL-3.0-or-later","optional": true,"os": [@@ -4422,9 +4397,6 @@"cpu": ["arm"],- "libc": [- "glibc"- ],"license": "Apache-2.0","optional": true,"os": [@@ -4447,9 +4419,6 @@"cpu": ["arm64"],- "libc": [- "glibc"- ],"license": "Apache-2.0","optional": true,"os": [@@ -4472,9 +4441,6 @@"cpu": ["ppc64"],- "libc": [- "glibc"- ],"license": "Apache-2.0","optional": true,"os": [@@ -4497,9 +4463,6 @@"cpu": ["riscv64"],- "libc": [- "glibc"- ],"license": "Apache-2.0","optional": true,"os": [@@ -4522,9 +4485,6 @@"cpu": ["s390x"],- "libc": [- "glibc"- ],"license": "Apache-2.0","optional": true,"os": [@@ -4547,9 +4507,6 @@"cpu": ["x64"],- "libc": [- "glibc"- ],"license": "Apache-2.0","optional": true,"os": [@@ -4572,9 +4529,6 @@"cpu": ["arm64"],- "libc": [- "musl"- ],"license": "Apache-2.0","optional": true,"os": [@@ -4597,9 +4551,6 @@"cpu": ["x64"],- "libc": [- "musl"- ],"license": "Apache-2.0","optional": true,"os": [@@ -6333,9 +6284,6 @@"cpu": ["arm64"],- "libc": [- "glibc"- ],"license": "MIT","optional": true,"os": [@@ -6352,9 +6300,6 @@"cpu": ["arm64"],- "libc": [- "musl"- ],"license": "MIT","optional": true,"os": [@@ -6371,9 +6316,6 @@"cpu": ["x64"],- "libc": [- "glibc"- ],"license": "MIT","optional": true,"os": [@@ -6390,9 +6332,6 @@"cpu": ["x64"],- "libc": [- "musl"- ],"license": "MIT","optional": true,"os": [@@ -6634,9 +6573,6 @@"arm64"],"dev": true,- "libc": [- "glibc"- ],"license": "MIT","optional": true,"os": [@@ -6654,9 +6590,6 @@"arm64"],"dev": true,- "libc": [- "musl"- ],"license": "MIT","optional": true,"os": [@@ -6674,9 +6607,6 @@"ppc64"],"dev": true,- "libc": [- "glibc"- ],"license": "MIT","optional": true,"os": [@@ -6694,9 +6624,6 @@"riscv64"],"dev": true,- "libc": [- "glibc"- ],"license": "MIT","optional": true,"os": [@@ -6714,9 +6641,6 @@"riscv64"],"dev": true,- "libc": [- "musl"- ],"license": "MIT","optional": true,"os": [@@ -6734,9 +6658,6 @@"s390x"],"dev": true,- "libc": [- "glibc"- ],"license": "MIT","optional": true,"os": [@@ -6754,9 +6675,6 @@"x64"],"dev": true,- "libc": [- "glibc"- ],"license": "MIT","optional": true,"os": [@@ -6774,9 +6692,6 @@"x64"],"dev": true,- "libc": [- "musl"- ],"license": "MIT","optional": true,"os": [@@ -6989,9 +6904,6 @@"arm64"],"dev": true,- "libc": [- "glibc"- ],"license": "MIT","optional": true,"os": [@@ -7006,9 +6918,6 @@"arm64"],"dev": true,- "libc": [- "musl"- ],"license": "MIT","optional": true,"os": [@@ -7023,9 +6932,6 @@"ppc64"],"dev": true,- "libc": [- "glibc"- ],"license": "MIT","optional": true,"os": [@@ -7040,9 +6946,6 @@"riscv64"],"dev": true,- "libc": [- "glibc"- ],"license": "MIT","optional": true,"os": [@@ -7057,9 +6960,6 @@"riscv64"],"dev": true,- "libc": [- "musl"- ],"license": "MIT","optional": true,"os": [@@ -7074,9 +6974,6 @@"s390x"],"dev": true,- "libc": [- "glibc"- ],"license": "MIT","optional": true,"os": [@@ -7091,9 +6988,6 @@"x64"],"dev": true,- "libc": [- "glibc"- ],"license": "MIT","optional": true,"os": [@@ -7108,9 +7002,6 @@"x64"],"dev": true,- "libc": [- "musl"- ],"license": "MIT","optional": true,"os": [@@ -7324,9 +7215,6 @@"cpu": ["arm"],- "libc": [- "glibc"- ],"license": "MIT","optional": true,"os": [@@ -7347,9 +7235,6 @@"cpu": ["arm"],- "libc": [- "musl"- ],"license": "MIT","optional": true,"os": [@@ -7370,9 +7255,6 @@"cpu": ["arm64"],- "libc": [- "glibc"- ],"license": "MIT","optional": true,"os": [@@ -7393,9 +7275,6 @@"cpu": ["arm64"],- "libc": [- "musl"- ],"license": "MIT","optional": true,"os": [@@ -7416,9 +7295,6 @@"cpu": ["x64"],- "libc": [- "glibc"- ],"license": "MIT","optional": true,"os": [@@ -7439,9 +7315,6 @@"cpu": ["x64"],- "libc": [- "musl"- ],"license": "MIT","optional": true,"os": [@@ -8605,9 +8478,6 @@"arm"],"dev": true,- "libc": [- "glibc"- ],"license": "MIT","optional": true,"os": [@@ -8622,9 +8492,6 @@"arm"],"dev": true,- "libc": [- "musl"- ],"license": "MIT","optional": true,"os": [@@ -8639,9 +8506,6 @@"arm64"],"dev": true,- "libc": [- "glibc"- ],"license": "MIT","optional": true,"os": [@@ -8656,9 +8520,6 @@"arm64"],"dev": true,- "libc": [- "musl"- ],"license": "MIT","optional": true,"os": [@@ -8673,9 +8534,6 @@"loong64"],"dev": true,- "libc": [- "glibc"- ],"license": "MIT","optional": true,"os": [@@ -8690,9 +8548,6 @@"loong64"],"dev": true,- "libc": [- "musl"- ],"license": "MIT","optional": true,"os": [@@ -8707,9 +8562,6 @@"ppc64"],"dev": true,- "libc": [- "glibc"- ],"license": "MIT","optional": true,"os": [@@ -8724,9 +8576,6 @@"ppc64"],"dev": true,- "libc": [- "musl"- ],"license": "MIT","optional": true,"os": [@@ -8741,9 +8590,6 @@"riscv64"],"dev": true,- "libc": [- "glibc"- ],"license": "MIT","optional": true,"os": [@@ -8758,9 +8604,6 @@"riscv64"],"dev": true,- "libc": [- "musl"- ],"license": "MIT","optional": true,"os": [@@ -8775,9 +8618,6 @@"s390x"],"dev": true,- "libc": [- "glibc"- ],"license": "MIT","optional": true,"os": [@@ -8792,9 +8632,6 @@"x64"],"dev": true,- "libc": [- "glibc"- ],"license": "MIT","optional": true,"os": [@@ -8809,9 +8646,6 @@"x64"],"dev": true,- "libc": [- "musl"- ],"license": "MIT","optional": true,"os": [@@ -10753,13 +10587,6 @@"dev": true,"license": "MIT"},- "node_modules/@types/ua-parser-js": {- "version": "0.7.39",- "resolved": "https://registry.npmjs.org/@types/ua-parser-js/-/ua-parser-js-0.7.39.tgz",- "integrity": "sha512-P/oDfpofrdtF5xw433SPALpdSchtJmY7nsJItf8h3KXqOslkbySh8zq4dSWXH2oTjRvJ5PczVEoCZPow6GicLg==",- "dev": true,- "license": "MIT"- },"node_modules/@types/unist": {"version": "2.0.11","resolved": "https://registry.npmjs.org/@types/unist/-/unist-2.0.11.tgz",@@ -11230,9 +11057,6 @@"arm64"],"dev": true,- "libc": [- "glibc"- ],"license": "MIT","optional": true,"os": [@@ -11247,9 +11071,6 @@"arm64"],"dev": true,- "libc": [- "musl"- ],"license": "MIT","optional": true,"os": [@@ -11264,9 +11085,6 @@"loong64"],"dev": true,- "libc": [- "glibc"- ],"license": "MIT","optional": true,"os": [@@ -11281,9 +11099,6 @@"loong64"],"dev": true,- "libc": [- "musl"- ],"license": "MIT","optional": true,"os": [@@ -11298,9 +11113,6 @@"ppc64"],"dev": true,- "libc": [- "glibc"- ],"license": "MIT","optional": true,"os": [@@ -11315,9 +11127,6 @@"riscv64"],"dev": true,- "libc": [- "glibc"- ],"license": "MIT","optional": true,"os": [@@ -11332,9 +11141,6 @@"riscv64"],"dev": true,- "libc": [- "musl"- ],"license": "MIT","optional": true,"os": [@@ -11349,9 +11155,6 @@"s390x"],"dev": true,- "libc": [- "glibc"- ],"license": "MIT","optional": true,"os": [@@ -11366,9 +11169,6 @@"x64"],"dev": true,- "libc": [- "glibc"- ],"license": "MIT","optional": true,"os": [@@ -11383,9 +11183,6 @@"x64"],"dev": true,- "libc": [- "musl"- ],"license": "MIT","optional": true,"os": [@@ -13145,6 +12942,12 @@"dev": true,"license": "ISC"},+ "node_modules/bowser": {+ "version": "2.14.1",+ "resolved": "https://registry.npmjs.org/bowser/-/bowser-2.14.1.tgz",+ "integrity": "sha512-tzPjzCxygAKWFOJP011oxFHs57HzIhOEracIgAePE4pqB3LikALKnSzUyU4MGs9/iCEUuHlAJTjTc5M+u7YEGg==",+ "license": "MIT"+ },"node_modules/brace-expansion": {"version": "5.0.7","resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.7.tgz",@@ -31595,9 +31398,6 @@"arm64"],"dev": true,- "libc": [- "glibc"- ],"license": "MIT","optional": true,"os": [@@ -31615,9 +31415,6 @@"arm64"],"dev": true,- "libc": [- "musl"- ],"license": "MIT","optional": true,"os": [@@ -31635,9 +31432,6 @@"ppc64"],"dev": true,- "libc": [- "glibc"- ],"license": "MIT","optional": true,"os": [@@ -31655,9 +31449,6 @@"riscv64"],"dev": true,- "libc": [- "glibc"- ],"license": "MIT","optional": true,"os": [@@ -31675,9 +31466,6 @@"riscv64"],"dev": true,- "libc": [- "musl"- ],"license": "MIT","optional": true,"os": [@@ -31695,9 +31483,6 @@"s390x"],"dev": true,- "libc": [- "glibc"- ],"license": "MIT","optional": true,"os": [@@ -31715,9 +31500,6 @@"x64"],"dev": true,- "libc": [- "glibc"- ],"license": "MIT","optional": true,"os": [@@ -31735,9 +31517,6 @@"x64"],"dev": true,- "libc": [- "musl"- ],"license": "MIT","optional": true,"os": [@@ -33905,32 +33684,6 @@"node": ">=14.17"}},- "node_modules/ua-parser-js": {- "version": "1.0.41",- "resolved": "https://registry.npmjs.org/ua-parser-js/-/ua-parser-js-1.0.41.tgz",- "integrity": "sha512-LbBDqdIC5s8iROCUjMbW1f5dJQTEFB1+KO9ogbvlb3nm9n4YHa5p4KTvFPWvh2Hs8gZMBuiB1/8+pdfe/tDPug==",- "funding": [- {- "type": "opencollective",- "url": "https://opencollective.com/ua-parser-js"- },- {- "type": "paypal",- "url": "https://paypal.me/faisalman"- },- {- "type": "github",- "url": "https://github.com/sponsors/faisalman"- }- ],- "license": "MIT",- "bin": {- "ua-parser-js": "script/cli.js"- },- "engines": {- "node": "*"- }- },"node_modules/uc.micro": {"version": "1.0.6","resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-1.0.6.tgz",diff --git a/web/package.json b/web/package.jsonindex e387667f88..f093f64764 100644--- a/web/package.json+++ b/web/package.json@@ -49,6 +49,7 @@"antd": "6.5.0","autoprefixer": "^10.4.14","babel-plugin-dynamic-import-node": "^2.3.3",+ "bowser": "2.14.1","chart.js": "^4.2.0","classnames": "2.5.1","date-fns": "^4.0.0",@@ -74,7 +75,6 @@"sanitize-html": "^2.11.0","semver": "^7.6.3","sharp": "0.34.5",- "ua-parser-js": "1.0.41","video.js": "^8.3.0","xstate": "^5.32.4","yaml": "2.9.0"@@ -98,7 +98,6 @@"@types/react": "18.3.31","@types/react-linkify": "1.0.4","@types/sanitize-html": "^2.9.0",- "@types/ua-parser-js": "0.7.39","@types/video.js": "^7.3.50","@typescript-eslint/eslint-plugin": "8.62.1","@typescript-eslint/parser": "8.62.1",diff --git a/web/tests/userAgent.test.ts b/web/tests/userAgent.test.tsnew file mode 100644index 0000000000..b964e8e2e0--- /dev/null+++ b/web/tests/userAgent.test.ts@@ -0,0 +1,56 @@+import { formatUAstring } from '../utils/format';+import { isMobileSafariHomeScreenApp, isMobileSafariIos } from '../utils/helpers';++const iphoneSafari =+ 'Mozilla/5.0 (iPhone; CPU iPhone OS 17_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.5 Mobile/15E148 Safari/604.1';+const iphoneChrome =+ 'Mozilla/5.0 (iPhone; CPU iPhone OS 17_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/126.0.6478.153 Mobile/15E148 Safari/604.1';+const ipadSafari =+ 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.5 Mobile/15E148 Safari/604.1';+const desktopSafari =+ 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.5 Safari/605.1.15';+const desktopChrome =+ 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36';++function setNavigator(+ userAgent: string,+ { platform = '', maxTouchPoints = 0, standalone = false } = {},+) {+ Object.defineProperties(window.navigator, {+ userAgent: { configurable: true, value: userAgent },+ platform: { configurable: true, value: platform },+ maxTouchPoints: { configurable: true, value: maxTouchPoints },+ standalone: { configurable: true, value: standalone },+ });+}++describe('mobile Safari detection', () => {+ test.each([+ ['iPhone Safari', iphoneSafari, 'iPhone', 5, true],+ ['iPhone Chrome', iphoneChrome, 'iPhone', 5, false],+ ['iPadOS Safari', ipadSafari, 'MacIntel', 5, true],+ ['desktop Safari', desktopSafari, 'MacIntel', 0, false],+ ])('%s', (_name, userAgent, platform, maxTouchPoints, expected) => {+ setNavigator(userAgent, { platform, maxTouchPoints });++ expect(isMobileSafariIos()).toBe(expected);+ });++ test('detects an installed iOS home screen app', () => {+ setNavigator(iphoneSafari, { platform: 'iPhone', maxTouchPoints: 5, standalone: true });++ expect(isMobileSafariHomeScreenApp()).toBe(true);+ });+});++describe('user agent formatting', () => {+ test('preserves the existing browser display format', () => {+ expect(formatUAstring(desktopChrome)).toBe('Chrome 126 on Windows 10\n ');+ expect(formatUAstring(iphoneSafari)).toBe('Mobile Safari 17 on iOS 17.5\n (iPhone)');+ });++ test('preserves special and unknown user agents', () => {+ expect(formatUAstring('libmpv')).toBe('mpv media player');+ expect(formatUAstring('curl/8.7.1')).toBe('curl/8.7.1');+ });+});diff --git a/web/utils/format.ts b/web/utils/format.tsindex ec6d60f8c4..c09d50e19e 100644--- a/web/utils/format.ts+++ b/web/utils/format.ts@@ -1,5 +1,5 @@import { format } from 'date-fns';-import UAParser from 'ua-parser-js';+import Bowser from 'bowser';// formatDisplayDate renders a user timestamp, including the year only when it// is not the current year. Shared by the admin user views.@@ -61,11 +61,15 @@ export function parseSecondsToDurationString(seconds = 0) {}export function formatUAstring(uaString: string) {- const parser = UAParser(uaString);- const { device, os, browser } = parser;- const { major: browserVersion, name } = browser;- const { version: osVersion, name: osName } = os;- const { model, type } = device;+ const { browser, os, platform } = Bowser.parse(uaString);+ const name =+ browser.name === 'Safari' && (platform.type === 'mobile' || platform.type === 'tablet')+ ? 'Mobile Safari'+ : browser.name;+ const browserVersion = browser.version?.split('.')[0];+ const osName = os.name === 'macOS' ? 'Mac OS' : os.name;+ const osVersion = os.versionName || os.version;+ const { model, type } = platform;if (uaString === 'libmpv') {return 'mpv media player';@@ -75,7 +79,8 @@ export function formatUAstring(uaString: string) {return uaString;}- const deviceString = model || type ? ` (${model || type})` : '';+ const device = model || (type === 'desktop' ? undefined : type);+ const deviceString = device ? ` (${device})` : '';return `${name} ${browserVersion} on ${osName} ${osVersion}${deviceString}`;}diff --git a/web/utils/helpers.js b/web/utils/helpers.jsindex f2c629f524..b3c36000ac 100644--- a/web/utils/helpers.js+++ b/web/utils/helpers.js@@ -1,4 +1,4 @@-import UAParser from 'ua-parser-js';+import Bowser from 'bowser';export function getDiffInDaysFromNow(timestamp) {const time = typeof timestamp === 'string' ? new Date(timestamp) : timestamp;@@ -7,16 +7,14 @@ export function getDiffInDaysFromNow(timestamp) {export const isMobileSafariIos = () => {try {- const ua = navigator.userAgent;- const uaParser = new UAParser(ua);- const browser = uaParser.getBrowser();- const device = uaParser.getDevice();+ const { browser, platform } = Bowser.parse(navigator.userAgent);+ const isIPadOS = navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1;- if (device.vendor !== 'Apple') {+ if (!isIPadOS && platform.vendor !== 'Apple') {return false;}- if (device.type !== 'mobile' && device.type !== 'tablet') {+ if (!isIPadOS && platform.type !== 'mobile' && platform.type !== 'tablet') {return false;}