feat: 精简配置和部署流程(#18)

feat: 支持docker一键部署脚本
feat: 支持数据库官方镜像
feat: 支持docker默认开启数据库
feat: 优化数据库自动连接重试
doc: 更新文档
This commit is contained in:
https://blog.iamtsm.cn
2023-08-09 18:15:37 +08:00
parent e3a837a28a
commit 55ff78d730
18 changed files with 517 additions and 285 deletions

6
.gitignore vendored
View File

@@ -47,11 +47,9 @@ svr/res/css/*.min.*
dist/
svr/res/dist
svr/dist
client/dist
package-lock.json
docker/mysql/data/*

View File

@@ -97,7 +97,7 @@ https模式启动后访问 https://你的机器ip:9092 即可
## 是否开启数据库
tl_rtc_file_db_open=false
## 数据库地址
tl_rtc_file_db_mysql_host=
tl_rtc_file_db_mysql_host=mysql
## 数据库端口
tl_rtc_file_db_mysql_port=3306
## 数据库名称
@@ -111,14 +111,13 @@ https模式启动后访问 https://你的机器ip:9092 即可
前提 : 需要开启数据库配置
修改 `tlrtcfile.env` 中的管理后台相关配置即可
修改 `tlrtcfile.env` 中的管理后台相关配置即可 启动后,输入配置的房间号,输入密码,即可进入管理后台
## 管理后台房间号
tl_rtc_file_manage_room=tlrtcfile
## 管理后台密码
tl_rtc_file_manage_password=tlrtcfile
访问 : http://localhost:9092 或者 http://本机ip:9092输入配置的房间号输入密码即可进入管理后台
## 企微通知 (非必须步骤)
@@ -218,60 +217,47 @@ ubuntu示例:
## Docker
### 使用官方镜像 :
目前支持 `官方镜像``自行打包镜像`,使用官方镜像目前支持两种操作方式 `docker脚本启动``docker-compose启动`
以下只是最基础参数,更多参数可以参考 `tlrtcfile.env`
和自行在 `服务器/电脑部署` 不同的是docke环境默认开启数据库coturn服务无须过多额外操作启动即可用。
docker pull iamtsm/tl-rtc-file-api
### 使用官方镜像(docker脚本启动) :
docker run --name=api -p 9092:9092 -e "tl_rtc_file_env_mode=http" -d iamtsm/tl-rtc-file-api tlapi
按需修改好 `tlrtcfile.env` 配置 (或使用默认配置也可) 后,进入 `bin/` 目录执行脚本 `auto-pull-and-start-docker.sh`
docker pull iamtsm/tl-rtc-file-socket
1. chmod +x ./auto-pull-and-start-docker.sh
docker run --name=socket -p 8444:8444 -e "tl_rtc_file_env_mode=http" -d iamtsm/tl-rtc-file-socket tlsocket
2. ./auto-pull-and-start-docker.sh
### 使用官方镜像(docker-compose) :
### 使用官方镜像(docker-compose启动) :
http模式启动镜像: `docker-compose --profile=http up -d`
按需修改好 `tlrtcfile.env` 配置 (或使用默认配置也可) 后,在主目录执行
https模式镜像: `docker-compose --profile=https up -d`
docker-compose --profile=http up -d
### 自行打包启动镜像(docker-compose打包启动) :
### 打包自己的镜像(docker-compose) :
确认修改好 `tlrtcfile.env` 配置文件 (或使用默认配置也可) 后, 进入 `docker/` 目录后执行
确认修改好 `tlrtcfile.env` 配置文件后, 进入docker目录后两种模式选一种操作即可
打包http模式镜像:
docker-compose -f docker-compose-build-code.yml --profile=http build
打包https模式镜像:
docker-compose -f docker-compose-build-code.yml --profile=https build
docker-compose -f docker-compose-build-code.yml up -d
## 其他形式部署
除了上面的手动安装docker官方镜像docker自己打包镜像之外还支持自动脚本托管平台一键部署等
下载项目后可以进入bin/目录,选择对应的系统脚本,直接执行即可
下载项目后,可以进入 `bin/` 目录,选择对应的系统脚本,直接执行即可
如果linux脚本没权限可以先修改一下脚本的可执行权限 `chmod +x bin/linux/*.sh`
### ubuntu自动脚本
### linux自动脚本
1. chmod +x ./ubuntu/*.sh
选一种模式启动即可
2. cd ubuntu/
- `auto-check-install-http.sh` : 自动检查安装node环境并自动运行启动http模式服务
- `auto-check-install-https.sh` : 自动检查安装node环境并自动运行启动https模式服务
3. ./auto-check-install-http.sh 或者 ./auto-check-install-https.sh
### windows自动脚本
选一种模式启动即可
- `auto-check-install-http.bat` : 自动检查安装node环境并自动运行启动http模式服务
- `auto-check-install-https.bat` : 自动检查安装node环境并自动运行启动https模式服务
windows/auto-check-install-http.bat 或者 windows/auto-check-install-https.bat
### zeabur平台一键部署

View File

@@ -1,28 +1,54 @@
#!/bin/bash
#########################
# 一键推送dockerhub的脚本
# @auther: iamtsm
# @version: v1.0.0
#########################
######################################## start ######################################
build_version=latest
hub_version=v10.3.3
hub_version=v10.3.4
######################################## build ######################################
## build by docker-compose-build-code.yml
docker-compose -f ../docker/docker-compose-build-code.yml build
## tag
docker tag docker-tl-rtc-file-api:$build_version iamtsm/tl-rtc-file-api:$hub_version
docker tag docker-tl-rtc-file-socket:$build_version iamtsm/tl-rtc-file-socket:$hub_version
docker tag docker-tl-rtc-file-api:$build_version iamtsm/tl-rtc-file-api:$build_version
docker tag docker-tl-rtc-file-socket:$build_version iamtsm/tl-rtc-file-socket:$build_version
######################################## tag ########################################
# tag hub version
docker tag docker-api:$build_version iamtsm/tl-rtc-file-api:$hub_version
docker tag docker-socket:$build_version iamtsm/tl-rtc-file-socket:$hub_version
docker tag docker-mysql:$build_version iamtsm/tl-rtc-file-mysql:$hub_version
## push to hub version and latest
# tag latest version
docker tag docker-api:$build_version iamtsm/tl-rtc-file-api:$build_version
docker tag docker-socket:$build_version iamtsm/tl-rtc-file-socket:$build_version
docker tag docker-mysql:$build_version iamtsm/tl-rtc-file-mysql:$build_version
######################################## push #######################################
# push hub version
docker push iamtsm/tl-rtc-file-api:$hub_version
docker push iamtsm/tl-rtc-file-socket:$hub_version
docker push iamtsm/tl-rtc-file-mysql:$hub_version
# push latest version
docker push iamtsm/tl-rtc-file-api:$build_version
docker push iamtsm/tl-rtc-file-socket:$build_version
docker push iamtsm/tl-rtc-file-mysql:$build_version
## remove local images
docker rmi docker-tl-rtc-file-api:$build_version
docker rmi docker-tl-rtc-file-socket:$build_version
######################################## del ########################################
## del build version
docker rmi docker-api:$build_version
docker rmi docker-socket:$build_version
docker rmi docker-mysql:$build_version
# # del tag build version
docker rmi iamtsm/tl-rtc-file-api:$build_version
docker rmi iamtsm/tl-rtc-file-socket:$build_version
docker rmi iamtsm/tl-rtc-file-mysql:$build_version
# del tag hub version
docker rmi iamtsm/tl-rtc-file-api:$hub_version
docker rmi iamtsm/tl-rtc-file-socket:$hub_version
docker rmi iamtsm/tl-rtc-file-socket:$hub_version
docker rmi iamtsm/tl-rtc-file-mysql:$hub_version
######################################## done #######################################

156
bin/auto-pull-and-start-docker.sh Executable file
View File

@@ -0,0 +1,156 @@
#!/bin/bash
#########################
# 提供一键部署docker的脚本
# @auther: iamtsm
# @version: v1.0.0
#########################
# 检查Docker是否启动
docker info > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "======> Docker is not running. Exiting."
exit 1
fi
# 读取配置文件中的每一行
while IFS= read -r line; do
# 忽略注释和空行
if [[ $line == \#* || -z $line ]]; then
continue
fi
# 将每一行拆分成键和值
IFS== read -r key value <<< "$line"
# 去除空白字符
key=$(echo "$key" | tr -d '[:space:]')
value=$(echo "$value" | tr -d '[:space:]')
# 设置环境变量
export "$key"="$value"
echo "======> " $key=$value
done < ./../tlrtcfile.env
# docker启动 默认开启数据库
export tl_rtc_file_db_open=true
# 从dockerhub拉取镜像
docker pull iamtsm/tl-rtc-file-api
docker pull iamtsm/tl-rtc-file-socket
docker pull iamtsm/tl-rtc-file-mysql
if docker images | grep -q "iamtsm/tl-rtc-file-api"; then
echo "======> check image iamtsm/tl-rtc-file-api exists ok..."
else
echo "======> Image $image_name does not exist. Exiting."
exit 1
fi
if docker images | grep -q "iamtsm/tl-rtc-file-socket"; then
echo "======> check image iamtsm/tl-rtc-file-socket exists ok..."
else
echo "======> Image $image_name does not exist. Exiting."
exit 1
fi
if docker images | grep -q "iamtsm/tl-rtc-file-mysql"; then
echo "======> check image iamtsm/tl-rtc-file-mysql exists ok..."
else
echo "Image $image_name does not exist. Exiting."
exit 1
fi
echo "======> start run docker..."
# 启动mysql容器
docker run \
--name=mysql \
-p $tl_rtc_file_db_mysql_port:$tl_rtc_file_db_mysql_port \
-e MYSQL_ROOT_PASSWORD=tlrtcfile \
-e MYSQL_DATABASE=webchat \
-e MYSQL_USER=tlrtcfile \
-e MYSQL_PASSWORD=tlrtcfile \
--restart=always \
-d iamtsm/tl-rtc-file-mysql
# 启动api容器
docker run \
--name=api \
-p $tl_rtc_file_api_port:$tl_rtc_file_api_port \
-e "tl_rtc_file_env_mode=http" \
-e tl_rtc_file_api_port \
-e tl_rtc_file_ws_port \
-e tl_rtc_file_ws_host \
-e tl_rtc_file_webrtc_stun_host \
-e tl_rtc_file_webrtc_turn_host \
-e tl_rtc_file_webrtc_turn_username \
-e tl_rtc_file_webrtc_turn_credential \
-e tl_rtc_file_webrtc_turn_secret \
-e tl_rtc_file_webrtc_turn_expire \
-e tl_rtc_file_db_open \
-e tl_rtc_file_db_mysql_host \
-e tl_rtc_file_db_mysql_port \
-e tl_rtc_file_db_mysql_dbName \
-e tl_rtc_file_db_mysql_user \
-e tl_rtc_file_db_mysql_password \
-e tl_rtc_file_oss_seafile_repoid \
-e tl_rtc_file_oss_seafile_host \
-e tl_rtc_file_oss_seafile_username \
-e tl_rtc_file_oss_seafile_password \
-e tl_rtc_file_oss_alyun_AccessKey \
-e tl_rtc_file_oss_alyun_Secretkey \
-e tl_rtc_file_oss_alyun_bucket \
-e tl_rtc_file_oss_txyun_AccessKey \
-e tl_rtc_file_oss_txyun_Secretkey \
-e tl_rtc_file_oss_txyun_bucket \
-e tl_rtc_file_oss_qiniuyun_AccessKey \
-e tl_rtc_file_oss_qiniuyun_Secretkey \
-e tl_rtc_file_oss_qiniuyun_bucket \
-e tl_rtc_file_manage_room \
-e tl_rtc_file_manage_password \
-e tl_rtc_file_notify_open \
-e tl_rtc_file_notify_qiwei_normal \
-e tl_rtc_file_notify_qiwei_error \
--link mysql \
-d iamtsm/tl-rtc-file-api tlapi
# 启动socket容器
docker run \
--name=socket \
-p $tl_rtc_file_ws_port:$tl_rtc_file_ws_port \
-e "tl_rtc_file_env_mode=http" \
-e tl_rtc_file_api_port \
-e tl_rtc_file_ws_port \
-e tl_rtc_file_ws_host \
-e tl_rtc_file_webrtc_stun_host \
-e tl_rtc_file_webrtc_turn_host \
-e tl_rtc_file_webrtc_turn_username \
-e tl_rtc_file_webrtc_turn_credential \
-e tl_rtc_file_webrtc_turn_secret \
-e tl_rtc_file_webrtc_turn_expire \
-e tl_rtc_file_db_open \
-e tl_rtc_file_db_mysql_host \
-e tl_rtc_file_db_mysql_port \
-e tl_rtc_file_db_mysql_dbName \
-e tl_rtc_file_db_mysql_user \
-e tl_rtc_file_db_mysql_password \
-e tl_rtc_file_oss_seafile_repoid \
-e tl_rtc_file_oss_seafile_host \
-e tl_rtc_file_oss_seafile_username \
-e tl_rtc_file_oss_seafile_password \
-e tl_rtc_file_oss_alyun_AccessKey \
-e tl_rtc_file_oss_alyun_Secretkey \
-e tl_rtc_file_oss_alyun_bucket \
-e tl_rtc_file_oss_txyun_AccessKey \
-e tl_rtc_file_oss_txyun_Secretkey \
-e tl_rtc_file_oss_txyun_bucket \
-e tl_rtc_file_oss_qiniuyun_AccessKey \
-e tl_rtc_file_oss_qiniuyun_Secretkey \
-e tl_rtc_file_oss_qiniuyun_bucket \
-e tl_rtc_file_manage_room \
-e tl_rtc_file_manage_password \
-e tl_rtc_file_notify_open \
-e tl_rtc_file_notify_qiwei_normal \
-e tl_rtc_file_notify_qiwei_error \
--link mysql \
-d iamtsm/tl-rtc-file-socket tlsocket

View File

@@ -1,4 +1,4 @@
# tl-rtc-file-tool - Beyond File Transmission, Originating from It
# tl-rtc-file-tool【From File Transfer, Beyond File Transfer】
[![](https://img.shields.io/badge/webrtc-p2p-blue)](https://webrtc.org.cn/)
[![](https://img.shields.io/badge/code-simple-green)](https://github.com/iamtsm/tl-rtc-file/)
@@ -7,7 +7,7 @@
[![](https://img.shields.io/badge/platform-unlimited-coral)](https://github.com/iamtsm/tl-rtc-file/)
<p align="center">
<a href="https://im.iamtsm.cn/file" target="_blank">Experience Here</a>
<a href="https://im.iamtsm.cn/file" target="_blank">Demo</a>
<a href="https://hub.docker.com/repositories/iamtsm" target="_blank">DockerHub</a>
<a href="https://github.com/tl-open-source/tl-rtc-file/blob/master/doc/README_EN.md" target="_blank">EN-DOC</a>
</p>
@@ -20,102 +20,86 @@
- [Introduction](#introduction)
- [Advantages](#advantages)
- [Extensions](#extensions)
- [Preparation (Required Steps)](#preparation-required-steps)
- [Configure Websocket (Required Steps)](#configure-websocket-required-steps)
- [Startup (Required Steps)](#startup-required-steps)
- [Configure Database (Optional Steps)](#configure-database-optional-steps)
- [Admin Panel (Optional Steps)](#admin-panel-optional-steps)
- [Enterprise WeChat Notification (Optional Steps)](#enterprise-wechat-notification-optional-steps)
- [OSS Cloud Storage (Optional Steps)](#oss-cloud-storage-optional-steps)
- [Chat-GPT (Optional Steps)](#chat-gpt-optional-steps)
- [Configure Turnserver (Local Network - Optional Steps, Public Network - Required Steps)](#configure-turnserver-local-network-optional-steps-public-network-required-steps)
- [Preparation (Mandatory Steps)](#preparation-mandatory-steps)
- [Configure Websocket (Mandatory Steps)](#configure-websocket-mandatory-steps)
- [Startup (Mandatory Steps)](#startup-mandatory-steps)
- [Configure Database (Optional)](#configure-database-optional)
- [Admin Panel (Optional)](#admin-panel-optional)
- [Enterprise WeChat Notifications (Optional)](#enterprise-wechat-notifications-optional)
- [OSS Cloud Storage (Optional)](#oss-cloud-storage-optional)
- [Chat-GPT Integration (Optional)](#chat-gpt-integration-optional)
- [Configure TURN Server (LAN-Optional, WAN-Mandatory)](#configure-turn-server-lan-optional-wan-mandatory)
- [Docker](#docker)
- [Other Deployment Methods](#other-deployment-methods)
- [Overview Diagram](#overview-diagram)
- [License](#license)
- [Disclaimer](#disclaimer)
#### Background: Consolidated from the Topic of the 20-year Graduation Project
#### Background: Developed from the topic of 2020 graduation project
#### Introduction: (tl webrtc datachannel filetools) Transferring files on the web using WebRTC, supporting transmission of large files.
#### Introduction: (tl webrtc datachannel filetools) Transferring files through WebRTC on the web, supporting transfer of large files.
#### Advantages: Chunked transmission, cross-platform, versatile usage, no speed restrictions on local networks (up to 70+ MB/s in LAN), supports private deployment, supports drag-and-drop sending of multiple files, web-based file preview.
#### Advantages: Fragmented transfer, cross-platform, platform-independent, easy to use, no internal network speed limit (up to 70+ MB/s in LAN), supports private deployment, supports multi-file drag-and-drop sending, web file preview.
#### Extensions: Many rich additional features have been added, such as local screen recording, remote screen sharing (no latency), remote audio and video calls (no latency), live streaming (no latency), password-protected rooms, OSS cloud storage, relay service configuration, WebRTC detection, WebRTC statistics, text transmission (group chat, private chat), public chat, remote whiteboard, AI chatbot, comprehensive backend management, real-time execution log display, robot alert notifications, and more.
#### Extensions: Extended with many rich features, such as local screen recording, remote screen sharing (zero-latency), remote audio-video calling (zero-latency), live streaming (zero-latency), password-protected rooms, OSS cloud storage, relay service settings, WebRTC testing, WebRTC statistics, text messaging (group, private), public chat, remote whiteboard, AI chatbot, comprehensive admin dashboard, real-time execution log display, robot alert notifications, etc.
## Preparation (Required Steps)
## Preparation (Mandatory Steps)
1. Install Node.js 14.21.x or above, and npm. Then, navigate to the project directory and run the following commands:
1. Install Node.js 14.21.x or above and npm. Then navigate to the project directory and run the following command:
```
```bash
cd svr/
npm install
```
2. For the first run or when developing your own pages, you can use either of the following commands:
2. For the first run or self-developed pages, you can use one of the following commands:
```
npm run build:dev # Use this command if you need to develop/modify frontend pages
npm run build:pro # Use this command if you don't need to develop/modify frontend pages
```bash
npm run build:dev # If you need to develop or modify frontend pages
npm run build:pro # If you don't need to develop or modify frontend pages
```
3. Modify the `http.env` and `https.env` configuration files.
3. Modify the `tlrtcfile.env` configuration file.
## Configure WebSocket (Required Steps)
## Configure Websocket (Mandatory Steps)
Modify the relevant WebSocket configuration in `http.env` and `https.env` files.
`http.env`
Modify the corresponding websocket configuration in `tlrtcfile.env`:
```ini
## WebSocket server port
## Websocket server port
tl_rtc_file_ws_port=8444
## WebSocket server address
## Websocket server address
## "ws://domain or ip:port or domain:port"
## For socket IP, use LAN IP/public IP. LAN IP can only be accessed within the LAN, public IP can be accessed from the internet
## For socket ip, use LAN IP for LAN access and public IP for public access
tl_rtc_file_ws_host=ws://127.0.0.1:8444
```
`https.env`
## Startup (Mandatory Steps)
Start the following two services, choose either mode, the difference between them is that the HTTPS environment is required for audio-video functions, live streaming, and screen sharing, but it won't affect other functionalities.
After starting in HTTP mode, access http://your_machine_ip:9092.
API service: `npm run http-api`
Socket service: `npm run http-socket`
After starting in HTTPS mode, access https://your_machine_ip:9092.
API service: `npm run https-api`
Socket service: `npm run https-socket`
## Configure Database (Optional)
Modify the database-related configuration in `tlrtcfile.env`:
```ini
## WebSocket server port
tl_rtc_file_wss_port=8444
## WebSocket server address
## "wss://domain or ip:port or domain:port"
## For socket IP, use LAN IP/public IP. LAN IP can only be accessed within the LAN, public IP can be accessed from the internet
tl_rtc_file_wss_host=wss://127.0.0.1:8444
```
## Startup (Required Steps)
Start the following two services; choose one mode to start. The only difference between the two modes is that the HTTPS environment allows the use of audio, video, live streaming, and screen sharing features, while the other functionalities remain unaffected.
For HTTP mode, access http://your-machine-ip:9092.
```
API service: npm run http-api
Socket service: npm run http-socket
```
For HTTPS mode, access https://your-machine-ip:9092.
```
API service: npm run https-api
Socket service: npm run https-socket
```
## Configure Database (Non-Required Step)
Modify the database-related configuration in `http.env` and `https.env`.
```ini
## Whether to enable the database
## Enable database
tl_rtc_file_db_open=false
## Database address
tl_rtc_file_db_mysql_host=
tl_rtc_file_db_mysql_host=mysql
## Database port
tl_rtc_file_db_mysql_port=3306
## Database name
@@ -126,43 +110,43 @@ tl_rtc_file_db_mysql_user=tlrtcfile
tl_rtc_file_db_mysql_password=tlrtcfile
```
## Admin Dashboard (Non-Required Step)
## Admin Panel (Optional)
Prerequisite: Database configuration must be enabled.
Prerequisite: Database configuration needs to be enabled.
Modify the admin dashboard-related configuration in `http.env` and `https.env`.
Modify the admin panel-related configuration in `tlrtcfile.env`. After starting, enter the configured room number and password to access the admin panel:
```ini
## Admin dashboard room number
## Admin panel room number
tl_rtc_file_manage_room=tlrtcfile
## Admin dashboard password
## Admin panel password
tl_rtc_file_manage_password=tlrtcfile
```
Access: http://localhost:9092 or http://your-machine-ip:9092, enter the configured room number and password to access the admin dashboard.
## Enterprise WeChat Notifications (Optional)
## Enterprise WeChat Notifications (Non-Required Step)
Modify the enterprise WeChat notification-related configuration in `http.env` and `https.env`.
Modify the Enterprise WeChat notification-related configuration in `tlrtcfile.env`:
```ini
# ## Enterprise WeChat notification switch
## Enterprise WeChat notification switch
tl_rtc_file_notify_open=false
## Enterprise WeChat notification robot keys, normal notifications (comma-separated if multiple keys)
## Enterprise WeChat notification robot key for normal notifications (comma-separated if multiple keys)
tl_rtc_file_notify_qiwei_normal=
## Enterprise WeChat notification robot keys, error notifications (comma-separated if multiple keys)
## Enterprise WeChat notification robot key for error notifications (comma-separated if multiple keys)
tl_rtc_file_notify_qiwei_error=
```
## OSS Cloud Storage (Non-Required Step)
## OSS Cloud Storage (Optional)
Modify the OSS storage-related configuration in `http.env` and `https.env`.
Modify the OSS storage-related configuration in `tlrtcfile.env`:
```ini
## oss-seafile storage repository ID
tl_rtc_file_oss_seafile_repoid=
## oss-seafile address
tl_rtc_file_oss_seafile_host=
tl
_rtc_file_oss_seafile_host=
## oss-seafile username
tl_rtc_file_oss_seafile_username=
## oss-seafile password
@@ -182,9 +166,7 @@ tl_rtc_file_oss_txyun_Secretkey=
## oss-txyun storage bucket
tl_rtc_file_oss_txyun_bucket=
## oss-q
iniuyun storage accessKey
## oss-qiniuyun storage accessKey
tl_rtc_file_oss_qiniuyun_AccessKey=
## oss-qiniuyun storage SecretKey
tl_rtc_file_oss_qiniuyun_Secretkey==
@@ -192,122 +174,106 @@ tl_rtc_file_oss_qiniuyun_Secretkey==
tl_rtc_file_oss_qiniuyun_bucket=
```
## Chat-GPT (Non-Required Step)
## Chat-GPT Integration (Optional)
Modify the OpenAI-related configuration in `http.env` and `https.env`.
Modify the OpenAI-related configuration in `tlrtcfile.env`:
```ini
## OpenAI key(s), comma-separated if multiple keys
## OpenAI keys (comma-separated if multiple keys)
tl_rtc_file_openai_keys=
```
## Configure TURN Server (Non-Required Step for LAN, Required Step for Public Network)
## Configure TURN Server (LAN-Optional, WAN-Mandatory)
Currently, there are two ways to generate credentials for using TURN service: fixed credentials (recommended) and credentials with expiration date. Choose one method.
Currently, two ways are available to generate and use TURN service credentials: fixed credentials (recommended) and temporary credentials with expiration. **Choose one method**.
Example for Ubuntu:
Install Coturn: `sudo apt-get install coturn`
Install coturn: `sudo apt-get install coturn`
Valid credentials: `docker/coturn/turnserver-with-secret-user.conf`
Fixed credentials: `docker/coturn/turnserver-with-secret-user.conf`
1. Modify the fields `listening-device`, `listening-ip`, `external-ip`, `static-auth-secret`, and `realm`.
2. Start TURN server: `turnserver -c /complete/path/to/conf/turn/turnserver-with-secret-user.conf`
1. Modify fields like `listening-device`, `listening-ip`, `external-ip`, `static-auth-secret`, `realm`.
Fixed credentials: `docker/coturn/turnserver-with-fixed-user.conf`
2. Start TURN server:
`turnserver -c /full/path/to/conf/turn/turnserver-with-secret-user.conf`
1. Modify the fields `listening-device`, `listening-ip`, `external-ip`, `user`, and `realm`.
2. Generate a user: `turnadmin -a -u username -p password -r realm`
3. Start TURN server: `turnserver -c /complete/path/to/docker/coturn/turnserver-with-secret-user.conf`
Temporary credentials: `docker/coturn/turnserver-with-fixed-user.conf`
After deploying Coturn, set up WebRTC-related information in the corresponding `http.env` and `https.env` configurations.
1. Modify fields like `listening-device`, `listening-ip`, `external-ip`, `user`, `realm`.
2. Generate user credentials:
`turnadmin -a -u username -p password -r realm`
3. Start TURN server:
`turnserver -c /full/path/to/docker/coturn/turnserver-with-secret-user.conf`
After setting up coturn, configure WebRTC related information in `tlrtcfile.env`:
```ini
## Webrtc-stun relay service address
## webrtc-stun server address
tl_rtc_file_webrtc_stun_host=
## Webrtc-turn relay service address
## webrtc-turn server address
tl_rtc_file_webrtc_turn_host=
## Webrtc relay service username
## webrtc-turn server username
tl_rtc_file_webrtc_turn_username=tlrtcfile
## Webrtc relay service password
## webrtc-turn server password
tl_rtc_file_webrtc_turn_credential=tlrtcfile
## Webrtc relay service Secret
## webrtc-turn server secret
tl_rtc_file_webrtc_turn_secret=tlrtcfile
## Webrtc relay service account expiration time (milliseconds)
## webrtc-turn server account expiration time (milliseconds)
tl_rtc_file_webrtc_turn_expire=86400000
```
## Docker
### Using Official Images:
Both `official images` and `self-packaged images` are supported. Using official images allows for two modes of operation: `Docker script startup` and `Docker Compose startup`.
The following are basic parameters; you can refer to `http.env` and `https.env` for more parameters.
Different from deploying on a server/computer, the Docker environment by default starts the database and coturn service. No additional actions are needed, simply start it.
Pull the API image:
### Using Official Images (Docker Script Startup):
After modifying the `tlrtcfile.env` configuration (or using the default configuration), navigate to the `bin/` directory and run the script `auto-pull-and-start-docker.sh`:
1. `chmod +x ./auto-pull-and-start-docker.sh`
2. `./auto-pull-and-start-docker.sh`
### Using Official Images (Docker Compose Startup):
After modifying the `tlrtcfile.env` configuration (or using the default configuration), execute the following command in the main directory:
```bash
docker pull iamtsm/tl-rtc-file-api
docker run --name=api -p 9092:9092 \
-e "tl_rtc_file_env_mode=http" \
-e "tl_rtc_file_ws_port=8444" \
-e "tl_rtc_file_ws_host=ws://127.0.0.1:8444" \
-d iamtsm/tl-rtc-file-api tlapi
docker-compose --profile=http up -d
```
Pull the Socket image:
### Self-Packaged Image (Docker Compose Packaged Startup):
After modifying the `tlrtcfile.env` configuration (or using the default configuration), navigate to the `docker/` directory and execute:
```bash
docker pull iamtsm/tl-rtc-file-socket
docker run --name=socket -p 8444:8444 \
-e "tl_rtc_file_env_mode=http" \
-e "tl_rtc_file_ws_port=8444" \
-e "tl_rtc_file_ws_host=ws://127.0.0.1:8444" \
-d iamtsm/tl-rtc-file-socket tlsocket
docker-compose -f docker-compose-build-code.yml up -d
```
### Using Official Images (docker-compose):
## Other Deployment Methods
Start the HTTP mode image: `docker-compose --profile=http up -d`
Apart from the manual installation, Docker official images, and self-packaged images, there are also options for automatic scripts and one-click deployment on hosting platforms.
Start the HTTPS mode image: `docker-compose --profile=https up -d`
After downloading the project, navigate to the `bin/` directory and execute the corresponding system script:
### Build Your Own Image (docker-compose):
After configuring `http.env` and `https.env`, go to the `docker` directory, and choose one mode to execute:
Build HTTP mode image:
### ubuntu Auto Script
```bash
docker-compose -f docker-compose-build-code.yml --profile=http build
chmod +x ./ubuntu/*.sh
cd ubuntu/
./auto-check-install-http.sh # or ./auto-check-install-https.sh
```
Build HTTPS mode image:
### Windows Auto Script
```bash
docker-compose -f docker-compose-build-code.yml --profile=https build
```
## Other Deployment Methods:
In addition to the manual installation, using official Docker images, and building Docker images yourself, there are also automatic scripts and one-click deployment options on hosting platforms.
After downloading the project, you can navigate to the `bin/` directory and execute the appropriate script for your system. If the Linux script lacks execution permissions, you can grant it by using the `chmod +x bin/linux/*.sh` command.
### Linux Automatic Scripts
Choose one mode to start:
- `auto-check-install-http.sh`: Automatically check and install Node.js environment, then start HTTP mode service.
- `auto-check-install-https.sh`: Automatically check and install Node.js environment, then start HTTPS mode service.
### Windows Automatic Scripts
Choose one mode to start:
- `auto-check-install-http.bat`: Automatically check and install Node.js environment, then start HTTP mode service.
- `auto-check-install-https.bat`: Automatically check and install Node.js environment, then start HTTPS mode service.
Run `windows/auto-check-install-http.bat` or `windows/auto-check-install-https.bat`.
### Zeabur Platform One-Click Deployment

View File

@@ -1,54 +1,105 @@
## 用于docker-compose部署启动官方镜像
## 用于docker-compose部署启动官方镜像
version: '3'
services:
## http
#http模式启动api服务
api-http:
profiles: ['http']
container_name: api
image: iamtsm/tl-rtc-file-api
env_file:
- tlrtcfile.env
- ./tlrtcfile.env
environment:
- tl_rtc_file_env_mode=http
- tl_rtc_file_env_mode=http
- tl_rtc_file_db_open=true
command:
- tlapi
ports:
- 9092:9092
command: tlapi
- 9092:9092
links:
- mysql
depends_on:
- mysql
volumes:
- ./tlrtcfile.env:/tlrtcfile/tlrtcfile.env
socket-http:
profiles: ['http']
container_name: socket
image: iamtsm/tl-rtc-file-socket
env_file:
- tlrtcfile.env
environment:
- tl_rtc_file_env_mode=http
ports:
- 8444:8444
command: tlsocket
#https
#https模式启动api服务
api-https:
profiles: ['https']
container_name: api
image: iamtsm/tl-rtc-file-api
env_file:
- tlrtcfile.env
- ./tlrtcfile.env
environment:
- tl_rtc_file_env_mode=https
- tl_rtc_file_env_mode=http
- tl_rtc_file_db_open=true
command:
- tlapi
ports:
- 9092:9092
command: tlapi
- 9092:9092
links:
- mysql
depends_on:
- mysql
volumes:
- ./tlrtcfile.env:/tlrtcfile/tlrtcfile.env
socket-https:
#http模式启动socket服务
socket-http:
profiles: ['http']
container_name: socket
image: iamtsm/tl-rtc-file-socket
command:
- tlsocket
env_file:
- ./tlrtcfile.env
environment:
- tl_rtc_file_env_mode=http
- tl_rtc_file_db_open=true
ports:
- 8444:8444
links:
- mysql
depends_on:
- mysql
volumes:
- ./tlrtcfile.env:/tlrtcfile/tlrtcfile.env
#https模式启动socket服务
socket-htts:
profiles: ['https']
container_name: socket
image: iamtsm/tl-rtc-file-socket
command:
- tlsocket
env_file:
- tlrtcfile.env
- ./tlrtcfile.env
environment:
- tl_rtc_file_env_mode=https
- tl_rtc_file_env_mode=https
- tl_rtc_file_db_open=true
ports:
- 8444:8444
command: tlsocket
- 8444:8444
links:
- mysql
depends_on:
- mysql
volumes:
- ./tlrtcfile.env:/tlrtcfile/tlrtcfile.env
#mysql服务
mysql:
profiles: ['http','https']
container_name: mysql
image: iamtsm/tl-rtc-file-mysql
restart: always
env_file:
- ./docker/mysql/mysql.env
ports:
- 3306:3306
volumes:
- ./docker/mysql/data/mysql.env:/tlrtcfile/docker/mysql/mysql.env
- ./docker/mysql/data/db:/var/lib/mysql
- ./docker/mysql/data/my.cnf:/etc/mysql/conf.d/my.cnf
- ./docker/mysql/data/log:/var/log/mysql
- ./docker/mysql/data/init.sql:/docker-entrypoint-initdb.d/init.sql

View File

@@ -1,29 +1,58 @@
## build the image from the Dockerfile in the current directory
## 1. 用于自己通过代码构建镜像
## 2. 用于推送到官方dockerhub
## 用于自己通过代码构建镜像并启动
version: '3'
services:
tl-rtc-file-api:
env_file:
- ../tlrtcfile.env
environment:
- tl_rtc_file_node_load_env=false
build:
context: ../
dockerfile: docker/Dockerfile-build-code
ports:
- 9092:9092
command: tlapi
tl-rtc-file-socket:
env_file:
- ../tlrtcfile.env
environment:
- tl_rtc_file_node_load_env=false
api:
container_name: api
build:
context: ../
dockerfile: docker/Dockerfile-build-code
context: ./../
dockerfile: ./Dockerfile
env_file:
- ../tlrtcfile.env
command:
- tlapi
ports:
- 8444:8444
command: tlsocket
- 9092:9092
links:
- mysql
depends_on:
- mysql
volumes:
- ../tlrtcfile.env:/tlrtcfile/tlrtcfile.env
socket:
container_name: socket
build:
context: ./../
dockerfile: ./Dockerfile
command:
- tlsocket
env_file:
- ../tlrtcfile.env
ports:
- 8444:8444
links:
- mysql
depends_on:
- mysql
volumes:
- ../tlrtcfile.env:/tlrtcfile/tlrtcfile.env
mysql:
container_name: mysql
restart: always
env_file:
- ./mysql/mysql.env
build:
context: ./mysql/
dockerfile: ./Dockerfile
ports:
- 3306:3306
volumes:
- ./mysql/data/mysql.env:/tlrtcfile/docker/mysql/mysql.env
- ./mysql/data/db:/var/lib/mysql
- ./mysql/data/my.cnf:/etc/mysql/conf.d/my.cnf
- ./mysql/data/log:/var/log/mysql
- ./mysql/data/init.sql:/docker-entrypoint-initdb.d/init.sql

1
docker/mysql/Dockerfile Normal file
View File

@@ -0,0 +1 @@
FROM mysql/mysql-server:5.7

View File

@@ -1 +1,9 @@
#mysql env feature use
#mysql env feature use
#设置root密码
MYSQL_ROOT_PASSWORD=tlrtcfile
#设置数据库
MYSQL_DATABASE=webchat
#设置用户
MYSQL_USER=tlrtcfile
MYSQL_PASSWORD=tlrtcfile

View File

@@ -1,5 +1,5 @@
{
"version": "10.3.3",
"version": "10.3.4",
"ws": {
"port": "请到 http.env 或者 https.env中进行配置",
"host": "请到 http.env 或者 https.env中进行配置"

View File

@@ -1,7 +1,8 @@
const sequelizeObj = require('sequelize');
const fs = require('fs');
const utils = require("../../src/utils/utils");
//db connect retry times
let connectRetryTimes = 0;
async function excute(config) {
let dbConf = config.db.mysql;
@@ -32,39 +33,49 @@ async function excute(config) {
}
}
);
try {
let connect = await dbClient.authenticate();
utils.tlConsole('db connect ok ... ');
} catch (e) {
utils.tlConsole('db connect err ...', e);
}
let tables = {}
let files = fs.readdirSync(__dirname);
for (let f of files) {
if (f[0] == '.' || f == 'db.js') continue;
async function connectDb(){
try {
let fn = require('./' + f);
if (typeof fn == 'function') {
let ms = fn(dbClient, sequelizeObj);
for (let k in ms) {
tables[k] = ms[k];
let connect = await dbClient.authenticate();
utils.tlConsole('db connect ok ... ');
let files = fs.readdirSync(__dirname);
for (let f of files) {
if (f[0] == '.' || f == 'db.js') continue;
try {
let fn = require('./' + f);
if (typeof fn == 'function') {
let ms = fn(dbClient, sequelizeObj);
for (let k in ms) {
tables[k] = ms[k];
}
}
} catch (e) {
utils.tlConsole(e);
}
}
try {
await dbClient.sync({ force: false });
utils.tlConsole("db sync ok ...");
} catch (e) {
utils.tlConsole("db sync err : ",e);
}
} catch (e) {
utils.tlConsole(e);
if(connectRetryTimes++ < 8){
utils.tlConsole('db connect err, retrying ... ',e.message);
await new Promise(resolve => setTimeout(resolve, connectRetryTimes * 3000));
await connectDb();
return;
}
utils.tlConsole('db connect err ',e);
}
}
try {
let res = await dbClient.sync({
force: false
});
utils.tlConsole("db sync ok ...");
} catch (e) {
utils.tlConsole("db sync err : ",e);
}
await connectDb();
return {
tables,

View File

@@ -26,15 +26,15 @@ tl_rtc_file_webrtc_turn_expire=86400000
## 是否开启数据库
tl_rtc_file_db_open=false
## 数据库地址
tl_rtc_file_db_mysql_host=
tl_rtc_file_db_mysql_host=mysql
## 数据库端口
tl_rtc_file_db_mysql_port=
tl_rtc_file_db_mysql_port=3306
## 数据库名称
tl_rtc_file_db_mysql_dbName=
tl_rtc_file_db_mysql_dbName=webchat
## 数据库用户名
tl_rtc_file_db_mysql_user=
tl_rtc_file_db_mysql_user=tlrtcfile
## 数据库密码
tl_rtc_file_db_mysql_password=
tl_rtc_file_db_mysql_password=tlrtcfile
#-----------------以下为oss相关配置-----------------#
## oss-seafile存储库ID