mirror of
https://github.com/tl-open-source/tl-rtc-file.git
synced 2025-11-03 11:10:56 +08:00
feat: docker
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -42,4 +42,3 @@ node_modules
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||
hs_err_pid*
|
||||
|
||||
*.map
|
||||
|
||||
11
Dockerfile
Normal file
11
Dockerfile
Normal file
@@ -0,0 +1,11 @@
|
||||
FROM node:14-alpine
|
||||
|
||||
ADD . /home/tlrtcfile
|
||||
|
||||
WORKDIR /home/tlrtcfile
|
||||
|
||||
RUN npm install
|
||||
|
||||
EXPOSE 9092 8444
|
||||
|
||||
CMD ["/bin/sh", "docker-entrypoint.sh"]
|
||||
@@ -69,7 +69,15 @@
|
||||
|
||||
4. chomd +x bin/startTurnServer.sh && ./startTurnServer.sh #启动turnserver,文件内容按需修改
|
||||
|
||||
## Docker
|
||||
|
||||
修改conf/cfg.json中的ws_online的ip地址(有更好的办法可以反馈下)
|
||||
|
||||
docker build -t iamtsm/tl-rtc-file .
|
||||
|
||||
docker run -p 9092:9092 -p 8444:8444 --name local -d iamtsm/tl-rtc-file
|
||||
|
||||
访问 : http://localhost:9092 或者 http://本机ip:9092
|
||||
## 概述图
|
||||
|
||||

