Migrating from Node's deprecated url API to browser's URL

Related to https://github.com/vector-im/element-web/pull/16292

Signed-off-by: Bekliev Parviz <nightkon95@gmail.com>
This commit is contained in:
Ibragim/Parviz Bekliev 2021-02-11 17:47:50 +03:00
parent 3e57378631
commit 92a5787528
4 changed files with 12 additions and 30 deletions

View file

@ -26,7 +26,6 @@ import {hideToast as hideUpdateToast, showToast as showUpdateToast} from "matrix
import {Action} from "matrix-react-sdk/src/dispatcher/actions";
import { CheckUpdatesPayload } from 'matrix-react-sdk/src/dispatcher/payloads/CheckUpdatesPayload';
import url from 'url';
import UAParser from 'ua-parser-js';
const POKE_RATE_MS = 10 * 60 * 1000; // 10 min
@ -184,17 +183,13 @@ export default class WebPlatform extends VectorBasePlatform {
getDefaultDeviceDisplayName(): string {
// strip query-string and fragment from uri
const u = url.parse(window.location.href);
u.protocol = "";
u.search = "";
u.hash = "";
// Remove trailing slash if present
u.pathname = u.pathname.replace(/\/$/, "");
const url = new URL(window.location.href);
let appName = u.format();
// Remove leading slashes if present
appName = appName.replace(/^\/\//, "");
// `appName` is now in the format `develop.element.io`.
// `appName` in the format `develop.element.io/abc/xyz`
const appName = [
url.host,
url.pathname.replace(/\/$/, ""), // Remove trailing slash if present
].join('');
const ua = new UAParser();
const browserName = ua.getBrowser().name || "unknown browser";