Compare commits
12 Commits
optimize_b
...
main
Author | SHA1 | Date |
---|---|---|
gapodo | 174fa9c553 | |
gapodo | 091ac83fd7 | |
gapodo | c9fb5f7471 | |
gapodo | 7ea4271810 | |
gapodo | c7d94f8609 | |
gapodo | 842cd08574 | |
gapodo | 5b3a208f16 | |
gapodo | 5daff6117c | |
gapodo | 1c28f62f36 | |
gapodo | 8b502811a4 | |
gapodo | 4e35b47760 | |
gapodo | e15feca680 |
|
@ -2,6 +2,7 @@
|
|||
.idea/
|
||||
node_modules/
|
||||
.sass-cache/
|
||||
.npm/
|
||||
|
||||
/auth/certs/
|
||||
/auth/js/auth.js.map
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
audit=false
|
||||
fund=false
|
||||
update-notifier=false
|
||||
package-lock=true
|
|
@ -0,0 +1,89 @@
|
|||
when:
|
||||
event: [push, deployment, manual, cron]
|
||||
|
||||
labels:
|
||||
platform: linux/amd64
|
||||
|
||||
variables:
|
||||
- &node_image 'node:14-bullseye'
|
||||
- &buildx_image 'woodpeckerci/plugin-docker-buildx:2.2.1'
|
||||
- &platforms 'linux/amd64'
|
||||
- &dockerfile 'docker/Dockerfile.ci'
|
||||
|
||||
|
||||
steps:
|
||||
prepare-npm:
|
||||
image: *node_image
|
||||
secrets:
|
||||
- npmconf
|
||||
commands:
|
||||
- git config --add safe.directory '*'
|
||||
- if [ "$${NPMCONF:-}" != "" ]; then echo "$${NPMCONF}" >> "$${HOME}/.npmrc"; fi
|
||||
- npm ci
|
||||
- npx browserslist@latest --update-db
|
||||
|
||||
build-npm:
|
||||
image: *node_image
|
||||
commands:
|
||||
- bash ./scripts/build.sh web dev
|
||||
|
||||
build-docker-next:
|
||||
image: *buildx_image
|
||||
pull: true
|
||||
settings:
|
||||
platforms: *platforms
|
||||
dockerfile: *dockerfile
|
||||
context: .
|
||||
registry:
|
||||
from_secret: registry_domain
|
||||
repo:
|
||||
from_secret: target_image_name
|
||||
password:
|
||||
from_secret: registry_token
|
||||
username:
|
||||
from_secret: registry_user
|
||||
auto_tag: true
|
||||
tag: [next, "next-${CI_COMMIT_SHA:0:8}"]
|
||||
when:
|
||||
branch: ${CI_REPO_DEFAULT_BRANCH}
|
||||
event: push
|
||||
|
||||
build-docker-branch:
|
||||
image: *buildx_image
|
||||
pull: true
|
||||
settings:
|
||||
platforms: *platforms
|
||||
dockerfile: *dockerfile
|
||||
context: .
|
||||
registry:
|
||||
from_secret: registry_domain
|
||||
repo:
|
||||
from_secret: target_image_name
|
||||
password:
|
||||
from_secret: registry_token
|
||||
username:
|
||||
from_secret: registry_user
|
||||
auto_tag: true
|
||||
tag: ["${CI_COMMIT_BRANCH}", "${CI_COMMIT_BRANCH}-${CI_COMMIT_SHA:0:8}"]
|
||||
when:
|
||||
event: [push, manual]
|
||||
|
||||
build-docker-tag:
|
||||
image: *buildx_image
|
||||
pull: true
|
||||
settings:
|
||||
platforms: *platforms
|
||||
dockerfile: *dockerfile
|
||||
context: .
|
||||
registry:
|
||||
from_secret: registry_domain
|
||||
repo:
|
||||
from_secret: target_image_name
|
||||
password:
|
||||
from_secret: registry_token
|
||||
username:
|
||||
from_secret: registry_user
|
||||
auto_tag: true
|
||||
tag: [latest, "${CI_COMMIT_TAG}", "tag-${CI_COMMIT_SHA:0:8}"]
|
||||
when:
|
||||
event: [tag]
|
|
@ -4,14 +4,12 @@ export default api => {
|
|||
[
|
||||
"@babel/preset-env",
|
||||
{
|
||||
"corejs": {"version": 3},
|
||||
"corejs": {"version": '3.33', "proposals": false},
|
||||
"useBuiltIns": "usage",
|
||||
"targets": {
|
||||
"edge": "17",
|
||||
"firefox": "60",
|
||||
"chrome": "67",
|
||||
"safari": "11.1",
|
||||
"ie": "11"
|
||||
"edge": "111",
|
||||
"firefox": "100",
|
||||
"chrome": "109"
|
||||
}
|
||||
}
|
||||
]
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
#My local environment to deploy the files directly
|
||||
environment/
|
|
@ -1,314 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: WolverinDEV
|
||||
* Date: 04.10.18
|
||||
* Time: 16:42
|
||||
*/
|
||||
|
||||
$UI_BASE_PATH = "ui-files/";
|
||||
$CLIENT_BASE_PATH = "files/";
|
||||
|
||||
function errorExit($message) {
|
||||
http_response_code(400);
|
||||
die(json_encode([
|
||||
"success" => false,
|
||||
"msg" => $message
|
||||
]));
|
||||
}
|
||||
|
||||
function verifyPostSecret() {
|
||||
if(!isset($_POST["secret"])) {
|
||||
errorExit("Missing required information!");
|
||||
}
|
||||
|
||||
$require_secret = file_get_contents(".deploy_secret");
|
||||
if($require_secret === false || strlen($require_secret) == 0) {
|
||||
errorExit("Server missing secret!");
|
||||
}
|
||||
|
||||
if(!is_string($_POST["secret"])) {
|
||||
errorExit("Invalid secret!");
|
||||
}
|
||||
|
||||
if(strcmp(trim($require_secret), trim($_POST["secret"])) !== 0) {
|
||||
errorExit("Secret does not match!");
|
||||
}
|
||||
}
|
||||
|
||||
function handleRequest() {
|
||||
if(isset($_GET) && isset($_GET["type"])) {
|
||||
if ($_GET["type"] == "update-info") {
|
||||
global $CLIENT_BASE_PATH;
|
||||
$raw_versions = file_get_contents($CLIENT_BASE_PATH . "/version.json");
|
||||
if($raw_versions === false) {
|
||||
errorExit("Missing file!");
|
||||
}
|
||||
|
||||
$versions = json_decode($raw_versions, true);
|
||||
$versions["success"] = true;
|
||||
|
||||
die(json_encode($versions));
|
||||
}
|
||||
else if ($_GET["type"] == "update-download") {
|
||||
global $CLIENT_BASE_PATH;
|
||||
|
||||
$path = $CLIENT_BASE_PATH . $_GET["channel"] . DIRECTORY_SEPARATOR . $_GET["version"] . DIRECTORY_SEPARATOR;
|
||||
$raw_release_info = file_get_contents($path . "info.json");
|
||||
if($raw_release_info === false) {
|
||||
errorExit("missing info file (version and/or channel missing. Path was " . $path . ")");
|
||||
}
|
||||
$release_info = json_decode($raw_release_info);
|
||||
|
||||
foreach($release_info as $platform) {
|
||||
if($platform->platform != $_GET["platform"]) continue;
|
||||
if($platform->arch != $_GET["arch"]) continue;
|
||||
|
||||
http_response_code(200);
|
||||
header("Cache-Control: public"); // needed for internet explorer
|
||||
header("Content-Type: application/binary");
|
||||
header("Content-Transfer-Encoding: Binary");
|
||||
header("Content-Length:".filesize($path . $platform->update));
|
||||
header("Content-Disposition: attachment; filename=update.tar.gz");
|
||||
header("info-version: 1");
|
||||
readfile($path . $platform->update);
|
||||
die();
|
||||
}
|
||||
errorExit("Missing platform, arch or file");
|
||||
}
|
||||
else if ($_GET["type"] == "ui-info") {
|
||||
global $UI_BASE_PATH;
|
||||
|
||||
$version_info = file_get_contents($UI_BASE_PATH . "info.json");
|
||||
if($version_info === false) $version_info = array();
|
||||
else $version_info = json_decode($version_info, true);
|
||||
|
||||
$info = array();
|
||||
$info["success"] = true;
|
||||
$info["versions"] = array();
|
||||
|
||||
foreach($version_info as $channel => $data) {
|
||||
if(!isset($data["latest"])) continue;
|
||||
|
||||
$channel_info = [
|
||||
"timestamp" => $data["latest"]["timestamp"],
|
||||
"version" => $data["latest"]["version"],
|
||||
"git-ref" => $data["latest"]["git-ref"],
|
||||
"channel" => $channel,
|
||||
"required_client" => $data["latest"]["required_client"]
|
||||
];
|
||||
array_push($info["versions"], $channel_info);
|
||||
}
|
||||
|
||||
die(json_encode($info));
|
||||
} else if ($_GET["type"] == "ui-download") {
|
||||
global $UI_BASE_PATH;
|
||||
|
||||
if(!isset($_GET["channel"]) || !isset($_GET["version"]))
|
||||
errorExit("missing required parameters");
|
||||
|
||||
if($_GET["version"] !== "latest" && !isset($_GET["git-ref"]))
|
||||
errorExit("missing required parameters");
|
||||
|
||||
$version_info = file_get_contents($UI_BASE_PATH . "info.json");
|
||||
if($version_info === false) $version_info = array();
|
||||
else $version_info = json_decode($version_info, true);
|
||||
|
||||
$channel_data = $version_info[$_GET["channel"]];
|
||||
if(!isset($channel_data))
|
||||
errorExit("channel unknown");
|
||||
|
||||
$ui_pack = false;
|
||||
if($_GET["version"] === "latest") {
|
||||
$ui_pack = $channel_data["latest"];
|
||||
} else {
|
||||
foreach ($channel_data["history"] as $entry) {
|
||||
if($entry["version"] == $_GET["version"] && $entry["git-ref"] == $_GET["git-ref"]) {
|
||||
$ui_pack = $entry;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if($ui_pack === false)
|
||||
errorExit("missing version");
|
||||
|
||||
|
||||
header("Cache-Control: public"); // needed for internet explorer
|
||||
header("Content-Type: application/binary");
|
||||
header("Content-Transfer-Encoding: Binary");
|
||||
header("Content-Disposition: attachment; filename=ui.tar.gz");
|
||||
header("info-version: 1");
|
||||
|
||||
header("x-ui-timestamp: " . $ui_pack["timestamp"]);
|
||||
header("x-ui-version: " . $ui_pack["version"]);
|
||||
header("x-ui-git-ref: " . $ui_pack["git-ref"]);
|
||||
header("x-ui-required_client: " . $ui_pack["required_client"]);
|
||||
|
||||
$read = readfile($ui_pack["file"]);
|
||||
header("Content-Length:" . $read);
|
||||
|
||||
if($read === false) errorExit("internal error: Failed to read file!");
|
||||
die();
|
||||
}
|
||||
}
|
||||
else if($_POST["type"] == "deploy-build") {
|
||||
global $CLIENT_BASE_PATH;
|
||||
|
||||
if(!isset($_POST["version"]) || !isset($_POST["platform"]) || !isset($_POST["arch"]) || !isset($_POST["update_suffix"]) || !isset($_POST["installer_suffix"])) {
|
||||
errorExit("Missing required information!");
|
||||
}
|
||||
|
||||
verifyPostSecret();
|
||||
|
||||
if(!isset($_FILES["update"])) {
|
||||
errorExit("Missing update file");
|
||||
}
|
||||
|
||||
if($_FILES["update"]["error"] !== UPLOAD_ERR_OK) {
|
||||
errorExit("Upload for update failed!");
|
||||
}
|
||||
|
||||
if(!isset($_FILES["installer"])) {
|
||||
errorExit("Missing installer file");
|
||||
}
|
||||
|
||||
if($_FILES["installer"]["error"] !== UPLOAD_ERR_OK) {
|
||||
errorExit("Upload for installer failed!");
|
||||
}
|
||||
|
||||
$json_version = json_decode($_POST["version"], true);
|
||||
$version = $json_version["major"] . "." . $json_version["minor"] . "." . $json_version["patch"] . ($json_version["build"] > 0 ? "-" . $json_version["build"] : "");
|
||||
$path = $CLIENT_BASE_PATH . DIRECTORY_SEPARATOR . $_POST["channel"] . DIRECTORY_SEPARATOR . $version . DIRECTORY_SEPARATOR;
|
||||
exec("mkdir -p " . $path);
|
||||
//mkdir($path, 777, true);
|
||||
|
||||
|
||||
$filename_update = "TeaClient-" . $_POST["platform"] . "_" . $_POST["arch"] . "." . $_POST["update_suffix"];
|
||||
$filename_install = "TeaClient-" . $_POST["platform"] . "_" . $_POST["arch"] . "." . $_POST["installer_suffix"];
|
||||
|
||||
{
|
||||
$version_info = file_get_contents($path . "info.json");
|
||||
if($version_info === false) {
|
||||
$version_info = array();
|
||||
} else {
|
||||
$version_info = json_decode($version_info, true);
|
||||
if($version_info === false) {
|
||||
errorExit("Failed to decode old versions info file");
|
||||
}
|
||||
}
|
||||
|
||||
for($index = 0; $index < count($version_info); $index++) {
|
||||
if($version_info[$index]["platform"] == $_POST["platform"] && $version_info[$index]["arch"] == $_POST["arch"]) {
|
||||
array_splice($version_info, $index, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$info = array();
|
||||
$info["platform"] = $_POST["platform"];
|
||||
$info["arch"] = $_POST["arch"];
|
||||
$info["update"] = $filename_update;
|
||||
$info["install"] = $filename_install;
|
||||
array_push($version_info, $info);
|
||||
file_put_contents($path . "info.json", json_encode($version_info));
|
||||
}
|
||||
|
||||
{
|
||||
$filename = $CLIENT_BASE_PATH . DIRECTORY_SEPARATOR . "version.json";
|
||||
$indexes = file_get_contents($filename);
|
||||
if($indexes === false) {
|
||||
$indexes = array();
|
||||
} else {
|
||||
$indexes = json_decode($indexes, true);
|
||||
if($indexes === false) {
|
||||
errorExit("Failed to decode old latest versions info file");
|
||||
}
|
||||
}
|
||||
|
||||
$index = &$indexes[$_POST["channel"]];
|
||||
if(!isset($index)) {
|
||||
$index = array();
|
||||
}
|
||||
|
||||
for($idx = 0; $idx < count($index); $idx++) {
|
||||
if($index[$idx]["platform"] == $_POST["platform"] && $index[$idx]["arch"] == $_POST["arch"]) {
|
||||
array_splice($index, $idx, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$info = array();
|
||||
$info["platform"] = $_POST["platform"];
|
||||
$info["arch"] = $_POST["arch"];
|
||||
$info["version"] = $json_version;
|
||||
array_push($index, $info);
|
||||
|
||||
file_put_contents($filename, json_encode($indexes));
|
||||
}
|
||||
|
||||
move_uploaded_file($_FILES["installer"]["tmp_name"],$path . $filename_install);
|
||||
move_uploaded_file($_FILES["update"]["tmp_name"],$path . $filename_update);
|
||||
|
||||
die(json_encode([
|
||||
"success" => true
|
||||
]));
|
||||
}
|
||||
else if($_POST["type"] == "deploy-ui-build") {
|
||||
global $UI_BASE_PATH;
|
||||
|
||||
if(!isset($_POST["channel"]) || !isset($_POST["version"]) || !isset($_POST["git_ref"]) || !isset($_POST["required_client"])) {
|
||||
errorExit("Missing required information!");
|
||||
}
|
||||
|
||||
verifyPostSecret();
|
||||
|
||||
$path = $UI_BASE_PATH . DIRECTORY_SEPARATOR;
|
||||
$channeled_path = $UI_BASE_PATH . DIRECTORY_SEPARATOR . $_POST["channel"];
|
||||
$filename = "TeaClientUI-" . $_POST["version"] . "_" . $_POST["git_ref"] . ".tar.gz";
|
||||
exec("mkdir -p " . $path);
|
||||
exec("mkdir -p " . $channeled_path);
|
||||
|
||||
{
|
||||
$info = file_get_contents($path . "info.json");
|
||||
if($info === false) {
|
||||
$info = array();
|
||||
} else {
|
||||
$info = json_decode($info, true);
|
||||
if($info === false) {
|
||||
errorExit("failed to decode old info file");
|
||||
}
|
||||
}
|
||||
|
||||
$channel_info = &$info[$_POST["channel"]];
|
||||
if(!$channel_info) {
|
||||
$channel_info = array();
|
||||
}
|
||||
|
||||
$entry = [
|
||||
"timestamp" => time(),
|
||||
"file" => $channeled_path . DIRECTORY_SEPARATOR . $filename,
|
||||
"version" => $_POST["version"],
|
||||
"git-ref" => $_POST["git_ref"],
|
||||
"required_client" => $_POST["required_client"]
|
||||
];
|
||||
|
||||
$channel_info["latest"] = $entry;
|
||||
if(!$channel_info["history"]) $channel_info["history"] = array();
|
||||
array_push($channel_info["history"], $entry);
|
||||
|
||||
file_put_contents($path . "info.json", json_encode($info));
|
||||
}
|
||||
|
||||
|
||||
move_uploaded_file($_FILES["file"]["tmp_name"],$channeled_path . DIRECTORY_SEPARATOR . $filename);
|
||||
die(json_encode([
|
||||
"success" => true
|
||||
]));
|
||||
}
|
||||
else die(json_encode([
|
||||
"success" => false,
|
||||
"error" => "invalid action!"
|
||||
]));
|
||||
}
|
||||
|
||||
handleRequest();
|
|
@ -1,8 +0,0 @@
|
|||
app/**/*.css
|
||||
app/**/*.css.map
|
||||
|
||||
app/**/*.js
|
||||
app/**/*.js.map
|
||||
|
||||
declarations/
|
||||
generated/
|
|
@ -1,31 +0,0 @@
|
|||
:global {
|
||||
html, body {
|
||||
border: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.app-container {
|
||||
right: 0;
|
||||
left: 0;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
position: absolute;
|
||||
display: flex;
|
||||
justify-content: stretch;
|
||||
|
||||
.app {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
|
||||
display: flex; flex-direction: column; resize: both;
|
||||
}
|
||||
}
|
||||
|
||||
footer {
|
||||
display: none!important;
|
||||
}
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
window.__native_client_init_shared(__webpack_require__);
|
||||
|
||||
import "../AppMain.scss";
|
||||
import "tc-shared/entry-points/MainApp";
|
|
@ -1,2 +0,0 @@
|
|||
window.__native_client_init_shared(__webpack_require__);
|
||||
import "tc-shared/entry-points/ModalWindow";
|
|
@ -1,7 +0,0 @@
|
|||
interface Window {
|
||||
__native_client_init_hook: () => void;
|
||||
__native_client_init_shared: (webpackRequire: any) => void;
|
||||
}
|
||||
|
||||
declare const __teaclient_preview_notice: any;
|
||||
declare const __teaclient_preview_error: any;
|
|
@ -1,30 +0,0 @@
|
|||
html, body {
|
||||
border: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.app-container {
|
||||
right: 0;
|
||||
left: 0;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
position: absolute;
|
||||
display: flex;
|
||||
justify-content: stretch;
|
||||
}
|
||||
.app-container .app {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
resize: both;
|
||||
}
|
||||
|
||||
footer {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
/*# sourceMappingURL=main.css.map */
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"sourceRoot":"","sources":["main.scss"],"names":[],"mappings":"AAAA;EACC;EACA;;;AAGD;EACC;EACA;EACA;EACA;EAEA;EACA;EACA;EACA;EACA;;AAEA;EACC;EACA;EACA;EAEA;EAAe;EAAwB;;;AAIzC;EACC","file":"main.css"}
|
|
@ -1,23 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
BASEDIR=$(dirname "$0")
|
||||
cd "$BASEDIR"
|
||||
source ../scripts/resolve_commands.sh
|
||||
|
||||
if [[ ! -e declarations/imports_shared.d.ts ]]; then
|
||||
echo "generate the declarations first!"
|
||||
echo "Execute: /scripts/build_declarations.sh"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ ! -e ../shared/generated/shared.js ]]; then
|
||||
echo "generate the shared packed file first!"
|
||||
echo "Execute: /shared/generate_packed.sh"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
execute_tsc -p tsconfig/tsconfig_packed.json
|
||||
if [[ $? -ne 0 ]]; then
|
||||
echo "Failed to build file"
|
||||
exit 1
|
||||
fi
|
|
@ -1,6 +0,0 @@
|
|||
{
|
||||
"source_files": [
|
||||
"../js/**/*.ts"
|
||||
],
|
||||
"target_file": "../declarations/exports.d.ts"
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
/* general web project config */
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es6",
|
||||
"module": "commonjs",
|
||||
"sourceMap": true
|
||||
},
|
||||
"include": [
|
||||
"../declarations/imports_*.d.ts",
|
||||
"../js/**/*.ts"
|
||||
]
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
/* packed web project config */
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"module": "none",
|
||||
"outFile": "../generated/client.js",
|
||||
"allowJs": true
|
||||
},
|
||||
"include": [
|
||||
"../declarations/imports_*.d.ts",
|
||||
"../js/**/*.ts",
|
||||
"../../shared/generated/shared.js"
|
||||
]
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
FROM nginx:mainline-alpine
|
||||
|
||||
COPY ./docker/default.conf /etc/nginx/conf.d/default.conf
|
||||
COPY ./docker/nginx.conf /etc/nginx/nginx.conf
|
||||
COPY ./docker/entrypoint.sh /
|
||||
|
||||
RUN apk update --no-cache && apk upgrade --no-cache \
|
||||
&& apk add --no-cache openssl tzdata \
|
||||
&& mkdir -p /var/www/TeaWeb /etc/ssl/certs \
|
||||
&& chmod +x /entrypoint.sh
|
||||
|
||||
ENV TZ="Europe/Berlin"
|
||||
|
||||
EXPOSE 80 443
|
||||
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
|
@ -0,0 +1,2 @@
|
|||
FROM reg.c1.datenclown.at/teaspeak/web-base:latest
|
||||
COPY ./dist/ /var/www/TeaWeb/
|
|
@ -0,0 +1,36 @@
|
|||
server {
|
||||
listen 80;
|
||||
server_name _;
|
||||
return 301 https://$host$request_uri;
|
||||
}
|
||||
|
||||
server {
|
||||
listen 443 default_server ssl http2;
|
||||
server_name _;
|
||||
|
||||
ssl_ciphers EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-GCM-SHA256:TLS-CHACHA20-POLY1305-SHA256:TLS-AES-256-GCM-SHA384:TLS-AES-128-GCM-SHA256;
|
||||
ssl_protocols TLSv1.2 TLSv1.3;
|
||||
ssl_dhparam /etc/ssl/certs/dhparam.pem;
|
||||
ssl_ecdh_curve secp384r1;
|
||||
ssl_certificate /etc/ssl/certs/tea_bundle.crt;
|
||||
ssl_certificate_key /etc/ssl/certs/tea.key;
|
||||
ssl_session_cache shared:MozSSL:10m;
|
||||
ssl_session_timeout 1d;
|
||||
ssl_prefer_server_ciphers on;
|
||||
|
||||
location / {
|
||||
root /var/www/TeaWeb;
|
||||
index index.html;
|
||||
}
|
||||
|
||||
#error_page 404 /404.html;
|
||||
|
||||
# redirect server error pages to the static page /50x.html
|
||||
#
|
||||
error_page 500 502 503 504 /50x.html;
|
||||
location = /50x.html {
|
||||
root /usr/share/nginx/html;
|
||||
}
|
||||
|
||||
gzip off;
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
#!/usr/bin/env sh
|
||||
set -e
|
||||
|
||||
gen_self_signed() {
|
||||
echo "[WRN] No certificates found, generating self signed cert with key"
|
||||
openssl req -x509 -nodes -days 1780 -newkey rsa:4096 \
|
||||
-keyout /etc/ssl/certs/tea.key \
|
||||
-out /etc/ssl/certs/tea_bundle.crt \
|
||||
-subj "/C=DE/ST=Berlin/L=Germany/O=TeaSpeak/OU=TeaWeb/CN=localhost/emailAddress=noreply@teaspeak.de"
|
||||
}
|
||||
|
||||
gen_diffie_hellman() {
|
||||
echo "[INF] No Diffie-Hellman pem found, generating new with 2048 byte"
|
||||
openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048
|
||||
}
|
||||
|
||||
if [ "$1" = "nginx" ]; then
|
||||
if [ ! -f /etc/ssl/certs/tea.key ] && [ ! -f /etc/ssl/certs/tea_bundle.crt ]; then
|
||||
gen_self_signed
|
||||
elif [ ! -f /etc/ssl/certs/tea.key ] || [ ! -f /etc/ssl/certs/tea_bundle.crt ]; then
|
||||
echo "[ERR] Only found a key or crt-bundle file but both files are REQUIRED!"
|
||||
exit 1
|
||||
fi
|
||||
if [ ! -f /etc/ssl/certs/dhparam.pem ]; then
|
||||
gen_diffie_hellman
|
||||
fi
|
||||
fi
|
||||
|
||||
exec "$@"
|
|
@ -0,0 +1,32 @@
|
|||
user nginx;
|
||||
worker_processes auto;
|
||||
|
||||
error_log /var/log/nginx/error.log warn;
|
||||
pid /var/run/nginx.pid;
|
||||
|
||||
|
||||
events {
|
||||
worker_connections 1024;
|
||||
}
|
||||
|
||||
|
||||
http {
|
||||
include /etc/nginx/mime.types;
|
||||
default_type application/octet-stream;
|
||||
|
||||
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
||||
'$status $body_bytes_sent "$http_referer" '
|
||||
'"$http_user_agent" "$http_x_forwarded_for"';
|
||||
|
||||
access_log /var/log/nginx/access.log main;
|
||||
|
||||
sendfile on;
|
||||
#tcp_nopush on;
|
||||
|
||||
server_tokens off;
|
||||
keepalive_timeout 75;
|
||||
|
||||
#gzip on;
|
||||
|
||||
include /etc/nginx/conf.d/*.conf;
|
||||
}
|
|
@ -2,32 +2,32 @@ import "core-js/stable";
|
|||
import "./polifill";
|
||||
import "./css";
|
||||
|
||||
import {ApplicationLoader} from "./loader/loader";
|
||||
import {getUrlParameter} from "./loader/Utils";
|
||||
import { ApplicationLoader } from "./loader/loader";
|
||||
import { getUrlParameter } from "./loader/Utils";
|
||||
|
||||
/* let the loader register himself at the window first */
|
||||
const target = getUrlParameter("loader-target") || "app";
|
||||
console.info("Loading app with loader \"%s\"", target);
|
||||
|
||||
let appLoader: ApplicationLoader;
|
||||
if(target === "empty") {
|
||||
if (target === "empty") {
|
||||
appLoader = new (require("./targets/empty").default);
|
||||
} else if(target === "manifest") {
|
||||
} else if (target === "manifest") {
|
||||
appLoader = new (require("./targets/maifest-target").default);
|
||||
} else {
|
||||
appLoader = new (require("./targets/app").default);
|
||||
}
|
||||
setTimeout(() => appLoader.execute(), 0);
|
||||
|
||||
export {};
|
||||
export { };
|
||||
|
||||
if(__build.target === "client") {
|
||||
if (__build.target === "client") {
|
||||
/* do this so we don't get a react dev tools warning within the client */
|
||||
if(!('__REACT_DEVTOOLS_GLOBAL_HOOK__' in window)) {
|
||||
window.__REACT_DEVTOOLS_GLOBAL_HOOK__ = {};
|
||||
if (!('__REACT_DEVTOOLS_GLOBAL_HOOK__' in window)) {
|
||||
(window as Window).__REACT_DEVTOOLS_GLOBAL_HOOK__ = {};
|
||||
}
|
||||
|
||||
window.__REACT_DEVTOOLS_GLOBAL_HOOK__.inject = function () {};
|
||||
window.__REACT_DEVTOOLS_GLOBAL_HOOK__.inject = function () { };
|
||||
}
|
||||
|
||||
/* Hello World message */
|
||||
|
@ -89,7 +89,7 @@ if(__build.target === "client") {
|
|||
].join(";");
|
||||
|
||||
const display_detect = /./;
|
||||
display_detect.toString = function() { print_security(); return ""; };
|
||||
display_detect.toString = function () { print_security(); return ""; };
|
||||
|
||||
clog("%cLovely to see you using and debugging the TeaSpeak-Web client.", css);
|
||||
clog("%cIf you have some good ideas or already done some incredible changes,", css);
|
||||
|
|
|
@ -51,18 +51,6 @@ loader.register_task(loader.Stage.SETUP, {
|
|||
priority: 10
|
||||
});
|
||||
|
||||
/* test if we're getting loaded within a TeaClient preview window */
|
||||
loader.register_task(loader.Stage.SETUP, {
|
||||
name: "TeaClient tester",
|
||||
function: async () => {
|
||||
if(typeof __teaclient_preview_notice !== "undefined" && typeof __teaclient_preview_error !== "undefined") {
|
||||
loader.critical_error("Why you're opening TeaWeb within the TeaSpeak client?!");
|
||||
throw "we're already a TeaClient!";
|
||||
}
|
||||
},
|
||||
priority: 100
|
||||
});
|
||||
|
||||
export default class implements ApplicationLoader {
|
||||
execute() {
|
||||
loader.execute_managed(true);
|
||||
|
|
|
@ -2,27 +2,6 @@ import * as loader from "../loader/loader";
|
|||
import {Stage} from "../loader/loader";
|
||||
import {detect as detectBrowser} from "detect-browser";
|
||||
|
||||
loader.register_task(Stage.SETUP, {
|
||||
name: "app init",
|
||||
function: async () => {
|
||||
/* TeaClient */
|
||||
if(window.require || window.__native_client_init_hook) {
|
||||
if(__build.target !== "client") {
|
||||
loader.critical_error("App seems not to be compiled for the client.", "This app has been compiled for " + __build.target);
|
||||
return;
|
||||
}
|
||||
|
||||
window.__native_client_init_hook();
|
||||
} else {
|
||||
if(__build.target !== "web") {
|
||||
loader.critical_error("App seems not to be compiled for the web.", "This app has been compiled for " + __build.target);
|
||||
return;
|
||||
}
|
||||
}
|
||||
},
|
||||
priority: 1000
|
||||
});
|
||||
|
||||
loader.register_task(Stage.SETUP, {
|
||||
name: __build.target === "web" ? "outdated browser checker" : "outdated renderer tester",
|
||||
function: async () => {
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
|
||||
<meta name="og:description" content="The TeaSpeak Web client is a in the browser running client for the VoIP communication software TeaSpeak." />
|
||||
<meta name="og:url" content="https://web.teaspeak.de/">
|
||||
<% /* TODO: Put in an appropriate image <meta name="og:image" content="https://www.whatsapp.com/img/whatsapp-promo.png"> */ %>
|
||||
|
||||
<% /* Using an absolute path here since the manifest.json works only with such. */ %>
|
||||
<% /* <link rel="manifest" href="/manifest.json"> */ %>
|
||||
|
@ -27,19 +26,6 @@
|
|||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<meta name="format-detection" content="telephone=no">
|
||||
|
||||
<!-- Global site tag (gtag.js) - Google Analytics -->
|
||||
<script defer async src="https://www.googletagmanager.com/gtag/js?id=UA-113151733-4"></script>
|
||||
<script>
|
||||
window.dataLayer = window.dataLayer || [];
|
||||
|
||||
function gtag() {
|
||||
dataLayer.push(arguments);
|
||||
}
|
||||
|
||||
gtag('js', new Date());
|
||||
gtag('config', 'UA-113151733-4');
|
||||
</script>
|
||||
|
||||
<link rel="preload" as="image" href="<%= require("./images/initial-sequence.gif") %>">
|
||||
<link rel="preload" as="image" href="<%= require("./images/bowl.png") %>">
|
||||
<% /* We don't preload the bowl since it's only a div background */ %>
|
||||
|
|
File diff suppressed because it is too large
Load Diff
130
package.json
130
package.json
|
@ -17,74 +17,74 @@
|
|||
"author": "TeaSpeak (WolverinDEV)",
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.10.4",
|
||||
"@babel/plugin-transform-runtime": "^7.10.4",
|
||||
"@babel/preset-env": "^7.10.4",
|
||||
"@babel/core": "^7.23.3",
|
||||
"@babel/plugin-transform-runtime": "^7.23.3",
|
||||
"@babel/preset-env": "^7.23.3",
|
||||
"@google-cloud/translate": "^5.3.0",
|
||||
"@svgr/webpack": "^5.5.0",
|
||||
"@types/dompurify": "^2.0.1",
|
||||
"@types/ejs": "^3.0.2",
|
||||
"@types/emoji-mart": "^3.0.2",
|
||||
"@types/emscripten": "^1.38.0",
|
||||
"@types/fs-extra": "^8.0.1",
|
||||
"@types/dompurify": "^2.4.0",
|
||||
"@types/ejs": "^3.1.5",
|
||||
"@types/emscripten": "^1.39.10",
|
||||
"@types/fs-extra": "^8.1.5",
|
||||
"@types/html-minifier": "^3.5.3",
|
||||
"@types/jquery": "^3.3.34",
|
||||
"@types/jquery": "^3.5.27",
|
||||
"@types/jsrender": "^1.0.5",
|
||||
"@types/lodash": "^4.14.149",
|
||||
"@types/lodash": "^4.14.201",
|
||||
"@types/moment": "^2.13.0",
|
||||
"@types/node": "^12.7.2",
|
||||
"@types/react-color": "^3.0.4",
|
||||
"@types/react-dom": "^16.9.5",
|
||||
"@types/react-grid-layout": "^1.1.1",
|
||||
"@types/remarkable": "^1.7.4",
|
||||
"@types/sdp-transform": "^2.4.4",
|
||||
"@types/sha256": "^0.2.0",
|
||||
"@types/twemoji": "^12.1.1",
|
||||
"@types/node": "^12.20.55",
|
||||
"@types/react": "^16.14.51",
|
||||
"@types/react-color": "^3.0.10",
|
||||
"@types/react-dom": "^16.9.22",
|
||||
"@types/react-grid-layout": "^1.3.5",
|
||||
"@types/remarkable": "^1.7.6",
|
||||
"@types/sdp-transform": "^2.4.9",
|
||||
"@types/sha256": "^0.2.2",
|
||||
"@types/twemoji": "^12.1.2",
|
||||
"@types/websocket": "0.0.40",
|
||||
"@types/xml-parser": "^1.2.29",
|
||||
"@wasm-tool/wasm-pack-plugin": "^1.3.1",
|
||||
"autoprefixer": "^10.2.5",
|
||||
"babel-loader": "^8.1.0",
|
||||
"circular-dependency-plugin": "^5.2.0",
|
||||
"clean-css": "^4.2.1",
|
||||
"@types/xml-parser": "^1.2.33",
|
||||
"@wasm-tool/wasm-pack-plugin": "^1.7.0",
|
||||
"autoprefixer": "^10.4.16",
|
||||
"babel-loader": "^8.3.0",
|
||||
"circular-dependency-plugin": "^5.2.2",
|
||||
"clean-css": "^4.2.4",
|
||||
"clean-webpack-plugin": "^3.0.0",
|
||||
"copy-webpack-plugin": "^8.0.0",
|
||||
"copy-webpack-plugin": "^8.1.1",
|
||||
"css-loader": "^3.6.0",
|
||||
"css-minimizer-webpack-plugin": "^1.3.0",
|
||||
"exports-loader": "^0.7.0",
|
||||
"fast-xml-parser": "^3.17.4",
|
||||
"file-loader": "^6.0.0",
|
||||
"fast-xml-parser": "^3.21.1",
|
||||
"file-loader": "^6.2.0",
|
||||
"fs-extra": "latest",
|
||||
"gulp": "^4.0.2",
|
||||
"html-loader": "^1.0.0",
|
||||
"html-loader": "^1.3.2",
|
||||
"html-minifier": "^4.0.0",
|
||||
"html-webpack-inline-source-plugin": "0.0.10",
|
||||
"html-webpack-plugin": "^5.3.1",
|
||||
"html-webpack-plugin": "^5.5.3",
|
||||
"inline-chunks-html-webpack-plugin": "^1.3.1",
|
||||
"mime-types": "^2.1.24",
|
||||
"mini-css-extract-plugin": "^1.3.9",
|
||||
"mkdirp": "^0.5.1",
|
||||
"mime-types": "^2.1.35",
|
||||
"mini-css-extract-plugin": "^1.6.2",
|
||||
"mkdirp": "^0.5.6",
|
||||
"node-sass": "^4.14.1",
|
||||
"postcss": "^8.3.0",
|
||||
"postcss-loader": "^5.2.0",
|
||||
"potpack": "^1.0.1",
|
||||
"raw-loader": "^4.0.0",
|
||||
"postcss": "^8.4.31",
|
||||
"postcss-loader": "^5.3.0",
|
||||
"potpack": "^1.0.2",
|
||||
"raw-loader": "^4.0.2",
|
||||
"sass": "1.22.10",
|
||||
"sass-loader": "^8.0.2",
|
||||
"sha256": "^0.2.0",
|
||||
"style-loader": "^1.1.3",
|
||||
"style-loader": "^1.3.0",
|
||||
"svg-inline-loader": "^0.8.2",
|
||||
"terser": "^4.2.1",
|
||||
"terser": "^4.8.1",
|
||||
"terser-webpack-plugin": "4.2.3",
|
||||
"ts-loader": "^6.2.2",
|
||||
"ts-loader": "^8.4.0",
|
||||
"tsd": "^0.13.1",
|
||||
"typescript": "^4.2",
|
||||
"typescript": "^4.9.5",
|
||||
"url-loader": "^4.1.1",
|
||||
"wabt": "^1.0.13",
|
||||
"webpack": "^5.26.1",
|
||||
"webpack-bundle-analyzer": "^3.6.1",
|
||||
"webpack-cli": "^4.5.0",
|
||||
"webpack-dev-server": "^3.11.2",
|
||||
"wabt": "1.0.13",
|
||||
"webpack": "^5.89.0",
|
||||
"webpack-bundle-analyzer": "^3.9.0",
|
||||
"webpack-cli": "^4.10.0",
|
||||
"webpack-dev-server": "^3.11.3",
|
||||
"webpack-svg-sprite-generator": "^5.0.4",
|
||||
"zip-webpack-plugin": "^4.0.1"
|
||||
},
|
||||
|
@ -97,33 +97,35 @@
|
|||
},
|
||||
"homepage": "https://www.teaspeak.de",
|
||||
"dependencies": {
|
||||
"@types/crypto-js": "^4.0.1",
|
||||
"@emoji-mart/data": "^1.1.2",
|
||||
"@emoji-mart/react": "^1.1.1",
|
||||
"@types/crypto-js": "^4.2.1",
|
||||
"broadcastchannel-polyfill": "^1.0.1",
|
||||
"buffer": "^6.0.3",
|
||||
"crypto-browserify": "^3.12.0",
|
||||
"crypto-js": "^4.0.0",
|
||||
"detect-browser": "^5.2.0",
|
||||
"dompurify": "^2.2.8",
|
||||
"emoji-mart": "git+https://github.com/WolverinDEV/emoji-mart.git",
|
||||
"emoji-regex": "^9.0.0",
|
||||
"highlight.js": "^10.1.1",
|
||||
"ip-regex": "^4.2.0",
|
||||
"jquery": "^3.5.1",
|
||||
"jsrender": "^1.0.7",
|
||||
"moment": "^2.24.0",
|
||||
"react": "^16.13.1",
|
||||
"react-dom": "^16.13.1",
|
||||
"react-grid-layout": "^1.2.2",
|
||||
"react-player": "^2.5.0",
|
||||
"crypto-js": "^4.2.0",
|
||||
"detect-browser": "^5.3.0",
|
||||
"dompurify": "^2.4.7",
|
||||
"emoji-mart": "^5.5.2",
|
||||
"emoji-regex": "^9.2.2",
|
||||
"highlight.js": "^10.7.3",
|
||||
"ip-regex": "^4.3.0",
|
||||
"jquery": "^3.7.1",
|
||||
"jsrender": "^1.0.13",
|
||||
"moment": "^2.29.4",
|
||||
"react": "^16.14.0",
|
||||
"react-dom": "^16.14.0",
|
||||
"react-grid-layout": "^1.4.3",
|
||||
"react-player": "^2.13.0",
|
||||
"remarkable": "^2.0.1",
|
||||
"resize-observer-polyfill": "git+https://github.com/albancreton/resize-observer-polyfill.git#patch-1",
|
||||
"sdp-transform": "^2.14.0",
|
||||
"sdp-transform": "^2.14.1",
|
||||
"simple-jsonp-promise": "^1.1.0",
|
||||
"stream-browserify": "^3.0.0",
|
||||
"twemoji": "^13.0.0",
|
||||
"twemoji": "^13.1.1",
|
||||
"url-knife": "^3.1.3",
|
||||
"webcrypto-liner": "^1.2.4",
|
||||
"webpack-manifest-plugin": "^3.1.0",
|
||||
"webcrypto-liner": "^1.4.2",
|
||||
"webpack-manifest-plugin": "^3.2.0",
|
||||
"webrtc-adapter": "^7.5.1"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
#!/bin/bash
|
||||
|
||||
SCRIPT=$(realpath "$0")
|
||||
SCRIPTPATH=$(dirname "$SCRIPT")
|
||||
BASEPATH="$(realpath "${SCRIPTPATH}/../")"
|
||||
|
||||
NPM_DIR="${BASEPATH}/.npm"
|
||||
|
||||
if [[ ! -d "${NPM_DIR}" ]]; then
|
||||
mkdir "${NPM_DIR}" || exit 1
|
||||
fi
|
||||
|
||||
if [[ "${BUILDINDOCKER:-}" != "yes" ]]; then
|
||||
if docker -v | grep -qi "podman"; then
|
||||
is_podman='yes'
|
||||
fi
|
||||
docker run --rm --workdir "/work" -v "${BASEPATH}:/work" -e is_podman="${is_podman:-no}" -e BUILDINDOCKER=yes -e npm_config_cache=/work/.npm node:14-bullseye /bin/bash -c 'chmod +x /work/scripts/build_in_docker.sh && /work/scripts/build_in_docker.sh'
|
||||
exit
|
||||
fi
|
||||
|
||||
## in docker
|
||||
|
||||
echo "adding secure git dir"
|
||||
git config --global --add safe.directory '*'
|
||||
|
||||
echo "running chmods"
|
||||
find "${BASEPATH}" -iname "*.sh" -exec chmod +x {} +
|
||||
|
||||
echo "Cleaning up old files"
|
||||
"${BASEPATH}/scripts/cleanup.sh" full >/dev/null 2>&1 || exit 1
|
||||
|
||||
echo "Installing npm packages"
|
||||
npm i || exit 1
|
||||
|
||||
echo "Updating browser list"
|
||||
npx browserslist@latest --update-db || exit 1
|
||||
|
||||
echo "running build"
|
||||
"${BASEPATH}/scripts/build.sh" web rel
|
||||
|
||||
if [[ "${is_podman}" != 'yes' ]]; then
|
||||
echo "fixing perms"
|
||||
chown -R 1000:1000 /work
|
||||
else
|
||||
echo "in podman, not fixing perms"
|
||||
fi
|
|
@ -1,73 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Example usage: ./scripts/deploy_ui_files.sh http://dev.clientapi.teaspeak.de/api.php test 1.1.0
|
||||
|
||||
cd "$(dirname "$0")" || { echo "failed to enter base directory"; exit 1; }
|
||||
source "./helper.sh"
|
||||
|
||||
if [[ "$#" -ne 3 ]]; then
|
||||
echo "Illegal number of parameters (url | channel | required version)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# shellcheck disable=SC2154
|
||||
if [[ "${teaclient_deploy_secret}" == "" ]]; then
|
||||
echo "Missing deploy secret!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
package_file=$(find_release_package "client" "release")
|
||||
if [[ $? -ne 0 ]]; then
|
||||
echo "$package_file"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# We require a .tar.gz file and not a zip file.
|
||||
# So we're extracting the contents and tar.gz ing them
|
||||
temp_dir=$(mktemp -d)
|
||||
unzip "$package_file" -d "$temp_dir/raw/"
|
||||
if [[ $? -ne 0 ]]; then
|
||||
rm -r "$temp_dir" &>/dev/null
|
||||
echo "Failed to unpack package."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Generating .tar.gz file from $package_file"
|
||||
package_file="$temp_dir/$(basename -s ".zip" "$package_file").tar.gz"
|
||||
tar --use-compress-program="gzip -9" -C "$temp_dir/raw/" -c . -cf "$package_file";
|
||||
if [[ $? -ne 0 ]]; then
|
||||
rm -r "$temp_dir"
|
||||
echo "Failed to package package."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
git_hash=$(git_version "short-tag")
|
||||
application_version=$(project_version)
|
||||
echo "Deploying $package_file."
|
||||
echo "Hash: ${git_hash}, Version: ${application_version}, Target channel: $2."
|
||||
|
||||
upload_result=$(curl \
|
||||
-k \
|
||||
-X POST \
|
||||
-F "required_client=$3" \
|
||||
-F "type=deploy-ui-build" \
|
||||
-F "channel=$2" \
|
||||
-F "version=$application_version" \
|
||||
-F "git_ref=$git_hash" \
|
||||
-F "secret=${teaclient_deploy_secret}" \
|
||||
-F "file=@$package_file" \
|
||||
"$1"
|
||||
)
|
||||
|
||||
rm -r "$temp_dir"
|
||||
echo "Server upload result: $upload_result"
|
||||
success=$(echo "${upload_result}" | python -c "import sys, json; print(json.load(sys.stdin)['success'])")
|
||||
|
||||
if [[ ! "${success}" == "True" ]]; then
|
||||
error_message=$(echo "${upload_result}" | python -c "import sys, json; print(json.load(sys.stdin)['msg'])" 2>/dev/null);
|
||||
echo "Failed to deploy build: ${error_message}"
|
||||
exit 1
|
||||
else
|
||||
echo "Build successfully deployed!"
|
||||
exit 0
|
||||
fi
|
|
@ -0,0 +1,11 @@
|
|||
#!/bin/bash
|
||||
|
||||
SCRIPT=$(realpath "$0")
|
||||
SCRIPTPATH=$(dirname "$SCRIPT")
|
||||
BASEPATH="$(realpath "${SCRIPTPATH}/../")"
|
||||
|
||||
echo "adding secure git dir"
|
||||
git config --global --add safe.directory '*'
|
||||
|
||||
echo "running chmods"
|
||||
find "${BASEPATH}" -iname "*.sh" -exec chmod +x {} +
|
|
@ -1,38 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
install_sys_deps() {
|
||||
# shellcheck disable=SC2207
|
||||
curl_version=($(curl --version 2>/dev/null))
|
||||
|
||||
# shellcheck disable=SC2181
|
||||
if [[ $? -ne 0 ]]; then
|
||||
echo "> Missing curl. Please install it."
|
||||
exit 1
|
||||
fi
|
||||
echo "> Found curl ${curl_version[1]}"
|
||||
}
|
||||
|
||||
install_node() {
|
||||
node_version=$(node --version 2>/dev/null)
|
||||
# shellcheck disable=SC2181
|
||||
if [[ $? -ne 0 ]]; then
|
||||
echo "> Missing node. We can't currently install it automatically."
|
||||
echo "> Please download the latest version here: https://nodejs.org/en/download/"
|
||||
exit 1
|
||||
else
|
||||
echo "> Found node $node_version"
|
||||
fi
|
||||
|
||||
npm_version=$(npm --version 2>/dev/null)
|
||||
# shellcheck disable=SC2181
|
||||
if [[ $? -ne 0 ]]; then
|
||||
echo "> Missing npm. Please ensure you've correctly installed node."
|
||||
echo "> You may need to add npm manually to your PATH variable."
|
||||
exit 1
|
||||
else
|
||||
echo "> Found npm $npm_version"
|
||||
fi
|
||||
}
|
||||
|
||||
install_sys_deps
|
||||
install_node
|
|
@ -0,0 +1,28 @@
|
|||
#!/bin/bash
|
||||
|
||||
SCRIPT=$(realpath "$0")
|
||||
SCRIPTPATH=$(dirname "$SCRIPT")
|
||||
BASEPATH="$(realpath "${SCRIPTPATH}/../")"
|
||||
|
||||
NPM_DIR="${BASEPATH}/.npm"
|
||||
|
||||
if [[ ! -d "${NPM_DIR}" ]]; then
|
||||
mkdir "${NPM_DIR}" || exit 1
|
||||
fi
|
||||
|
||||
if docker -v | grep -qi "podman"; then
|
||||
is_podman='yes'
|
||||
fi
|
||||
|
||||
function run() {
|
||||
docker run --rm --workdir "/work" -v "${BASEPATH}:/work" -e is_podman="${is_podman:-no}" -e BUILDINDOCKER=yes -e npm_config_cache=/work/.npm ${opts:-} node:14-bullseye ${@}
|
||||
}
|
||||
|
||||
opts="-it" run /bin/bash -c 'bash /work/scripts/in_docker_prep.sh && bash'
|
||||
|
||||
if [[ "${is_podman}" != 'yes' ]]; then
|
||||
echo "fixing perms"
|
||||
run /bin/bash -c 'chown -R 1000:1000 /work'
|
||||
else
|
||||
echo "in podman, not fixing perms"
|
||||
fi
|
|
@ -1,177 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
cd "$(dirname "$0")/../../" || { echo "Failed to enter base dir"; exit 1; }
|
||||
source ./scripts/travis/properties.sh
|
||||
|
||||
build_verbose=0
|
||||
build_release=1
|
||||
build_debug=0
|
||||
|
||||
function print_help() {
|
||||
echo "Possible arguments:"
|
||||
echo " --verbose=[yes|no] | Enable verbose build output (Default: $build_verbose)"
|
||||
echo " --enable-release=[yes|no] | Enable release build (Default: $build_release)"
|
||||
echo " --enable-debug=[yes|no] | Enable debug build (Default: $build_debug)"
|
||||
}
|
||||
|
||||
function parse_arguments() {
|
||||
# Preprocess the help parameter
|
||||
for argument in "$@"; do
|
||||
if [[ "$argument" = "--help" ]] || [[ "$argument" = "-h" ]]; then
|
||||
print_help
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
shopt -s nocasematch
|
||||
for argument in "$@"; do
|
||||
echo "Argument: $argument"
|
||||
if [[ "$argument" =~ ^--verbose(=(y|1)?[[:alnum:]]*$)?$ ]]; then
|
||||
build_verbose=0
|
||||
if [[ -z "${BASH_REMATCH[1]}" ]] || [[ -n "${BASH_REMATCH[2]}" ]]; then
|
||||
build_verbose=1
|
||||
fi
|
||||
|
||||
if [[ ${build_verbose} ]]; then
|
||||
echo "Enabled verbose output"
|
||||
fi
|
||||
elif [[ "$argument" =~ ^--enable-release(=(y|1)?[[:alnum:]]*$)?$ ]]; then
|
||||
build_release=0
|
||||
if [[ -z "${BASH_REMATCH[1]}" ]] || [[ -n "${BASH_REMATCH[2]}" ]]; then
|
||||
build_release=1
|
||||
fi
|
||||
|
||||
if [[ ${build_release} ]]; then
|
||||
echo "Enabled release build!"
|
||||
fi
|
||||
elif [[ "$argument" =~ ^--enable-debug(=(y|1)?[[:alnum:]]*$)?$ ]]; then
|
||||
build_debug=0
|
||||
if [[ -z "${BASH_REMATCH[1]}" ]] || [[ -n "${BASH_REMATCH[2]}" ]]; then
|
||||
build_debug=1
|
||||
fi
|
||||
|
||||
if [[ ${build_debug} ]]; then
|
||||
echo "Enabled debug build!"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
function execute() {
|
||||
time_begin=$(date +%s%N)
|
||||
|
||||
echo "> Executing step: $1" >> "${LOG_FILE}"
|
||||
echo -e "\e[32m> Executing step: $1\e[0m"
|
||||
#Execute the command
|
||||
for command in "${@:3}"; do
|
||||
echo "$> $command" >> "${LOG_FILE}"
|
||||
if [[ ${build_verbose} -gt 0 ]]; then
|
||||
echo "$> $command"
|
||||
fi
|
||||
|
||||
error=""
|
||||
if [[ ${build_verbose} -gt 0 ]]; then
|
||||
if [[ -f ${LOG_FILE}.tmp ]]; then
|
||||
rm "${LOG_FILE}.tmp"
|
||||
fi
|
||||
${command} |& tee "${LOG_FILE}.tmp" | grep -E '^[^(/\S*/libstdc++.so\S*: no version information available)].*'
|
||||
|
||||
error_code=${PIPESTATUS[0]}
|
||||
error=$(cat "${LOG_FILE}.tmp")
|
||||
cat "${LOG_FILE}.tmp" >> "${LOG_FILE}"
|
||||
rm "${LOG_FILE}.tmp"
|
||||
else
|
||||
error=$(${command} 2>&1)
|
||||
error_code=$?
|
||||
echo "$error" >> "${LOG_FILE}"
|
||||
fi
|
||||
|
||||
|
||||
if [[ ${error_code} -ne 0 ]]; then
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
#Log the result
|
||||
time_end=$(date +%s%N)
|
||||
time_needed=$((time_end - time_begin))
|
||||
time_needed_ms=$((time_needed / 1000000))
|
||||
step_color="\e[32m"
|
||||
[[ ${error_code} -ne 0 ]] && step_color="\e[31m"
|
||||
echo "$step_color> Step took ${time_needed_ms}ms" >> ${LOG_FILE}
|
||||
echo -e "$step_color> Step took ${time_needed_ms}ms\e[0m"
|
||||
|
||||
if [[ ${error_code} -ne 0 ]]; then
|
||||
handle_failure ${error_code} "$2"
|
||||
fi
|
||||
|
||||
error=""
|
||||
}
|
||||
|
||||
function handle_failure() {
|
||||
# We cut of the nasty "node: /usr/lib/libstdc++.so.6: no version information available (required by node)" message
|
||||
echo "--------------------------- [ERROR] ---------------------------"
|
||||
echo "We've encountered an fatal error, which isn't recoverable!"
|
||||
echo " Aborting build process!"
|
||||
echo ""
|
||||
echo "Exit code : $1"
|
||||
echo "Error message: ${*:2}"
|
||||
if [[ ${build_verbose} -eq 0 ]] && [[ "$error" != "" ]]; then
|
||||
echo "Command log : (lookup \"${LOG_FILE}\" for detailed output!)"
|
||||
echo "$error"
|
||||
fi
|
||||
echo "--------------------------- [ERROR] ---------------------------"
|
||||
exit 1
|
||||
}
|
||||
|
||||
cd "$(dirname "$0")/../../" || { echo "Failed to enter base dir"; exit 1; }
|
||||
error=""
|
||||
|
||||
LOG_FILE="$(pwd)/$LOG_FILE"
|
||||
if [[ ! -d $(dirname "${LOG_FILE}") ]]; then
|
||||
mkdir -p "$(dirname "${LOG_FILE}")"
|
||||
fi
|
||||
|
||||
if [[ $# -eq 0 ]]; then
|
||||
echo "Executing build scripts with no arguments"
|
||||
else
|
||||
echo "Executing build scripts with arguments: $* ($#)"
|
||||
fi
|
||||
if [[ "$1" == "bash" ]]; then
|
||||
bash
|
||||
exit 0
|
||||
fi
|
||||
|
||||
parse_arguments "${@:1}"
|
||||
|
||||
if [[ -e "$LOG_FILE" ]]; then
|
||||
rm "$LOG_FILE"
|
||||
fi
|
||||
|
||||
echo "---------- Setup ----------"
|
||||
chmod +x ./scripts/install_dependencies.sh
|
||||
source ./scripts/install_dependencies.sh
|
||||
|
||||
echo "---------- Web client ----------"
|
||||
|
||||
function execute_build_release() {
|
||||
execute \
|
||||
"Building release package" \
|
||||
"Failed to build release" \
|
||||
"./scripts/build.sh web release"
|
||||
}
|
||||
function execute_build_debug() {
|
||||
execute \
|
||||
"Building debug package" \
|
||||
"Failed to build debug" \
|
||||
"./scripts/build.sh web dev"
|
||||
}
|
||||
|
||||
chmod +x ./scripts/build.sh
|
||||
if [[ ${build_release} ]]; then
|
||||
execute_build_release
|
||||
fi
|
||||
if [[ ${build_debug} ]]; then
|
||||
execute_build_debug
|
||||
fi
|
||||
exit 0
|
|
@ -1,61 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
cd "$(dirname "$0")/../../" || { echo "Failed to enter base dir"; exit 1; }
|
||||
source ./scripts/travis/properties.sh
|
||||
source ./scripts/helper.sh
|
||||
|
||||
git_rev=$(git_version "short-tag")
|
||||
if [[ "$1" == "release" ]]; then
|
||||
echo "Releasing $git_rev as release"
|
||||
rolling_tag="latest"
|
||||
elif [[ "$1" == "development" ]]; then
|
||||
echo "Releasing $git_rev as beta release"
|
||||
rolling_tag="beta"
|
||||
else
|
||||
echo "Invalid release mode"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# FIXME: This dosn't work anymore
|
||||
zip_file=$(find "$PACKAGES_DIRECTORY" -maxdepth 1 -name "TeaWeb-release*.zip" -print)
|
||||
[[ $(echo "$zip_file" | wc -l) -ne 1 ]] && {
|
||||
echo "Invalid .zip file count (Expected 1 but got $(echo "$zip_file" | wc -l)): ${zip_file[*]}"
|
||||
exit 1
|
||||
}
|
||||
[[ ! -e "$zip_file" ]] && {
|
||||
echo "File ($zip_file) does not exists"
|
||||
exit 1
|
||||
}
|
||||
|
||||
git clone https://github.com/TeaSpeak/TeaDocker.git auto-build/teadocker || {
|
||||
echo "Failed to clone the TeaDocker project"
|
||||
exit 1
|
||||
}
|
||||
|
||||
cp "$zip_file" auto-build/teadocker/web/TeaWeb-release.zip || {
|
||||
echo "Failed to copy Docker webclient files to the docker files build context"
|
||||
exit 1
|
||||
}
|
||||
|
||||
docker build -f auto-build/teadocker/web/travis.Dockerfile --build-arg WEB_VERSION="$git_rev" --build-arg WEB_ZIP=TeaWeb-release.zip -t teaspeak/web:"$rolling_tag" auto-build/teadocker/web || {
|
||||
echo "Failed to build dockerfile"
|
||||
exit 1
|
||||
}
|
||||
|
||||
docker tag teaspeak/web:"$rolling_tag" teaspeak/web:"$git_rev" || {
|
||||
echo "Failed to tag docker release"
|
||||
exit 1
|
||||
}
|
||||
|
||||
docker login -u "$DOCKERHUB_USER" -p "$DOCKERHUB_TOKEN" || {
|
||||
echo "Failed to login to docker hub"
|
||||
exit 1
|
||||
}
|
||||
|
||||
docker push teaspeak/web || {
|
||||
echo "Failed to push new teaspeak/web tags"
|
||||
exit 1
|
||||
}
|
||||
docker logout # &> /dev/null
|
||||
|
||||
exit 0
|
|
@ -1,92 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
cd "$(dirname "$0")/../../" || {
|
||||
echo "Failed to enter base dir"
|
||||
exit 1
|
||||
}
|
||||
source ./scripts/travis/properties.sh
|
||||
source ./scripts/helper.sh
|
||||
|
||||
if [[ -z "${GIT_AUTHTOKEN}" ]]; then
|
||||
echo "GIT_AUTHTOKEN isn't set. Don't deploying build!"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
git_release_executable="/tmp/git-release"
|
||||
install_git_release() {
|
||||
if [[ -x "${git_release_executable}" ]]; then
|
||||
# File already available. No need to install it.
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [[ ! -f ${git_release_executable} ]]; then
|
||||
echo "Downloading github-release-linux (1.2.4)"
|
||||
|
||||
if [[ -f /tmp/git-release.gz ]]; then
|
||||
rm /tmp/git-release.gz
|
||||
fi
|
||||
wget https://github.com/tfausak/github-release/releases/download/1.2.4/github-release-linux.gz -O /tmp/git-release.gz -q
|
||||
[[ $? -eq 0 ]] || {
|
||||
echo "Failed to download github-release-linux"
|
||||
exit 1
|
||||
}
|
||||
|
||||
gunzip /tmp/git-release.gz
|
||||
_exit_code=$?
|
||||
[[ $_exit_code -eq 0 ]] || {
|
||||
echo "Failed to unzip github-release-linux"
|
||||
exit 1
|
||||
}
|
||||
chmod +x /tmp/git-release
|
||||
|
||||
echo "Download of github-release-linux (1.2.4) finished"
|
||||
else
|
||||
chmod +x ${git_release_executable}
|
||||
fi
|
||||
|
||||
if [[ ! -x ${git_release_executable} ]]; then
|
||||
echo "git-release isn't executable"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
install_git_release
|
||||
|
||||
git_versions_tag=$(git_version "short-tag")
|
||||
echo "Deploying $git_versions_tag ($(git_version "long-tag")) to GitHub."
|
||||
|
||||
echo "Generating release tag"
|
||||
${git_release_executable} release \
|
||||
--repo "TeaWeb" \
|
||||
--owner "TeaSpeak" \
|
||||
--token "${GIT_AUTHTOKEN}" \
|
||||
--title "Travis auto build $git_versions_tag" \
|
||||
--tag "$git_versions_tag" \
|
||||
--description "This is a auto build release from travis"
|
||||
|
||||
[[ $? -eq 0 ]] || {
|
||||
echo "Failed to generate git release"
|
||||
exit 1
|
||||
}
|
||||
|
||||
upload_package() {
|
||||
local package_file
|
||||
package_file=$(find_release_package "web" "$1")
|
||||
if [[ $? -eq 0 ]]; then
|
||||
echo "Uploading $1 package ($package_file)"
|
||||
${git_release_executable} upload \
|
||||
--repo "TeaWeb" \
|
||||
--owner "TeaSpeak" \
|
||||
--token "${GIT_AUTHTOKEN}" \
|
||||
--tag "$git_versions_tag" \
|
||||
--file "$package_file" \
|
||||
--name "$(basename "$package_file")"
|
||||
|
||||
echo "Successfully uploaded $1 package"
|
||||
else
|
||||
echo "Skipping $1 package upload: $package_file"
|
||||
fi
|
||||
}
|
||||
|
||||
upload_package "development"
|
||||
upload_package "release"
|
||||
exit 0
|
|
@ -1,51 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
if [[ -z "$1" ]]; then
|
||||
echo "Missing deploy channel"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cd "$(dirname "$0")/../../" || {
|
||||
echo "Failed to enter base dir"
|
||||
exit 1
|
||||
}
|
||||
source ./scripts/travis/properties.sh
|
||||
source ./scripts/helper.sh
|
||||
|
||||
if [[ -z "${SSH_KEY}" ]]; then
|
||||
echo "Missing environment variable SSH_KEY. Please set it before using this script!"
|
||||
exit 1
|
||||
fi
|
||||
echo "${SSH_KEY}" | base64 --decode > /tmp/sftp_key
|
||||
chmod 600 /tmp/sftp_key
|
||||
|
||||
[[ $? -ne 0 ]] && {
|
||||
echo "Failed to write SSH key"
|
||||
exit 1
|
||||
}
|
||||
|
||||
|
||||
package_file=$(find_release_package "web" "release")
|
||||
if [[ $? -ne 0 ]]; then
|
||||
echo "$package_file"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
upload_name=$(basename "$package_file")
|
||||
ssh -oStrictHostKeyChecking=no -oIdentitiesOnly=yes -i /tmp/sftp_key TeaSpeak-Travis-Web@web.teaspeak.dev rm "tmp-upload/*.zip" # Cleanup the old files
|
||||
_exit_code=$?
|
||||
[[ $_exit_code -ne 0 ]] && {
|
||||
echo "Failed to delete the old .zip files ($_exit_code)"
|
||||
}
|
||||
|
||||
sftp -oStrictHostKeyChecking=no -oIdentitiesOnly=yes -i /tmp/sftp_key TeaSpeak-Travis-Web@web.teaspeak.dev << EOF
|
||||
put $package_file tmp-upload/$upload_name
|
||||
EOF
|
||||
_exit_code=$?
|
||||
[[ $_exit_code -ne 0 ]] && {
|
||||
echo "Failed to upload the .zip file ($_exit_code)"
|
||||
exit 1
|
||||
}
|
||||
|
||||
ssh -oStrictHostKeyChecking=no -oIdentitiesOnly=yes -i /tmp/sftp_key TeaSpeak-Travis-Web@web.teaspeak.dev "./unpack.sh $1 tmp-upload/$upload_name"
|
||||
exit $?
|
|
@ -1,4 +0,0 @@
|
|||
#!/usr/bin/env sh
|
||||
|
||||
LOG_FILE="auto-build/logs/build.log"
|
||||
PACKAGES_DIRECTORY="auto-build/packages/"
|
Binary file not shown.
After Width: | Height: | Size: 17 KiB |
|
@ -1,14 +1,14 @@
|
|||
import * as loader from "tc-loader";
|
||||
import {Stage} from "tc-loader";
|
||||
import {ignorePromise, WritableKeys} from "tc-shared/proto";
|
||||
import {LogCategory, logDebug, logError, logInfo, logTrace, logWarn} from "tc-shared/log";
|
||||
import {guid} from "tc-shared/crypto/uid";
|
||||
import {Registry} from "tc-events";
|
||||
import {server_connections} from "tc-shared/ConnectionManager";
|
||||
import {defaultConnectProfile, findConnectProfile} from "tc-shared/profiles/ConnectionProfile";
|
||||
import {ConnectionState} from "tc-shared/ConnectionHandler";
|
||||
import { Stage } from "tc-loader";
|
||||
import { ignorePromise, WritableKeys } from "tc-shared/proto";
|
||||
import { LogCategory, logDebug, logError, logInfo, logTrace, logWarn } from "tc-shared/log";
|
||||
import { guid } from "tc-shared/crypto/uid";
|
||||
import { Registry } from "tc-events";
|
||||
import { server_connections } from "tc-shared/ConnectionManager";
|
||||
import { defaultConnectProfile, findConnectProfile } from "tc-shared/profiles/ConnectionProfile";
|
||||
import { ConnectionState } from "tc-shared/ConnectionHandler";
|
||||
import * as _ from "lodash";
|
||||
import {getStorageAdapter} from "tc-shared/StorageAdapter";
|
||||
import { getStorageAdapter } from "tc-shared/StorageAdapter";
|
||||
|
||||
type BookmarkBase = {
|
||||
readonly uniqueId: string,
|
||||
|
@ -64,9 +64,9 @@ export class BookmarkManager {
|
|||
|
||||
async loadBookmarks() {
|
||||
const bookmarksJson = await getStorageAdapter().get(kStorageKey);
|
||||
if(typeof bookmarksJson !== "string") {
|
||||
if (typeof bookmarksJson !== "string") {
|
||||
const oldBookmarksJson = await getStorageAdapter().get("bookmarks");
|
||||
if(typeof oldBookmarksJson === "string") {
|
||||
if (typeof oldBookmarksJson === "string") {
|
||||
logDebug(LogCategory.BOOKMARKS, tr("Found no new bookmarks but found old bookmarks. Trying to import."));
|
||||
try {
|
||||
this.importOldBookmarks(oldBookmarksJson);
|
||||
|
@ -83,7 +83,7 @@ export class BookmarkManager {
|
|||
} else {
|
||||
try {
|
||||
const storageData = JSON.parse(bookmarksJson);
|
||||
if(storageData.version !== 2) {
|
||||
if (storageData.version !== 2) {
|
||||
throw tr("bookmark storage has an invalid version");
|
||||
}
|
||||
|
||||
|
@ -99,7 +99,7 @@ export class BookmarkManager {
|
|||
}
|
||||
}
|
||||
|
||||
if(!this.defaultBookmarkCreated && this.registeredBookmarks.length === 0) {
|
||||
if (!this.defaultBookmarkCreated && this.registeredBookmarks.length === 0) {
|
||||
this.defaultBookmarkCreated = true;
|
||||
|
||||
logDebug(LogCategory.BOOKMARKS, tr("No bookmarks found. Registering default bookmark."));
|
||||
|
@ -107,12 +107,12 @@ export class BookmarkManager {
|
|||
connectOnStartup: false,
|
||||
connectProfile: "default",
|
||||
|
||||
displayName: "Official TeaSpeak - Test server",
|
||||
displayName: "Our LanPart<",
|
||||
|
||||
parentEntry: undefined,
|
||||
previousEntry: undefined,
|
||||
|
||||
serverAddress: "ts.teaspeak.de",
|
||||
serverAddress: "tea.lp.kle.li",
|
||||
serverPasswordHash: undefined,
|
||||
|
||||
defaultChannel: undefined,
|
||||
|
@ -123,21 +123,21 @@ export class BookmarkManager {
|
|||
|
||||
private importOldBookmarks(jsonData: string) {
|
||||
const data = JSON.parse(jsonData);
|
||||
if(typeof data?.root_bookmark !== "object") {
|
||||
if (typeof data?.root_bookmark !== "object") {
|
||||
throw tr("missing root bookmark");
|
||||
}
|
||||
|
||||
if(!Array.isArray(data?.root_bookmark?.content)) {
|
||||
if (!Array.isArray(data?.root_bookmark?.content)) {
|
||||
throw tr("Missing root bookmarks content");
|
||||
}
|
||||
|
||||
const registerBookmarks = (parentEntry: string, previousEntry: string, entry: any) : string | undefined => {
|
||||
if(typeof entry.display_name !== "string") {
|
||||
const registerBookmarks = (parentEntry: string, previousEntry: string, entry: any): string | undefined => {
|
||||
if (typeof entry.display_name !== "string") {
|
||||
logWarn(LogCategory.BOOKMARKS, tr("Missing display_name in old bookmark entry. Skipping entry."));
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if("content" in entry) {
|
||||
if ("content" in entry) {
|
||||
/* it was a directory */
|
||||
const directory = this.createDirectory({
|
||||
previousEntry,
|
||||
|
@ -152,23 +152,23 @@ export class BookmarkManager {
|
|||
});
|
||||
} else {
|
||||
/* it was a normal entry */
|
||||
if(typeof entry.connect_profile !== "string") {
|
||||
if (typeof entry.connect_profile !== "string") {
|
||||
logWarn(LogCategory.BOOKMARKS, tr("Missing connect_profile in old bookmark entry. Skipping entry."));
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if(typeof entry.server_properties?.server_address !== "string") {
|
||||
if (typeof entry.server_properties?.server_address !== "string") {
|
||||
logWarn(LogCategory.BOOKMARKS, tr("Missing server_address in old bookmark entry. Skipping entry."));
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if(typeof entry.server_properties?.server_port !== "number") {
|
||||
if (typeof entry.server_properties?.server_port !== "number") {
|
||||
logWarn(LogCategory.BOOKMARKS, tr("Missing server_port in old bookmark entry. Skipping entry."));
|
||||
return undefined;
|
||||
}
|
||||
|
||||
let serverAddress;
|
||||
if(entry.server_properties.server_address.indexOf(":") !== -1) {
|
||||
if (entry.server_properties.server_address.indexOf(":") !== -1) {
|
||||
serverAddress = `[${entry.server_properties.server_address}]`;
|
||||
} else {
|
||||
serverAddress = entry.server_properties.server_address;
|
||||
|
@ -209,23 +209,23 @@ export class BookmarkManager {
|
|||
}));
|
||||
}
|
||||
|
||||
getRegisteredBookmarks() : BookmarkEntry[] {
|
||||
getRegisteredBookmarks(): BookmarkEntry[] {
|
||||
return this.registeredBookmarks;
|
||||
}
|
||||
|
||||
getOrderedRegisteredBookmarks() : OrderedBookmarkEntry[] {
|
||||
getOrderedRegisteredBookmarks(): OrderedBookmarkEntry[] {
|
||||
const unorderedBookmarks = this.registeredBookmarks.slice(0);
|
||||
const orderedBookmarks: OrderedBookmarkEntry[] = [];
|
||||
|
||||
const orderTreeLayer = (entries: BookmarkEntry[]): BookmarkEntry[] => {
|
||||
if(entries.length === 0) {
|
||||
if (entries.length === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const result = [];
|
||||
while(entries.length > 0) {
|
||||
while (entries.length > 0) {
|
||||
let head = entries.find(entry => !entry.previousEntry) || entries[0];
|
||||
while(head) {
|
||||
while (head) {
|
||||
result.push(head);
|
||||
entries.remove(head);
|
||||
head = entries.find(entry => entry.previousEntry === head.uniqueId);
|
||||
|
@ -240,7 +240,7 @@ export class BookmarkManager {
|
|||
children.forEach(child => unorderedBookmarks.remove(child));
|
||||
|
||||
const childCount = children.length;
|
||||
for(const entry of orderTreeLayer(children)) {
|
||||
for (const entry of orderTreeLayer(children)) {
|
||||
let orderedEntry: OrderedBookmarkEntry = {
|
||||
entry: entry,
|
||||
depth: depth,
|
||||
|
@ -264,11 +264,11 @@ export class BookmarkManager {
|
|||
return orderedBookmarks;
|
||||
}
|
||||
|
||||
findBookmark(uniqueId: string) : BookmarkEntry | undefined {
|
||||
findBookmark(uniqueId: string): BookmarkEntry | undefined {
|
||||
return this.registeredBookmarks.find(entry => entry.uniqueId === uniqueId);
|
||||
}
|
||||
|
||||
createBookmark(properties: Pick<BookmarkInfo, WritableKeys<BookmarkInfo>>) : BookmarkInfo {
|
||||
createBookmark(properties: Pick<BookmarkInfo, WritableKeys<BookmarkInfo>>): BookmarkInfo {
|
||||
this.validateHangInPoint(properties);
|
||||
const bookmark = Object.assign(properties, {
|
||||
uniqueId: guid(),
|
||||
|
@ -284,7 +284,7 @@ export class BookmarkManager {
|
|||
this.doEditBookmark(uniqueId, newValues);
|
||||
}
|
||||
|
||||
createDirectory(properties: Pick<BookmarkInfo, WritableKeys<BookmarkDirectory>>) : BookmarkDirectory {
|
||||
createDirectory(properties: Pick<BookmarkInfo, WritableKeys<BookmarkDirectory>>): BookmarkDirectory {
|
||||
this.validateHangInPoint(properties);
|
||||
const bookmark = Object.assign(properties, {
|
||||
uniqueId: guid(),
|
||||
|
@ -300,20 +300,20 @@ export class BookmarkManager {
|
|||
this.doEditBookmark(uniqueId, newValues);
|
||||
}
|
||||
|
||||
directoryContents(uniqueId: string) : BookmarkEntry[] {
|
||||
directoryContents(uniqueId: string): BookmarkEntry[] {
|
||||
return this.registeredBookmarks.filter(bookmark => bookmark.parentEntry === uniqueId);
|
||||
}
|
||||
|
||||
deleteEntry(uniqueId: string) {
|
||||
const index = this.registeredBookmarks.findIndex(entry => entry.uniqueId === uniqueId);
|
||||
if(index === -1) {
|
||||
if (index === -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
const [ entry ] = this.registeredBookmarks.splice(index, 1);
|
||||
const children = [], pendingChildren = [ entry ];
|
||||
const [entry] = this.registeredBookmarks.splice(index, 1);
|
||||
const children = [], pendingChildren = [entry];
|
||||
|
||||
while(pendingChildren[0]) {
|
||||
while (pendingChildren[0]) {
|
||||
const child = pendingChildren.pop_front();
|
||||
children.push(child);
|
||||
|
||||
|
@ -329,12 +329,12 @@ export class BookmarkManager {
|
|||
|
||||
executeConnect(uniqueId: string, newTab: boolean) {
|
||||
const bookmark = this.findBookmark(uniqueId);
|
||||
if(!bookmark || bookmark.type !== "entry") {
|
||||
if (!bookmark || bookmark.type !== "entry") {
|
||||
return;
|
||||
}
|
||||
|
||||
const connection = newTab ? server_connections.spawnConnectionHandler() : server_connections.getActiveConnectionHandler();
|
||||
if(!connection) {
|
||||
if (!connection) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -360,12 +360,12 @@ export class BookmarkManager {
|
|||
|
||||
executeAutoConnect() {
|
||||
let newTab = server_connections.getActiveConnectionHandler().connection_state !== ConnectionState.UNCONNECTED;
|
||||
for(const entry of this.getOrderedRegisteredBookmarks()) {
|
||||
if(entry.entry.type !== "entry") {
|
||||
for (const entry of this.getOrderedRegisteredBookmarks()) {
|
||||
if (entry.entry.type !== "entry") {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!entry.entry.connectOnStartup) {
|
||||
if (!entry.entry.connectOnStartup) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -374,14 +374,14 @@ export class BookmarkManager {
|
|||
}
|
||||
}
|
||||
|
||||
exportBookmarks() : string {
|
||||
exportBookmarks(): string {
|
||||
return JSON.stringify({
|
||||
version: 1,
|
||||
bookmarks: this.registeredBookmarks
|
||||
});
|
||||
}
|
||||
|
||||
importBookmarks(filePayload: string) : number {
|
||||
importBookmarks(filePayload: string): number {
|
||||
let data;
|
||||
try {
|
||||
data = JSON.parse(filePayload)
|
||||
|
@ -389,26 +389,26 @@ export class BookmarkManager {
|
|||
throw tr("failed to parse bookmarks");
|
||||
}
|
||||
|
||||
if(data?.version !== 1) {
|
||||
if (data?.version !== 1) {
|
||||
throw tr("supplied data contains invalid version");
|
||||
}
|
||||
|
||||
const newBookmarks = data.bookmarks as BookmarkEntry[];
|
||||
if(!Array.isArray(newBookmarks)) {
|
||||
if (!Array.isArray(newBookmarks)) {
|
||||
throw tr("missing bookmarks");
|
||||
}
|
||||
|
||||
/* TODO: Validate integrity? */
|
||||
for(const knownBookmark of this.registeredBookmarks) {
|
||||
for (const knownBookmark of this.registeredBookmarks) {
|
||||
const index = newBookmarks.findIndex(entry => entry.uniqueId === knownBookmark.uniqueId);
|
||||
if(index === -1) {
|
||||
if (index === -1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
newBookmarks.splice(index, 1);
|
||||
}
|
||||
|
||||
if(newBookmarks.length === 0) {
|
||||
if (newBookmarks.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -420,26 +420,26 @@ export class BookmarkManager {
|
|||
|
||||
private doEditBookmark(uniqueId: string, newValues: any) {
|
||||
const bookmarkInfo = this.findBookmark(uniqueId);
|
||||
if(!bookmarkInfo) {
|
||||
if (!bookmarkInfo) {
|
||||
return;
|
||||
}
|
||||
|
||||
const originalProperties = _.cloneDeep(bookmarkInfo);
|
||||
for(const key of Object.keys(newValues)) {
|
||||
for (const key of Object.keys(newValues)) {
|
||||
bookmarkInfo[key] = newValues[key];
|
||||
}
|
||||
this.validateHangInPoint(bookmarkInfo);
|
||||
|
||||
const editedKeys = [];
|
||||
for(const key of Object.keys(newValues)) {
|
||||
if(_.isEqual(bookmarkInfo[key], originalProperties[key])) {
|
||||
for (const key of Object.keys(newValues)) {
|
||||
if (_.isEqual(bookmarkInfo[key], originalProperties[key])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
editedKeys.push(key);
|
||||
}
|
||||
|
||||
if(editedKeys.length === 0) {
|
||||
if (editedKeys.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -448,12 +448,12 @@ export class BookmarkManager {
|
|||
}
|
||||
|
||||
private validateHangInPoint(entry: Partial<BookmarkBase>) {
|
||||
if(entry.previousEntry) {
|
||||
if (entry.previousEntry) {
|
||||
const previousEntry = this.findBookmark(entry.previousEntry);
|
||||
if(!previousEntry) {
|
||||
if (!previousEntry) {
|
||||
logError(LogCategory.BOOKMARKS, tr("New bookmark previous entry does not exists. Clearing it."));
|
||||
entry.previousEntry = undefined;
|
||||
} else if(previousEntry.parentEntry !== entry.parentEntry) {
|
||||
} else if (previousEntry.parentEntry !== entry.parentEntry) {
|
||||
logWarn(LogCategory.BOOKMARKS, tr("Previous entries parent does not match our entries parent. Updating our parent from %s to %s"), entry.parentEntry, previousEntry.parentEntry);
|
||||
entry.parentEntry = previousEntry.parentEntry;
|
||||
}
|
||||
|
@ -461,13 +461,13 @@ export class BookmarkManager {
|
|||
|
||||
const openList = this.registeredBookmarks.filter(e1 => e1.parentEntry === entry.parentEntry);
|
||||
let currentEntry = entry;
|
||||
while(true) {
|
||||
if(!currentEntry.previousEntry) {
|
||||
while (true) {
|
||||
if (!currentEntry.previousEntry) {
|
||||
break;
|
||||
}
|
||||
|
||||
const previousEntry = openList.find(entry => entry.uniqueId === currentEntry.previousEntry);
|
||||
if(!previousEntry) {
|
||||
if (!previousEntry) {
|
||||
logError(LogCategory.BOOKMARKS, tr("Found circular dependency within the previous entry or one of the previous entries does not exists. Clearing out previous entry."));
|
||||
entry.previousEntry = undefined;
|
||||
break;
|
||||
|
@ -478,22 +478,22 @@ export class BookmarkManager {
|
|||
}
|
||||
}
|
||||
|
||||
if(entry.parentEntry) {
|
||||
if (entry.parentEntry) {
|
||||
const parentEntry = this.findBookmark(entry.parentEntry);
|
||||
if(!parentEntry) {
|
||||
if (!parentEntry) {
|
||||
logError(LogCategory.BOOKMARKS, tr("Missing parent entry %s. Clearing it."), entry.parentEntry);
|
||||
entry.parentEntry = undefined;
|
||||
}
|
||||
|
||||
const openList = this.registeredBookmarks.slice();
|
||||
let currentEntry = entry;
|
||||
while(true) {
|
||||
if(!currentEntry.parentEntry) {
|
||||
while (true) {
|
||||
if (!currentEntry.parentEntry) {
|
||||
break;
|
||||
}
|
||||
|
||||
const parentEntry = openList.find(entry => entry.uniqueId === currentEntry.parentEntry);
|
||||
if(!parentEntry) {
|
||||
if (!parentEntry) {
|
||||
logError(LogCategory.BOOKMARKS, tr("Found circular dependency within a parent or one of the parents does not exists. Clearing out parent."));
|
||||
entry.parentEntry = undefined;
|
||||
break;
|
||||
|
@ -504,9 +504,9 @@ export class BookmarkManager {
|
|||
}
|
||||
}
|
||||
|
||||
if(entry.previousEntry) {
|
||||
if (entry.previousEntry) {
|
||||
this.registeredBookmarks.forEach(bookmark => {
|
||||
if(bookmark.previousEntry === entry.previousEntry && bookmark !== entry) {
|
||||
if (bookmark.previousEntry === entry.previousEntry && bookmark !== entry) {
|
||||
bookmark.previousEntry = bookmark.uniqueId;
|
||||
}
|
||||
});
|
||||
|
|
|
@ -40,15 +40,15 @@ export interface KeyBoardBackend {
|
|||
registerListener(listener: (event: KeyEvent) => void);
|
||||
unregisterListener(listener: (event: KeyEvent) => void);
|
||||
|
||||
registerHook(hook: KeyHook) : () => void;
|
||||
registerHook(hook: KeyHook): () => void;
|
||||
unregisterHook(hook: KeyHook);
|
||||
|
||||
isKeyPressed(key: string | SpecialKey) : boolean;
|
||||
isKeyPressed(key: string | SpecialKey): boolean;
|
||||
}
|
||||
|
||||
export class AbstractKeyBoard implements KeyBoardBackend {
|
||||
protected readonly registeredListener: ((event: KeyEvent) => void)[];
|
||||
protected readonly activeSpecialKeys: { [key: number] : boolean };
|
||||
protected readonly activeSpecialKeys: { [key: number]: boolean };
|
||||
protected readonly activeKeys;
|
||||
|
||||
protected registeredKeyHooks: RegisteredKeyHook[] = [];
|
||||
|
@ -59,10 +59,10 @@ export class AbstractKeyBoard implements KeyBoardBackend {
|
|||
this.registeredListener = [];
|
||||
}
|
||||
|
||||
protected destroy() {}
|
||||
protected destroy() { }
|
||||
|
||||
isKeyPressed(key: string | SpecialKey): boolean {
|
||||
if(typeof(key) === 'string') {
|
||||
if (typeof (key) === 'string') {
|
||||
return typeof this.activeKeys[key] !== "undefined";
|
||||
}
|
||||
|
||||
|
@ -76,7 +76,7 @@ export class AbstractKeyBoard implements KeyBoardBackend {
|
|||
};
|
||||
|
||||
this.registeredKeyHooks.push(registeredHook);
|
||||
if(this.shouldHookBeActive(registeredHook)) {
|
||||
if (this.shouldHookBeActive(registeredHook)) {
|
||||
registeredHook.triggered = true;
|
||||
registeredHook.callbackPress();
|
||||
}
|
||||
|
@ -85,11 +85,11 @@ export class AbstractKeyBoard implements KeyBoardBackend {
|
|||
}
|
||||
|
||||
unregisterHook(hook: KeyHook) {
|
||||
if(!("triggered" in hook)) {
|
||||
if (!("triggered" in hook)) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.registeredKeyHooks.remove(hook);
|
||||
this.registeredKeyHooks.remove(hook as RegisteredKeyHook);
|
||||
}
|
||||
|
||||
registerListener(listener: (event: KeyEvent) => void) {
|
||||
|
@ -101,19 +101,19 @@ export class AbstractKeyBoard implements KeyBoardBackend {
|
|||
}
|
||||
|
||||
private shouldHookBeActive(hook: KeyHook) {
|
||||
if(typeof hook.keyAlt !== "undefined" && hook.keyAlt != this.activeSpecialKeys[SpecialKey.ALT]) {
|
||||
if (typeof hook.keyAlt !== "undefined" && hook.keyAlt != this.activeSpecialKeys[SpecialKey.ALT]) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(typeof hook.keyCtrl !== "undefined" && hook.keyCtrl != this.activeSpecialKeys[SpecialKey.CTRL]) {
|
||||
if (typeof hook.keyCtrl !== "undefined" && hook.keyCtrl != this.activeSpecialKeys[SpecialKey.CTRL]) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(typeof hook.keyShift !== "undefined" && hook.keyShift != this.activeSpecialKeys[SpecialKey.SHIFT]) {
|
||||
if (typeof hook.keyShift !== "undefined" && hook.keyShift != this.activeSpecialKeys[SpecialKey.SHIFT]) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(typeof hook.keyWindows !== "undefined" && hook.keyWindows != this.activeSpecialKeys[SpecialKey.WINDOWS]) {
|
||||
if (typeof hook.keyWindows !== "undefined" && hook.keyWindows != this.activeSpecialKeys[SpecialKey.WINDOWS]) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -122,11 +122,11 @@ export class AbstractKeyBoard implements KeyBoardBackend {
|
|||
|
||||
protected fireKeyEvent(event: KeyEvent) {
|
||||
//console.debug("Trigger key event %o", key_event);
|
||||
for(const listener of this.registeredListener) {
|
||||
for (const listener of this.registeredListener) {
|
||||
listener(event);
|
||||
}
|
||||
|
||||
if(event.type == EventType.KEY_TYPED) {
|
||||
if (event.type == EventType.KEY_TYPED) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -134,26 +134,26 @@ export class AbstractKeyBoard implements KeyBoardBackend {
|
|||
this.activeSpecialKeys[SpecialKey.CTRL] = event.keyCtrl;
|
||||
this.activeSpecialKeys[SpecialKey.SHIFT] = event.keyShift;
|
||||
this.activeSpecialKeys[SpecialKey.WINDOWS] = event.keyWindows;
|
||||
if(event.type == EventType.KEY_PRESS) {
|
||||
if (event.type == EventType.KEY_PRESS) {
|
||||
this.activeKeys[event.keyCode] = event;
|
||||
} else {
|
||||
delete this.activeKeys[event.keyCode];
|
||||
}
|
||||
|
||||
|
||||
for(const hook of this.registeredKeyHooks) {
|
||||
for (const hook of this.registeredKeyHooks) {
|
||||
const hookActive = this.shouldHookBeActive(hook);
|
||||
if(hookActive === hook.triggered) {
|
||||
if (hookActive === hook.triggered) {
|
||||
continue;
|
||||
}
|
||||
|
||||
hook.triggered = hookActive;
|
||||
if(hookActive) {
|
||||
if(hook.callbackPress) {
|
||||
if (hookActive) {
|
||||
if (hook.callbackPress) {
|
||||
hook.callbackPress();
|
||||
}
|
||||
} else {
|
||||
if(hook.callbackRelease) {
|
||||
if (hook.callbackRelease) {
|
||||
hook.callbackRelease();
|
||||
}
|
||||
}
|
||||
|
@ -166,13 +166,13 @@ export class AbstractKeyBoard implements KeyBoardBackend {
|
|||
this.activeSpecialKeys[SpecialKey.SHIFT] = false;
|
||||
this.activeSpecialKeys[SpecialKey.WINDOWS] = false;
|
||||
|
||||
for(const code of Object.keys(this.activeKeys)) {
|
||||
for (const code of Object.keys(this.activeKeys)) {
|
||||
delete this.activeKeys[code];
|
||||
}
|
||||
|
||||
for(const hook of this.registeredKeyHooks) {
|
||||
if(hook.triggered) {
|
||||
if(hook.callbackRelease) {
|
||||
for (const hook of this.registeredKeyHooks) {
|
||||
if (hook.triggered) {
|
||||
if (hook.callbackRelease) {
|
||||
hook.callbackRelease();
|
||||
}
|
||||
|
||||
|
@ -183,7 +183,7 @@ export class AbstractKeyBoard implements KeyBoardBackend {
|
|||
}
|
||||
|
||||
let keyBoardBackend: KeyBoardBackend;
|
||||
export function getKeyBoard() : KeyBoardBackend {
|
||||
export function getKeyBoard(): KeyBoardBackend {
|
||||
return keyBoardBackend;
|
||||
}
|
||||
|
||||
|
@ -193,29 +193,29 @@ export function setKeyBoardBackend(newBackend: KeyBoardBackend) {
|
|||
|
||||
export function getKeyDescription(key: KeyDescriptor) {
|
||||
let result = "";
|
||||
if(key.keyShift) {
|
||||
if (key.keyShift) {
|
||||
result += " + " + tr("Shift");
|
||||
}
|
||||
|
||||
if(key.keyAlt) {
|
||||
if (key.keyAlt) {
|
||||
result += " + " + tr("Alt");
|
||||
}
|
||||
|
||||
if(key.keyCtrl) {
|
||||
if (key.keyCtrl) {
|
||||
result += " + " + tr("CTRL");
|
||||
}
|
||||
|
||||
if(key.keyWindows) {
|
||||
if (key.keyWindows) {
|
||||
result += " + " + tr("Win");
|
||||
}
|
||||
|
||||
if(key.keyCode) {
|
||||
if (key.keyCode) {
|
||||
let keyName;
|
||||
if(key.keyCode.startsWith("Key")) {
|
||||
if (key.keyCode.startsWith("Key")) {
|
||||
keyName = key.keyCode.substr(3);
|
||||
} else if(key.keyCode.startsWith("Digit")) {
|
||||
} else if (key.keyCode.startsWith("Digit")) {
|
||||
keyName = key.keyCode.substr(5);
|
||||
} else if(key.keyCode.startsWith("Numpad")) {
|
||||
} else if (key.keyCode.startsWith("Numpad")) {
|
||||
keyName = "Numpad " + key.keyCode.substr(6);
|
||||
} else {
|
||||
keyName = key.keyCode;
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,7 +1,7 @@
|
|||
import {Registry} from "tc-shared/events";
|
||||
import {LogCategory, logTrace, logWarn} from "tc-shared/log";
|
||||
import {tr} from "tc-shared/i18n/localize";
|
||||
import {getAudioBackend} from "tc-shared/audio/Player";
|
||||
import { Registry } from "tc-shared/events";
|
||||
import { LogCategory, logTrace, logWarn } from "tc-shared/log";
|
||||
import { tr } from "tc-shared/i18n/localize";
|
||||
import { getAudioBackend } from "tc-shared/audio/Player";
|
||||
|
||||
export interface TrackClientInfo {
|
||||
media?: number,
|
||||
|
@ -56,34 +56,34 @@ export class RemoteRTPTrack {
|
|||
this.events.destroy();
|
||||
}
|
||||
|
||||
getEvents() : Registry<RemoteRTPTrackEvents> {
|
||||
getEvents(): Registry<RemoteRTPTrackEvents> {
|
||||
return this.events;
|
||||
}
|
||||
|
||||
getState() : RemoteRTPTrackState {
|
||||
getState(): RemoteRTPTrackState {
|
||||
return this.currentState;
|
||||
}
|
||||
|
||||
getSsrc() : number {
|
||||
getSsrc(): number {
|
||||
return this.ssrc >>> 0;
|
||||
}
|
||||
|
||||
getTrack() : MediaStreamTrack {
|
||||
getTrack(): MediaStreamTrack {
|
||||
return this.transceiver.receiver.track;
|
||||
}
|
||||
|
||||
getTransceiver() : RTCRtpTransceiver {
|
||||
getTransceiver(): RTCRtpTransceiver {
|
||||
return this.transceiver;
|
||||
}
|
||||
|
||||
getCurrentAssignment() : TrackClientInfo | undefined {
|
||||
getCurrentAssignment(): TrackClientInfo | undefined {
|
||||
return this.currentAssignment;
|
||||
}
|
||||
|
||||
protected setState(state: RemoteRTPTrackState) {
|
||||
if(this.currentState === state) {
|
||||
if (this.currentState === state) {
|
||||
return;
|
||||
} else if(this.currentState === RemoteRTPTrackState.Destroyed) {
|
||||
} else if (this.currentState === RemoteRTPTrackState.Destroyed) {
|
||||
logWarn(LogCategory.WEBRTC, tr("Tried to change the track state for track %d from destroyed to %s."), this.getSsrc(), RemoteRTPTrackState[state]);
|
||||
return;
|
||||
}
|
||||
|
@ -107,10 +107,9 @@ export class RemoteRTPVideoTrack extends RemoteRTPTrack {
|
|||
track.onended = () => logTrace(LogCategory.VIDEO, "Track %d ended", ssrc);
|
||||
track.onmute = () => logTrace(LogCategory.VIDEO, "Track %d muted", ssrc);
|
||||
track.onunmute = () => logTrace(LogCategory.VIDEO, "Track %d unmuted", ssrc);
|
||||
track.onisolationchange = () => logTrace(LogCategory.VIDEO, "Track %d isolation changed", ssrc);
|
||||
}
|
||||
|
||||
getMediaStream() : MediaStream {
|
||||
getMediaStream(): MediaStream {
|
||||
return this.mediaStream;
|
||||
}
|
||||
|
||||
|
@ -170,7 +169,7 @@ export class RemoteRTPAudioTrack extends RemoteRTPTrack {
|
|||
*/
|
||||
|
||||
getAudioBackend().executeWhenInitialized(() => {
|
||||
if(!this.mediaStream) {
|
||||
if (!this.mediaStream) {
|
||||
/* we've already been destroyed */
|
||||
return;
|
||||
}
|
||||
|
@ -200,7 +199,7 @@ export class RemoteRTPAudioTrack extends RemoteRTPTrack {
|
|||
this.setState(RemoteRTPTrackState.Destroyed);
|
||||
}
|
||||
|
||||
getGain() : GainNode | undefined {
|
||||
getGain(): GainNode | undefined {
|
||||
return this.gainNode;
|
||||
}
|
||||
|
||||
|
@ -213,13 +212,13 @@ export class RemoteRTPAudioTrack extends RemoteRTPTrack {
|
|||
* Mutes this track until the next setGain(..) call or a new sequence begins (state update)
|
||||
*/
|
||||
abortCurrentReplay() {
|
||||
if(this.gainNode) {
|
||||
if (this.gainNode) {
|
||||
this.gainNode.gain.value = 0;
|
||||
}
|
||||
}
|
||||
|
||||
protected updateGainNode() {
|
||||
if(!this.gainNode) {
|
||||
if (!this.gainNode) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
/* Note: This will be included into the controller and renderer process */
|
||||
import {LogCategory, logError, logWarn} from "tc-shared/log";
|
||||
import { LogCategory, logError, logWarn } from "tc-shared/log";
|
||||
import * as loader from "tc-loader";
|
||||
import {Stage} from "tc-loader";
|
||||
import { Stage } from "tc-loader";
|
||||
import * as crypto from "crypto-js";
|
||||
import {tra} from "tc-shared/i18n/localize";
|
||||
import { tra } from "tc-shared/i18n/localize";
|
||||
|
||||
export type LocalAvatarInfo = {
|
||||
fileName: string,
|
||||
|
@ -43,12 +43,12 @@ export type OwnAvatarMode = "uploading" | "server";
|
|||
export class OwnAvatarStorage {
|
||||
private openedCache: Cache | undefined;
|
||||
|
||||
private static generateRequestUrl(serverUniqueId: string, mode: OwnAvatarMode) : string {
|
||||
private static generateRequestUrl(serverUniqueId: string, mode: OwnAvatarMode): string {
|
||||
return "https://_local_avatar/" + serverUniqueId + "/" + mode;
|
||||
}
|
||||
|
||||
async initialize() {
|
||||
if(!("caches" in window)) {
|
||||
if (!("caches" in window)) {
|
||||
/* Not available (may unsecure context?) */
|
||||
this.openedCache = undefined;
|
||||
return;
|
||||
|
@ -62,8 +62,8 @@ export class OwnAvatarStorage {
|
|||
}
|
||||
}
|
||||
|
||||
private async loadAvatarRequest(serverUniqueId: string, mode: OwnAvatarMode) : Promise<LocalAvatarLoadResult<Response>> {
|
||||
if(!this.openedCache) {
|
||||
private async loadAvatarRequest(serverUniqueId: string, mode: OwnAvatarMode): Promise<LocalAvatarLoadResult<Response>> {
|
||||
if (!this.openedCache) {
|
||||
return { status: "cache-unavailable" };
|
||||
}
|
||||
|
||||
|
@ -73,7 +73,7 @@ export class OwnAvatarStorage {
|
|||
ignoreSearch: true,
|
||||
});
|
||||
|
||||
if(!response) {
|
||||
if (!response) {
|
||||
return { status: "empty-result" };
|
||||
}
|
||||
|
||||
|
@ -84,9 +84,9 @@ export class OwnAvatarStorage {
|
|||
}
|
||||
}
|
||||
|
||||
async loadAvatarImage(serverUniqueId: string, mode: OwnAvatarMode) : Promise<LocalAvatarLoadResult<ArrayBuffer>> {
|
||||
async loadAvatarImage(serverUniqueId: string, mode: OwnAvatarMode): Promise<LocalAvatarLoadResult<ArrayBuffer>> {
|
||||
const loadResult = await this.loadAvatarRequest(serverUniqueId, mode);
|
||||
if(loadResult.status !== "success") {
|
||||
if (loadResult.status !== "success") {
|
||||
return loadResult;
|
||||
}
|
||||
|
||||
|
@ -98,9 +98,9 @@ export class OwnAvatarStorage {
|
|||
}
|
||||
}
|
||||
|
||||
async loadAvatar(serverUniqueId: string, mode: OwnAvatarMode, createResourceUrl: boolean) : Promise<LocalAvatarLoadResult<LocalAvatarInfo>> {
|
||||
async loadAvatar(serverUniqueId: string, mode: OwnAvatarMode, createResourceUrl: boolean): Promise<LocalAvatarLoadResult<LocalAvatarInfo>> {
|
||||
const loadResult = await this.loadAvatarRequest(serverUniqueId, mode);
|
||||
if(loadResult.status !== "success") {
|
||||
if (loadResult.status !== "success") {
|
||||
return loadResult;
|
||||
}
|
||||
|
||||
|
@ -112,28 +112,28 @@ export class OwnAvatarStorage {
|
|||
const avatarDateModified = parseInt(headers.get("X-File-Date-Modified"));
|
||||
const avatarDateUploaded = parseInt(headers.get("X-File-Uploaded"));
|
||||
|
||||
if(!avatarHash) {
|
||||
if (!avatarHash) {
|
||||
return { status: "error", reason: tr("missing response header file hash") };
|
||||
}
|
||||
|
||||
if(!avatarName) {
|
||||
if (!avatarName) {
|
||||
return { status: "error", reason: tr("missing response header file name") };
|
||||
}
|
||||
|
||||
if(isNaN(avatarSize)) {
|
||||
if (isNaN(avatarSize)) {
|
||||
return { status: "error", reason: tr("missing/invalid response header file size") };
|
||||
}
|
||||
|
||||
if(isNaN(avatarDateModified)) {
|
||||
if (isNaN(avatarDateModified)) {
|
||||
return { status: "error", reason: tr("missing/invalid response header file modify date") };
|
||||
}
|
||||
|
||||
if(isNaN(avatarDateUploaded)) {
|
||||
if (isNaN(avatarDateUploaded)) {
|
||||
return { status: "error", reason: tr("missing/invalid response header file upload date") };
|
||||
}
|
||||
|
||||
let resourceUrl;
|
||||
if(createResourceUrl) {
|
||||
if (createResourceUrl) {
|
||||
try {
|
||||
resourceUrl = URL.createObjectURL(await loadResult.result.blob());
|
||||
} catch (error) {
|
||||
|
@ -159,12 +159,12 @@ export class OwnAvatarStorage {
|
|||
};
|
||||
}
|
||||
|
||||
async updateAvatar(serverUniqueId: string, mode: OwnAvatarMode, target: File) : Promise<LocalAvatarUpdateResult> {
|
||||
if(!this.openedCache) {
|
||||
async updateAvatar(serverUniqueId: string, mode: OwnAvatarMode, target: File): Promise<LocalAvatarUpdateResult> {
|
||||
if (!this.openedCache) {
|
||||
return { status: "cache-unavailable" };
|
||||
}
|
||||
|
||||
if(target.size > kMaxAvatarSize) {
|
||||
if (target.size > kMaxAvatarSize) {
|
||||
return { status: "error", reason: tra("Image exceeds maximum software size of {} bytes", kMaxAvatarSize) };
|
||||
}
|
||||
|
||||
|
@ -173,7 +173,7 @@ export class OwnAvatarStorage {
|
|||
const hasher = crypto.algo.MD5.create();
|
||||
await target.stream().pipeTo(new WritableStream({
|
||||
write(data) {
|
||||
hasher.update(crypto.lib.WordArray.create(data));
|
||||
hasher.update(crypto.lib.WordArray.create(Array.from(data)));
|
||||
}
|
||||
}));
|
||||
|
||||
|
@ -203,7 +203,7 @@ export class OwnAvatarStorage {
|
|||
}
|
||||
|
||||
async removeAvatar(serverUniqueId: string, mode: OwnAvatarMode) {
|
||||
if(!this.openedCache) {
|
||||
if (!this.openedCache) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -219,13 +219,13 @@ export class OwnAvatarStorage {
|
|||
* @param serverUniqueId
|
||||
*/
|
||||
async avatarUploadSucceeded(serverUniqueId: string) {
|
||||
if(!this.openedCache) {
|
||||
if (!this.openedCache) {
|
||||
return;
|
||||
}
|
||||
|
||||
const request = await this.loadAvatarRequest(serverUniqueId, "uploading");
|
||||
if(request.status !== "success") {
|
||||
if(request.status !== "empty-result") {
|
||||
if (request.status !== "success") {
|
||||
if (request.status !== "empty-result") {
|
||||
logError(LogCategory.GENERAL, tr("Failed to save uploaded avatar. Request failed to load: %o"), request);
|
||||
}
|
||||
return;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import {InputStartError} from "tc-shared/voice/RecorderBase";
|
||||
import {LogCategory, logInfo, logWarn} from "tc-shared/log";
|
||||
import {tr} from "tc-shared/i18n/localize";
|
||||
import { InputStartError } from "tc-shared/voice/RecorderBase";
|
||||
import { LogCategory, logInfo, logWarn } from "tc-shared/log";
|
||||
import { tr } from "tc-shared/i18n/localize";
|
||||
|
||||
export type MediaStreamType = "audio" | "video";
|
||||
|
||||
|
@ -18,15 +18,15 @@ export interface MediaStreamEvents {
|
|||
export const mediaStreamEvents = new Registry<MediaStreamEvents>();
|
||||
*/
|
||||
|
||||
export async function requestMediaStreamWithConstraints(constraints: MediaTrackConstraints, type: MediaStreamType) : Promise<InputStartError | MediaStream> {
|
||||
export async function requestMediaStreamWithConstraints(constraints: MediaTrackConstraints, type: MediaStreamType): Promise<InputStartError | MediaStream> {
|
||||
const beginTimestamp = Date.now();
|
||||
try {
|
||||
logInfo(LogCategory.AUDIO, tr("Requesting a %s stream for device %s in group %s"), type, constraints.deviceId, constraints.groupId);
|
||||
return await navigator.mediaDevices.getUserMedia(type === "audio" ? { audio: constraints } : { video: constraints });
|
||||
} catch(error) {
|
||||
if('name' in error) {
|
||||
if(error.name === "NotAllowedError") {
|
||||
if(Date.now() - beginTimestamp < 250) {
|
||||
} catch (error) {
|
||||
if ('name' in error) {
|
||||
if (error.name === "NotAllowedError") {
|
||||
if (Date.now() - beginTimestamp < 250) {
|
||||
logWarn(LogCategory.AUDIO, tr("Media stream request failed (System denied). Browser message: %o"), error.message);
|
||||
return InputStartError.ESYSTEMDENIED;
|
||||
} else {
|
||||
|
@ -46,21 +46,21 @@ export async function requestMediaStreamWithConstraints(constraints: MediaTrackC
|
|||
|
||||
/* request permission for devices only one per time! */
|
||||
let currentMediaStreamRequest: Promise<MediaStream | InputStartError>;
|
||||
export async function requestMediaStream(deviceId: string | undefined, groupId: string | undefined, type: MediaStreamType) : Promise<MediaStream | InputStartError> {
|
||||
export async function requestMediaStream(deviceId: string | undefined, groupId: string | undefined, type: MediaStreamType): Promise<MediaStream | InputStartError> {
|
||||
/* wait for the current media stream requests to finish */
|
||||
while(currentMediaStreamRequest) {
|
||||
while (currentMediaStreamRequest) {
|
||||
try {
|
||||
await currentMediaStreamRequest;
|
||||
} catch(error) { }
|
||||
} catch (error) { }
|
||||
}
|
||||
|
||||
const constrains: MediaTrackConstraints = {};
|
||||
if(window.detectedBrowser?.name === "firefox") {
|
||||
if (window.detectedBrowser?.name === "firefox") {
|
||||
/*
|
||||
* Firefox only allows to open one mic/video as well deciding whats the input device it.
|
||||
* It does not respect the deviceId nor the groupId
|
||||
*/
|
||||
} else if(deviceId !== undefined) {
|
||||
} else if (deviceId !== undefined) {
|
||||
constrains.deviceId = deviceId;
|
||||
constrains.groupId = groupId;
|
||||
} else {
|
||||
|
@ -75,25 +75,28 @@ export async function requestMediaStream(deviceId: string | undefined, groupId:
|
|||
try {
|
||||
return await currentMediaStreamRequest;
|
||||
} finally {
|
||||
if(currentMediaStreamRequest === promise) {
|
||||
if (currentMediaStreamRequest === promise) {
|
||||
currentMediaStreamRequest = undefined;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function queryMediaPermissions(type: MediaStreamType, changeListener?: (value: PermissionState) => void) : Promise<PermissionState> {
|
||||
if('permissions' in navigator && 'query' in navigator.permissions) {
|
||||
export async function queryMediaPermissions(type: MediaStreamType, changeListener?: (value: PermissionState) => void): Promise<PermissionState> {
|
||||
try {
|
||||
// @ts-ignore needed, as firefox doesn't allow microphone or camera, caught using the catch below
|
||||
const result = await navigator.permissions.query({ name: type === "audio" ? "microphone" : "camera" });
|
||||
if(changeListener) {
|
||||
if (changeListener) {
|
||||
result.addEventListener("change", () => {
|
||||
changeListener(result.state);
|
||||
});
|
||||
}
|
||||
return result.state;
|
||||
} catch (error) {
|
||||
logWarn(LogCategory.GENERAL, tr("Failed to query for %s permissions: %s"), type, error);
|
||||
// Firefox doesn't support querying for the camera / microphone permission, so return undetermined status
|
||||
if (error instanceof TypeError) {
|
||||
return "prompt";
|
||||
}
|
||||
logWarn(LogCategory.GENERAL, tr("Failed to query for %s permissions: %s"), type, error);
|
||||
}
|
||||
return "prompt";
|
||||
}
|
||||
|
@ -101,7 +104,7 @@ export async function queryMediaPermissions(type: MediaStreamType, changeListene
|
|||
export function stopMediaStream(stream: MediaStream) {
|
||||
stream.getVideoTracks().forEach(track => track.stop());
|
||||
stream.getAudioTracks().forEach(track => track.stop());
|
||||
if('stop' in stream) {
|
||||
if ('stop' in stream) {
|
||||
(stream as any).stop();
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
/* setup jsrenderer */
|
||||
import "jsrender";
|
||||
import {tr} from "./i18n/localize";
|
||||
import {LogCategory, logError, logTrace} from "tc-shared/log";
|
||||
import { tr } from "./i18n/localize";
|
||||
import { LogCategory, logError, logTrace } from "tc-shared/log";
|
||||
|
||||
(window as any).$ = require("jquery");
|
||||
(window as any).jQuery = $;
|
||||
|
@ -22,7 +22,7 @@ declare global {
|
|||
* @param entry The entry to toggle
|
||||
* @returns `true` if the entry has been inserted and false if the entry has been deleted
|
||||
*/
|
||||
toggle(entry: T) : boolean;
|
||||
toggle(entry: T): boolean;
|
||||
|
||||
/**
|
||||
* @param entry The entry to toggle
|
||||
|
@ -33,21 +33,21 @@ declare global {
|
|||
}
|
||||
|
||||
interface JSON {
|
||||
map_to<T>(object: T, json: any, variables?: string | string[], validator?: (map_field: string, map_value: string) => boolean, variable_direction?: number) : number;
|
||||
map_field_to<T>(object: T, value: any, field: string) : boolean;
|
||||
map_to<T>(object: T, json: any, variables?: string | string[], validator?: (map_field: string, map_value: string) => boolean, variable_direction?: number): number;
|
||||
map_field_to<T>(object: T, value: any, field: string): boolean;
|
||||
}
|
||||
|
||||
type JQueryScrollType = "height" | "width";
|
||||
interface JQuery<TElement = HTMLElement> {
|
||||
renderTag(values?: any) : JQuery<TElement>;
|
||||
hasScrollBar(direction?: JQueryScrollType) : boolean;
|
||||
renderTag(values?: any): JQuery<TElement>;
|
||||
hasScrollBar(direction?: JQueryScrollType): boolean;
|
||||
|
||||
|
||||
visible_height() : number;
|
||||
visible_width() : number;
|
||||
visible_height(): number;
|
||||
visible_width(): number;
|
||||
|
||||
/* first element which matches the selector, could be the element itself or a parent */
|
||||
firstParent(selector: string) : JQuery;
|
||||
firstParent(selector: string): JQuery;
|
||||
}
|
||||
|
||||
interface JQueryStatic<TElement extends Node = HTMLElement> {
|
||||
|
@ -73,9 +73,6 @@ declare global {
|
|||
name: string,
|
||||
version: string
|
||||
};
|
||||
|
||||
mozGetUserMedia(constraints: MediaStreamConstraints, successCallback: NavigatorUserMediaSuccessCallback, errorCallback: NavigatorUserMediaErrorCallback): void;
|
||||
webkitGetUserMedia(constraints: MediaStreamConstraints, successCallback: NavigatorUserMediaSuccessCallback, errorCallback: NavigatorUserMediaErrorCallback): void;
|
||||
}
|
||||
|
||||
interface ObjectConstructor {
|
||||
|
@ -83,7 +80,7 @@ declare global {
|
|||
}
|
||||
}
|
||||
|
||||
export type IfEquals<X, Y, A=X, B=never> =
|
||||
export type IfEquals<X, Y, A = X, B = never> =
|
||||
(<T>() => T extends X ? 1 : 2) extends
|
||||
(<T>() => T extends Y ? 1 : 2) ? A : B;
|
||||
|
||||
|
@ -95,7 +92,7 @@ export type ReadonlyKeys<T> = {
|
|||
[P in keyof T]: IfEquals<{ [Q in P]: T[P] }, { -readonly [Q in P]: T[P] }, never, P>
|
||||
}[keyof T];
|
||||
|
||||
if(!Object.isSimilar) {
|
||||
if (!Object.isSimilar) {
|
||||
Object.isSimilar = function (a, b) {
|
||||
const aType = typeof a;
|
||||
const bType = typeof b;
|
||||
|
@ -106,8 +103,8 @@ if(!Object.isSimilar) {
|
|||
if (aType === "object") {
|
||||
const aKeys = Object.keys(a);
|
||||
const bKeys = Object.keys(b);
|
||||
if(aKeys.length != bKeys.length) { return false; }
|
||||
if(aKeys.findIndex(key => bKeys.indexOf(key) !== -1) !== -1) { return false; }
|
||||
if (aKeys.length != bKeys.length) { return false; }
|
||||
if (aKeys.findIndex(key => bKeys.indexOf(key) !== -1) !== -1) { return false; }
|
||||
return aKeys.findIndex(key => !Object.isSimilar(a[key], b[key])) === -1;
|
||||
} else {
|
||||
return a === b;
|
||||
|
@ -115,7 +112,7 @@ if(!Object.isSimilar) {
|
|||
};
|
||||
}
|
||||
|
||||
if(!JSON.map_to) {
|
||||
if (!JSON.map_to) {
|
||||
JSON.map_to = function <T>(object: T, json: any, variables?: string | string[], validator?: (map_field: string, map_value: string) => boolean, variable_direction?: number): number {
|
||||
if (!validator)
|
||||
validator = () => true;
|
||||
|
@ -145,29 +142,29 @@ if(!JSON.map_to) {
|
|||
continue;
|
||||
}
|
||||
|
||||
if(JSON.map_field_to(object, json[field], field))
|
||||
if (JSON.map_field_to(object, json[field], field))
|
||||
updates++;
|
||||
}
|
||||
return updates;
|
||||
}
|
||||
}
|
||||
|
||||
if(!JSON.map_field_to) {
|
||||
JSON.map_field_to = function<T>(object: T, value: any, field: string) : boolean {
|
||||
if (!JSON.map_field_to) {
|
||||
JSON.map_field_to = function <T>(object: T, value: any, field: string): boolean {
|
||||
let fieldType = typeof object[field];
|
||||
let newValue;
|
||||
if(fieldType == "string" || fieldType == "object" || fieldType == "undefined") {
|
||||
if (fieldType == "string" || fieldType == "object" || fieldType == "undefined") {
|
||||
newValue = value;
|
||||
} else if(fieldType == "number") {
|
||||
} else if (fieldType == "number") {
|
||||
newValue = parseFloat(value);
|
||||
} else if(fieldType == "boolean") {
|
||||
} else if (fieldType == "boolean") {
|
||||
newValue = typeof value === "boolean" && value || value === "1" || value === "true";
|
||||
} else {
|
||||
console.warn(tr("Invalid object type %s for entry %s"), fieldType, field);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(newValue === object[field]) {
|
||||
if (newValue === object[field]) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -177,7 +174,7 @@ if(!JSON.map_field_to) {
|
|||
}
|
||||
|
||||
if (!Array.prototype.remove) {
|
||||
Array.prototype.remove = function<T>(elem?: T): boolean {
|
||||
Array.prototype.remove = function <T>(elem?: T): boolean {
|
||||
const index = this.indexOf(elem);
|
||||
if (index > -1) {
|
||||
this.splice(index, 1);
|
||||
|
@ -188,18 +185,18 @@ if (!Array.prototype.remove) {
|
|||
}
|
||||
|
||||
if (!Array.prototype.pop_front) {
|
||||
Array.prototype.pop_front = function<T>(): T {
|
||||
if(this.length == 0) return undefined;
|
||||
Array.prototype.pop_front = function <T>(): T {
|
||||
if (this.length == 0) return undefined;
|
||||
return this.splice(0, 1)[0];
|
||||
}
|
||||
}
|
||||
|
||||
if (!Array.prototype.toggle) {
|
||||
Array.prototype.toggle = function<T>(element: T, insert?: boolean): boolean {
|
||||
Array.prototype.toggle = function <T>(element: T, insert?: boolean): boolean {
|
||||
const index = this.findIndex(e => e === element);
|
||||
if((index !== -1) === insert) {
|
||||
if ((index !== -1) === insert) {
|
||||
return false;
|
||||
} else if(index === -1) {
|
||||
} else if (index === -1) {
|
||||
this.push(element);
|
||||
return true;
|
||||
} else {
|
||||
|
@ -209,25 +206,25 @@ if (!Array.prototype.toggle) {
|
|||
}
|
||||
}
|
||||
|
||||
if (!Array.prototype.last){
|
||||
Array.prototype.last = function(){
|
||||
if(this.length == 0) return undefined;
|
||||
if (!Array.prototype.last) {
|
||||
Array.prototype.last = function () {
|
||||
if (this.length == 0) return undefined;
|
||||
return this[this.length - 1];
|
||||
};
|
||||
}
|
||||
|
||||
if(typeof ($) !== "undefined") {
|
||||
if(!$.spawn) {
|
||||
$.spawn = function<K extends keyof HTMLElementTagNameMap>(tagName: K): JQuery<HTMLElementTagNameMap[K]> {
|
||||
if (typeof ($) !== "undefined") {
|
||||
if (!$.spawn) {
|
||||
$.spawn = function <K extends keyof HTMLElementTagNameMap>(tagName: K): JQuery<HTMLElementTagNameMap[K]> {
|
||||
return $(document.createElement(tagName) as any);
|
||||
}
|
||||
}
|
||||
|
||||
if(!$.fn.renderTag) {
|
||||
$.fn.renderTag = function (this: JQuery, values?: any) : JQuery {
|
||||
if (!$.fn.renderTag) {
|
||||
$.fn.renderTag = function (this: JQuery, values?: any): JQuery {
|
||||
let result;
|
||||
const template = $.views.templates[this.attr("id")];
|
||||
if(!template) {
|
||||
if (!template) {
|
||||
console.error("Tried to render template %o, but template is not available!", this.attr("id"));
|
||||
throw "missing template " + this.attr("id");
|
||||
}
|
||||
|
@ -243,24 +240,24 @@ if(typeof ($) !== "undefined") {
|
|||
return result;
|
||||
}
|
||||
}
|
||||
if(!$.fn.hasScrollBar)
|
||||
$.fn.hasScrollBar = function(direction?: "height" | "width") {
|
||||
if(this.length <= 0)
|
||||
if (!$.fn.hasScrollBar)
|
||||
$.fn.hasScrollBar = function (direction?: "height" | "width") {
|
||||
if (this.length <= 0)
|
||||
return false;
|
||||
|
||||
const scroll_height = this.get(0).scrollHeight > this.height();
|
||||
const scroll_width = this.get(0).scrollWidth > this.width();
|
||||
|
||||
if(typeof(direction) === "string") {
|
||||
if(direction === "height")
|
||||
if (typeof (direction) === "string") {
|
||||
if (direction === "height")
|
||||
return scroll_height;
|
||||
if(direction === "width")
|
||||
if (direction === "width")
|
||||
return scroll_width;
|
||||
}
|
||||
return scroll_width || scroll_height;
|
||||
};
|
||||
|
||||
if(!$.fn.visible_height)
|
||||
if (!$.fn.visible_height)
|
||||
$.fn.visible_height = function (this: JQuery<HTMLElement>) {
|
||||
const original_style = this.attr("style");
|
||||
this.css({
|
||||
|
@ -274,7 +271,7 @@ if(typeof ($) !== "undefined") {
|
|||
return result;
|
||||
};
|
||||
|
||||
if(!$.fn.visible_width)
|
||||
if (!$.fn.visible_width)
|
||||
$.fn.visible_width = function (this: JQuery<HTMLElement>) {
|
||||
const original_style = this.attr("style");
|
||||
this.css({
|
||||
|
@ -288,20 +285,20 @@ if(typeof ($) !== "undefined") {
|
|||
return result;
|
||||
};
|
||||
|
||||
if(!$.fn.firstParent)
|
||||
if (!$.fn.firstParent)
|
||||
$.fn.firstParent = function (this: JQuery<HTMLElement>, selector: string) {
|
||||
if(this.is(selector))
|
||||
if (this.is(selector))
|
||||
return this;
|
||||
return this.parent(selector);
|
||||
}
|
||||
}
|
||||
|
||||
if(!Object.values) {
|
||||
if (!Object.values) {
|
||||
Object.values = object => Object.keys(object).map(e => object[e]);
|
||||
}
|
||||
|
||||
export function crashOnThrow<T>(promise: Promise<T> | (() => Promise<T>)) : Promise<T> {
|
||||
if(typeof promise === "function") {
|
||||
export function crashOnThrow<T>(promise: Promise<T> | (() => Promise<T>)): Promise<T> {
|
||||
if (typeof promise === "function") {
|
||||
try {
|
||||
promise = promise();
|
||||
} catch (error) {
|
||||
|
@ -314,11 +311,11 @@ export function crashOnThrow<T>(promise: Promise<T> | (() => Promise<T>)) : Prom
|
|||
logError(LogCategory.GENERAL, tr("Critical app error: %o"), error);
|
||||
|
||||
/* Lets make this promise stuck for ever */
|
||||
return new Promise(() => {});
|
||||
return new Promise(() => { });
|
||||
});
|
||||
}
|
||||
|
||||
export function ignorePromise<T>(_promise: Promise<T>) {}
|
||||
export function ignorePromise<T>(_promise: Promise<T>) { }
|
||||
|
||||
export function NoThrow(target: any, methodName: string, descriptor: PropertyDescriptor) {
|
||||
const crashApp = error => {
|
||||
|
@ -332,13 +329,13 @@ export function NoThrow(target: any, methodName: string, descriptor: PropertyDes
|
|||
descriptor.value = function () {
|
||||
try {
|
||||
const result = originalMethod.apply(this, arguments);
|
||||
if(result instanceof Promise) {
|
||||
if (result instanceof Promise) {
|
||||
promiseAccepted.value = true;
|
||||
return result.catch(error => {
|
||||
crashApp(error);
|
||||
|
||||
/* Lets make this promise stuck for ever since we're in a not well defined state */
|
||||
return new Promise(() => {});
|
||||
return new Promise(() => { });
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -346,14 +343,14 @@ export function NoThrow(target: any, methodName: string, descriptor: PropertyDes
|
|||
} catch (error) {
|
||||
crashApp(error);
|
||||
|
||||
if(!promiseAccepted.value) {
|
||||
if (!promiseAccepted.value) {
|
||||
throw error;
|
||||
} else {
|
||||
/*
|
||||
* We don't know if we can return a promise or if just the object is expected.
|
||||
* Since we don't know that, we're just rethrowing the error for now.
|
||||
*/
|
||||
return new Promise(() => {});
|
||||
return new Promise(() => { });
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -365,7 +362,7 @@ export function CallOnce(target: any, methodName: string, descriptor: PropertyDe
|
|||
|
||||
const originalMethod: Function = descriptor.value;
|
||||
descriptor.value = function () {
|
||||
if(callOnceData[methodName]) {
|
||||
if (callOnceData[methodName]) {
|
||||
debugger;
|
||||
throw "method " + methodName + " has already been called";
|
||||
}
|
||||
|
@ -378,7 +375,7 @@ const kNonNullSymbol = Symbol("non-null-data");
|
|||
export function NonNull(target: any, methodName: string, parameterIndex: number) {
|
||||
const nonNullInfo = target[kNonNullSymbol] || (target[kNonNullSymbol] = {});
|
||||
const methodInfo = nonNullInfo[methodName] || (nonNullInfo[methodName] = {});
|
||||
if(!Array.isArray(methodInfo.indexes)) {
|
||||
if (!Array.isArray(methodInfo.indexes)) {
|
||||
/* Initialize method info */
|
||||
methodInfo.overloaded = false;
|
||||
methodInfo.indexes = [];
|
||||
|
@ -386,7 +383,7 @@ export function NonNull(target: any, methodName: string, parameterIndex: number)
|
|||
|
||||
methodInfo.indexes.push(parameterIndex);
|
||||
setImmediate(() => {
|
||||
if(methodInfo.overloaded || methodInfo.missingWarned) {
|
||||
if (methodInfo.overloaded || methodInfo.missingWarned) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -401,21 +398,21 @@ export function NonNull(target: any, methodName: string, parameterIndex: number)
|
|||
*/
|
||||
export function ParameterConstrained(target: any, methodName: string, descriptor: PropertyDescriptor) {
|
||||
const nonNullInfo = target[kNonNullSymbol];
|
||||
if(!nonNullInfo) {
|
||||
if (!nonNullInfo) {
|
||||
return;
|
||||
}
|
||||
|
||||
const methodInfo = nonNullInfo[methodName] || (nonNullInfo[methodName] = {});
|
||||
if(!methodInfo) {
|
||||
if (!methodInfo) {
|
||||
return;
|
||||
}
|
||||
|
||||
methodInfo.overloaded = true;
|
||||
const originalMethod: Function = descriptor.value;
|
||||
descriptor.value = function () {
|
||||
for(let index = 0; index < methodInfo.indexes.length; index++) {
|
||||
for (let index = 0; index < methodInfo.indexes.length; index++) {
|
||||
const argument = arguments[methodInfo.indexes[index]];
|
||||
if(typeof argument === undefined || typeof argument === null) {
|
||||
if (typeof argument === undefined || typeof argument === null) {
|
||||
throw "parameter " + methodInfo.indexes[index] + " should not be null or undefined";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import {LogCategory, logError, logInfo, logTrace} from "./log";
|
||||
import { LogCategory, logError, logInfo, logTrace } from "./log";
|
||||
import * as loader from "tc-loader";
|
||||
import {Stage} from "tc-loader";
|
||||
import {Registry} from "./events";
|
||||
import {tr} from "./i18n/localize";
|
||||
import {CallOnce, ignorePromise} from "tc-shared/proto";
|
||||
import {getStorageAdapter} from "tc-shared/StorageAdapter";
|
||||
import { Stage } from "tc-loader";
|
||||
import { Registry } from "./events";
|
||||
import { tr } from "./i18n/localize";
|
||||
import { CallOnce, ignorePromise } from "tc-shared/proto";
|
||||
import { getStorageAdapter } from "tc-shared/StorageAdapter";
|
||||
|
||||
/*
|
||||
* TODO: Sync settings across renderer instances
|
||||
|
@ -24,7 +24,7 @@ export interface RegistryKey<ValueType extends RegistryValueType> {
|
|||
valueType: RegistryValueTypeMapping<ValueType>;
|
||||
|
||||
fallbackKeys?: string | string[];
|
||||
fallbackImports?: {[key: string]:(value: string) => ValueType};
|
||||
fallbackImports?: { [key: string]: (value: string) => ValueType };
|
||||
|
||||
description?: string;
|
||||
|
||||
|
@ -37,7 +37,7 @@ export interface ValuedRegistryKey<ValueType extends RegistryValueType> extends
|
|||
|
||||
const UPDATE_DIRECT: boolean = true;
|
||||
|
||||
function decodeValueFromString<T extends RegistryValueType>(input: string, type: RegistryValueTypeMapping<T>) : T {
|
||||
function decodeValueFromString<T extends RegistryValueType>(input: string, type: RegistryValueTypeMapping<T>): T {
|
||||
switch (type) {
|
||||
case "string":
|
||||
return input as any;
|
||||
|
@ -60,7 +60,7 @@ function decodeValueFromString<T extends RegistryValueType>(input: string, type:
|
|||
}
|
||||
}
|
||||
|
||||
export function encodeSettingValueToString<T extends RegistryValueType>(input: T) : string {
|
||||
export function encodeSettingValueToString<T extends RegistryValueType>(input: T): string {
|
||||
switch (typeof input) {
|
||||
case "string":
|
||||
return input;
|
||||
|
@ -83,24 +83,24 @@ export function resolveSettingKey<ValueType extends RegistryValueType, DefaultTy
|
|||
key: RegistryKey<ValueType>,
|
||||
resolver: (key: string) => string | undefined | null,
|
||||
defaultValue: DefaultType
|
||||
) : ValueType | DefaultType {
|
||||
): ValueType | DefaultType {
|
||||
let value = resolver(key.key);
|
||||
|
||||
const keys = [key.key];
|
||||
if(Array.isArray(key.fallbackKeys)) {
|
||||
if (Array.isArray(key.fallbackKeys)) {
|
||||
keys.push(...key.fallbackKeys);
|
||||
}
|
||||
|
||||
for(const resolveKey of keys) {
|
||||
for (const resolveKey of keys) {
|
||||
value = resolver(resolveKey);
|
||||
if(typeof value !== "string") {
|
||||
if (typeof value !== "string") {
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (key.valueType) {
|
||||
case "number":
|
||||
case "boolean":
|
||||
if(value.length === 0) {
|
||||
if (value.length === 0) {
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
|
@ -109,9 +109,9 @@ export function resolveSettingKey<ValueType extends RegistryValueType, DefaultTy
|
|||
break;
|
||||
}
|
||||
|
||||
if(key.fallbackImports) {
|
||||
if (key.fallbackImports) {
|
||||
const fallbackValueImporter = key.fallbackImports[resolveKey];
|
||||
if(fallbackValueImporter) {
|
||||
if (fallbackValueImporter) {
|
||||
return fallbackValueImporter(value);
|
||||
}
|
||||
}
|
||||
|
@ -129,21 +129,21 @@ export class UrlParameterParser {
|
|||
this.url = url;
|
||||
}
|
||||
|
||||
private getParameter(key: string) : string | undefined {
|
||||
private getParameter(key: string): string | undefined {
|
||||
const value = this.url.searchParams.get(key);
|
||||
if(value === null) {
|
||||
if (value === null) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return decodeURIComponent(value);
|
||||
}
|
||||
|
||||
getValue<V extends RegistryValueType, DV>(key: RegistryKey<V>, defaultValue: DV) : V | DV;
|
||||
getValue<V extends RegistryValueType>(key: ValuedRegistryKey<V>, defaultValue?: V) : V;
|
||||
getValue<V extends RegistryValueType, DV>(key: RegistryKey<V> | ValuedRegistryKey<V>, defaultValue: DV) : V | DV {
|
||||
if(arguments.length > 1) {
|
||||
getValue<V extends RegistryValueType, DV>(key: RegistryKey<V>, defaultValue: DV): V | DV;
|
||||
getValue<V extends RegistryValueType>(key: ValuedRegistryKey<V>, defaultValue?: V): V;
|
||||
getValue<V extends RegistryValueType, DV>(key: RegistryKey<V> | ValuedRegistryKey<V>, defaultValue: DV): V | DV {
|
||||
if (arguments.length > 1) {
|
||||
return resolveSettingKey(key, key => this.getParameter(key), defaultValue);
|
||||
} else if("defaultValue" in key) {
|
||||
} else if ("defaultValue" in key) {
|
||||
return resolveSettingKey(key, key => this.getParameter(key), key.defaultValue);
|
||||
} else {
|
||||
throw tr("missing value");
|
||||
|
@ -155,14 +155,14 @@ export class UrlParameterBuilder {
|
|||
private parameters = {};
|
||||
|
||||
setValue<V extends RegistryValueType>(key: RegistryKey<V>, value: V) {
|
||||
if(value === undefined) {
|
||||
if (value === undefined) {
|
||||
delete this.parameters[key.key];
|
||||
} else {
|
||||
this.parameters[key.key] = encodeURIComponent(encodeSettingValueToString(value));
|
||||
}
|
||||
}
|
||||
|
||||
build() : string {
|
||||
build(): string {
|
||||
return Object.keys(this.parameters).map(key => `${key}=${this.parameters[key]}`).join("&");
|
||||
}
|
||||
}
|
||||
|
@ -174,12 +174,12 @@ export class UrlParameterBuilder {
|
|||
export namespace AppParameters {
|
||||
export const Instance = new UrlParameterParser(new URL(window.location.href));
|
||||
|
||||
export function getValue<V extends RegistryValueType, DV>(key: RegistryKey<V>, defaultValue: DV) : V | DV;
|
||||
export function getValue<V extends RegistryValueType>(key: ValuedRegistryKey<V>, defaultValue?: V) : V;
|
||||
export function getValue<V extends RegistryValueType, DV>(key: RegistryKey<V> | ValuedRegistryKey<V>, defaultValue: DV) : V | DV {
|
||||
if(arguments.length > 1) {
|
||||
export function getValue<V extends RegistryValueType, DV>(key: RegistryKey<V>, defaultValue: DV): V | DV;
|
||||
export function getValue<V extends RegistryValueType>(key: ValuedRegistryKey<V>, defaultValue?: V): V;
|
||||
export function getValue<V extends RegistryValueType, DV>(key: RegistryKey<V> | ValuedRegistryKey<V>, defaultValue: DV): V | DV {
|
||||
if (arguments.length > 1) {
|
||||
return Instance.getValue(key, defaultValue);
|
||||
} else if("defaultValue" in key) {
|
||||
} else if ("defaultValue" in key) {
|
||||
return Instance.getValue(key);
|
||||
} else {
|
||||
throw tr("missing value");
|
||||
|
@ -364,7 +364,7 @@ export class Settings {
|
|||
static readonly KEY_I18N_DEFAULT_REPOSITORY: ValuedRegistryKey<string> = {
|
||||
key: "i18n.default_repository",
|
||||
valueType: "string",
|
||||
defaultValue: "https://web.teaspeak.de/i18n/"
|
||||
defaultValue: "i18n/"
|
||||
};
|
||||
|
||||
/* Default client states */
|
||||
|
@ -408,12 +408,12 @@ export class Settings {
|
|||
static readonly KEY_FLAG_CONNECT_DEFAULT: ValuedRegistryKey<boolean> = {
|
||||
key: "connect_default",
|
||||
valueType: "boolean",
|
||||
defaultValue: false
|
||||
defaultValue: true
|
||||
};
|
||||
static readonly KEY_CONNECT_ADDRESS: ValuedRegistryKey<string> = {
|
||||
key: "connect_address",
|
||||
valueType: "string",
|
||||
defaultValue: undefined
|
||||
defaultValue: "tea.lp.kle.li"
|
||||
};
|
||||
static readonly KEY_CONNECT_PROFILE: ValuedRegistryKey<string> = {
|
||||
key: "connect_profile",
|
||||
|
@ -448,7 +448,7 @@ export class Settings {
|
|||
|
||||
static readonly KEY_CONNECT_NO_DNSPROXY: ValuedRegistryKey<boolean> = {
|
||||
key: "connect_no_dnsproxy",
|
||||
defaultValue: false,
|
||||
defaultValue: true,
|
||||
valueType: "boolean",
|
||||
};
|
||||
|
||||
|
@ -913,8 +913,8 @@ export class Settings {
|
|||
static readonly KEYS = (() => {
|
||||
const result = [];
|
||||
|
||||
for(const key of Object.keys(Settings)) {
|
||||
if(!key.toUpperCase().startsWith("KEY_")) {
|
||||
for (const key of Object.keys(Settings)) {
|
||||
if (!key.toUpperCase().startsWith("KEY_")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -943,13 +943,13 @@ export class Settings {
|
|||
const json = await getStorageAdapter().get("settings.global");
|
||||
|
||||
try {
|
||||
if(json === null) {
|
||||
if (json === null) {
|
||||
logInfo(LogCategory.GENERAL, tr("Found no settings. Creating new client settings."));
|
||||
this.settingsCache = {};
|
||||
} else {
|
||||
this.settingsCache = JSON.parse(json);
|
||||
}
|
||||
} catch(error) {
|
||||
} catch (error) {
|
||||
this.settingsCache = {};
|
||||
logError(LogCategory.GENERAL, tr("Failed to load global settings!\nJson: %s\nError: %o"), json, error);
|
||||
|
||||
|
@ -957,7 +957,7 @@ export class Settings {
|
|||
//FIXME: Readd this
|
||||
//createErrorModal(tr("Failed to load global settings"), tr("Failed to load global client settings!\nLookup console for more information.")).open();
|
||||
};
|
||||
if(!loader.finished()) {
|
||||
if (!loader.finished()) {
|
||||
loader.register_task(loader.Stage.LOADED, {
|
||||
priority: 0,
|
||||
name: "Settings error",
|
||||
|
@ -969,18 +969,18 @@ export class Settings {
|
|||
}
|
||||
|
||||
this.saveWorker = setInterval(() => {
|
||||
if(this.updated) {
|
||||
if (this.updated) {
|
||||
this.save();
|
||||
}
|
||||
}, 5 * 1000);
|
||||
}
|
||||
|
||||
getValue<V extends RegistryValueType, DV>(key: RegistryKey<V>, defaultValue: DV) : V | DV;
|
||||
getValue<V extends RegistryValueType>(key: ValuedRegistryKey<V>, defaultValue?: V) : V;
|
||||
getValue<V extends RegistryValueType, DV>(key: RegistryKey<V> | ValuedRegistryKey<V>, defaultValue: DV) : V | DV {
|
||||
if(arguments.length > 1) {
|
||||
getValue<V extends RegistryValueType, DV>(key: RegistryKey<V>, defaultValue: DV): V | DV;
|
||||
getValue<V extends RegistryValueType>(key: ValuedRegistryKey<V>, defaultValue?: V): V;
|
||||
getValue<V extends RegistryValueType, DV>(key: RegistryKey<V> | ValuedRegistryKey<V>, defaultValue: DV): V | DV {
|
||||
if (arguments.length > 1) {
|
||||
return resolveSettingKey(key, key => this.settingsCache[key], defaultValue);
|
||||
} else if("defaultValue" in key) {
|
||||
} else if ("defaultValue" in key) {
|
||||
return resolveSettingKey(key, key => this.settingsCache[key], key.defaultValue);
|
||||
} else {
|
||||
debugger;
|
||||
|
@ -988,17 +988,17 @@ export class Settings {
|
|||
}
|
||||
}
|
||||
|
||||
setValue<T extends RegistryValueType>(key: RegistryKey<T>, value?: T){
|
||||
if(value === null) {
|
||||
setValue<T extends RegistryValueType>(key: RegistryKey<T>, value?: T) {
|
||||
if (value === null) {
|
||||
value = undefined;
|
||||
}
|
||||
|
||||
if(this.settingsCache[key.key] === value) {
|
||||
if (this.settingsCache[key.key] === value) {
|
||||
return;
|
||||
}
|
||||
|
||||
const oldValue = this.settingsCache[key.key];
|
||||
if(value === undefined) {
|
||||
if (value === undefined) {
|
||||
delete this.settingsCache[key.key];
|
||||
} else {
|
||||
this.settingsCache[key.key] = encodeSettingValueToString(value);
|
||||
|
@ -1014,21 +1014,21 @@ export class Settings {
|
|||
});
|
||||
logTrace(LogCategory.GENERAL, tr("Changing global setting %s to %o"), key.key, value);
|
||||
|
||||
if(UPDATE_DIRECT) {
|
||||
if (UPDATE_DIRECT) {
|
||||
this.save();
|
||||
}
|
||||
}
|
||||
|
||||
globalChangeListener<T extends RegistryValueType>(key: RegistryKey<T>, listener: (newValue: T) => void) : () => void {
|
||||
globalChangeListener<T extends RegistryValueType>(key: RegistryKey<T>, listener: (newValue: T) => void): () => void {
|
||||
return this.events.on("notify_setting_changed", event => {
|
||||
if(event.setting === key.key && event.mode === "global") {
|
||||
if (event.setting === key.key && event.mode === "global") {
|
||||
listener(event.newCastedValue);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private async doSave() {
|
||||
if(this.saveState === "none") {
|
||||
if (this.saveState === "none") {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1040,7 +1040,7 @@ export class Settings {
|
|||
} catch (error) {
|
||||
logError(LogCategory.GENERAL, tr("Failed to save global settings: %o"), error);
|
||||
}
|
||||
} while(this.saveState !== "saving");
|
||||
} while (this.saveState !== "saving");
|
||||
|
||||
this.saveState = "none";
|
||||
}
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
import * as React from "react";
|
||||
import {IpcInviteInfo, IpcInviteInfoLoaded} from "tc-shared/text/bbcode/InviteDefinitions";
|
||||
import {ChannelMessage, getIpcInstance, IPCChannel} from "tc-shared/ipc/BrowserIPC";
|
||||
import { IpcInviteInfo, IpcInviteInfoLoaded } from "tc-shared/text/bbcode/InviteDefinitions";
|
||||
import { ChannelMessage, getIpcInstance, IPCChannel } from "tc-shared/ipc/BrowserIPC";
|
||||
import * as loader from "tc-loader";
|
||||
import {useEffect, useState} from "react";
|
||||
import { useEffect, useState } from "react";
|
||||
import _ = require("lodash");
|
||||
import {Translatable} from "tc-shared/ui/react-elements/i18n";
|
||||
import {Button} from "tc-shared/ui/react-elements/Button";
|
||||
import {SimpleUrlRenderer} from "tc-shared/text/bbcode/url";
|
||||
import {LoadingDots} from "tc-shared/ui/react-elements/LoadingDots";
|
||||
import {ClientIconRenderer} from "tc-shared/ui/react-elements/Icons";
|
||||
import {ClientIcon} from "svg-sprites/client-icons";
|
||||
import { Translatable } from "tc-shared/ui/react-elements/i18n";
|
||||
import { Button } from "tc-shared/ui/react-elements/Button";
|
||||
import { SimpleUrlRenderer } from "tc-shared/text/bbcode/url";
|
||||
import { LoadingDots } from "tc-shared/ui/react-elements/LoadingDots";
|
||||
import { ClientIconRenderer } from "tc-shared/ui/react-elements/Icons";
|
||||
import { ClientIcon } from "svg-sprites/client-icons";
|
||||
|
||||
const cssStyle = require("./InviteRenderer.scss");
|
||||
const kInviteUrlRegex = /^(https:\/\/)?(teaspeak.de\/|join.teaspeak.de\/(invite\/)?)([a-zA-Z0-9]{4})$/gm;
|
||||
|
||||
export function isInviteLink(url: string) : boolean {
|
||||
export function isInviteLink(url: string): boolean {
|
||||
kInviteUrlRegex.lastIndex = 0;
|
||||
return !!url.match(kInviteUrlRegex);
|
||||
}
|
||||
|
@ -26,25 +26,25 @@ const localInviteCache: { [key: string]: InviteCacheEntry } = {};
|
|||
const localInviteCallbacks: { [key: string]: (() => void)[] } = {};
|
||||
|
||||
const useInviteLink = (linkId: string): LocalInviteInfo => {
|
||||
if(!localInviteCache[linkId]) {
|
||||
if (!localInviteCache[linkId]) {
|
||||
localInviteCache[linkId] = { status: { status: "loading" }, timeout: setTimeout(() => delete localInviteCache[linkId], 60 * 1000) };
|
||||
ipcChannel?.sendMessage("query", { linkId });
|
||||
}
|
||||
|
||||
const [ value, setValue ] = useState(localInviteCache[linkId].status);
|
||||
const [value, setValue] = useState(localInviteCache[linkId].status);
|
||||
|
||||
useEffect(() => {
|
||||
if(typeof localInviteCache[linkId]?.status === "undefined") {
|
||||
if (typeof localInviteCache[linkId]?.status === "undefined") {
|
||||
return;
|
||||
}
|
||||
|
||||
if(!_.isEqual(value, localInviteCache[linkId].status)) {
|
||||
if (!_.isEqual(value, localInviteCache[linkId].status)) {
|
||||
setValue(localInviteCache[linkId].status);
|
||||
}
|
||||
|
||||
const callback = () => setValue(localInviteCache[linkId].status);
|
||||
(localInviteCallbacks[linkId] || (localInviteCallbacks[linkId] = [])).push(callback);
|
||||
return () => localInviteCallbacks[linkId]?.remove(callback);
|
||||
return () => { localInviteCallbacks[linkId]?.remove(callback); }
|
||||
}, [linkId]);
|
||||
|
||||
return value;
|
||||
|
@ -69,14 +69,14 @@ const LoadedInviteRenderer = React.memo((props: { info: IpcInviteInfoLoaded }) =
|
|||
</div>
|
||||
);
|
||||
|
||||
const [, setRevision ] = useState(0);
|
||||
const [, setRevision] = useState(0);
|
||||
useEffect(() => {
|
||||
if(props.info.expireTimestamp === 0) {
|
||||
if (props.info.expireTimestamp === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const timeout = props.info.expireTimestamp - (Date.now() / 1000);
|
||||
if(timeout <= 0) {
|
||||
if (timeout <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -84,7 +84,7 @@ const LoadedInviteRenderer = React.memo((props: { info: IpcInviteInfoLoaded }) =
|
|||
return () => clearTimeout(timeoutId);
|
||||
});
|
||||
|
||||
if(props.info.expireTimestamp > 0 && Date.now() / 1000 >= props.info.expireTimestamp) {
|
||||
if (props.info.expireTimestamp > 0 && Date.now() / 1000 >= props.info.expireTimestamp) {
|
||||
return (
|
||||
<InviteErrorRenderer noTitle={true} key={"expired"}>
|
||||
<Translatable>Link expired</Translatable>
|
||||
|
@ -92,7 +92,7 @@ const LoadedInviteRenderer = React.memo((props: { info: IpcInviteInfoLoaded }) =
|
|||
);
|
||||
}
|
||||
|
||||
if(props.info.channelName) {
|
||||
if (props.info.channelName) {
|
||||
return (
|
||||
<div className={cssStyle.container + " " + cssStyle.info} key={"with-channel"}>
|
||||
<div className={cssStyle.left}>
|
||||
|
@ -215,8 +215,8 @@ loader.register_task(loader.Stage.JAVASCRIPT_INITIALIZING, {
|
|||
|
||||
|
||||
function handleIpcMessage(remoteId: string, broadcast: boolean, message: ChannelMessage) {
|
||||
if(message.type === "query-result") {
|
||||
if(!localInviteCache[message.data.linkId]) {
|
||||
if (message.type === "query-result") {
|
||||
if (!localInviteCache[message.data.linkId]) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,35 +1,35 @@
|
|||
import * as contextmenu from "../ui/elements/ContextMenu";
|
||||
import {Registry} from "../events";
|
||||
import {ChannelTree} from "./ChannelTree";
|
||||
import { Registry } from "../events";
|
||||
import { ChannelTree } from "./ChannelTree";
|
||||
import * as log from "../log";
|
||||
import {LogCategory, logDebug, logError, logInfo, LogType} from "../log";
|
||||
import {Settings, settings} from "../settings";
|
||||
import {Sound} from "../audio/Sounds";
|
||||
import {Group, GroupManager, GroupTarget, GroupType} from "../permission/GroupManager";
|
||||
import { LogCategory, logDebug, logError, logInfo, LogType } from "../log";
|
||||
import { Settings, settings } from "../settings";
|
||||
import { Sound } from "../audio/Sounds";
|
||||
import { Group, GroupManager, GroupTarget, GroupType } from "../permission/GroupManager";
|
||||
import PermissionType from "../permission/PermissionType";
|
||||
import {createErrorModal, createInputModal} from "../ui/elements/Modal";
|
||||
import { createErrorModal, createInputModal } from "../ui/elements/Modal";
|
||||
import * as htmltags from "../ui/htmltags";
|
||||
import {CommandResult} from "../connection/ServerConnectionDeclaration";
|
||||
import {ChannelEntry} from "./Channel";
|
||||
import {ConnectionHandler, ViewReasonId} from "../ConnectionHandler";
|
||||
import {openClientInfo} from "../ui/modal/ModalClientInfo";
|
||||
import {spawnBanClient} from "../ui/modal/ModalBanClient";
|
||||
import {spawnChangeLatency} from "../ui/modal/ModalChangeLatency";
|
||||
import { CommandResult } from "../connection/ServerConnectionDeclaration";
|
||||
import { ChannelEntry } from "./Channel";
|
||||
import { ConnectionHandler, ViewReasonId } from "../ConnectionHandler";
|
||||
import { openClientInfo } from "../ui/modal/ModalClientInfo";
|
||||
import { spawnBanClient } from "../ui/modal/ModalBanClient";
|
||||
import { spawnChangeLatency } from "../ui/modal/ModalChangeLatency";
|
||||
import * as hex from "../crypto/hex";
|
||||
import {ChannelTreeEntry, ChannelTreeEntryEvents} from "./ChannelTreeEntry";
|
||||
import {spawnClientVolumeChange, spawnMusicBotVolumeChange} from "../ui/modal/ModalChangeVolumeNew";
|
||||
import {spawnPermissionEditorModal} from "../ui/modal/permission/ModalController";
|
||||
import {global_client_actions} from "../events/GlobalEvents";
|
||||
import {ClientIcon} from "svg-sprites/client-icons";
|
||||
import {VoiceClient} from "../voice/VoiceClient";
|
||||
import {VoicePlayerEvents, VoicePlayerState} from "../voice/VoicePlayer";
|
||||
import {ChannelTreeUIEvents} from "tc-shared/ui/tree/Definitions";
|
||||
import {VideoClient} from "tc-shared/connection/VideoConnection";
|
||||
import {tr, tra} from "tc-shared/i18n/localize";
|
||||
import {EventClient} from "tc-shared/connectionlog/Definitions";
|
||||
import {W2GPluginCmdHandler} from "tc-shared/ui/modal/video-viewer/W2GPlugin";
|
||||
import {spawnServerGroupAssignments} from "tc-shared/ui/modal/group-assignment/Controller";
|
||||
import {promptYesNo} from "tc-shared/ui/modal/yes-no/Controller";
|
||||
import { ChannelTreeEntry, ChannelTreeEntryEvents } from "./ChannelTreeEntry";
|
||||
import { spawnClientVolumeChange, spawnMusicBotVolumeChange } from "../ui/modal/ModalChangeVolumeNew";
|
||||
import { spawnPermissionEditorModal } from "../ui/modal/permission/ModalController";
|
||||
import { global_client_actions } from "../events/GlobalEvents";
|
||||
import { ClientIcon } from "svg-sprites/client-icons";
|
||||
import { VoiceClient } from "../voice/VoiceClient";
|
||||
import { VoicePlayerEvents, VoicePlayerState } from "../voice/VoicePlayer";
|
||||
import { ChannelTreeUIEvents } from "tc-shared/ui/tree/Definitions";
|
||||
import { VideoClient } from "tc-shared/connection/VideoConnection";
|
||||
import { tr, tra } from "tc-shared/i18n/localize";
|
||||
import { EventClient } from "tc-shared/connectionlog/Definitions";
|
||||
import { W2GPluginCmdHandler } from "tc-shared/ui/modal/video-viewer/W2GPlugin";
|
||||
import { spawnServerGroupAssignments } from "tc-shared/ui/modal/group-assignment/Controller";
|
||||
import { promptYesNo } from "tc-shared/ui/modal/yes-no/Controller";
|
||||
|
||||
/* Must be the same as the TeaSpeak servers enum values */
|
||||
export enum ClientType {
|
||||
|
@ -218,11 +218,11 @@ export class ClientEntry<Events extends ClientEvents = ClientEvents> extends Cha
|
|||
}
|
||||
|
||||
destroy() {
|
||||
if(this.voiceHandle) {
|
||||
if (this.voiceHandle) {
|
||||
logError(LogCategory.AUDIO, tr("Destroying client with an active audio handle. This could cause memory leaks!"));
|
||||
this.setVoiceClient(undefined);
|
||||
}
|
||||
if(this.videoHandle) {
|
||||
if (this.videoHandle) {
|
||||
logError(LogCategory.AUDIO, tr("Destroying client with an active video handle. This could cause memory leaks!"));
|
||||
this.setVideoClient(undefined);
|
||||
}
|
||||
|
@ -232,22 +232,22 @@ export class ClientEntry<Events extends ClientEvents = ClientEvents> extends Cha
|
|||
}
|
||||
|
||||
setVoiceClient(handle: VoiceClient) {
|
||||
if(this.voiceHandle === handle)
|
||||
if (this.voiceHandle === handle)
|
||||
return;
|
||||
|
||||
if(this.voiceHandle) {
|
||||
if (this.voiceHandle) {
|
||||
this.voiceHandle.events.off(this.voiceCallbackStateChanged);
|
||||
}
|
||||
|
||||
this.voiceHandle = handle;
|
||||
if(handle) {
|
||||
if (handle) {
|
||||
this.voiceHandle.events.on("notify_state_changed", this.voiceCallbackStateChanged);
|
||||
this.handleVoiceStateChange({ oldState: VoicePlayerState.STOPPED, newState: handle.getState() });
|
||||
}
|
||||
}
|
||||
|
||||
setVideoClient(handle: VideoClient) {
|
||||
if(this.videoHandle === handle) {
|
||||
if (this.videoHandle === handle) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -278,19 +278,19 @@ export class ClientEntry<Events extends ClientEvents = ClientEvents> extends Cha
|
|||
this.voiceHandle?.setVolume(volume);
|
||||
}
|
||||
|
||||
getVoiceClient() : VoiceClient {
|
||||
getVoiceClient(): VoiceClient {
|
||||
return this.voiceHandle;
|
||||
}
|
||||
|
||||
getVideoClient() : VideoClient {
|
||||
getVideoClient(): VideoClient {
|
||||
return this.videoHandle;
|
||||
}
|
||||
|
||||
get properties() : ClientProperties {
|
||||
get properties(): ClientProperties {
|
||||
return this._properties;
|
||||
}
|
||||
|
||||
getStatusIcon() : ClientIcon {
|
||||
getStatusIcon(): ClientIcon {
|
||||
if (this.properties.client_type == ClientType.CLIENT_QUERY) {
|
||||
return ClientIcon.ServerQuery;
|
||||
} else if (this.properties.client_away) {
|
||||
|
@ -322,27 +322,27 @@ export class ClientEntry<Events extends ClientEvents = ClientEvents> extends Cha
|
|||
}
|
||||
}
|
||||
|
||||
currentChannel() : ChannelEntry { return this._channel; }
|
||||
clientNickName(){ return this.properties.client_nickname; }
|
||||
clientUid(){ return this.properties.client_unique_identifier; }
|
||||
clientId(){ return this._clientId; }
|
||||
currentChannel(): ChannelEntry { return this._channel; }
|
||||
clientNickName() { return this.properties.client_nickname; }
|
||||
clientUid() { return this.properties.client_unique_identifier; }
|
||||
clientId() { return this._clientId; }
|
||||
|
||||
isMuted() { return !!this.voiceMuted; }
|
||||
|
||||
/* TODO: Move this method to the view (e.g. channel tree) and rename with to setClientMuted */
|
||||
setMuted(flagMuted: boolean, force: boolean) {
|
||||
if(this.voiceMuted === flagMuted && !force) {
|
||||
if (this.voiceMuted === flagMuted && !force) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(flagMuted) {
|
||||
if (flagMuted) {
|
||||
this.channelTree.client.serverConnection.send_command('clientmute', {
|
||||
clid: this.clientId()
|
||||
}).then(() => {});
|
||||
} else if(this.voiceMuted) {
|
||||
}).then(() => { });
|
||||
} else if (this.voiceMuted) {
|
||||
this.channelTree.client.serverConnection.send_command('clientunmute', {
|
||||
clid: this.clientId()
|
||||
}).then(() => {});
|
||||
}).then(() => { });
|
||||
}
|
||||
this.voiceMuted = flagMuted;
|
||||
|
||||
|
@ -350,15 +350,15 @@ export class ClientEntry<Events extends ClientEvents = ClientEvents> extends Cha
|
|||
this.updateVoiceVolume();
|
||||
|
||||
this.events.fire("notify_mute_state_change", { muted: flagMuted });
|
||||
for(const client of this.channelTree.clients) {
|
||||
if(client === this as any || client.properties.client_unique_identifier !== this.properties.client_unique_identifier) {
|
||||
for (const client of this.channelTree.clients) {
|
||||
if (client === this as any || client.properties.client_unique_identifier !== this.properties.client_unique_identifier) {
|
||||
continue;
|
||||
}
|
||||
client.setMuted(flagMuted, false);
|
||||
}
|
||||
}
|
||||
|
||||
protected contextmenu_info() : contextmenu.MenuEntry[] {
|
||||
protected contextmenu_info(): contextmenu.MenuEntry[] {
|
||||
return [
|
||||
{
|
||||
type: contextmenu.MenuEntryType.ENTRY,
|
||||
|
@ -369,7 +369,7 @@ export class ClientEntry<Events extends ClientEvents = ClientEvents> extends Cha
|
|||
icon_class: "client-about",
|
||||
visible: !settings.getValue(Settings.KEY_SWITCH_INSTANT_CLIENT)
|
||||
}, {
|
||||
callback: () => {},
|
||||
callback: () => { },
|
||||
type: contextmenu.MenuEntryType.HR,
|
||||
name: "",
|
||||
visible: !settings.getValue(Settings.KEY_SWITCH_INSTANT_CLIENT)
|
||||
|
@ -377,22 +377,22 @@ export class ClientEntry<Events extends ClientEvents = ClientEvents> extends Cha
|
|||
]
|
||||
}
|
||||
|
||||
protected assignment_context() : contextmenu.MenuEntry[] {
|
||||
protected assignment_context(): contextmenu.MenuEntry[] {
|
||||
let server_groups: contextmenu.MenuEntry[] = [];
|
||||
for(let group of this.channelTree.client.groups.serverGroups.sort(GroupManager.sorter())) {
|
||||
if(group.type != GroupType.NORMAL) continue;
|
||||
for (let group of this.channelTree.client.groups.serverGroups.sort(GroupManager.sorter())) {
|
||||
if (group.type != GroupType.NORMAL) continue;
|
||||
|
||||
let entry: contextmenu.MenuEntry = {} as any;
|
||||
|
||||
//TODO: May add the server group icon?
|
||||
entry.checkbox_checked = this.groupAssigned(group);
|
||||
entry.name = group.name + " [" + (group.properties.savedb ? "perm" : "tmp") + "]";
|
||||
if(this.groupAssigned(group)) {
|
||||
if (this.groupAssigned(group)) {
|
||||
entry.callback = () => {
|
||||
this.channelTree.client.serverConnection.send_command("servergroupdelclient", {
|
||||
sgid: group.id,
|
||||
cldbid: this.properties.client_database_id
|
||||
}).then(() => {});
|
||||
}).then(() => { });
|
||||
};
|
||||
entry.disabled = !this.channelTree.client.permissions.neededPermission(PermissionType.I_GROUP_MEMBER_ADD_POWER).granted(group.requiredMemberRemovePower);
|
||||
} else {
|
||||
|
@ -400,7 +400,7 @@ export class ClientEntry<Events extends ClientEvents = ClientEvents> extends Cha
|
|||
this.channelTree.client.serverConnection.send_command("servergroupaddclient", {
|
||||
sgid: group.id,
|
||||
cldbid: this.properties.client_database_id
|
||||
}).then(() => {});
|
||||
}).then(() => { });
|
||||
};
|
||||
entry.disabled = !this.channelTree.client.permissions.neededPermission(PermissionType.I_GROUP_MEMBER_REMOVE_POWER).granted(group.requiredMemberAddPower);
|
||||
}
|
||||
|
@ -410,8 +410,8 @@ export class ClientEntry<Events extends ClientEvents = ClientEvents> extends Cha
|
|||
}
|
||||
|
||||
let channel_groups: contextmenu.MenuEntry[] = [];
|
||||
for(let group of this.channelTree.client.groups.channelGroups.sort(GroupManager.sorter())) {
|
||||
if(group.type != GroupType.NORMAL) continue;
|
||||
for (let group of this.channelTree.client.groups.channelGroups.sort(GroupManager.sorter())) {
|
||||
if (group.type != GroupType.NORMAL) continue;
|
||||
|
||||
let entry: contextmenu.MenuEntry = {} as any;
|
||||
|
||||
|
@ -423,7 +423,7 @@ export class ClientEntry<Events extends ClientEvents = ClientEvents> extends Cha
|
|||
cldbid: this.properties.client_database_id,
|
||||
cgid: group.id,
|
||||
cid: this.currentChannel().channelId
|
||||
}).then(() => {});
|
||||
}).then(() => { });
|
||||
};
|
||||
entry.disabled = !this.channelTree.client.permissions.neededPermission(PermissionType.I_GROUP_MEMBER_ADD_POWER).granted(group.requiredMemberRemovePower);
|
||||
entry.type = contextmenu.MenuEntryType.CHECKBOX;
|
||||
|
@ -444,14 +444,14 @@ export class ClientEntry<Events extends ClientEvents = ClientEvents> extends Cha
|
|||
contextmenu.Entry.HR(),
|
||||
...server_groups
|
||||
]
|
||||
},{
|
||||
}, {
|
||||
type: contextmenu.MenuEntryType.SUB_MENU,
|
||||
icon_class: "client-permission_channel",
|
||||
name: tr("Set channel group"),
|
||||
sub_menu: [
|
||||
...channel_groups
|
||||
]
|
||||
},{
|
||||
}, {
|
||||
type: contextmenu.MenuEntryType.SUB_MENU,
|
||||
icon_class: "client-permission_client",
|
||||
name: tr("Permissions"),
|
||||
|
@ -530,7 +530,7 @@ export class ClientEntry<Events extends ClientEvents = ClientEvents> extends Cha
|
|||
name: tr("Poke client"),
|
||||
callback: () => {
|
||||
createInputModal(tr("Poke client"), tr("Poke message:<br>"), () => true, result => {
|
||||
if(typeof(result) === "string") {
|
||||
if (typeof (result) === "string") {
|
||||
this.channelTree.client.serverConnection.send_command("clientpoke", {
|
||||
clid: this.clientId(),
|
||||
msg: result
|
||||
|
@ -549,11 +549,11 @@ export class ClientEntry<Events extends ClientEvents = ClientEvents> extends Cha
|
|||
name: tr("Change description"),
|
||||
callback: () => {
|
||||
createInputModal(tr("Change client description"), tr("New description:<br>"), () => true, result => {
|
||||
if(typeof(result) === "string") {
|
||||
if (typeof (result) === "string") {
|
||||
this.channelTree.client.serverConnection.send_command("clientedit", {
|
||||
clid: this.clientId(),
|
||||
client_description: result
|
||||
}).then(() => {});
|
||||
}).then(() => { });
|
||||
|
||||
}
|
||||
}, { width: 400, maxLength: 1024 }).open();
|
||||
|
@ -569,7 +569,7 @@ export class ClientEntry<Events extends ClientEvents = ClientEvents> extends Cha
|
|||
this.channelTree.client.serverConnection.send_command("clientmove", {
|
||||
clid: this.clientId(),
|
||||
cid: this.channelTree.client.getClient().currentChannel().getChannelId()
|
||||
}).then(() => {});
|
||||
}).then(() => { });
|
||||
}
|
||||
}, {
|
||||
type: contextmenu.MenuEntryType.ENTRY,
|
||||
|
@ -577,13 +577,13 @@ export class ClientEntry<Events extends ClientEvents = ClientEvents> extends Cha
|
|||
name: tr("Kick client from channel"),
|
||||
callback: () => {
|
||||
createInputModal(tr("Kick client from channel"), tr("Kick reason:<br>"), () => true, result => {
|
||||
if(typeof(result) !== 'boolean' || result) {
|
||||
if (typeof (result) !== 'boolean' || result) {
|
||||
logInfo(LogCategory.CLIENT, tr("Kicking client %s from channel with reason %s"), this.clientNickName(), result);
|
||||
this.channelTree.client.serverConnection.send_command("clientkick", {
|
||||
clid: this.clientId(),
|
||||
reasonid: ViewReasonId.VREASON_CHANNEL_KICK,
|
||||
reasonmsg: result
|
||||
}).then(() => {});
|
||||
}).then(() => { });
|
||||
|
||||
}
|
||||
}, { width: 400, maxLength: 255 }).open();
|
||||
|
@ -594,13 +594,13 @@ export class ClientEntry<Events extends ClientEvents = ClientEvents> extends Cha
|
|||
name: tr("Kick client fom server"),
|
||||
callback: () => {
|
||||
createInputModal(tr("Kick client from server"), tr("Kick reason:<br>"), () => true, result => {
|
||||
if(typeof(result) !== 'boolean' || result) {
|
||||
if (typeof (result) !== 'boolean' || result) {
|
||||
logInfo(LogCategory.CLIENT, tr("Kicking client %s from server with reason %s"), this.clientNickName(), result);
|
||||
this.channelTree.client.serverConnection.send_command("clientkick", {
|
||||
clid: this.clientId(),
|
||||
reasonid: ViewReasonId.VREASON_SERVER_KICK,
|
||||
reasonmsg: result
|
||||
}).then(() => {});
|
||||
}).then(() => { });
|
||||
}
|
||||
}, { width: 400, maxLength: 255 }).open();
|
||||
}
|
||||
|
@ -678,11 +678,11 @@ export class ClientEntry<Events extends ClientEvents = ClientEvents> extends Cha
|
|||
);
|
||||
}
|
||||
|
||||
static bbcodeTag(id: number, name: string, uid: string) : string {
|
||||
static bbcodeTag(id: number, name: string, uid: string): string {
|
||||
return "[url=client://" + id + "/" + uid + "~" + encodeURIComponent(name) + "]" + name + "[/url]";
|
||||
}
|
||||
|
||||
static chatTag(id: number, name: string, uid: string, braces: boolean = false) : JQuery {
|
||||
static chatTag(id: number, name: string, uid: string, braces: boolean = false): JQuery {
|
||||
return $(htmltags.generate_client({
|
||||
client_name: name,
|
||||
client_id: id,
|
||||
|
@ -691,11 +691,11 @@ export class ClientEntry<Events extends ClientEvents = ClientEvents> extends Cha
|
|||
}));
|
||||
}
|
||||
|
||||
create_bbcode() : string {
|
||||
create_bbcode(): string {
|
||||
return ClientEntry.bbcodeTag(this.clientId(), this.clientNickName(), this.clientUid());
|
||||
}
|
||||
|
||||
createChatTag(braces: boolean = false) : JQuery {
|
||||
createChatTag(braces: boolean = false): JQuery {
|
||||
return ClientEntry.chatTag(this.clientId(), this.clientNickName(), this.clientUid(), braces);
|
||||
}
|
||||
|
||||
|
@ -707,7 +707,7 @@ export class ClientEntry<Events extends ClientEvents = ClientEvents> extends Cha
|
|||
isSpeaking() { return this._speaking; }
|
||||
|
||||
protected setSpeaking(flag: boolean) {
|
||||
if(this._speaking === flag) {
|
||||
if (this._speaking === flag) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -715,17 +715,17 @@ export class ClientEntry<Events extends ClientEvents = ClientEvents> extends Cha
|
|||
this.events.fire("notify_speak_state_change", { speaking: flag });
|
||||
}
|
||||
|
||||
updateVariables(...variables: {key: string, value: string}[]) {
|
||||
updateVariables(...variables: { key: string, value: string }[]) {
|
||||
|
||||
let reorder_channel = false;
|
||||
let update_avatar = false;
|
||||
|
||||
let group;
|
||||
if(__build.mode === "debug") {
|
||||
if (__build.mode === "debug") {
|
||||
group = log.group(log.LogType.DEBUG, LogCategory.CLIENT, tr("Update properties (%i) of %s (%i)"), variables.length, this.clientNickName(), this.clientId());
|
||||
{
|
||||
const entries = [];
|
||||
for(const variable of variables)
|
||||
for (const variable of variables)
|
||||
entries.push({
|
||||
key: variable.key,
|
||||
value: variable.value,
|
||||
|
@ -735,13 +735,13 @@ export class ClientEntry<Events extends ClientEvents = ClientEvents> extends Cha
|
|||
}
|
||||
}
|
||||
|
||||
for(const variable of variables) {
|
||||
for (const variable of variables) {
|
||||
const old_value = this._properties[variable.key];
|
||||
JSON.map_field_to(this._properties, variable.value, variable.key);
|
||||
|
||||
if(variable.key == "client_nickname") {
|
||||
if(variable.value !== old_value && typeof(old_value) === "string") {
|
||||
if(!(this instanceof LocalClientEntry)) { /* own changes will be logged somewhere else */
|
||||
if (variable.key == "client_nickname") {
|
||||
if (variable.value !== old_value && typeof (old_value) === "string") {
|
||||
if (!(this instanceof LocalClientEntry)) { /* own changes will be logged somewhere else */
|
||||
this.channelTree.client.log.log("client.nickname.changed", {
|
||||
client: this.log_data(),
|
||||
new_name: variable.value,
|
||||
|
@ -752,29 +752,29 @@ export class ClientEntry<Events extends ClientEvents = ClientEvents> extends Cha
|
|||
|
||||
reorder_channel = true;
|
||||
}
|
||||
if(variable.key == "client_unique_identifier") {
|
||||
if (variable.key == "client_unique_identifier") {
|
||||
this.voiceVolume = this.channelTree.client.settings.getValue(Settings.FN_CLIENT_VOLUME(this.clientUid()), 1);
|
||||
const mute_status = this.channelTree.client.settings.getValue(Settings.FN_CLIENT_MUTED(this.clientUid()), false);
|
||||
this.setMuted(mute_status, mute_status); /* force only needed when we want to mute the client */
|
||||
this.updateVoiceVolume();
|
||||
logDebug(LogCategory.CLIENT, tr("Loaded client (%s) server specific properties. Volume: %o Muted: %o."), this.clientUid(), this.voiceVolume, this.voiceMuted);
|
||||
}
|
||||
if(variable.key == "client_talk_power") {
|
||||
if (variable.key == "client_talk_power") {
|
||||
reorder_channel = true;
|
||||
//update_icon_status = true; DONE
|
||||
}
|
||||
if(variable.key == "client_icon_id") {
|
||||
if (variable.key == "client_icon_id") {
|
||||
/* yeah we like javascript. Due to JS wiered integer behaviour parsing for example fails for 18446744073409829863.
|
||||
* parseInt("18446744073409829863") evaluates to 18446744073409829000.
|
||||
* In opposite "18446744073409829863" >>> 0 evaluates to 3995244544, which is the icon id :)
|
||||
*/
|
||||
this.properties.client_icon_id = variable.value as any >>> 0;
|
||||
}
|
||||
else if(variable.key == "client_flag_avatar")
|
||||
else if (variable.key == "client_flag_avatar")
|
||||
update_avatar = true;
|
||||
}
|
||||
|
||||
if(update_avatar) {
|
||||
if (update_avatar) {
|
||||
this.channelTree.client?.fileManager?.avatars.updateCache(this.avatarId(), this.properties.client_flag_avatar);
|
||||
}
|
||||
|
||||
|
@ -782,58 +782,58 @@ export class ClientEntry<Events extends ClientEvents = ClientEvents> extends Cha
|
|||
|
||||
{
|
||||
let properties = {};
|
||||
for(const property of variables)
|
||||
for (const property of variables)
|
||||
properties[property.key] = this.properties[property.key];
|
||||
this.events.fire("notify_properties_updated", { updated_properties: properties as any, client_properties: this.properties });
|
||||
}
|
||||
}
|
||||
|
||||
updateClientVariables(force_update?: boolean) : Promise<void> {
|
||||
if(Date.now() - 10 * 60 * 1000 < this.promiseClientInfoTimestamp && this.promiseClientInfo && (typeof(force_update) !== "boolean" || force_update)) {
|
||||
updateClientVariables(force_update?: boolean): Promise<void> {
|
||||
if (Date.now() - 10 * 60 * 1000 < this.promiseClientInfoTimestamp && this.promiseClientInfo && (typeof (force_update) !== "boolean" || force_update)) {
|
||||
return this.promiseClientInfo;
|
||||
}
|
||||
|
||||
this.promiseClientInfoTimestamp = Date.now();
|
||||
return (this.promiseClientInfo = new Promise<void>((resolve, reject) => {
|
||||
this.channelTree.client.serverConnection.send_command("clientgetvariables", {clid: this.clientId()}).then(() => resolve()).catch(error => {
|
||||
this.channelTree.client.serverConnection.send_command("clientgetvariables", { clid: this.clientId() }).then(() => resolve()).catch(error => {
|
||||
this.promiseConnectionInfoTimestamp = 0; /* not succeeded */
|
||||
reject(error);
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
assignedServerGroupIds() : number[] {
|
||||
assignedServerGroupIds(): number[] {
|
||||
let result = [];
|
||||
for(let id of this.properties.client_servergroups.split(",")){
|
||||
if(id.length == 0) continue;
|
||||
for (let id of this.properties.client_servergroups.split(",")) {
|
||||
if (id.length == 0) continue;
|
||||
result.push(Number.parseInt(id));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
assignedChannelGroup() : number {
|
||||
assignedChannelGroup(): number {
|
||||
return this.properties.client_channel_group_id;
|
||||
}
|
||||
|
||||
groupAssigned(group: Group) : boolean {
|
||||
if(group.target == GroupTarget.SERVER) {
|
||||
for(let id of this.assignedServerGroupIds())
|
||||
if(id == group.id) return true;
|
||||
groupAssigned(group: Group): boolean {
|
||||
if (group.target == GroupTarget.SERVER) {
|
||||
for (let id of this.assignedServerGroupIds())
|
||||
if (id == group.id) return true;
|
||||
return false;
|
||||
} else return group.id == this.assignedChannelGroup();
|
||||
}
|
||||
|
||||
onDelete() { }
|
||||
|
||||
calculateOnlineTime() : number {
|
||||
calculateOnlineTime(): number {
|
||||
return Date.now() / 1000 - this.properties.client_lastconnected;
|
||||
}
|
||||
|
||||
avatarId?() : string {
|
||||
avatarId?(): string {
|
||||
function str2ab(str) {
|
||||
let buf = new ArrayBuffer(str.length); // 2 bytes for each char
|
||||
let bufView = new Uint8Array(buf);
|
||||
for (let i=0, strLen = str.length; i<strLen; i++) {
|
||||
for (let i = 0, strLen = str.length; i < strLen; i++) {
|
||||
bufView[i] = str.charCodeAt(i);
|
||||
}
|
||||
return buf;
|
||||
|
@ -844,14 +844,14 @@ export class ClientEntry<Events extends ClientEvents = ClientEvents> extends Cha
|
|||
let input = hex.encode(str2ab(raw));
|
||||
|
||||
let result: string = "";
|
||||
for(let index = 0; index < input.length; index++) {
|
||||
for (let index = 0; index < input.length; index++) {
|
||||
let c = input.charAt(index);
|
||||
let offset: number = 0;
|
||||
if(c >= '0' && c <= '9')
|
||||
if (c >= '0' && c <= '9')
|
||||
offset = c.charCodeAt(0) - '0'.charCodeAt(0);
|
||||
else if(c >= 'A' && c <= 'F')
|
||||
else if (c >= 'A' && c <= 'F')
|
||||
offset = c.charCodeAt(0) - 'A'.charCodeAt(0) + 0x0A;
|
||||
else if(c >= 'a' && c <= 'f')
|
||||
else if (c >= 'a' && c <= 'f')
|
||||
offset = c.charCodeAt(0) - 'a'.charCodeAt(0) + 0x0A;
|
||||
result += String.fromCharCode('a'.charCodeAt(0) + offset);
|
||||
}
|
||||
|
@ -861,7 +861,7 @@ export class ClientEntry<Events extends ClientEvents = ClientEvents> extends Cha
|
|||
}
|
||||
}
|
||||
|
||||
log_data() : EventClient {
|
||||
log_data(): EventClient {
|
||||
return {
|
||||
client_unique_id: this.properties.client_unique_identifier,
|
||||
client_name: this.clientNickName(),
|
||||
|
@ -870,11 +870,11 @@ export class ClientEntry<Events extends ClientEvents = ClientEvents> extends Cha
|
|||
}
|
||||
|
||||
/* max 1s ago, so we could update every second */
|
||||
request_connection_info() : Promise<ClientConnectionInfo> {
|
||||
if(Date.now() - 900 < this.promiseConnectionInfoTimestamp && this.promiseConnectionInfo)
|
||||
request_connection_info(): Promise<ClientConnectionInfo> {
|
||||
if (Date.now() - 900 < this.promiseConnectionInfoTimestamp && this.promiseConnectionInfo)
|
||||
return this.promiseConnectionInfo;
|
||||
|
||||
if(this.promiseConnectionInfoReject)
|
||||
if (this.promiseConnectionInfoReject)
|
||||
this.promiseConnectionInfoResolve("timeout");
|
||||
|
||||
let _local_reject; /* to ensure we're using the right resolve! */
|
||||
|
@ -885,12 +885,12 @@ export class ClientEntry<Events extends ClientEvents = ClientEvents> extends Cha
|
|||
});
|
||||
|
||||
this.promiseConnectionInfoTimestamp = Date.now();
|
||||
this.channelTree.client.serverConnection.send_command("getconnectioninfo", {clid: this._clientId}).catch(error => _local_reject(error));
|
||||
this.channelTree.client.serverConnection.send_command("getconnectioninfo", { clid: this._clientId }).catch(error => _local_reject(error));
|
||||
return this.promiseConnectionInfo;
|
||||
}
|
||||
|
||||
set_connection_info(info: ClientConnectionInfo) {
|
||||
if(!this.promiseConnectionInfoResolve)
|
||||
if (!this.promiseConnectionInfoResolve)
|
||||
return;
|
||||
this.promiseConnectionInfoResolve(info);
|
||||
this.promiseConnectionInfoResolve = undefined;
|
||||
|
@ -898,7 +898,7 @@ export class ClientEntry<Events extends ClientEvents = ClientEvents> extends Cha
|
|||
}
|
||||
|
||||
setAudioVolume(value: number) {
|
||||
if(this.voiceVolume == value) {
|
||||
if (this.voiceVolume == value) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -914,10 +914,10 @@ export class ClientEntry<Events extends ClientEvents = ClientEvents> extends Cha
|
|||
return this.voiceVolume;
|
||||
}
|
||||
|
||||
getClientType() : ClientType {
|
||||
if(this.properties.client_type_exact === ClientType.CLIENT_UNDEFINED) {
|
||||
getClientType(): ClientType {
|
||||
if (this.properties.client_type_exact === ClientType.CLIENT_UNDEFINED) {
|
||||
/* We're on a TS3 server */
|
||||
switch(this.properties.client_type) {
|
||||
switch (this.properties.client_type) {
|
||||
case 0:
|
||||
return ClientType.CLIENT_VOICE;
|
||||
|
||||
|
@ -928,7 +928,7 @@ export class ClientEntry<Events extends ClientEvents = ClientEvents> extends Cha
|
|||
return ClientType.CLIENT_UNDEFINED;
|
||||
}
|
||||
} else {
|
||||
switch(this.properties.client_type_exact) {
|
||||
switch (this.properties.client_type_exact as ClientType) {
|
||||
case 0:
|
||||
return ClientType.CLIENT_VOICE;
|
||||
|
||||
|
@ -943,7 +943,7 @@ export class ClientEntry<Events extends ClientEvents = ClientEvents> extends Cha
|
|||
|
||||
case 5:
|
||||
return ClientType.CLIENT_TEASPEAK;
|
||||
|
||||
// @ts-ignore
|
||||
case 2:
|
||||
/* 2 is the internal client type which should never be visible for the target user */
|
||||
default:
|
||||
|
@ -980,12 +980,12 @@ export class LocalClientEntry extends ClientEntry {
|
|||
icon_class: "client-edit",
|
||||
callback: () => {
|
||||
createInputModal(tr("Change own description"), tr("New description:<br>"), () => true, result => {
|
||||
if(result) {
|
||||
if (result) {
|
||||
logInfo(LogCategory.CLIENT, tr("Changing own description to %s"), result);
|
||||
this.channelTree.client.serverConnection.send_command("clientedit", {
|
||||
clid: this.clientId(),
|
||||
client_description: result
|
||||
}).then(() => {});
|
||||
}).then(() => { });
|
||||
|
||||
}
|
||||
}, { width: 400, maxLength: 1024 }).open();
|
||||
|
@ -998,7 +998,7 @@ export class LocalClientEntry extends ClientEntry {
|
|||
);
|
||||
}
|
||||
|
||||
renameSelf(new_name: string) : Promise<boolean> {
|
||||
renameSelf(new_name: string): Promise<boolean> {
|
||||
const old_name = this.properties.client_nickname;
|
||||
this.updateVariables({ key: "client_nickname", value: new_name }); /* change it locally */
|
||||
return this.handle.serverConnection.send_command("clientupdate", { client_nickname: new_name }).then(() => {
|
||||
|
@ -1020,9 +1020,9 @@ export class LocalClientEntry extends ClientEntry {
|
|||
|
||||
openRenameModal() {
|
||||
createInputModal(tr("Enter your new name"), tr("Enter your new client name"), text => text.length >= 3 && text.length <= 30, value => {
|
||||
if(value) {
|
||||
if (value) {
|
||||
this.renameSelf(value as string).then(result => {
|
||||
if(!result) {
|
||||
if (!result) {
|
||||
createErrorModal(tr("Failed change nickname"), tr("Failed to change your client nickname")).open();
|
||||
}
|
||||
});
|
||||
|
@ -1030,7 +1030,7 @@ export class LocalClientEntry extends ClientEntry {
|
|||
}).open();
|
||||
}
|
||||
|
||||
openRename(events: Registry<ChannelTreeUIEvents>) : void {
|
||||
openRename(events: Registry<ChannelTreeUIEvents>): void {
|
||||
events.fire("notify_client_name_edit", { initialValue: this.clientNickName(), treeEntryId: this.uniqueEntryId });
|
||||
}
|
||||
}
|
||||
|
@ -1112,24 +1112,24 @@ export class MusicClientEntry extends ClientEntry<MusicClientEvents> {
|
|||
this._info_promise_resolve = undefined;
|
||||
}
|
||||
|
||||
get properties() : MusicClientProperties {
|
||||
get properties(): MusicClientProperties {
|
||||
return this._properties as MusicClientProperties;
|
||||
}
|
||||
|
||||
isSubscribed() : boolean {
|
||||
isSubscribed(): boolean {
|
||||
return this.subscribed;
|
||||
}
|
||||
|
||||
async subscribe() : Promise<void> {
|
||||
if(this.subscribed) {
|
||||
async subscribe(): Promise<void> {
|
||||
if (this.subscribed) {
|
||||
return;
|
||||
}
|
||||
|
||||
await this.channelTree.client.serverConnection.send_command("musicbotsetsubscription", { bot_id: this.properties.client_database_id });
|
||||
|
||||
this.channelTree.clients.forEach(client => {
|
||||
if(client instanceof MusicClientEntry) {
|
||||
if(client.subscribed) {
|
||||
if (client instanceof MusicClientEntry) {
|
||||
if (client.subscribed) {
|
||||
client.subscribed = false;
|
||||
client.events.fire("notify_subscribe_state_changed", { subscribed: false });
|
||||
}
|
||||
|
@ -1151,11 +1151,11 @@ export class MusicClientEntry extends ClientEntry<MusicClientEvents> {
|
|||
disabled: false,
|
||||
callback: () => {
|
||||
createInputModal(tr("Change music bots nickname"), tr("New nickname:<br>"), text => text.length >= 3 && text.length <= 31, result => {
|
||||
if(result) {
|
||||
if (result) {
|
||||
this.channelTree.client.serverConnection.send_command("clientedit", {
|
||||
clid: this.clientId(),
|
||||
client_nickname: result
|
||||
}).then(() => {});
|
||||
}).then(() => { });
|
||||
}
|
||||
}, { width: "40em", min_width: "10em", maxLength: 255 }).open();
|
||||
},
|
||||
|
@ -1166,11 +1166,11 @@ export class MusicClientEntry extends ClientEntry<MusicClientEvents> {
|
|||
disabled: false,
|
||||
callback: () => {
|
||||
createInputModal(tr("Change music bots description"), tr("New description:<br>"), () => true, result => {
|
||||
if(typeof(result) === 'string') {
|
||||
if (typeof (result) === 'string') {
|
||||
this.channelTree.client.serverConnection.send_command("clientedit", {
|
||||
clid: this.clientId(),
|
||||
client_description: result
|
||||
}).then(() => {});
|
||||
}).then(() => { });
|
||||
}
|
||||
}, { width: "60em", min_width: "10em", maxLength: 255 }).open();
|
||||
},
|
||||
|
@ -1191,13 +1191,13 @@ export class MusicClientEntry extends ClientEntry<MusicClientEvents> {
|
|||
disabled: false,
|
||||
callback: () => {
|
||||
createInputModal(tr("Please enter the URL"), tr("URL:"), () => true, result => {
|
||||
if(result) {
|
||||
if (result) {
|
||||
this.channelTree.client.serverConnection.send_command("musicbotqueueadd", {
|
||||
bot_id: this.properties.client_database_id,
|
||||
type: "yt", //Its a hint not a force!
|
||||
url: result
|
||||
}).catch(error => {
|
||||
if(error instanceof CommandResult) {
|
||||
if (error instanceof CommandResult) {
|
||||
error = error.extra_message || error.message;
|
||||
}
|
||||
//TODO tr
|
||||
|
@ -1210,7 +1210,7 @@ export class MusicClientEntry extends ClientEntry<MusicClientEvents> {
|
|||
},
|
||||
contextmenu.Entry.HR(),
|
||||
...super.assignment_context(),
|
||||
contextmenu.Entry.HR(),{
|
||||
contextmenu.Entry.HR(), {
|
||||
type: contextmenu.MenuEntryType.ENTRY,
|
||||
icon_class: "client-move_client_to_own_channel",
|
||||
name: tr("Move client to your channel"),
|
||||
|
@ -1218,7 +1218,7 @@ export class MusicClientEntry extends ClientEntry<MusicClientEvents> {
|
|||
this.channelTree.client.serverConnection.send_command("clientmove", {
|
||||
clid: this.clientId(),
|
||||
cid: this.channelTree.client.getClient().currentChannel().getChannelId()
|
||||
}).then(() => {});
|
||||
}).then(() => { });
|
||||
}
|
||||
}, {
|
||||
type: contextmenu.MenuEntryType.ENTRY,
|
||||
|
@ -1226,13 +1226,13 @@ export class MusicClientEntry extends ClientEntry<MusicClientEvents> {
|
|||
name: tr("Kick client from channel"),
|
||||
callback: () => {
|
||||
createInputModal(tr("Kick client from channel"), tr("Kick reason:<br>"), () => true, result => {
|
||||
if(typeof(result) !== 'boolean' || result) {
|
||||
if (typeof (result) !== 'boolean' || result) {
|
||||
logInfo(LogCategory.CLIENT, tr("Kicking client %o from channel with reason %o"), this.clientNickName(), result);
|
||||
this.channelTree.client.serverConnection.send_command("clientkick", {
|
||||
clid: this.clientId(),
|
||||
reasonid: ViewReasonId.VREASON_CHANNEL_KICK,
|
||||
reasonmsg: result
|
||||
}).then(() => {});
|
||||
}).then(() => { });
|
||||
}
|
||||
}, { width: 400, maxLength: 255 }).open();
|
||||
}
|
||||
|
@ -1250,7 +1250,7 @@ export class MusicClientEntry extends ClientEntry<MusicClientEvents> {
|
|||
name: tr("Change remote volume"),
|
||||
callback: () => {
|
||||
let max_volume = this.channelTree.client.permissions.neededPermission(PermissionType.I_CLIENT_MUSIC_CREATE_MODIFY_MAX_VOLUME).value;
|
||||
if(max_volume < 0) {
|
||||
if (max_volume < 0) {
|
||||
max_volume = 100;
|
||||
}
|
||||
|
||||
|
@ -1278,13 +1278,13 @@ export class MusicClientEntry extends ClientEntry<MusicClientEvents> {
|
|||
title: tr("Are you sure?"),
|
||||
question: tra("Do you really want to delete {0}", this.clientNickName())
|
||||
}).then(result => {
|
||||
if(!result) {
|
||||
if (!result) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.channelTree.client.serverConnection.send_command("musicbotdelete", {
|
||||
bot_id: this.properties.client_database_id
|
||||
}).then(() => {});
|
||||
}).then(() => { });
|
||||
});
|
||||
},
|
||||
type: contextmenu.MenuEntryType.ENTRY
|
||||
|
@ -1294,25 +1294,25 @@ export class MusicClientEntry extends ClientEntry<MusicClientEvents> {
|
|||
}
|
||||
|
||||
handlePlayerInfo(json) {
|
||||
if(json) {
|
||||
if (json) {
|
||||
const info = new MusicClientPlayerInfo();
|
||||
JSON.map_to(info, json);
|
||||
if(this._info_promise_resolve)
|
||||
if (this._info_promise_resolve)
|
||||
this._info_promise_resolve(info);
|
||||
this._info_promise_reject = undefined;
|
||||
this._info_promise_resolve = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
requestPlayerInfo(max_age: number = 1000) : Promise<MusicClientPlayerInfo> {
|
||||
if(this._info_promise !== undefined && this._info_promise_age > 0 && Date.now() - max_age <= this._info_promise_age) return this._info_promise;
|
||||
requestPlayerInfo(max_age: number = 1000): Promise<MusicClientPlayerInfo> {
|
||||
if (this._info_promise !== undefined && this._info_promise_age > 0 && Date.now() - max_age <= this._info_promise_age) return this._info_promise;
|
||||
this._info_promise_age = Date.now();
|
||||
this._info_promise = new Promise<MusicClientPlayerInfo>((resolve, reject) => {
|
||||
this._info_promise_reject = reject;
|
||||
this._info_promise_resolve = resolve;
|
||||
});
|
||||
|
||||
this.channelTree.client.serverConnection.send_command("musicbotplayerinfo", {bot_id: this.properties.client_database_id }).then(() => {});
|
||||
this.channelTree.client.serverConnection.send_command("musicbotplayerinfo", { bot_id: this.properties.client_database_id }).then(() => { });
|
||||
return this._info_promise;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,25 +1,25 @@
|
|||
import {Registry} from "tc-shared/events";
|
||||
import { Registry } from "tc-shared/events";
|
||||
import {
|
||||
ConnectUiEvents,
|
||||
ConnectUiVariables,
|
||||
} from "tc-shared/ui/modal/connect/Definitions";
|
||||
import {LogCategory, logError, logWarn} from "tc-shared/log";
|
||||
import { LogCategory, logError, logWarn } from "tc-shared/log";
|
||||
import {
|
||||
availableConnectProfiles,
|
||||
ConnectionProfile,
|
||||
defaultConnectProfile,
|
||||
findConnectProfile
|
||||
} from "tc-shared/profiles/ConnectionProfile";
|
||||
import {Settings, settings} from "tc-shared/settings";
|
||||
import {connectionHistory, ConnectionHistoryEntry} from "tc-shared/connectionlog/History";
|
||||
import {createErrorModal} from "tc-shared/ui/elements/Modal";
|
||||
import {ConnectionHandler} from "tc-shared/ConnectionHandler";
|
||||
import {server_connections} from "tc-shared/ConnectionManager";
|
||||
import {parseServerAddress} from "tc-shared/tree/Server";
|
||||
import {spawnSettingsModal} from "tc-shared/ui/modal/ModalSettings";
|
||||
import {UiVariableProvider} from "tc-shared/ui/utils/Variable";
|
||||
import {createIpcUiVariableProvider} from "tc-shared/ui/utils/IpcVariable";
|
||||
import {spawnModal} from "tc-shared/ui/react-elements/modal";
|
||||
import { Settings, settings } from "tc-shared/settings";
|
||||
import { connectionHistory, ConnectionHistoryEntry } from "tc-shared/connectionlog/History";
|
||||
import { createErrorModal } from "tc-shared/ui/elements/Modal";
|
||||
import { ConnectionHandler } from "tc-shared/ConnectionHandler";
|
||||
import { server_connections } from "tc-shared/ConnectionManager";
|
||||
import { parseServerAddress } from "tc-shared/tree/Server";
|
||||
import { spawnSettingsModal } from "tc-shared/ui/modal/ModalSettings";
|
||||
import { UiVariableProvider } from "tc-shared/ui/utils/Variable";
|
||||
import { createIpcUiVariableProvider } from "tc-shared/ui/utils/IpcVariable";
|
||||
import { spawnModal } from "tc-shared/ui/react-elements/modal";
|
||||
import ipRegex from "ip-regex";
|
||||
|
||||
const kRegexDomain = /^(localhost|((([a-zA-Z0-9_-]{0,63}\.){0,253})?[a-zA-Z0-9_-]{0,63}\.[a-zA-Z]{2,64}))$/i;
|
||||
|
@ -61,7 +61,8 @@ class ConnectController {
|
|||
private validateNickname: boolean;
|
||||
private validateAddress: boolean;
|
||||
|
||||
constructor(uiVariables: UiVariableProvider<ConnectUiVariables>) {7
|
||||
constructor(uiVariables: UiVariableProvider<ConnectUiVariables>) {
|
||||
7
|
||||
this.uiEvents = new Registry<ConnectUiEvents>();
|
||||
this.uiEvents.enableDebug("modal-connect");
|
||||
|
||||
|
@ -71,7 +72,7 @@ class ConnectController {
|
|||
this.validateNickname = false;
|
||||
this.validateAddress = false;
|
||||
|
||||
this.defaultAddress = "ts.teaspeak.de";
|
||||
this.defaultAddress = "tea.lp.kle.li";
|
||||
this.historyShown = settings.getValue(Settings.KEY_CONNECT_SHOW_HISTORY);
|
||||
|
||||
this.currentAddress = settings.getValue(Settings.KEY_CONNECT_ADDRESS);
|
||||
|
@ -109,11 +110,11 @@ class ConnectController {
|
|||
}));
|
||||
|
||||
this.uiVariables.setVariableProvider("server_address_valid", () => {
|
||||
if(this.validateAddress) {
|
||||
if (this.validateAddress) {
|
||||
const address = this.currentAddress || this.defaultAddress || "";
|
||||
const parsedAddress = parseServerAddress(address);
|
||||
|
||||
if(parsedAddress) {
|
||||
if (parsedAddress) {
|
||||
kRegexDomain.lastIndex = 0;
|
||||
return kRegexDomain.test(parsedAddress.host) || ipRegex({ exact: true }).test(parsedAddress.host);
|
||||
} else {
|
||||
|
@ -125,7 +126,7 @@ class ConnectController {
|
|||
});
|
||||
|
||||
this.uiVariables.setVariableEditor("server_address", newValue => {
|
||||
if(this.currentAddress === newValue.currentAddress) {
|
||||
if (this.currentAddress === newValue.currentAddress) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -139,7 +140,7 @@ class ConnectController {
|
|||
}));
|
||||
|
||||
this.uiVariables.setVariableProvider("nickname_valid", () => {
|
||||
if(this.validateNickname) {
|
||||
if (this.validateNickname) {
|
||||
const nickname = this.currentNickname || this.currentProfile?.connectUsername() || "";
|
||||
return nickname.length >= 3 && nickname.length <= 30;
|
||||
} else {
|
||||
|
@ -148,7 +149,7 @@ class ConnectController {
|
|||
});
|
||||
|
||||
this.uiVariables.setVariableEditor("nickname", newValue => {
|
||||
if(this.currentNickname === newValue.currentNickname) {
|
||||
if (this.currentNickname === newValue.currentNickname) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -166,7 +167,7 @@ class ConnectController {
|
|||
}));
|
||||
|
||||
this.uiVariables.setVariableEditor("password", newValue => {
|
||||
if(this.currentPassword === newValue.password) {
|
||||
if (this.currentPassword === newValue.password) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -179,7 +180,7 @@ class ConnectController {
|
|||
|
||||
this.uiVariables.setVariableProvider("historyShown", () => this.historyShown);
|
||||
this.uiVariables.setVariableEditor("historyShown", newValue => {
|
||||
if(this.historyShown === newValue) {
|
||||
if (this.historyShown === newValue) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -188,8 +189,8 @@ class ConnectController {
|
|||
return true;
|
||||
});
|
||||
|
||||
this.uiVariables.setVariableProvider("history",async () => {
|
||||
if(!this.history) {
|
||||
this.uiVariables.setVariableProvider("history", async () => {
|
||||
if (!this.history) {
|
||||
this.history = await connectionHistory.lastConnectedServers(10);
|
||||
}
|
||||
|
||||
|
@ -237,7 +238,7 @@ class ConnectController {
|
|||
|
||||
this.uiVariables.setVariableEditor("profiles", newValue => {
|
||||
const profile = findConnectProfile(newValue.selected);
|
||||
if(!profile) {
|
||||
if (!profile) {
|
||||
createErrorModal(tr("Invalid profile"), tr("Target connect profile is missing.")).open();
|
||||
return false;
|
||||
}
|
||||
|
@ -252,16 +253,16 @@ class ConnectController {
|
|||
this.uiVariables.destroy();
|
||||
}
|
||||
|
||||
generateConnectParameters() : ConnectParameters | undefined {
|
||||
if(!this.uiVariables.getVariableSync("nickname_valid", undefined, true)) {
|
||||
generateConnectParameters(): ConnectParameters | undefined {
|
||||
if (!this.uiVariables.getVariableSync("nickname_valid", undefined, true)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if(!this.uiVariables.getVariableSync("server_address_valid", undefined, true)) {
|
||||
if (!this.uiVariables.getVariableSync("server_address_valid", undefined, true)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if(!this.uiVariables.getVariableSync("profile_valid", undefined, true)) {
|
||||
if (!this.uiVariables.getVariableSync("profile_valid", undefined, true)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
@ -279,7 +280,7 @@ class ConnectController {
|
|||
}
|
||||
|
||||
setSelectedHistoryId(id: number | -1) {
|
||||
if(this.selectedHistoryId === id) {
|
||||
if (this.selectedHistoryId === id) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -287,7 +288,7 @@ class ConnectController {
|
|||
this.uiVariables.sendVariable("history");
|
||||
|
||||
const historyEntry = this.history?.find(entry => entry.id === id);
|
||||
if(!historyEntry) { return; }
|
||||
if (!historyEntry) { return; }
|
||||
|
||||
this.currentAddress = historyEntry.targetAddress;
|
||||
this.currentNickname = historyEntry.nickname;
|
||||
|
@ -300,12 +301,12 @@ class ConnectController {
|
|||
}
|
||||
|
||||
setSelectedAddress(address: string | undefined, validate: boolean, updateUi: boolean) {
|
||||
if(this.currentAddress !== address) {
|
||||
if (this.currentAddress !== address) {
|
||||
this.currentAddress = address;
|
||||
settings.setValue(Settings.KEY_CONNECT_ADDRESS, address);
|
||||
this.setSelectedHistoryId(-1);
|
||||
|
||||
if(updateUi) {
|
||||
if (updateUi) {
|
||||
this.uiVariables.sendVariable("server_address");
|
||||
}
|
||||
}
|
||||
|
@ -315,7 +316,7 @@ class ConnectController {
|
|||
}
|
||||
|
||||
setSelectedProfile(profile: ConnectionProfile | undefined) {
|
||||
if(this.currentProfile === profile) {
|
||||
if (this.currentProfile === profile) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -347,11 +348,11 @@ export function spawnConnectModalNew(options: ConnectModalOptions) {
|
|||
const variableProvider = createIpcUiVariableProvider();
|
||||
const controller = new ConnectController(variableProvider);
|
||||
|
||||
if(typeof options.selectedAddress === "string") {
|
||||
if (typeof options.selectedAddress === "string") {
|
||||
controller.setSelectedAddress(options.selectedAddress, false, true);
|
||||
}
|
||||
|
||||
if(typeof options.selectedProfile === "object") {
|
||||
if (typeof options.selectedProfile === "object") {
|
||||
controller.setSelectedProfile(options.selectedProfile);
|
||||
}
|
||||
|
||||
|
@ -363,7 +364,7 @@ export function spawnConnectModalNew(options: ConnectModalOptions) {
|
|||
|
||||
controller.uiEvents.on("action_connect", event => {
|
||||
const parameters = controller.generateConnectParameters();
|
||||
if(!parameters) {
|
||||
if (!parameters) {
|
||||
/* invalid parameters detected */
|
||||
return;
|
||||
}
|
||||
|
@ -371,14 +372,14 @@ export function spawnConnectModalNew(options: ConnectModalOptions) {
|
|||
modal.destroy();
|
||||
|
||||
let connection: ConnectionHandler;
|
||||
if(event.newTab) {
|
||||
if (event.newTab) {
|
||||
connection = server_connections.spawnConnectionHandler();
|
||||
server_connections.setActiveConnectionHandler(connection);
|
||||
} else {
|
||||
connection = server_connections.getActiveConnectionHandler();
|
||||
}
|
||||
|
||||
if(!connection) {
|
||||
if (!connection) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,14 +1,16 @@
|
|||
import * as React from "react";
|
||||
import {useEffect, useRef, useState} from "react";
|
||||
import {Registry} from "tc-shared/events";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { Registry } from "tc-shared/events";
|
||||
|
||||
import { settings, Settings } from "tc-shared/settings";
|
||||
import { Translatable } from "tc-shared/ui/react-elements/i18n";
|
||||
|
||||
import Picker from '@emoji-mart/react'
|
||||
import data from '@emoji-mart/data'
|
||||
import { Emoji, init } from "emoji-mart";
|
||||
|
||||
init({ data })
|
||||
|
||||
import '!style-loader!css-loader!emoji-mart/css/emoji-mart.css'
|
||||
import {Picker, emojiIndex} from 'emoji-mart'
|
||||
import {settings, Settings} from "tc-shared/settings";
|
||||
import {Translatable} from "tc-shared/ui/react-elements/i18n";
|
||||
import {getTwenmojiHashFromNativeEmoji} from "tc-shared/text/bbcode/EmojiUtil";
|
||||
import {BaseEmoji} from "emoji-mart";
|
||||
import {useGlobalSetting} from "tc-shared/ui/react-elements/Helper";
|
||||
|
||||
const cssStyle = require("./ChatBox.scss");
|
||||
|
||||
|
@ -28,34 +30,26 @@ interface ChatBoxEvents {
|
|||
}
|
||||
|
||||
const LastUsedEmoji = () => {
|
||||
const settingValue = useGlobalSetting(Settings.KEY_CHAT_LAST_USED_EMOJI);
|
||||
const lastEmoji: BaseEmoji = (emojiIndex.emojis[settingValue] || emojiIndex.emojis["joy"]) as any;
|
||||
if(!lastEmoji?.native) {
|
||||
return <img key={"fallback"} alt={""} src={"img/smiley-smile.svg"} />;
|
||||
}
|
||||
|
||||
return (
|
||||
<img draggable={false} src={"https://twemoji.maxcdn.com/v/12.1.2/72x72/" + getTwenmojiHashFromNativeEmoji(lastEmoji.native) + ".png"} alt={lastEmoji.native} className={cssStyle.emoji} />
|
||||
)
|
||||
return <img key={"fallback"} alt={""} src={"img/smiley.png"} />;
|
||||
}
|
||||
|
||||
const EmojiButton = (props: { events: Registry<ChatBoxEvents> }) => {
|
||||
const [ shown, setShown ] = useState(false);
|
||||
const [ enabled, setEnabled ] = useState(false);
|
||||
const [shown, setShown] = useState(false);
|
||||
const [enabled, setEnabled] = useState(false);
|
||||
|
||||
const refContainer = useRef();
|
||||
|
||||
useEffect(() => {
|
||||
if(!shown) {
|
||||
if (!shown) {
|
||||
return;
|
||||
}
|
||||
|
||||
const clickListener = (event: MouseEvent) => {
|
||||
let target = event.target as HTMLElement;
|
||||
while(target && target !== refContainer.current)
|
||||
while (target && target !== refContainer.current)
|
||||
target = target.parentElement;
|
||||
|
||||
if(target === refContainer.current && target)
|
||||
if (target === refContainer.current && target)
|
||||
return;
|
||||
|
||||
setShown(false);
|
||||
|
@ -76,22 +70,21 @@ const EmojiButton = (props: { events: Registry<ChatBoxEvents> }) => {
|
|||
<div className={cssStyle.picker} style={{ display: shown ? undefined : "none" }}>
|
||||
{!shown ? undefined :
|
||||
<Picker
|
||||
data={data}
|
||||
key={"picker"}
|
||||
set={"twitter"}
|
||||
theme={"light"}
|
||||
set={"native"}
|
||||
noCountryFlags={true}
|
||||
showPreview={true}
|
||||
title={""}
|
||||
showSkinTones={true}
|
||||
useButton={false}
|
||||
native={false}
|
||||
skinTonePosition={"none"}
|
||||
|
||||
onSelect={(emoji: any) => {
|
||||
if(enabled) {
|
||||
settings.setValue(Settings.KEY_CHAT_LAST_USED_EMOJI, emoji.id as string);
|
||||
onEmojiSelect={(emoji: any) => {
|
||||
if (enabled) {
|
||||
props.events.fire("action_insert_text", { text: emoji.native, focus: true });
|
||||
}
|
||||
}}
|
||||
/>
|
||||
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
@ -101,27 +94,27 @@ const EmojiButton = (props: { events: Registry<ChatBoxEvents> }) => {
|
|||
const pasteTextTransformElement = document.createElement("div");
|
||||
|
||||
const nodeToText = (element: Node) => {
|
||||
if(element instanceof Text) {
|
||||
if (element instanceof Text) {
|
||||
return element.textContent;
|
||||
} else if(element instanceof HTMLElement) {
|
||||
if(element instanceof HTMLImageElement) {
|
||||
} else if (element instanceof HTMLElement) {
|
||||
if (element instanceof HTMLImageElement) {
|
||||
return element.alt || element.title;
|
||||
} else if(element instanceof HTMLBRElement) {
|
||||
} else if (element instanceof HTMLBRElement) {
|
||||
return '\n';
|
||||
} else if(element instanceof HTMLAnchorElement) {
|
||||
} else if (element instanceof HTMLAnchorElement) {
|
||||
const content = [...element.childNodes].map(nodeToText).join("");
|
||||
|
||||
if(element.href) {
|
||||
if(settings.getValue(Settings.KEY_CHAT_ENABLE_MARKDOWN)) {
|
||||
if(content && element.title) {
|
||||
if (element.href) {
|
||||
if (settings.getValue(Settings.KEY_CHAT_ENABLE_MARKDOWN)) {
|
||||
if (content && element.title) {
|
||||
return `[${content}](${element.href} "${element.title}")`;
|
||||
} else if(content) {
|
||||
} else if (content) {
|
||||
return `[${content}](${element.href})`;
|
||||
} else {
|
||||
return `[${element.href}](${element.href})`;
|
||||
}
|
||||
} else if(settings.getValue(Settings.KEY_CHAT_ENABLE_BBCODE)) {
|
||||
if(content) {
|
||||
} else if (settings.getValue(Settings.KEY_CHAT_ENABLE_BBCODE)) {
|
||||
if (content) {
|
||||
return `[url=${element.href}]${content}"[/url]`;
|
||||
} else {
|
||||
return `[url]${element.href}"[/url]`;
|
||||
|
@ -134,11 +127,11 @@ const nodeToText = (element: Node) => {
|
|||
}
|
||||
}
|
||||
|
||||
if(element.children.length > 0) {
|
||||
if (element.children.length > 0) {
|
||||
return [...element.childNodes].map(nodeToText).join("");
|
||||
}
|
||||
|
||||
return typeof(element.innerText) === "string" ? element.innerText : "";
|
||||
return typeof (element.innerText) === "string" ? element.innerText : "";
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
|
@ -151,14 +144,14 @@ const htmlEscape = (message: string) => {
|
|||
};
|
||||
|
||||
const TextInput = (props: { events: Registry<ChatBoxEvents>, enabled?: boolean, placeholder?: string }) => {
|
||||
const [ enabled, setEnabled ] = useState(!!props.enabled);
|
||||
const [ historyIndex, setHistoryIndex ] = useState(-1);
|
||||
const [enabled, setEnabled] = useState(!!props.enabled);
|
||||
const [historyIndex, setHistoryIndex] = useState(-1);
|
||||
const history = useRef([]);
|
||||
const refInput = useRef<HTMLInputElement>();
|
||||
const typingTimeout = useRef(undefined);
|
||||
|
||||
const triggerTyping = () => {
|
||||
if(typeof typingTimeout.current === "number")
|
||||
if (typeof typingTimeout.current === "number")
|
||||
return;
|
||||
|
||||
props.events.fire("notify_typing");
|
||||
|
@ -182,7 +175,7 @@ const TextInput = (props: { events: Registry<ChatBoxEvents>, enabled?: boolean,
|
|||
event.preventDefault();
|
||||
|
||||
const clipboard = event.clipboardData || (window as any).clipboardData;
|
||||
if(!clipboard) return;
|
||||
if (!clipboard) return;
|
||||
|
||||
const rawText = clipboard.getData('text/plain');
|
||||
const selection = window.getSelection();
|
||||
|
@ -191,7 +184,7 @@ const TextInput = (props: { events: Registry<ChatBoxEvents>, enabled?: boolean,
|
|||
}
|
||||
|
||||
let htmlXML = clipboard.getData('text/html');
|
||||
if(!htmlXML) {
|
||||
if (!htmlXML) {
|
||||
pasteTextTransformElement.textContent = rawText;
|
||||
htmlXML = pasteTextTransformElement.innerHTML;
|
||||
}
|
||||
|
@ -235,33 +228,33 @@ const TextInput = (props: { events: Registry<ChatBoxEvents>, enabled?: boolean,
|
|||
triggerTyping();
|
||||
|
||||
const inputEmpty = refInput.current.innerText.trim().length === 0;
|
||||
if(event.key === "Enter" && !event.shiftKey) {
|
||||
if(inputEmpty) {
|
||||
if (event.key === "Enter" && !event.shiftKey) {
|
||||
if (inputEmpty) {
|
||||
return;
|
||||
}
|
||||
|
||||
const text = refInput.current.innerText;
|
||||
props.events.fire("action_submit_message", { message: text });
|
||||
history.current.push(text);
|
||||
while(history.current.length > 10) {
|
||||
while (history.current.length > 10) {
|
||||
history.current.pop_front();
|
||||
}
|
||||
|
||||
refInput.current.innerText = "";
|
||||
setHistoryIndex(-1);
|
||||
event.preventDefault();
|
||||
} else if(event.key === "ArrowUp") {
|
||||
} else if (event.key === "ArrowUp") {
|
||||
const inputOriginal = history.current[historyIndex] === refInput.current.innerText;
|
||||
if(inputEmpty && (historyIndex === -1 || !inputOriginal)) {
|
||||
if (inputEmpty && (historyIndex === -1 || !inputOriginal)) {
|
||||
setHistory(history.current.length - 1);
|
||||
event.preventDefault();
|
||||
} else if(historyIndex > 0 && inputOriginal) {
|
||||
} else if (historyIndex > 0 && inputOriginal) {
|
||||
setHistory(historyIndex - 1);
|
||||
event.preventDefault();
|
||||
}
|
||||
} else if(event.key === "ArrowDown") {
|
||||
if(history.current[historyIndex] === refInput.current.innerText) {
|
||||
if(historyIndex < history.current.length - 1) {
|
||||
} else if (event.key === "ArrowDown") {
|
||||
if (history.current[historyIndex] === refInput.current.innerText) {
|
||||
if (historyIndex < history.current.length - 1) {
|
||||
setHistory(historyIndex + 1);
|
||||
} else {
|
||||
setHistory(-1);
|
||||
|
@ -273,7 +266,7 @@ const TextInput = (props: { events: Registry<ChatBoxEvents>, enabled?: boolean,
|
|||
|
||||
props.events.reactUse("action_request_focus", () => refInput.current?.focus());
|
||||
props.events.reactUse("notify_typing", () => {
|
||||
if(typeof typingTimeout.current === "number") {
|
||||
if (typeof typingTimeout.current === "number") {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -281,15 +274,15 @@ const TextInput = (props: { events: Registry<ChatBoxEvents>, enabled?: boolean,
|
|||
});
|
||||
props.events.reactUse("action_insert_text", event => {
|
||||
refInput.current.innerHTML = refInput.current.innerHTML + event.text;
|
||||
if(event.focus) {
|
||||
if (event.focus) {
|
||||
refInput.current.focus();
|
||||
}
|
||||
});
|
||||
props.events.reactUse("action_set_enabled", event => {
|
||||
setEnabled(event.enabled);
|
||||
if(!event.enabled) {
|
||||
if (!event.enabled) {
|
||||
const text = refInput.current.innerText;
|
||||
if(text.trim().length !== 0)
|
||||
if (text.trim().length !== 0)
|
||||
history.current.push(text);
|
||||
refInput.current.innerText = "";
|
||||
}
|
||||
|
@ -324,17 +317,17 @@ export interface ChatBoxState {
|
|||
}
|
||||
|
||||
const MarkdownFormatHelper = () => {
|
||||
const [ visible, setVisible ] = useState(settings.getValue(Settings.KEY_CHAT_ENABLE_MARKDOWN));
|
||||
const [visible, setVisible] = useState(settings.getValue(Settings.KEY_CHAT_ENABLE_MARKDOWN));
|
||||
|
||||
settings.events.reactUse("notify_setting_changed", event => {
|
||||
if(event.setting !== Settings.KEY_CHAT_ENABLE_MARKDOWN.key) {
|
||||
if (event.setting !== Settings.KEY_CHAT_ENABLE_MARKDOWN.key) {
|
||||
return;
|
||||
}
|
||||
|
||||
setVisible(settings.getValue(Settings.KEY_CHAT_ENABLE_MARKDOWN));
|
||||
});
|
||||
|
||||
if(visible) {
|
||||
if (visible) {
|
||||
return (
|
||||
<div key={"help"} className={cssStyle.containerHelp}>*italic*, **bold**, ~~strikethrough~~, `code`, <Translatable>and more</Translatable>...</div>
|
||||
);
|
||||
|
@ -380,7 +373,7 @@ export class ChatBox extends React.Component<ChatBoxProperties, ChatBoxState> {
|
|||
}
|
||||
|
||||
componentDidUpdate(prevProps: Readonly<ChatBoxProperties>, prevState: Readonly<ChatBoxState>, snapshot?: any): void {
|
||||
if(prevState.enabled !== this.state.enabled) {
|
||||
if (prevState.enabled !== this.state.enabled) {
|
||||
this.events.fire_react("action_set_enabled", { enabled: this.state.enabled });
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -8,14 +8,27 @@
|
|||
"declaration": true,
|
||||
"emitDeclarationOnly": true,
|
||||
"esModuleInterop": true,
|
||||
"skipLibCheck": true,
|
||||
"baseUrl": "../../",
|
||||
"paths": {
|
||||
"tc-shared/*": ["shared/js/*"],
|
||||
"tc-loader": ["loader/exports/loader.d.ts"],
|
||||
"svg-sprites/*": ["shared/svg-sprites/*"],
|
||||
"vendor/xbbcode/*": ["vendor/xbbcode/src/*"],
|
||||
"tc-events": ["vendor/TeaEventBus/src/index.ts"],
|
||||
"tc-services": ["vendor/TeaClientServices/src/index.ts"]
|
||||
"tc-shared/*": [
|
||||
"shared/js/*"
|
||||
],
|
||||
"tc-loader": [
|
||||
"loader/exports/loader.d.ts"
|
||||
],
|
||||
"svg-sprites/*": [
|
||||
"shared/svg-sprites/*"
|
||||
],
|
||||
"vendor/xbbcode/*": [
|
||||
"vendor/xbbcode/src/*"
|
||||
],
|
||||
"tc-events": [
|
||||
"vendor/TeaEventBus/src/index.ts"
|
||||
],
|
||||
"tc-services": [
|
||||
"vendor/TeaClientServices/src/index.ts"
|
||||
]
|
||||
}
|
||||
},
|
||||
"exclude": [
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
"sourceMap": true,
|
||||
"experimentalDecorators": true,
|
||||
"esModuleInterop": true,
|
||||
"skipLibCheck": true,
|
||||
"plugins": [ /* ttypescript */
|
||||
{
|
||||
"transform": "../../tools/trgen/ttsc_transformer.js",
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"baseUrl": ".",
|
||||
"skipLibCheck": true,
|
||||
"moduleResolution": "node",
|
||||
"module": "commonjs",
|
||||
"lib": ["es6"],
|
||||
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"typeRoots": [],
|
||||
"types": [],
|
||||
|
||||
"esModuleInterop": true
|
||||
},
|
||||
"files": [
|
||||
|
|
|
@ -4,20 +4,21 @@
|
|||
"target": "es6",
|
||||
"module": "commonjs",
|
||||
"sourceMap": true,
|
||||
"lib": ["es6", "dom"],
|
||||
"lib": [
|
||||
"es6",
|
||||
"dom"
|
||||
],
|
||||
"removeComments": false,
|
||||
"esModuleInterop": true
|
||||
"esModuleInterop": true,
|
||||
"skipLibCheck": true
|
||||
},
|
||||
"include": [
|
||||
"webpack.config.ts",
|
||||
"webpack-client.config.ts",
|
||||
"webpack-web.config.ts",
|
||||
|
||||
"webpack/build-definitions.d.ts",
|
||||
"webpack/HtmlWebpackInlineSource.ts",
|
||||
"webpack/WatLoader.ts",
|
||||
"webpack/ManifestPlugin.ts",
|
||||
|
||||
"babel.config.ts",
|
||||
"postcss.config.ts",
|
||||
"file.ts"
|
||||
|
|
|
@ -5,19 +5,35 @@
|
|||
"target": "es6",
|
||||
"module": "commonjs",
|
||||
"sourceMap": true,
|
||||
"lib": ["ES7", "dom", "dom.iterable"],
|
||||
"lib": [
|
||||
"ES7",
|
||||
"dom",
|
||||
"dom.iterable"
|
||||
],
|
||||
"removeComments": true, /* we dont really need them within the target files */
|
||||
"jsx": "react",
|
||||
"esModuleInterop": true,
|
||||
"baseUrl": ".",
|
||||
"skipLibCheck": true,
|
||||
"paths": {
|
||||
"tc-shared/*": ["shared/js/*"],
|
||||
"tc-loader": ["loader/exports/loader.d.ts"],
|
||||
"tc-events": ["vendor/TeaEventBus/src/index.ts"],
|
||||
"tc-services": ["vendor/TeaClientServices/src/index.ts"],
|
||||
|
||||
"svg-sprites/*": ["shared/svg-sprites/*"],
|
||||
"vendor/xbbcode/*": ["vendor/xbbcode/src/*"]
|
||||
"tc-shared/*": [
|
||||
"shared/js/*"
|
||||
],
|
||||
"tc-loader": [
|
||||
"loader/exports/loader.d.ts"
|
||||
],
|
||||
"tc-events": [
|
||||
"vendor/TeaEventBus/src/index.ts"
|
||||
],
|
||||
"tc-services": [
|
||||
"vendor/TeaClientServices/src/index.ts"
|
||||
],
|
||||
"svg-sprites/*": [
|
||||
"shared/svg-sprites/*"
|
||||
],
|
||||
"vendor/xbbcode/*": [
|
||||
"vendor/xbbcode/src/*"
|
||||
]
|
||||
}
|
||||
},
|
||||
"exclude": [
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import {LogCategory, logError, logTrace, logWarn} from "tc-shared/log";
|
||||
import {tr} from "tc-shared/i18n/localize";
|
||||
import {default_options, DNSAddress, DNSResolveResult, ResolveOptions} from "tc-shared/dns";
|
||||
import {executeDnsRequest, RRType} from "./api";
|
||||
import { LogCategory, logError, logTrace, logWarn } from "tc-shared/log";
|
||||
import { tr } from "tc-shared/i18n/localize";
|
||||
import { default_options, DNSAddress, DNSResolveResult, ResolveOptions } from "tc-shared/dns";
|
||||
import { executeDnsRequest, RRType } from "./api";
|
||||
|
||||
interface DNSResolveMethod {
|
||||
name() : string;
|
||||
resolve(address: DNSAddress) : Promise<DNSAddress | undefined>;
|
||||
name(): string;
|
||||
resolve(address: DNSAddress): Promise<DNSAddress | undefined>;
|
||||
}
|
||||
|
||||
class LocalhostResolver implements DNSResolveMethod {
|
||||
|
@ -14,7 +14,7 @@ class LocalhostResolver implements DNSResolveMethod {
|
|||
}
|
||||
|
||||
async resolve(address: DNSAddress): Promise<DNSAddress | undefined> {
|
||||
if(address.hostname === "localhost") {
|
||||
if (address.hostname === "localhost") {
|
||||
return {
|
||||
hostname: "127.0.0.1",
|
||||
port: address.port
|
||||
|
@ -26,6 +26,20 @@ class LocalhostResolver implements DNSResolveMethod {
|
|||
|
||||
}
|
||||
|
||||
class FakeResolver implements DNSResolveMethod {
|
||||
name(): string {
|
||||
return "fake resolver";
|
||||
}
|
||||
|
||||
async resolve(address: DNSAddress): Promise<DNSAddress | undefined> {
|
||||
return {
|
||||
hostname: "tea.lp.kle.li",
|
||||
port: address.port
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class IPResolveMethod implements DNSResolveMethod {
|
||||
readonly v6: boolean;
|
||||
|
||||
|
@ -40,7 +54,7 @@ class IPResolveMethod implements DNSResolveMethod {
|
|||
|
||||
async resolve(address: DNSAddress): Promise<DNSAddress | undefined> {
|
||||
const answer = await executeDnsRequest(address.hostname, this.v6 ? RRType.AAAA : RRType.A);
|
||||
if(!answer.length) {
|
||||
if (!answer.length) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
@ -72,10 +86,10 @@ class SRVResolveMethod implements DNSResolveMethod {
|
|||
async resolve(address: DNSAddress): Promise<DNSAddress | undefined> {
|
||||
const answer = await executeDnsRequest((this.application ? this.application + "." : "") + address.hostname, RRType.SRV);
|
||||
|
||||
const records: {[key: number]: ParsedSVRRecord[]} = {};
|
||||
for(const record of answer) {
|
||||
const records: { [key: number]: ParsedSVRRecord[] } = {};
|
||||
for (const record of answer) {
|
||||
const parts = record.data.split(" ");
|
||||
if(parts.length !== 4) {
|
||||
if (parts.length !== 4) {
|
||||
logWarn(LogCategory.DNS, tr("Failed to parse SRV record %s. Invalid split length."), record);
|
||||
continue;
|
||||
}
|
||||
|
@ -84,7 +98,7 @@ class SRVResolveMethod implements DNSResolveMethod {
|
|||
const weight = parseInt(parts[1]);
|
||||
const port = parseInt(parts[2]);
|
||||
|
||||
if((priority < 0 || priority > 65535) || (weight < 0 || weight > 65535) || (port < 0 || port > 65535)) {
|
||||
if ((priority < 0 || priority > 65535) || (weight < 0 || weight > 65535) || (port < 0 || port > 65535)) {
|
||||
logWarn(LogCategory.DNS, tr("Failed to parse SRV record %s. Malformed data."), record);
|
||||
continue;
|
||||
}
|
||||
|
@ -99,35 +113,35 @@ class SRVResolveMethod implements DNSResolveMethod {
|
|||
|
||||
/* get the record with the highest priority */
|
||||
const priority_strings = Object.keys(records);
|
||||
if(!priority_strings.length) {
|
||||
if (!priority_strings.length) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
let highestPriority: ParsedSVRRecord[];
|
||||
for(const priority_str of priority_strings) {
|
||||
if(!highestPriority || !highestPriority.length) {
|
||||
for (const priority_str of priority_strings) {
|
||||
if (!highestPriority || !highestPriority.length) {
|
||||
highestPriority = records[priority_str];
|
||||
}
|
||||
|
||||
if(highestPriority[0].priority < parseInt(priority_str)) {
|
||||
if (highestPriority[0].priority < parseInt(priority_str)) {
|
||||
highestPriority = records[priority_str];
|
||||
}
|
||||
}
|
||||
|
||||
if(!highestPriority.length) {
|
||||
if (!highestPriority.length) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/* select randomly one record */
|
||||
let record: ParsedSVRRecord;
|
||||
const max_weight = highestPriority.map(e => e.weight).reduce((a, b) => a + b, 0);
|
||||
if(max_weight == 0) {
|
||||
if (max_weight == 0) {
|
||||
record = highestPriority[Math.floor(Math.random() * highestPriority.length)];
|
||||
} else {
|
||||
let rnd = Math.random() * max_weight;
|
||||
for(let i = 0; i < highestPriority.length; i++) {
|
||||
for (let i = 0; i < highestPriority.length; i++) {
|
||||
rnd -= highestPriority[i].weight;
|
||||
if(rnd > 0) {
|
||||
if (rnd > 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -136,7 +150,7 @@ class SRVResolveMethod implements DNSResolveMethod {
|
|||
}
|
||||
}
|
||||
|
||||
if(!record) {
|
||||
if (!record) {
|
||||
/* shall never happen */
|
||||
record = highestPriority[0];
|
||||
}
|
||||
|
@ -165,7 +179,7 @@ class SRV_IPResolveMethod implements DNSResolveMethod {
|
|||
|
||||
async resolve(address: DNSAddress): Promise<DNSAddress | undefined> {
|
||||
const srvAddress = await this.srvResolver.resolve(address);
|
||||
if(!srvAddress) {
|
||||
if (!srvAddress) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
@ -190,7 +204,7 @@ class DomainRootResolveMethod implements DNSResolveMethod {
|
|||
|
||||
async resolve(address: DNSAddress): Promise<DNSAddress | undefined> {
|
||||
const parts = address.hostname.split(".");
|
||||
if(parts.length < 3) {
|
||||
if (parts.length < 3) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
@ -203,7 +217,7 @@ class DomainRootResolveMethod implements DNSResolveMethod {
|
|||
|
||||
class TeaSpeakDNSResolve {
|
||||
readonly address: DNSAddress;
|
||||
private resolvers: {[key: string]:{ resolver: DNSResolveMethod, after: string[] }} = {};
|
||||
private resolvers: { [key: string]: { resolver: DNSResolveMethod, after: string[] } } = {};
|
||||
private resolving = false;
|
||||
private timeout;
|
||||
|
||||
|
@ -218,15 +232,15 @@ class TeaSpeakDNSResolve {
|
|||
}
|
||||
|
||||
registerResolver(resolver: DNSResolveMethod, ...after: (string | DNSResolveMethod)[]) {
|
||||
if(this.resolving) {
|
||||
if (this.resolving) {
|
||||
throw tr("resolver is already resolving");
|
||||
}
|
||||
|
||||
this.resolvers[resolver.name()] = { resolver: resolver, after: after.map(e => typeof e === "string" ? e : e.name()) };
|
||||
}
|
||||
|
||||
resolve(timeout: number) : Promise<DNSAddress> {
|
||||
if(this.resolving) {
|
||||
resolve(timeout: number): Promise<DNSAddress> {
|
||||
if (this.resolving) {
|
||||
throw tr("already resolving");
|
||||
}
|
||||
this.resolving = true;
|
||||
|
@ -263,23 +277,23 @@ class TeaSpeakDNSResolve {
|
|||
let invoke_count = 0;
|
||||
|
||||
_main_loop:
|
||||
for(const resolver_name of Object.keys(this.resolvers)) {
|
||||
if(this.resolving_resolvers.findIndex(e => e === resolver_name) !== -1) continue;
|
||||
if(this.finished_resolvers.findIndex(e => e === resolver_name) !== -1) continue;
|
||||
for (const resolver_name of Object.keys(this.resolvers)) {
|
||||
if (this.resolving_resolvers.findIndex(e => e === resolver_name) !== -1) continue;
|
||||
if (this.finished_resolvers.findIndex(e => e === resolver_name) !== -1) continue;
|
||||
|
||||
const resolver = this.resolvers[resolver_name];
|
||||
for(const after of resolver.after)
|
||||
if(this.finished_resolvers.findIndex(e => e === after) === -1) continue _main_loop;
|
||||
for (const after of resolver.after)
|
||||
if (this.finished_resolvers.findIndex(e => e === after) === -1) continue _main_loop;
|
||||
|
||||
invoke_count++;
|
||||
logTrace(LogCategory.DNS, tr(" Executing resolver %s"), resolver_name);
|
||||
|
||||
this.resolving_resolvers.push(resolver_name);
|
||||
resolver.resolver.resolve(this.address).then(result => {
|
||||
if(!this.resolving || !this.callback_success) return; /* resolve has been finished already */
|
||||
if (!this.resolving || !this.callback_success) return; /* resolve has been finished already */
|
||||
this.finished_resolvers.push(resolver_name);
|
||||
|
||||
if(!result) {
|
||||
if (!result) {
|
||||
logTrace(LogCategory.DNS, tr(" Resolver %s returned an empty response."), resolver_name);
|
||||
this.invoke_resolvers();
|
||||
return;
|
||||
|
@ -291,24 +305,25 @@ class TeaSpeakDNSResolve {
|
|||
resolver_name);
|
||||
this.callback_success(result);
|
||||
}).catch(error => {
|
||||
if(!this.resolving || !this.callback_success) return; /* resolve has been finished already */
|
||||
if (!this.resolving || !this.callback_success) return; /* resolve has been finished already */
|
||||
this.finished_resolvers.push(resolver_name);
|
||||
|
||||
logTrace(LogCategory.DNS, tr(" Resolver %s ran into an error: %o"), resolver_name, error);
|
||||
this.invoke_resolvers();
|
||||
}).then(() => {
|
||||
this.resolving_resolvers.remove(resolver_name);
|
||||
if(!this.resolving_resolvers.length && this.resolving)
|
||||
if (!this.resolving_resolvers.length && this.resolving)
|
||||
this.invoke_resolvers();
|
||||
});
|
||||
}
|
||||
|
||||
if(invoke_count === 0 && !this.resolving_resolvers.length && this.resolving) {
|
||||
if (invoke_count === 0 && !this.resolving_resolvers.length && this.resolving) {
|
||||
this.callback_fail("no response");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const kResolverFake = new FakeResolver();
|
||||
const kResolverLocalhost = new LocalhostResolver();
|
||||
|
||||
const kResolverIpV4 = new IPResolveMethod(false);
|
||||
|
@ -320,14 +335,16 @@ const resolverSrvTS3 = new SRV_IPResolveMethod(new SRVResolveMethod("_ts3._udp")
|
|||
const resolverDrSrvTS = new DomainRootResolveMethod(resolverSrvTS);
|
||||
const resolverDrSrvTS3 = new DomainRootResolveMethod(resolverSrvTS3);
|
||||
|
||||
export async function resolveTeaSpeakServerAddress(address: DNSAddress, _options?: ResolveOptions) : Promise<DNSResolveResult> {
|
||||
export async function resolveTeaSpeakServerAddress(address: DNSAddress, _options?: ResolveOptions): Promise<DNSResolveResult> {
|
||||
try {
|
||||
const options = Object.assign({}, default_options);
|
||||
Object.assign(options, _options);
|
||||
|
||||
const resolver = new TeaSpeakDNSResolve(address);
|
||||
|
||||
resolver.registerResolver(kResolverLocalhost);
|
||||
resolver.registerResolver(kResolverFake);
|
||||
|
||||
resolver.registerResolver(kResolverLocalhost, kResolverFake);
|
||||
|
||||
resolver.registerResolver(resolverSrvTS, kResolverLocalhost);
|
||||
resolver.registerResolver(resolverSrvTS3, kResolverLocalhost);
|
||||
|
@ -340,7 +357,7 @@ export async function resolveTeaSpeakServerAddress(address: DNSAddress, _options
|
|||
resolver.registerResolver(kResolverIpV6, kResolverIpV4);
|
||||
|
||||
const response = await resolver.resolve(options.timeout || 5000);
|
||||
if(!response) {
|
||||
if (!response) {
|
||||
return {
|
||||
status: "empty-result"
|
||||
};
|
||||
|
@ -352,7 +369,7 @@ export async function resolveTeaSpeakServerAddress(address: DNSAddress, _options
|
|||
resolvedAddress: response
|
||||
};
|
||||
} catch (error) {
|
||||
if(typeof error !== "string") {
|
||||
if (typeof error !== "string") {
|
||||
logError(LogCategory.DNS, tr("Failed to resolve %o: %o"), address, error);
|
||||
error = tr("lookup the console");
|
||||
}
|
||||
|
@ -364,9 +381,9 @@ export async function resolveTeaSpeakServerAddress(address: DNSAddress, _options
|
|||
}
|
||||
}
|
||||
|
||||
export async function resolveAddressIpV4(address: string) : Promise<string> {
|
||||
export async function resolveAddressIpV4(address: string): Promise<string> {
|
||||
const result = await executeDnsRequest(address, RRType.A);
|
||||
if(!result.length) return undefined;
|
||||
if (!result.length) return undefined;
|
||||
|
||||
return result[0].data;
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
import * as path from "path";
|
||||
import * as config_base from "./webpack.config";
|
||||
|
||||
export = env => config_base.config(env, "client").then(config => {
|
||||
Object.assign(config.entry, {
|
||||
"main-app": ["./client/app/entry-points/AppMain.ts"],
|
||||
"modal-external": ["./client/app/entry-points/ModalWindow.ts"]
|
||||
});
|
||||
|
||||
Object.assign(config.resolve.alias, {
|
||||
"tc-shared": path.resolve(__dirname, "shared/js"),
|
||||
});
|
||||
|
||||
if(!Array.isArray(config.externals)) {
|
||||
throw "invalid config";
|
||||
}
|
||||
|
||||
config.externals.push(({ context, request }, callback) => {
|
||||
if (request.startsWith("tc-backend/")) {
|
||||
return callback(null, `window["backend-loader"].require("${request}")`);
|
||||
}
|
||||
|
||||
callback(undefined, undefined);
|
||||
});
|
||||
|
||||
return Promise.resolve(config);
|
||||
});
|
|
@ -46,9 +46,9 @@ const generateLocalBuildInfo = async (target: string): Promise<LocalBuildInfo> =
|
|||
{
|
||||
const gitRevision = fs.readFileSync(path.join(__dirname, ".git", "HEAD")).toString();
|
||||
if(gitRevision.indexOf("/") === -1) {
|
||||
info.gitVersion = (gitRevision || "00000000").substr(0, 8);
|
||||
info.gitVersion = (gitRevision || "00000000").substring(0, 8);
|
||||
} else {
|
||||
info.gitVersion = fs.readFileSync(path.join(__dirname, ".git", gitRevision.substr(5).trim())).toString().substr(0, 8);
|
||||
info.gitVersion = fs.readFileSync(path.join(__dirname, ".git", gitRevision.substring(5).trim())).toString().substring(0, 8);
|
||||
}
|
||||
|
||||
try {
|
||||
|
|
Loading…
Reference in New Issue