|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"ws" : {
|
||||
"port": 8444,
|
||||
"ssl_port": 8444,
|
||||
"ws_online": "your online socket ip/host like wss://xxx.xxx.xxx, if just local test, dont need"
|
||||
"ws_online": "ws://本机ip:8444"
|
||||
},
|
||||
"node" : {
|
||||
"port" : 9092
|
||||
|
||||
7
docker-entrypoint.sh
Normal file
7
docker-entrypoint.sh
Normal file
@@ -0,0 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
npm run dev & npm run devsocket
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
<iframe frameborder="0" scrolling="no" src="./vertical.html" width="100%" height="30px"></iframe>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div id="fileApp" v-cloak>
|
||||
<div class="tool">
|
||||
<a title="github" href="https://github.com/iamtsm" target="_blank">
|
||||
@@ -44,9 +46,16 @@
|
||||
</svg>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
|
||||
<div style="text-align: center;font-size: 20px;color: beige;">注 : 仅用于学习用途, 请勿他用</div>
|
||||
<div class="roomClass" >
|
||||
<div style="text-align: center;font-size: 15px;color: beige;margin-bottom: 5px;margin-top: 8px;">qq交流群 : <a target="_blank" href="https://jq.qq.com/?_wv=1027&k=TKCwMBjN">624214498</a> </div>
|
||||
<div style="text-align: center;font-size: 12px;color: beige;margin-bottom: 5px;margin-top: 8px;">
|
||||
<svg style="width: 13px;height: 8px;" viewBox="0 0 1024 1024" p-id="4241" width="128" height="128">
|
||||
<path d="M512 277.333333a234.666667 234.666667 0 1 0 0 469.333334 234.666667 234.666667 0 0 0 0-469.333334z" p-id="4242" fill="#1afa29"></path>
|
||||
</svg>
|
||||
当前在线人数 : {{allManCount}}
|
||||
</div> <div class="roomClass" >
|
||||
<input :disabled="createDisabled" :class="[{'layui-btn-disabled':createDisabled}]" type="text" name="title" maxlength="15" autocomplete="off" class="layui-input cusInput" v-model="roomId" placeholder="输入房间编号">
|
||||
<i title="随机刷新房间号" v-show="!createDisabled" @click="refleshRoom()" class="layui-icon layui-icon-refresh" style="cursor: pointer; left: 85%;position: absolute;font-size: 24px;margin-top: -40px;"></i>
|
||||
<div class="layui-btn-container center">
|
||||
@@ -58,21 +67,21 @@
|
||||
<div class="layui-col-sm6 layui-col-md3" id="self">
|
||||
<input type="file" ref="self-file" v-model="fileName" v-show="false">
|
||||
|
||||
<button class="sendFileBtn-disable layui-btn-disabled" @click="clickChooseFile" v-show="uploadDisabled && !createDisabled" disabled>
|
||||
<button class="sendFileBtn-disable layui-btn-disabled" @click="clickChooseFile" v-show="(uploadDisabled && !createDisabled) || noOthersInRoom || sending" disabled>
|
||||
<svg viewBox="0 0 1024 1024" style="width: 30px;height: 30px;margin-left: -8px;margin-right: 10px;">
|
||||
<path d="M840.65 540.62h-655.9c-12.18 0-22.05-9.87-22.05-22.05v-5.9c0-12.18 9.87-22.05 22.05-22.05h655.9c12.18 0 22.05 9.87 22.05 22.05v5.9c0 12.18-9.87 22.05-22.05 22.05z" fill="#565656" p-id="1269"></path>
|
||||
<path d="M517.69 863.19h-5.9c-12.18 0-22.05-9.87-22.05-22.05v-655.9c0-12.18 9.87-22.05 22.05-22.05h5.9c12.18 0 22.05 9.87 22.05 22.05v655.9c0 12.17-9.87 22.05-22.05 22.05z" fill="#565656" p-id="1270"></path>
|
||||
</svg>
|
||||
<div style="font-size: 14px;word-break: keep-all;" >选择文件</div>
|
||||
</button>
|
||||
<button class="sendFileBtn" @click="clickChooseFile" v-show="uploadDisabled && createDisabled">
|
||||
<button class="sendFileBtn" @click="clickChooseFile" v-show="uploadDisabled && createDisabled && !noOthersInRoom && !sending">
|
||||
<svg viewBox="0 0 1024 1024" style="width: 30px;height: 30px;margin-left: -8px;margin-right: 10px;">
|
||||
<path d="M840.65 540.62h-655.9c-12.18 0-22.05-9.87-22.05-22.05v-5.9c0-12.18 9.87-22.05 22.05-22.05h655.9c12.18 0 22.05 9.87 22.05 22.05v5.9c0 12.18-9.87 22.05-22.05 22.05z" fill="#565656" p-id="1269"></path>
|
||||
<path d="M517.69 863.19h-5.9c-12.18 0-22.05-9.87-22.05-22.05v-655.9c0-12.18 9.87-22.05 22.05-22.05h5.9c12.18 0 22.05 9.87 22.05 22.05v655.9c0 12.17-9.87 22.05-22.05 22.05z" fill="#565656" p-id="1270"></path>
|
||||
</svg>
|
||||
<div style="font-size: 14px;word-break: keep-all;" >选择文件</div>
|
||||
</button>
|
||||
<button class="sendFileBtn" style="background-color: #79b0e8;" @click="submitChooseFile" v-show="!uploadDisabled">
|
||||
<button class="sendFileBtn" style="background-color: #79b0e8;" @click="submitChooseFile" v-show="!uploadDisabled && !sending">
|
||||
<svg viewBox="0 0 1024 1024" style="width: 30px;height: 25px;margin-left: -8px;margin-right: 10px;">
|
||||
<path d="M341.333333 277.333333l115.2-115.2c8.533333-8.533333 17.066667-12.8 29.866667-17.066666v473.6c0 17.066667 12.8 29.866667 25.6 29.866666s25.6-12.8 25.6-29.866666V140.8c8.533333 4.266667 21.333333 8.533333 29.866667 17.066667L682.666667 277.333333c4.266667 4.266667 12.8 8.533333 21.333333 8.533334s12.8-4.266667 21.333333-8.533334c12.8-12.8 12.8-29.866667 0-38.4l-115.2-115.2C554.666667 68.266667 469.333333 68.266667 418.133333 119.466667L302.933333 234.666667c-12.8 12.8-12.8 29.866667 0 38.4s25.6 12.8 38.4 4.266666z" fill="#191A1A" p-id="2860"></path>
|
||||
<path d="M738.133333 435.2h-72.533333c-17.066667 0-29.866667 12.8-29.866667 25.6s12.8 25.6 29.866667 25.6h72.533333c42.666667 0 76.8 34.133333 76.8 76.8V810.666667c0 42.666667-34.133333 76.8-76.8 76.8H285.866667c-42.666667 0-76.8-34.133333-76.8-76.8v-243.2c0-42.666667 34.133333-76.8 76.8-76.8h72.533333c17.066667 0 25.6-12.8 25.6-25.6s-12.8-25.6-25.6-25.6H285.866667c-72.533333 0-132.266667 59.733333-132.266667 132.266666V810.666667c0 72.533333 59.733333 132.266667 132.266667 132.266666h456.533333c72.533333 0 132.266667-59.733333 132.266667-132.266666v-243.2c0-72.533333-59.733333-132.266667-136.533334-132.266667z" fill="#191A1A" p-id="2861"></path>
|
||||
|
||||
@@ -29,13 +29,14 @@ axios.get(window.prefix + "/api/comm/initData",{}).then((initData)=>{
|
||||
fileReader : null, //文件读取对象
|
||||
rtcConns : {}, //远程连接
|
||||
remoteMap : {}, //远程连接map
|
||||
allManCount : 0,//在线人数
|
||||
|
||||
chunkSize : 256 * 1024, //一块256kb
|
||||
offset : 0, //当前文件分片位移
|
||||
fileName : null, //文件名称
|
||||
allSended : false,//当前文件是否全部发送给房间内所有用户
|
||||
currentReceiveSize : 0, //统计收到文件的大小
|
||||
currentSendingId : "", //当前正在发送的文件
|
||||
hasSending : "", //是否有正在发送的文件
|
||||
chooseFile : null, //选择的文件
|
||||
sendFileList : [], //发过文件的列表
|
||||
receiveFileList : [], //接收文件的列表
|
||||
@@ -49,14 +50,26 @@ axios.get(window.prefix + "/api/comm/initData",{}).then((initData)=>{
|
||||
exsitDisabled : function(){
|
||||
return !this.isJoined;
|
||||
},
|
||||
sending : function(){
|
||||
return this.hasSending;
|
||||
},
|
||||
uploadDisabled : function(){
|
||||
return !this.fileName || this.allSended;
|
||||
},
|
||||
showSendFileList : function() {
|
||||
return this.sendFileList && this.sendFileList.length > 5;
|
||||
},
|
||||
noOthersInRoom : function(){
|
||||
return Object.keys(this.remoteMap).length === 0;
|
||||
}
|
||||
},
|
||||
watch : {
|
||||
allManCount : function(newV,oldV){
|
||||
|
||||
},
|
||||
hasSending : function(newV,oldV){
|
||||
|
||||
},
|
||||
currentMenu :function(newV,oldV){
|
||||
|
||||
},
|
||||
@@ -438,6 +451,8 @@ axios.get(window.prefix + "/api/comm/initData",{}).then((initData)=>{
|
||||
}
|
||||
}
|
||||
if(hasAllSended){ //全部发送完毕
|
||||
this.allSended = true;
|
||||
this.hasSending = false
|
||||
return;
|
||||
}
|
||||
for(let id in this.remoteMap){ //还有还没发送的
|
||||
@@ -452,6 +467,7 @@ axios.get(window.prefix + "/api/comm/initData",{}).then((initData)=>{
|
||||
|
||||
|
||||
if(needSendingId != ''){
|
||||
this.hasSending = true
|
||||
let remote = this.remoteMap[needSendingId];
|
||||
let status = remote.status || 0;
|
||||
if(status === 1){ //保证同一时间只能发送房间内对应的一个用户
|
||||
@@ -782,6 +798,12 @@ axios.get(window.prefix + "/api/comm/initData",{}).then((initData)=>{
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//在线数量
|
||||
this.socket.on('count', function (data) {
|
||||
that.allManCount = data.mc;
|
||||
});
|
||||
|
||||
},
|
||||
initCss : function(e){
|
||||
if(!e) return;
|
||||
|
||||
6
res/js/index.min.js
vendored
6
res/js/index.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -5,12 +5,10 @@ const webrtcConf = conf.webrtc;
|
||||
|
||||
//获取ip地址,初始化等相关配置
|
||||
function initData(req,res) {
|
||||
let localIp = utils.getLocalIP();
|
||||
let clientIp = utils.getClientIP(req);
|
||||
let isLocal = clientIp === '1';
|
||||
let localIp = utils.getClientIP(req);
|
||||
|
||||
let data = {
|
||||
wsHost : isLocal ? "ws://"+localIp+":"+wsConf.port : wsConf.ws_online,
|
||||
wsHost : wsConf.ws_online ? wsConf.ws_online : "ws://"+localIp+":"+wsConf.port,
|
||||
rtcConfig : {iceServers : webrtcConf.iceServers} ,
|
||||
options : webrtcConf.options
|
||||
};
|
||||
|
||||
@@ -133,6 +133,11 @@ function listen(io) {
|
||||
socket.on('catchError', function (err) {
|
||||
console.log('err : ', err)
|
||||
})
|
||||
|
||||
|
||||
socket.on('count', function (message) {
|
||||
handler._count(message,{})
|
||||
})
|
||||
|
||||
|
||||
socket.on('message', function (message) {
|
||||
|
||||
@@ -7,6 +7,39 @@ class SocketHandler {
|
||||
this.socket = socket;
|
||||
}
|
||||
|
||||
/**
|
||||
* 数量
|
||||
* @param {*} message
|
||||
* @param {*} params
|
||||
*/
|
||||
_count( message, params){
|
||||
try{
|
||||
let allRoom = this.sockets.adapter.rooms;
|
||||
let allManCount = 0;
|
||||
|
||||
for(let room in allRoom){
|
||||
let clientsInRoom = allRoom[room];
|
||||
let otherSocketIds = Object.keys(clientsInRoom.sockets);
|
||||
let numClients = clientsInRoom ? otherSocketIds.length : 0;
|
||||
allManCount += numClients;
|
||||
}
|
||||
|
||||
for(let room in allRoom){
|
||||
let clientsInRoom = allRoom[room];
|
||||
let otherSocketIds = Object.keys(clientsInRoom.sockets);
|
||||
if( otherSocketIds.length > 0){
|
||||
for (let i = 0; i < otherSocketIds.length; i++) {
|
||||
let otherSocket = this.sockets.connected[otherSocketIds[i]];
|
||||
otherSocket.emit("count", {
|
||||
mc : allManCount
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}catch(e){
|
||||
console.log(e)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 链接断开
|
||||
@@ -19,6 +52,7 @@ class SocketHandler {
|
||||
from : socketId,
|
||||
};
|
||||
this.socket.broadcast.emit('exit',data);
|
||||
this._count(message, params)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -68,6 +102,7 @@ class SocketHandler {
|
||||
Object.assign(createdData,params['created'])
|
||||
this.socket.emit('created', createdData);
|
||||
}
|
||||
this._count(message, params)
|
||||
}
|
||||
|
||||
|
||||
@@ -133,6 +168,7 @@ class SocketHandler {
|
||||
otherSocket.emit('exit', message);
|
||||
}
|
||||
}
|
||||
this._count(message, params)
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user