完成基本功能

This commit is contained in:
Cloyir 2026-01-12 03:56:47 +08:00
commit f0b91409b6
57 changed files with 9700 additions and 0 deletions

53
.gitignore vendored Normal file
View File

@ -0,0 +1,53 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
# Dependencies
node_modules
node_modules/
server/node_modules/
# Build outputs
dist
dist-ssr
*.local
# Tauri
src-tauri/target/
# IDE
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
# Environment
.env
.env.local
.env.*.local
# OS
.DS_Store
Thumbs.db
# Lock files (optional - uncomment if you don't want to commit them)
# pnpm-lock.yaml
# package-lock.json
# yarn.lock
# IDE specific
.trae/
.history/
*.swp
*.swo
*~

7
.vscode/extensions.json vendored Normal file
View File

@ -0,0 +1,7 @@
{
"recommendations": [
"Vue.volar",
"tauri-apps.tauri-vscode",
"rust-lang.rust-analyzer"
]
}

7
README.md Normal file
View File

@ -0,0 +1,7 @@
# Tauri + Vue 3
This template should help get you started developing with Tauri + Vue 3 in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.
## Recommended IDE Setup
- [VS Code](https://code.visualstudio.com/) + [Vue - Official](https://marketplace.visualstudio.com/items?itemName=Vue.volar) + [Tauri](https://marketplace.visualstudio.com/items?itemName=tauri-apps.tauri-vscode) + [rust-analyzer](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer)

14
index.html Normal file
View File

@ -0,0 +1,14 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/p2p-icon.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>P2P File Transfer</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
</body>
</html>

24
package.json Normal file
View File

@ -0,0 +1,24 @@
{
"name": "p2p-transfer",
"private": true,
"version": "0.1.0",
"type": "module",
"scripts": {
"dev": "vite --host",
"build": "vite build",
"preview": "vite preview",
"tauri": "tauri"
},
"dependencies": {
"@tauri-apps/api": "^2",
"@tauri-apps/plugin-opener": "^2",
"socket.io-client": "^4.8.1",
"vue": "^3.5.13",
"vue-i18n": "12.0.0-alpha.3"
},
"devDependencies": {
"@tauri-apps/cli": "^2",
"@vitejs/plugin-vue": "^5.2.1",
"vite": "^6.0.3"
}
}

1127
pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load Diff

19
public/p2p-icon.svg Normal file
View File

@ -0,0 +1,19 @@
<svg width="256" height="256" viewBox="0 0 256 256" fill="none" xmlns="http://www.w3.org/2000/svg">
<defs>
<linearGradient id="grad1" x1="0%" y1="0%" x2="100%" y2="100%">
<stop offset="0%" style="stop-color:#3B82F6;stop-opacity:1" />
<stop offset="100%" style="stop-color:#60A5FA;stop-opacity:1" />
</linearGradient>
<linearGradient id="bgGrad" x1="0%" y1="0%" x2="100%" y2="100%">
<stop offset="0%" style="stop-color:#F8FAFC;stop-opacity:1" />
<stop offset="100%" style="stop-color:#E2E8F0;stop-opacity:1" />
</linearGradient>
</defs>
<rect width="256" height="256" rx="48" fill="url(#bgGrad)"/>
<g transform="translate(78, 48)">
<rect x="0" y="0" width="100" height="160" rx="12" fill="url(#grad1)" opacity="0.9"/>
<path d="M25 50 L75 50 M25 80 L75 80 M25 110 L60 110" stroke="white" stroke-width="6" stroke-linecap="round"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 903 B

6
public/tauri.svg Normal file
View File

@ -0,0 +1,6 @@
<svg width="206" height="231" viewBox="0 0 206 231" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M143.143 84C143.143 96.1503 133.293 106 121.143 106C108.992 106 99.1426 96.1503 99.1426 84C99.1426 71.8497 108.992 62 121.143 62C133.293 62 143.143 71.8497 143.143 84Z" fill="#FFC131"/>
<ellipse cx="84.1426" cy="147" rx="22" ry="22" transform="rotate(180 84.1426 147)" fill="#24C8DB"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M166.738 154.548C157.86 160.286 148.023 164.269 137.757 166.341C139.858 160.282 141 153.774 141 147C141 144.543 140.85 142.121 140.558 139.743C144.975 138.204 149.215 136.139 153.183 133.575C162.73 127.404 170.292 118.608 174.961 108.244C179.63 97.8797 181.207 86.3876 179.502 75.1487C177.798 63.9098 172.884 53.4021 165.352 44.8883C157.82 36.3744 147.99 30.2165 137.042 27.1546C126.095 24.0926 114.496 24.2568 103.64 27.6274C92.7839 30.998 83.1319 37.4317 75.8437 46.1553C74.9102 47.2727 74.0206 48.4216 73.176 49.5993C61.9292 50.8488 51.0363 54.0318 40.9629 58.9556C44.2417 48.4586 49.5653 38.6591 56.679 30.1442C67.0505 17.7298 80.7861 8.57426 96.2354 3.77762C111.685 -1.01901 128.19 -1.25267 143.769 3.10474C159.348 7.46215 173.337 16.2252 184.056 28.3411C194.775 40.457 201.767 55.4101 204.193 71.404C206.619 87.3978 204.374 103.752 197.73 118.501C191.086 133.25 180.324 145.767 166.738 154.548ZM41.9631 74.275L62.5557 76.8042C63.0459 72.813 63.9401 68.9018 65.2138 65.1274C57.0465 67.0016 49.2088 70.087 41.9631 74.275Z" fill="#FFC131"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M38.4045 76.4519C47.3493 70.6709 57.2677 66.6712 67.6171 64.6132C65.2774 70.9669 64 77.8343 64 85.0001C64 87.1434 64.1143 89.26 64.3371 91.3442C60.0093 92.8732 55.8533 94.9092 51.9599 97.4256C42.4128 103.596 34.8505 112.392 30.1816 122.756C25.5126 133.12 23.9357 144.612 25.6403 155.851C27.3449 167.09 32.2584 177.598 39.7906 186.112C47.3227 194.626 57.153 200.784 68.1003 203.846C79.0476 206.907 90.6462 206.743 101.502 203.373C112.359 200.002 122.011 193.568 129.299 184.845C130.237 183.722 131.131 182.567 131.979 181.383C143.235 180.114 154.132 176.91 164.205 171.962C160.929 182.49 155.596 192.319 148.464 200.856C138.092 213.27 124.357 222.426 108.907 227.222C93.458 232.019 76.9524 232.253 61.3736 227.895C45.7948 223.538 31.8055 214.775 21.0867 202.659C10.3679 190.543 3.37557 175.59 0.949823 159.596C-1.47592 143.602 0.768139 127.248 7.41237 112.499C14.0566 97.7497 24.8183 85.2327 38.4045 76.4519ZM163.062 156.711L163.062 156.711C162.954 156.773 162.846 156.835 162.738 156.897C162.846 156.835 162.954 156.773 163.062 156.711Z" fill="#24C8DB"/>
</svg>

After

Width:  |  Height:  |  Size: 2.5 KiB

1
public/vite.svg Normal file
View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

128
server/index.js Normal file
View File

@ -0,0 +1,128 @@
import Koa from 'koa';
import Router from 'koa-router';
import bodyParser from 'koa-bodyparser';
import cors from '@koa/cors';
import { createServer } from 'http';
import { Server } from 'socket.io';
import os from 'os';
import signalRouter from './routes/signal.js';
import filesRouter from './routes/files.js';
const app = new Koa();
const router = new Router();
const httpServer = createServer(app);
const io = new Server(httpServer, {
cors: {
origin: '*',
methods: ['GET', 'POST'],
credentials: true,
allowedHeaders: ['Content-Type', 'Authorization']
},
transports: ['websocket', 'polling']
});
app.use(cors({
origin: '*',
credentials: true,
allowMethods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
allowHeaders: ['Content-Type', 'Authorization']
}));
app.use(bodyParser());
app.use(async (ctx, next) => {
ctx.io = io;
await next();
});
router.get('/', async (ctx) => {
ctx.body = {
message: 'P2P File Transfer Server',
version: '1.0.0'
};
});
app.use(router.routes());
app.use(router.allowedMethods());
app.use(signalRouter.routes());
app.use(signalRouter.allowedMethods());
app.use(filesRouter.routes());
app.use(filesRouter.allowedMethods());
const rooms = new Map();
const users = new Map();
io.on('connection', (socket) => {
console.log('User connected:', socket.id);
socket.on('join-room', ({ roomId, userId, nickname }) => {
socket.join(roomId);
users.set(socket.id, { roomId, userId, nickname });
const room = rooms.get(roomId) || new Set();
room.add(socket.id);
rooms.set(roomId, room);
socket.to(roomId).emit('user-joined', { userId, socketId: socket.id, nickname });
const roomUsers = Array.from(room).map(id => ({
socketId: id,
userId: users.get(id)?.userId,
nickname: users.get(id)?.nickname
}));
socket.emit('room-users', roomUsers);
});
socket.on('signal', ({ targetSocketId, signal }) => {
const targetUser = users.get(targetSocketId);
if (targetUser) {
io.to(targetSocketId).emit('signal', {
senderSocketId: socket.id,
signal
});
}
});
socket.on('disconnect', () => {
console.log('User disconnected:', socket.id);
const user = users.get(socket.id);
if (user) {
const room = rooms.get(user.roomId);
if (room) {
room.delete(socket.id);
socket.to(user.roomId).emit('user-left', {
userId: user.userId,
socketId: socket.id
});
if (room.size === 0) {
rooms.delete(user.roomId);
}
}
users.delete(socket.id);
}
});
});
const PORT = process.env.PORT || 3000;
const HOST = process.env.HOST || '0.0.0.0';
httpServer.listen(PORT, HOST, () => {
console.log(`P2P Transfer Server running on http://${HOST}:${PORT}`);
console.log(`Local access: http://localhost:${PORT}`);
console.log(`LAN access: http://${getLocalIP()}:${PORT}`);
});
function getLocalIP() {
const interfaces = os.networkInterfaces();
for (const name of Object.keys(interfaces)) {
for (const iface of interfaces[name]) {
if (iface.family === 'IPv4' && !iface.internal) {
return iface.address;
}
}
}
return 'localhost';
}

29
server/package.json Normal file
View File

@ -0,0 +1,29 @@
{
"name": "p2p-transfer-server",
"version": "1.0.0",
"type": "module",
"description": "P2P file transfer server with Koa2 and Socket.io",
"main": "index.js",
"scripts": {
"start": "node index.js",
"dev": "node --watch index.js"
},
"keywords": [
"p2p",
"file-transfer",
"webrtc",
"koa2"
],
"author": "",
"license": "MIT",
"dependencies": {
"@koa/cors": "^5.0.0",
"@koa/multer": "^3.0.2",
"koa": "^2.15.3",
"koa-bodyparser": "^4.4.1",
"koa-router": "^12.0.1",
"multer": "^1.4.5-lts.1",
"socket.io": "^4.8.1",
"ws": "^8.18.0"
}
}

939
server/pnpm-lock.yaml generated Normal file
View File

@ -0,0 +1,939 @@
lockfileVersion: '9.0'
settings:
autoInstallPeers: true
excludeLinksFromLockfile: false
importers:
.:
dependencies:
'@koa/cors':
specifier: ^5.0.0
version: 5.0.0
'@koa/multer':
specifier: ^3.0.2
version: 3.1.0(multer@1.4.5-lts.2)
koa:
specifier: ^2.15.3
version: 2.16.3
koa-bodyparser:
specifier: ^4.4.1
version: 4.4.1
koa-router:
specifier: ^12.0.1
version: 12.0.1
multer:
specifier: ^1.4.5-lts.1
version: 1.4.5-lts.2
socket.io:
specifier: ^4.8.1
version: 4.8.3
ws:
specifier: ^8.18.0
version: 8.19.0
packages:
'@hapi/bourne@3.0.0':
resolution: {integrity: sha512-Waj1cwPXJDucOib4a3bAISsKJVb15MKi9IvmTI/7ssVEm6sywXGjVJDhl6/umt1pK1ZS7PacXU3A1PmFKHEZ2w==}
'@koa/cors@5.0.0':
resolution: {integrity: sha512-x/iUDjcS90W69PryLDIMgFyV21YLTnG9zOpPXS7Bkt2b8AsY3zZsIpOLBkYr9fBcF3HbkKaER5hOBZLfpLgYNw==}
engines: {node: '>= 14.0.0'}
'@koa/multer@3.1.0':
resolution: {integrity: sha512-ETf4OLpOew9XE9lyU+5HIqk3TCmdGAw9pUXgxzrlYip+PkxLGoU4meiVTxiW4B6lxdBNijb3DFQ7M2woLcDL1g==}
engines: {node: '>= 14'}
peerDependencies:
multer: '*'
'@socket.io/component-emitter@3.1.2':
resolution: {integrity: sha512-9BCxFwvbGg/RsZK9tjXd8s4UcwR0MWeFQ1XEKIQVVvAGJyINdrqKMcTRyLoK8Rse1GjzLV9cwjWV1olXRWEXVA==}
'@types/cors@2.8.19':
resolution: {integrity: sha512-mFNylyeyqN93lfe/9CSxOGREz8cpzAhH+E93xJ4xWQf62V8sQ/24reV2nyzUWM6H6Xji+GGHpkbLe7pVoUEskg==}
'@types/node@25.0.6':
resolution: {integrity: sha512-NNu0sjyNxpoiW3YuVFfNz7mxSQ+S4X2G28uqg2s+CzoqoQjLPsWSbsFFyztIAqt2vb8kfEAsJNepMGPTxFDx3Q==}
accepts@1.3.8:
resolution: {integrity: sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==}
engines: {node: '>= 0.6'}
append-field@1.0.0:
resolution: {integrity: sha512-klpgFSWLW1ZEs8svjfb7g4qWY0YS5imI82dTg+QahUvJ8YqAY0P10Uk8tTyh9ZGuYEZEMaeJYCF5BFuX552hsw==}
base64id@2.0.0:
resolution: {integrity: sha512-lGe34o6EHj9y3Kts9R4ZYs/Gr+6N7MCaMlIFA3F1R2O5/m7K06AxfSeO5530PEERE6/WyEg3lsuyw4GHlPZHog==}
engines: {node: ^4.5.0 || >= 5.9}
buffer-from@1.1.2:
resolution: {integrity: sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==}
busboy@1.6.0:
resolution: {integrity: sha512-8SFQbg/0hQ9xy3UNTB0YEnsNBbWfhf7RtnzpL7TkBiTBRfrQ9Fxcnz7VJsleJpyp6rVLvXiuORqjlHi5q+PYuA==}
engines: {node: '>=10.16.0'}
bytes@3.1.2:
resolution: {integrity: sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==}
engines: {node: '>= 0.8'}
cache-content-type@1.0.1:
resolution: {integrity: sha512-IKufZ1o4Ut42YUrZSo8+qnMTrFuKkvyoLXUywKz9GJ5BrhOFGhLdkx9sG4KAnVvbY6kEcSFjLQul+DVmBm2bgA==}
engines: {node: '>= 6.0.0'}
call-bind-apply-helpers@1.0.2:
resolution: {integrity: sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==}
engines: {node: '>= 0.4'}
call-bound@1.0.4:
resolution: {integrity: sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg==}
engines: {node: '>= 0.4'}
co-body@6.2.0:
resolution: {integrity: sha512-Kbpv2Yd1NdL1V/V4cwLVxraHDV6K8ayohr2rmH0J87Er8+zJjcTa6dAn9QMPC9CRgU8+aNajKbSf1TzDB1yKPA==}
engines: {node: '>=8.0.0'}
co@4.6.0:
resolution: {integrity: sha512-QVb0dM5HvG+uaxitm8wONl7jltx8dqhfU33DcqtOZcLSVIKSDDLDi7+0LbAKiyI8hD9u42m2YxXSkMGWThaecQ==}
engines: {iojs: '>= 1.0.0', node: '>= 0.12.0'}
concat-stream@1.6.2:
resolution: {integrity: sha512-27HBghJxjiZtIk3Ycvn/4kbJk/1uZuJFfuPEns6LaEvpvG1f0hTea8lilrouyo9mVc2GWdcEZ8OLoGmSADlrCw==}
engines: {'0': node >= 0.8}
content-disposition@0.5.4:
resolution: {integrity: sha512-FveZTNuGw04cxlAiWbzi6zTAL/lhehaWbTtgluJh4/E95DqMwTmha3KZN1aAWA8cFIhHzMZUvLevkw5Rqk+tSQ==}
engines: {node: '>= 0.6'}
content-type@1.0.5:
resolution: {integrity: sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==}
engines: {node: '>= 0.6'}
cookie@0.7.2:
resolution: {integrity: sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w==}
engines: {node: '>= 0.6'}
cookies@0.9.1:
resolution: {integrity: sha512-TG2hpqe4ELx54QER/S3HQ9SRVnQnGBtKUz5bLQWtYAQ+o6GpgMs6sYUvaiJjVxb+UXwhRhAEP3m7LbsIZ77Hmw==}
engines: {node: '>= 0.8'}
copy-to@2.0.1:
resolution: {integrity: sha512-3DdaFaU/Zf1AnpLiFDeNCD4TOWe3Zl2RZaTzUvWiIk5ERzcCodOE20Vqq4fzCbNoHURFHT4/us/Lfq+S2zyY4w==}
core-util-is@1.0.3:
resolution: {integrity: sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==}
cors@2.8.5:
resolution: {integrity: sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==}
engines: {node: '>= 0.10'}
debug@4.4.3:
resolution: {integrity: sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==}
engines: {node: '>=6.0'}
peerDependencies:
supports-color: '*'
peerDependenciesMeta:
supports-color:
optional: true
deep-equal@1.0.1:
resolution: {integrity: sha512-bHtC0iYvWhyaTzvV3CZgPeZQqCOBGyGsVV7v4eevpdkLHfiSrXUdBG+qAuSz4RI70sszvjQ1QSZ98An1yNwpSw==}
delegates@1.0.0:
resolution: {integrity: sha512-bd2L678uiWATM6m5Z1VzNCErI3jiGzt6HGY8OVICs40JQq/HALfbyNJmp0UDakEY4pMMaN0Ly5om/B1VI/+xfQ==}
depd@1.1.2:
resolution: {integrity: sha512-7emPTl6Dpo6JRXOXjLRxck+FlLRX5847cLKEn00PLAgc3g2hTZZgr+e4c2v6QpSmLeFP3n5yUo7ft6avBK/5jQ==}
engines: {node: '>= 0.6'}
depd@2.0.0:
resolution: {integrity: sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==}
engines: {node: '>= 0.8'}
destroy@1.2.0:
resolution: {integrity: sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==}
engines: {node: '>= 0.8', npm: 1.2.8000 || >= 1.4.16}
dunder-proto@1.0.1:
resolution: {integrity: sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==}
engines: {node: '>= 0.4'}
ee-first@1.1.1:
resolution: {integrity: sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==}
encodeurl@1.0.2:
resolution: {integrity: sha512-TPJXq8JqFaVYm2CWmPvnP2Iyo4ZSM7/QKcSmuMLDObfpH5fi7RUGmd/rTDf+rut/saiDiQEeVTNgAmJEdAOx0w==}
engines: {node: '>= 0.8'}
engine.io-parser@5.2.3:
resolution: {integrity: sha512-HqD3yTBfnBxIrbnM1DoD6Pcq8NECnh8d4As1Qgh0z5Gg3jRRIqijury0CL3ghu/edArpUYiYqQiDUQBIs4np3Q==}
engines: {node: '>=10.0.0'}
engine.io@6.6.5:
resolution: {integrity: sha512-2RZdgEbXmp5+dVbRm0P7HQUImZpICccJy7rN7Tv+SFa55pH+lxnuw6/K1ZxxBfHoYpSkHLAO92oa8O4SwFXA2A==}
engines: {node: '>=10.2.0'}
es-define-property@1.0.1:
resolution: {integrity: sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==}
engines: {node: '>= 0.4'}
es-errors@1.3.0:
resolution: {integrity: sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==}
engines: {node: '>= 0.4'}
es-object-atoms@1.1.1:
resolution: {integrity: sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==}
engines: {node: '>= 0.4'}
escape-html@1.0.3:
resolution: {integrity: sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==}
fresh@0.5.2:
resolution: {integrity: sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q==}
engines: {node: '>= 0.6'}
function-bind@1.1.2:
resolution: {integrity: sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==}
generator-function@2.0.1:
resolution: {integrity: sha512-SFdFmIJi+ybC0vjlHN0ZGVGHc3lgE0DxPAT0djjVg+kjOnSqclqmj0KQ7ykTOLP6YxoqOvuAODGdcHJn+43q3g==}
engines: {node: '>= 0.4'}
get-intrinsic@1.3.0:
resolution: {integrity: sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==}
engines: {node: '>= 0.4'}
get-proto@1.0.1:
resolution: {integrity: sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==}
engines: {node: '>= 0.4'}
gopd@1.2.0:
resolution: {integrity: sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==}
engines: {node: '>= 0.4'}
has-symbols@1.1.0:
resolution: {integrity: sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==}
engines: {node: '>= 0.4'}
has-tostringtag@1.0.2:
resolution: {integrity: sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==}
engines: {node: '>= 0.4'}
hasown@2.0.2:
resolution: {integrity: sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==}
engines: {node: '>= 0.4'}
http-assert@1.5.0:
resolution: {integrity: sha512-uPpH7OKX4H25hBmU6G1jWNaqJGpTXxey+YOUizJUAgu0AjLUeC8D73hTrhvDS5D+GJN1DN1+hhc/eF/wpxtp0w==}
engines: {node: '>= 0.8'}
http-errors@1.8.1:
resolution: {integrity: sha512-Kpk9Sm7NmI+RHhnj6OIWDI1d6fIoFAtFt9RLaTMRlg/8w49juAStsrBgp0Dp4OdxdVbRIeKhtCUvoi/RuAhO4g==}
engines: {node: '>= 0.6'}
http-errors@2.0.1:
resolution: {integrity: sha512-4FbRdAX+bSdmo4AUFuS0WNiPz8NgFt+r8ThgNWmlrjQjt1Q7ZR9+zTlce2859x4KSXrwIsaeTqDoKQmtP8pLmQ==}
engines: {node: '>= 0.8'}
iconv-lite@0.4.24:
resolution: {integrity: sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==}
engines: {node: '>=0.10.0'}
inflation@2.1.0:
resolution: {integrity: sha512-t54PPJHG1Pp7VQvxyVCJ9mBbjG3Hqryges9bXoOO6GExCPa+//i/d5GSuFtpx3ALLd7lgIAur6zrIlBQyJuMlQ==}
engines: {node: '>= 0.8.0'}
inherits@2.0.4:
resolution: {integrity: sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==}
is-generator-function@1.1.2:
resolution: {integrity: sha512-upqt1SkGkODW9tsGNG5mtXTXtECizwtS2kA161M+gJPc1xdb/Ax629af6YrTwcOeQHbewrPNlE5Dx7kzvXTizA==}
engines: {node: '>= 0.4'}
is-regex@1.2.1:
resolution: {integrity: sha512-MjYsKHO5O7mCsmRGxWcLWheFqN9DJ/2TmngvjKXihe6efViPqc274+Fx/4fYj/r03+ESvBdTXK0V6tA3rgez1g==}
engines: {node: '>= 0.4'}
isarray@1.0.0:
resolution: {integrity: sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==}
keygrip@1.1.0:
resolution: {integrity: sha512-iYSchDJ+liQ8iwbSI2QqsQOvqv58eJCEanyJPJi+Khyu8smkcKSFUCbPwzFcL7YVtZ6eONjqRX/38caJ7QjRAQ==}
engines: {node: '>= 0.6'}
deprecated: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
koa-bodyparser@4.4.1:
resolution: {integrity: sha512-kBH3IYPMb+iAXnrxIhXnW+gXV8OTzCu8VPDqvcDHW9SQrbkHmqPQtiZwrltNmSq6/lpipHnT7k7PsjlVD7kK0w==}
engines: {node: '>=8.0.0'}
koa-compose@4.1.0:
resolution: {integrity: sha512-8ODW8TrDuMYvXRwra/Kh7/rJo9BtOfPc6qO8eAfC80CnCvSjSl0bkRM24X6/XBBEyj0v1nRUQ1LyOy3dbqOWXw==}
koa-convert@2.0.0:
resolution: {integrity: sha512-asOvN6bFlSnxewce2e/DK3p4tltyfC4VM7ZwuTuepI7dEQVcvpyFuBcEARu1+Hxg8DIwytce2n7jrZtRlPrARA==}
engines: {node: '>= 10'}
koa-router@12.0.1:
resolution: {integrity: sha512-gaDdj3GtzoLoeosacd50kBBTnnh3B9AYxDThQUo4sfUyXdOhY6ku1qyZKW88tQCRgc3Sw6ChXYXWZwwgjOxE0w==}
engines: {node: '>= 12'}
deprecated: 'Please use @koa/router instead, starting from v9! '
koa@2.16.3:
resolution: {integrity: sha512-zPPuIt+ku1iCpFBRwseMcPYQ1cJL8l60rSmKeOuGfOXyE6YnTBmf2aEFNL2HQGrD0cPcLO/t+v9RTgC+fwEh/g==}
engines: {node: ^4.8.4 || ^6.10.1 || ^7.10.1 || >= 8.1.4}
math-intrinsics@1.1.0:
resolution: {integrity: sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==}
engines: {node: '>= 0.4'}
media-typer@0.3.0:
resolution: {integrity: sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ==}
engines: {node: '>= 0.6'}
methods@1.1.2:
resolution: {integrity: sha512-iclAHeNqNm68zFtnZ0e+1L2yUIdvzNoauKU4WBA3VvH/vPFieF7qfRlwUZU+DA9P9bPXIS90ulxoUoCH23sV2w==}
engines: {node: '>= 0.6'}
mime-db@1.52.0:
resolution: {integrity: sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==}
engines: {node: '>= 0.6'}
mime-types@2.1.35:
resolution: {integrity: sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==}
engines: {node: '>= 0.6'}
minimist@1.2.8:
resolution: {integrity: sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==}
mkdirp@0.5.6:
resolution: {integrity: sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==}
hasBin: true
ms@2.1.3:
resolution: {integrity: sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==}
multer@1.4.5-lts.2:
resolution: {integrity: sha512-VzGiVigcG9zUAoCNU+xShztrlr1auZOlurXynNvO9GiWD1/mTBbUljOKY+qMeazBqXgRnjzeEgJI/wyjJUHg9A==}
engines: {node: '>= 6.0.0'}
deprecated: Multer 1.x is impacted by a number of vulnerabilities, which have been patched in 2.x. You should upgrade to the latest 2.x version.
negotiator@0.6.3:
resolution: {integrity: sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==}
engines: {node: '>= 0.6'}
object-assign@4.1.1:
resolution: {integrity: sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==}
engines: {node: '>=0.10.0'}
object-inspect@1.13.4:
resolution: {integrity: sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew==}
engines: {node: '>= 0.4'}
on-finished@2.4.1:
resolution: {integrity: sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==}
engines: {node: '>= 0.8'}
only@0.0.2:
resolution: {integrity: sha512-Fvw+Jemq5fjjyWz6CpKx6w9s7xxqo3+JCyM0WXWeCSOboZ8ABkyvP8ID4CZuChA/wxSx+XSJmdOm8rGVyJ1hdQ==}
parseurl@1.3.3:
resolution: {integrity: sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==}
engines: {node: '>= 0.8'}
path-to-regexp@6.3.0:
resolution: {integrity: sha512-Yhpw4T9C6hPpgPeA28us07OJeqZ5EzQTkbfwuhsUg0c237RomFoETJgmp2sa3F/41gfLE6G5cqcYwznmeEeOlQ==}
process-nextick-args@2.0.1:
resolution: {integrity: sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==}
qs@6.14.1:
resolution: {integrity: sha512-4EK3+xJl8Ts67nLYNwqw/dsFVnCf+qR7RgXSK9jEEm9unao3njwMDdmsdvoKBKHzxd7tCYz5e5M+SnMjdtXGQQ==}
engines: {node: '>=0.6'}
raw-body@2.5.3:
resolution: {integrity: sha512-s4VSOf6yN0rvbRZGxs8Om5CWj6seneMwK3oDb4lWDH0UPhWcxwOWw5+qk24bxq87szX1ydrwylIOp2uG1ojUpA==}
engines: {node: '>= 0.8'}
readable-stream@2.3.8:
resolution: {integrity: sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA==}
safe-buffer@5.1.2:
resolution: {integrity: sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==}
safe-buffer@5.2.1:
resolution: {integrity: sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==}
safe-regex-test@1.1.0:
resolution: {integrity: sha512-x/+Cz4YrimQxQccJf5mKEbIa1NzeCRNI5Ecl/ekmlYaampdNLPalVyIcCZNNH3MvmqBugV5TMYZXv0ljslUlaw==}
engines: {node: '>= 0.4'}
safer-buffer@2.1.2:
resolution: {integrity: sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==}
setprototypeof@1.2.0:
resolution: {integrity: sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==}
side-channel-list@1.0.0:
resolution: {integrity: sha512-FCLHtRD/gnpCiCHEiJLOwdmFP+wzCmDEkc9y7NsYxeF4u7Btsn1ZuwgwJGxImImHicJArLP4R0yX4c2KCrMrTA==}
engines: {node: '>= 0.4'}
side-channel-map@1.0.1:
resolution: {integrity: sha512-VCjCNfgMsby3tTdo02nbjtM/ewra6jPHmpThenkTYh8pG9ucZ/1P8So4u4FGBek/BjpOVsDCMoLA/iuBKIFXRA==}
engines: {node: '>= 0.4'}
side-channel-weakmap@1.0.2:
resolution: {integrity: sha512-WPS/HvHQTYnHisLo9McqBHOJk2FkHO/tlpvldyrnem4aeQp4hai3gythswg6p01oSoTl58rcpiFAjF2br2Ak2A==}
engines: {node: '>= 0.4'}
side-channel@1.1.0:
resolution: {integrity: sha512-ZX99e6tRweoUXqR+VBrslhda51Nh5MTQwou5tnUDgbtyM0dBgmhEDtWGP/xbKn6hqfPRHujUNwz5fy/wbbhnpw==}
engines: {node: '>= 0.4'}
socket.io-adapter@2.5.6:
resolution: {integrity: sha512-DkkO/dz7MGln0dHn5bmN3pPy+JmywNICWrJqVWiVOyvXjWQFIv9c2h24JrQLLFJ2aQVQf/Cvl1vblnd4r2apLQ==}
socket.io-parser@4.2.5:
resolution: {integrity: sha512-bPMmpy/5WWKHea5Y/jYAP6k74A+hvmRCQaJuJB6I/ML5JZq/KfNieUVo/3Mh7SAqn7TyFdIo6wqYHInG1MU1bQ==}
engines: {node: '>=10.0.0'}
socket.io@4.8.3:
resolution: {integrity: sha512-2Dd78bqzzjE6KPkD5fHZmDAKRNe3J15q+YHDrIsy9WEkqttc7GY+kT9OBLSMaPbQaEd0x1BjcmtMtXkfpc+T5A==}
engines: {node: '>=10.2.0'}
statuses@1.5.0:
resolution: {integrity: sha512-OpZ3zP+jT1PI7I8nemJX4AKmAX070ZkYPVWV/AaKTJl+tXCTGyVdC1a4SL8RUQYEwk/f34ZX8UTykN68FwrqAA==}
engines: {node: '>= 0.6'}
statuses@2.0.2:
resolution: {integrity: sha512-DvEy55V3DB7uknRo+4iOGT5fP1slR8wQohVdknigZPMpMstaKJQWhwiYBACJE3Ul2pTnATihhBYnRhZQHGBiRw==}
engines: {node: '>= 0.8'}
streamsearch@1.1.0:
resolution: {integrity: sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg==}
engines: {node: '>=10.0.0'}
string_decoder@1.1.1:
resolution: {integrity: sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==}
toidentifier@1.0.1:
resolution: {integrity: sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==}
engines: {node: '>=0.6'}
tsscmp@1.0.6:
resolution: {integrity: sha512-LxhtAkPDTkVCMQjt2h6eBVY28KCjikZqZfMcC15YBeNjkgUpdCfBu5HoiOTDu86v6smE8yOjyEktJ8hlbANHQA==}
engines: {node: '>=0.6.x'}
type-is@1.6.18:
resolution: {integrity: sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==}
engines: {node: '>= 0.6'}
typedarray@0.0.6:
resolution: {integrity: sha512-/aCDEGatGvZ2BIk+HmLf4ifCJFwvKFNb9/JeZPMulfgFracn9QFcAf5GO8B/mweUjSoblS5In0cWhqpfs/5PQA==}
undici-types@7.16.0:
resolution: {integrity: sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw==}
unpipe@1.0.0:
resolution: {integrity: sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==}
engines: {node: '>= 0.8'}
util-deprecate@1.0.2:
resolution: {integrity: sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==}
vary@1.1.2:
resolution: {integrity: sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==}
engines: {node: '>= 0.8'}
ws@8.18.3:
resolution: {integrity: sha512-PEIGCY5tSlUt50cqyMXfCzX+oOPqN0vuGqWzbcJ2xvnkzkq46oOpz7dQaTDBdfICb4N14+GARUDw2XV2N4tvzg==}
engines: {node: '>=10.0.0'}
peerDependencies:
bufferutil: ^4.0.1
utf-8-validate: '>=5.0.2'
peerDependenciesMeta:
bufferutil:
optional: true
utf-8-validate:
optional: true
ws@8.19.0:
resolution: {integrity: sha512-blAT2mjOEIi0ZzruJfIhb3nps74PRWTCz1IjglWEEpQl5XS/UNama6u2/rjFkDDouqr4L67ry+1aGIALViWjDg==}
engines: {node: '>=10.0.0'}
peerDependencies:
bufferutil: ^4.0.1
utf-8-validate: '>=5.0.2'
peerDependenciesMeta:
bufferutil:
optional: true
utf-8-validate:
optional: true
xtend@4.0.2:
resolution: {integrity: sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==}
engines: {node: '>=0.4'}
ylru@1.4.0:
resolution: {integrity: sha512-2OQsPNEmBCvXuFlIni/a+Rn+R2pHW9INm0BxXJ4hVDA8TirqMj+J/Rp9ItLatT/5pZqWwefVrTQcHpixsxnVlA==}
engines: {node: '>= 4.0.0'}
snapshots:
'@hapi/bourne@3.0.0': {}
'@koa/cors@5.0.0':
dependencies:
vary: 1.1.2
'@koa/multer@3.1.0(multer@1.4.5-lts.2)':
dependencies:
multer: 1.4.5-lts.2
'@socket.io/component-emitter@3.1.2': {}
'@types/cors@2.8.19':
dependencies:
'@types/node': 25.0.6
'@types/node@25.0.6':
dependencies:
undici-types: 7.16.0
accepts@1.3.8:
dependencies:
mime-types: 2.1.35
negotiator: 0.6.3
append-field@1.0.0: {}
base64id@2.0.0: {}
buffer-from@1.1.2: {}
busboy@1.6.0:
dependencies:
streamsearch: 1.1.0
bytes@3.1.2: {}
cache-content-type@1.0.1:
dependencies:
mime-types: 2.1.35
ylru: 1.4.0
call-bind-apply-helpers@1.0.2:
dependencies:
es-errors: 1.3.0
function-bind: 1.1.2
call-bound@1.0.4:
dependencies:
call-bind-apply-helpers: 1.0.2
get-intrinsic: 1.3.0
co-body@6.2.0:
dependencies:
'@hapi/bourne': 3.0.0
inflation: 2.1.0
qs: 6.14.1
raw-body: 2.5.3
type-is: 1.6.18
co@4.6.0: {}
concat-stream@1.6.2:
dependencies:
buffer-from: 1.1.2
inherits: 2.0.4
readable-stream: 2.3.8
typedarray: 0.0.6
content-disposition@0.5.4:
dependencies:
safe-buffer: 5.2.1
content-type@1.0.5: {}
cookie@0.7.2: {}
cookies@0.9.1:
dependencies:
depd: 2.0.0
keygrip: 1.1.0
copy-to@2.0.1: {}
core-util-is@1.0.3: {}
cors@2.8.5:
dependencies:
object-assign: 4.1.1
vary: 1.1.2
debug@4.4.3:
dependencies:
ms: 2.1.3
deep-equal@1.0.1: {}
delegates@1.0.0: {}
depd@1.1.2: {}
depd@2.0.0: {}
destroy@1.2.0: {}
dunder-proto@1.0.1:
dependencies:
call-bind-apply-helpers: 1.0.2
es-errors: 1.3.0
gopd: 1.2.0
ee-first@1.1.1: {}
encodeurl@1.0.2: {}
engine.io-parser@5.2.3: {}
engine.io@6.6.5:
dependencies:
'@types/cors': 2.8.19
'@types/node': 25.0.6
accepts: 1.3.8
base64id: 2.0.0
cookie: 0.7.2
cors: 2.8.5
debug: 4.4.3
engine.io-parser: 5.2.3
ws: 8.18.3
transitivePeerDependencies:
- bufferutil
- supports-color
- utf-8-validate
es-define-property@1.0.1: {}
es-errors@1.3.0: {}
es-object-atoms@1.1.1:
dependencies:
es-errors: 1.3.0
escape-html@1.0.3: {}
fresh@0.5.2: {}
function-bind@1.1.2: {}
generator-function@2.0.1: {}
get-intrinsic@1.3.0:
dependencies:
call-bind-apply-helpers: 1.0.2
es-define-property: 1.0.1
es-errors: 1.3.0
es-object-atoms: 1.1.1
function-bind: 1.1.2
get-proto: 1.0.1
gopd: 1.2.0
has-symbols: 1.1.0
hasown: 2.0.2
math-intrinsics: 1.1.0
get-proto@1.0.1:
dependencies:
dunder-proto: 1.0.1
es-object-atoms: 1.1.1
gopd@1.2.0: {}
has-symbols@1.1.0: {}
has-tostringtag@1.0.2:
dependencies:
has-symbols: 1.1.0
hasown@2.0.2:
dependencies:
function-bind: 1.1.2
http-assert@1.5.0:
dependencies:
deep-equal: 1.0.1
http-errors: 1.8.1
http-errors@1.8.1:
dependencies:
depd: 1.1.2
inherits: 2.0.4
setprototypeof: 1.2.0
statuses: 1.5.0
toidentifier: 1.0.1
http-errors@2.0.1:
dependencies:
depd: 2.0.0
inherits: 2.0.4
setprototypeof: 1.2.0
statuses: 2.0.2
toidentifier: 1.0.1
iconv-lite@0.4.24:
dependencies:
safer-buffer: 2.1.2
inflation@2.1.0: {}
inherits@2.0.4: {}
is-generator-function@1.1.2:
dependencies:
call-bound: 1.0.4
generator-function: 2.0.1
get-proto: 1.0.1
has-tostringtag: 1.0.2
safe-regex-test: 1.1.0
is-regex@1.2.1:
dependencies:
call-bound: 1.0.4
gopd: 1.2.0
has-tostringtag: 1.0.2
hasown: 2.0.2
isarray@1.0.0: {}
keygrip@1.1.0:
dependencies:
tsscmp: 1.0.6
koa-bodyparser@4.4.1:
dependencies:
co-body: 6.2.0
copy-to: 2.0.1
type-is: 1.6.18
koa-compose@4.1.0: {}
koa-convert@2.0.0:
dependencies:
co: 4.6.0
koa-compose: 4.1.0
koa-router@12.0.1:
dependencies:
debug: 4.4.3
http-errors: 2.0.1
koa-compose: 4.1.0
methods: 1.1.2
path-to-regexp: 6.3.0
transitivePeerDependencies:
- supports-color
koa@2.16.3:
dependencies:
accepts: 1.3.8
cache-content-type: 1.0.1
content-disposition: 0.5.4
content-type: 1.0.5
cookies: 0.9.1
debug: 4.4.3
delegates: 1.0.0
depd: 2.0.0
destroy: 1.2.0
encodeurl: 1.0.2
escape-html: 1.0.3
fresh: 0.5.2
http-assert: 1.5.0
http-errors: 1.8.1
is-generator-function: 1.1.2
koa-compose: 4.1.0
koa-convert: 2.0.0
on-finished: 2.4.1
only: 0.0.2
parseurl: 1.3.3
statuses: 1.5.0
type-is: 1.6.18
vary: 1.1.2
transitivePeerDependencies:
- supports-color
math-intrinsics@1.1.0: {}
media-typer@0.3.0: {}
methods@1.1.2: {}
mime-db@1.52.0: {}
mime-types@2.1.35:
dependencies:
mime-db: 1.52.0
minimist@1.2.8: {}
mkdirp@0.5.6:
dependencies:
minimist: 1.2.8
ms@2.1.3: {}
multer@1.4.5-lts.2:
dependencies:
append-field: 1.0.0
busboy: 1.6.0
concat-stream: 1.6.2
mkdirp: 0.5.6
object-assign: 4.1.1
type-is: 1.6.18
xtend: 4.0.2
negotiator@0.6.3: {}
object-assign@4.1.1: {}
object-inspect@1.13.4: {}
on-finished@2.4.1:
dependencies:
ee-first: 1.1.1
only@0.0.2: {}
parseurl@1.3.3: {}
path-to-regexp@6.3.0: {}
process-nextick-args@2.0.1: {}
qs@6.14.1:
dependencies:
side-channel: 1.1.0
raw-body@2.5.3:
dependencies:
bytes: 3.1.2
http-errors: 2.0.1
iconv-lite: 0.4.24
unpipe: 1.0.0
readable-stream@2.3.8:
dependencies:
core-util-is: 1.0.3
inherits: 2.0.4
isarray: 1.0.0
process-nextick-args: 2.0.1
safe-buffer: 5.1.2
string_decoder: 1.1.1
util-deprecate: 1.0.2
safe-buffer@5.1.2: {}
safe-buffer@5.2.1: {}
safe-regex-test@1.1.0:
dependencies:
call-bound: 1.0.4
es-errors: 1.3.0
is-regex: 1.2.1
safer-buffer@2.1.2: {}
setprototypeof@1.2.0: {}
side-channel-list@1.0.0:
dependencies:
es-errors: 1.3.0
object-inspect: 1.13.4
side-channel-map@1.0.1:
dependencies:
call-bound: 1.0.4
es-errors: 1.3.0
get-intrinsic: 1.3.0
object-inspect: 1.13.4
side-channel-weakmap@1.0.2:
dependencies:
call-bound: 1.0.4
es-errors: 1.3.0
get-intrinsic: 1.3.0
object-inspect: 1.13.4
side-channel-map: 1.0.1
side-channel@1.1.0:
dependencies:
es-errors: 1.3.0
object-inspect: 1.13.4
side-channel-list: 1.0.0
side-channel-map: 1.0.1
side-channel-weakmap: 1.0.2
socket.io-adapter@2.5.6:
dependencies:
debug: 4.4.3
ws: 8.18.3
transitivePeerDependencies:
- bufferutil
- supports-color
- utf-8-validate
socket.io-parser@4.2.5:
dependencies:
'@socket.io/component-emitter': 3.1.2
debug: 4.4.3
transitivePeerDependencies:
- supports-color
socket.io@4.8.3:
dependencies:
accepts: 1.3.8
base64id: 2.0.0
cors: 2.8.5
debug: 4.4.3
engine.io: 6.6.5
socket.io-adapter: 2.5.6
socket.io-parser: 4.2.5
transitivePeerDependencies:
- bufferutil
- supports-color
- utf-8-validate
statuses@1.5.0: {}
statuses@2.0.2: {}
streamsearch@1.1.0: {}
string_decoder@1.1.1:
dependencies:
safe-buffer: 5.1.2
toidentifier@1.0.1: {}
tsscmp@1.0.6: {}
type-is@1.6.18:
dependencies:
media-typer: 0.3.0
mime-types: 2.1.35
typedarray@0.0.6: {}
undici-types@7.16.0: {}
unpipe@1.0.0: {}
util-deprecate@1.0.2: {}
vary@1.1.2: {}
ws@8.18.3: {}
ws@8.19.0: {}
xtend@4.0.2: {}
ylru@1.4.0: {}

122
server/routes/files.js Normal file
View File

@ -0,0 +1,122 @@
import Router from 'koa-router';
import multer from '@koa/multer';
import path from 'path';
import fs from 'fs';
const router = new Router({
prefix: '/api/files'
});
const uploadDir = path.join(process.cwd(), 'uploads');
if (!fs.existsSync(uploadDir)) {
fs.mkdirSync(uploadDir, { recursive: true });
}
const storage = multer.diskStorage({
destination: (req, file, cb) => {
cb(null, uploadDir);
},
filename: (req, file, cb) => {
const uniqueSuffix = Date.now() + '-' + Math.round(Math.random() * 1E9);
cb(null, uniqueSuffix + '-' + file.originalname);
}
});
const upload = multer({ storage });
const fileTransfers = new Map();
router.get('/info', async (ctx) => {
ctx.body = {
message: 'File API endpoint'
};
});
router.post('/metadata', async (ctx) => {
const { fileId, name, size, type, senderId, receiverId } = ctx.request.body;
fileTransfers.set(fileId, {
fileId,
name,
size,
type,
senderId,
receiverId,
progress: 0,
status: 'pending',
createdAt: new Date()
});
ctx.body = {
success: true,
fileId,
message: 'File metadata registered'
};
});
router.get('/metadata/:fileId', async (ctx) => {
const { fileId } = ctx.params;
const fileData = fileTransfers.get(fileId);
if (!fileData) {
ctx.status = 404;
ctx.body = {
error: 'File not found'
};
return;
}
ctx.body = fileData;
});
router.put('/progress/:fileId', async (ctx) => {
const { fileId } = ctx.params;
const { progress, status } = ctx.request.body;
const fileData = fileTransfers.get(fileId);
if (fileData) {
fileData.progress = progress;
if (status) {
fileData.status = status;
}
ctx.io?.to(fileData.senderId).emit('file-progress', {
fileId,
progress,
status
});
ctx.io?.to(fileData.receiverId).emit('file-progress', {
fileId,
progress,
status
});
}
ctx.body = {
success: true,
fileId,
progress
};
});
router.delete('/:fileId', async (ctx) => {
const { fileId } = ctx.params;
fileTransfers.delete(fileId);
ctx.body = {
success: true,
message: 'File transfer cancelled'
};
});
router.get('/transfers', async (ctx) => {
const { userId } = ctx.query;
const transfers = Array.from(fileTransfers.values()).filter(
transfer => transfer.senderId === userId || transfer.receiverId === userId
);
ctx.body = transfers;
});
export default router;

14
server/routes/signal.js Normal file
View File

@ -0,0 +1,14 @@
import Router from 'koa-router';
const router = new Router({
prefix: '/api/signal'
});
router.get('/status', async (ctx) => {
ctx.body = {
status: 'ok',
message: 'Signal server is running'
};
});
export default router;

7
src-tauri/.gitignore vendored Normal file
View File

@ -0,0 +1,7 @@
# Generated by Cargo
# will have compiled files and executables
/target/
# Generated by Tauri
# will have schema files for capabilities auto-completion
/gen/schemas

5145
src-tauri/Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

25
src-tauri/Cargo.toml Normal file
View File

@ -0,0 +1,25 @@
[package]
name = "p2p-transfer"
version = "0.1.0"
description = "A Tauri App"
authors = ["you"]
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
# The `_lib` suffix may seem redundant but it is necessary
# to make the lib name unique and wouldn't conflict with the bin name.
# This seems to be only an issue on Windows, see https://github.com/rust-lang/cargo/issues/8519
name = "p2p_transfer_lib"
crate-type = ["staticlib", "cdylib", "rlib"]
[build-dependencies]
tauri-build = { version = "2", features = [] }
[dependencies]
tauri = { version = "2", features = [] }
tauri-plugin-opener = "2"
serde = { version = "1", features = ["derive"] }
serde_json = "1"

3
src-tauri/build.rs Normal file
View File

@ -0,0 +1,3 @@
fn main() {
tauri_build::build()
}

View File

@ -0,0 +1,10 @@
{
"$schema": "../gen/schemas/desktop-schema.json",
"identifier": "default",
"description": "Capability for the main window",
"windows": ["main"],
"permissions": [
"core:default",
"opener:default"
]
}

BIN
src-tauri/icons/128x128.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

BIN
src-tauri/icons/32x32.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 974 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 903 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

BIN
src-tauri/icons/icon.icns Normal file

Binary file not shown.

BIN
src-tauri/icons/icon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

BIN
src-tauri/icons/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

3
src-tauri/mocks/path.js Normal file
View File

@ -0,0 +1,3 @@
export async function downloadDir() {
throw new Error('Tauri path API is only available in desktop environment');
}

3
src-tauri/mocks/tauri.js Normal file
View File

@ -0,0 +1,3 @@
export async function invoke(cmd, args) {
throw new Error('Tauri invoke is only available in desktop environment');
}

43
src-tauri/src/lib.rs Normal file
View File

@ -0,0 +1,43 @@
// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/
#[tauri::command]
fn greet(name: &str) -> String {
format!("Hello, {}! You've been greeted from Rust!", name)
}
#[tauri::command]
async fn open_folder(path: String) -> Result<(), String> {
#[cfg(target_os = "windows")]
{
std::process::Command::new("explorer")
.arg(&path)
.spawn()
.map_err(|e| e.to_string())?;
}
#[cfg(target_os = "macos")]
{
std::process::Command::new("open")
.arg(&path)
.spawn()
.map_err(|e| e.to_string())?;
}
#[cfg(target_os = "linux")]
{
std::process::Command::new("xdg-open")
.arg(&path)
.spawn()
.map_err(|e| e.to_string())?;
}
Ok(())
}
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
.plugin(tauri_plugin_opener::init())
.invoke_handler(tauri::generate_handler![greet, open_folder])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}

6
src-tauri/src/main.rs Normal file
View File

@ -0,0 +1,6 @@
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
fn main() {
p2p_transfer_lib::run()
}

35
src-tauri/tauri.conf.json Normal file
View File

@ -0,0 +1,35 @@
{
"$schema": "https://schema.tauri.app/config/2",
"productName": "p2p-transfer",
"version": "0.1.0",
"identifier": "com.cloyir.p2p-transfer",
"build": {
"beforeDevCommand": "pnpm dev",
"devUrl": "http://localhost:1420",
"beforeBuildCommand": "pnpm build",
"frontendDist": "../dist"
},
"app": {
"windows": [
{
"title": "p2p-transfer",
"width": 800,
"height": 600
}
],
"security": {
"csp": "default-src 'self'; connect-src 'self' http://localhost:3000 http://127.0.0.1:3000 ws://localhost:3000 ws://127.0.0.1:3000; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob:; font-src 'self' data:; media-src 'self' blob:;"
}
},
"bundle": {
"active": true,
"targets": "all",
"icon": [
"icons/32x32.png",
"icons/128x128.png",
"icons/128x128@2x.png",
"icons/icon.icns",
"icons/icon.ico"
]
}
}

318
src/App.vue Normal file
View File

@ -0,0 +1,318 @@
<script setup>
import { ref, onMounted, onUnmounted } from 'vue';
import { io } from 'socket.io-client';
//
import Header from './components/Header.vue';
import RoomControls from './components/RoomControls.vue';
import UserList from './components/UserList.vue';
import FileSend from './components/FileSend.vue';
import TransferList from './components/TransferList.vue';
import PendingTransfers from './components/PendingTransfers.vue';
//
import { useSocket } from './composables/useSocket.js';
import { useWebRTC } from './composables/useWebRTC.js';
import { useFileTransfer } from './composables/useFileTransfer.js';
// 使
const { socket, userId, nickname, connected, roomUsers, roomId, joinRoom, serverUrl, connectToServer, disconnectFromServer } = useSocket();
const localServerUrl = ref(serverUrl.value);
//
function handleConnect() {
connectToServer(localServerUrl.value);
}
//
function handleDisconnect() {
disconnectFromServer();
}
const {
peerConnections,
dataChannels,
dataChannelReady,
createPeerConnection,
handleSignal,
setupDataChannel,
closePeerConnection
} = useWebRTC();
const {
transfers,
pendingTransfers,
selectedFile,
handleDataMessage,
sendFile,
acceptFile,
rejectFile,
selectFile
} = useFileTransfer();
//
async function connectToUser(socketId) {
console.log('Connecting to user:', socketId);
const pc = createPeerConnection(socket.value, socketId, (event, channel, id) => {
handleDataMessage(event, channel, id, userId.value, roomUsers.value);
});
// offer
const offer = await pc.createOffer();
await pc.setLocalDescription(offer);
socket.value.emit('signal', {
targetSocketId: socketId,
signal: { type: 'offer', sdp: offer }
});
}
//
async function sendFileToUser(socketId) {
const channel = dataChannels.value.get(socketId);
if (channel) {
await sendFile(socketId, channel, userId.value);
}
}
//
function acceptFileRequest(fileId, senderSocketId) {
const channel = dataChannels.value.get(senderSocketId);
if (channel) {
acceptFile(fileId, senderSocketId, channel);
}
}
//
function rejectFileRequest(fileId, senderSocketId) {
const channel = dataChannels.value.get(senderSocketId);
if (channel) {
rejectFile(fileId, senderSocketId, channel);
}
}
//
function handleJoinRoom(newRoomId, newNickname) {
roomId.value = newRoomId;
joinRoom(newNickname);
}
//
function handleDisconnectUser(socketId) {
closePeerConnection(socketId);
}
//
onMounted(() => {
if (socket.value) {
socket.value.on('signal', async ({ senderSocketId, signal }) => {
await handleSignal(
socket.value,
senderSocketId,
signal,
(channel, id) => {
setupDataChannel(
channel,
id,
(event, ch, socketId) => {
handleDataMessage(event, ch, socketId, userId.value, roomUsers.value);
}
);
}
);
});
}
});
//
onUnmounted(() => {
peerConnections.value.forEach(pc => pc.close());
dataChannels.value.forEach(dc => dc.close());
});
</script>
<template>
<div class="app">
<Header />
<main class="container">
<h1>{{ $t('common.p2p_file_transfer') }}</h1>
<div class="status-bar">
<div class="status-info">
<span :class="{ connected: connected, disconnected: !connected }">
{{ connected ? $t('common.connected') : $t('common.disconnected') }}
</span>
<span>{{ $t('common.user_id') }}: {{ userId }}</span>
</div>
<div class="server-controls" v-if="peerConnections.size === 0">
<div class="server-url-input">
<label for="server-url">{{ $t('common.server_url') }}:</label>
<input
type="text"
id="server-url"
v-model="localServerUrl"
placeholder="http://localhost:3000"
class="server-input"
/>
</div>
<div class="connection-buttons">
<button
@click="handleConnect"
:disabled="connected"
class="connect-btn"
>
{{ $t('common.connect') }}
</button>
<button
@click="handleDisconnect"
:disabled="!connected"
class="disconnect-btn"
>
{{ $t('common.disconnect') }}
</button>
</div>
</div>
</div>
<RoomControls
v-if="peerConnections.size === 0"
:connected="connected"
@join-room="handleJoinRoom"
/>
<UserList
:room-users="roomUsers"
:peer-connections="peerConnections"
:room-id="roomId"
:current-socket-id="socket?.id"
@connect-user="connectToUser"
@disconnect-user="handleDisconnectUser"
/>
<FileSend
:peer-connections="peerConnections"
:room-users="roomUsers"
@send-file="sendFileToUser"
@select-file="selectFile"
/>
<TransferList :transfers="transfers" />
<PendingTransfers
:pending-transfers="pendingTransfers"
@accept-file="acceptFileRequest"
@reject-file="rejectFileRequest"
/>
</main>
</div>
</template>
<style scoped>
.container {
max-width: 800px;
margin: 0 auto;
padding: 20px;
}
h1 {
text-align: center;
color: #333;
margin-bottom: 30px;
}
.status-bar {
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px 15px;
background: #f5f5f5;
border-radius: 8px;
margin-bottom: 20px;
flex-wrap: wrap;
gap: 15px;
}
.status-info {
display: flex;
gap: 15px;
align-items: center;
}
.server-controls {
display: flex;
gap: 15px;
align-items: center;
flex-wrap: wrap;
}
.server-url-input {
display: flex;
align-items: center;
gap: 8px;
}
.server-input {
padding: 6px 10px;
border: 1px solid #ddd;
border-radius: 4px;
width: 250px;
font-size: 0.9em;
}
.connection-buttons {
display: flex;
gap: 8px;
}
.connect-btn {
padding: 6px 12px;
background: #4caf50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 0.9em;
}
.disconnect-btn {
padding: 6px 12px;
background: #f44336;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 0.9em;
}
.connect-btn:disabled,
.disconnect-btn:disabled {
background: #ccc;
cursor: not-allowed;
}
.connected {
color: #4caf50;
font-weight: bold;
}
.disconnected {
color: #f44336;
font-weight: bold;
}
button {
transition: all 0.2s ease;
}
button:hover:not(:disabled) {
transform: translateY(-1px);
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}
button:active:not(:disabled) {
transform: translateY(0);
}
input:focus {
outline: none;
border-color: #2196f3;
}
</style>

1
src/assets/vue.svg Normal file
View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="37.07" height="36" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 198"><path fill="#41B883" d="M204.8 0H256L128 220.8L0 0h97.92L128 51.2L157.44 0h47.36Z"></path><path fill="#41B883" d="m0 0l128 220.8L256 0h-51.2L128 132.48L50.56 0H0Z"></path><path fill="#35495E" d="M50.56 0L128 133.12L204.8 0h-47.36L128 51.2L97.92 0H50.56Z"></path></svg>

After

Width:  |  Height:  |  Size: 496 B

150
src/components/FileSend.vue Normal file
View File

@ -0,0 +1,150 @@
<template>
<div class="section" v-if="peerConnections.size > 0">
<h2>{{ $t('file_transfer.send_file') }}</h2>
<div class="file-controls">
<input type="file" @change="selectFile" ref="fileInput" class="file-input" />
<button @click="triggerFileSelect" class="select-file-btn">
{{ $t('file_transfer.select_file') }}
</button>
<div class="selected-file" v-if="selectedFile">
{{ selectedFile.name }}
</div>
<div class="send-buttons">
<button
v-for="[socketId] in peerConnections"
:key="socketId"
@click="sendFileToUser(socketId)"
:disabled="!selectedFile"
class="send-btn"
>
{{ $t('file_transfer.send_to') }} {{ getUserName(socketId) }}
</button>
</div>
</div>
</div>
</template>
<script setup>
import { ref } from 'vue';
// props
const props = defineProps({
peerConnections: {
type: Map,
required: true
},
roomUsers: {
type: Array,
required: true
}
});
// emit
const emit = defineEmits(['sendFile', 'selectFile']);
//
const selectedFile = ref(null);
const fileInput = ref(null);
//
function triggerFileSelect() {
fileInput.value.click();
}
//
function selectFile(event) {
selectedFile.value = event.target.files[0];
emit('selectFile', event.target.files[0]);
}
//
function sendFileToUser(socketId) {
if (selectedFile.value) {
emit('sendFile', socketId);
}
}
//
function getUserName(socketId) {
const user = props.roomUsers.find(u => u.socketId === socketId);
return user?.nickname || user?.userId || socketId;
}
</script>
<style scoped>
.section {
background: white;
padding: 20px;
border-radius: 8px;
margin-bottom: 20px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
.file-controls {
display: flex;
flex-direction: column;
gap: 15px;
}
.file-input {
display: none;
}
.select-file-btn {
padding: 10px 20px;
background: #2196f3;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
transition: all 0.2s ease;
align-self: flex-start;
}
.select-file-btn:hover {
transform: translateY(-1px);
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}
.select-file-btn:active {
transform: translateY(0);
}
.selected-file {
padding: 10px;
background: #e3f2fd;
border-radius: 4px;
color: #1976d2;
font-weight: bold;
}
.send-buttons {
display: flex;
flex-wrap: wrap;
gap: 10px;
}
.send-btn {
padding: 10px 20px;
background: #4caf50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
transition: all 0.2s ease;
}
.send-btn:disabled {
background: #ccc;
cursor: not-allowed;
}
.send-btn:hover:not(:disabled) {
transform: translateY(-1px);
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}
.send-btn:active:not(:disabled) {
transform: translateY(0);
}
</style>

120
src/components/Header.vue Normal file
View File

@ -0,0 +1,120 @@
<template>
<header class="header">
<div class="header-container">
<h1 class="logo">{{ $t('common.p2p_file_transfer') }}</h1>
<div class="header-right">
<div class="language-selector">
<label for="language">{{ $t('common.language') }}:</label>
<select
id="language"
v-model="selectedLanguage"
@change="changeLanguage"
>
<option value="zh-CN">{{ $t('common.chinese') }}</option>
<option value="en-US">{{ $t('common.english') }}</option>
</select>
</div>
</div>
</div>
</header>
</template>
<script setup>
import { ref, onMounted } from 'vue';
import { useI18n } from 'vue-i18n';
const { locale } = useI18n();
const selectedLanguage = ref(locale.value);
//
function changeLanguage() {
locale.value = selectedLanguage.value;
localStorage.setItem('p2p-language', selectedLanguage.value);
}
//
onMounted(() => {
const savedLanguage = localStorage.getItem('p2p-language');
if (savedLanguage) {
selectedLanguage.value = savedLanguage;
locale.value = savedLanguage;
}
});
</script>
<style scoped>
.header {
background-color: #2196f3;
color: white;
padding: 1rem 0;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
position: sticky;
top: 0;
z-index: 100;
}
.header-container {
max-width: 800px;
margin: 0 auto;
padding: 0 20px;
display: flex;
justify-content: space-between;
align-items: center;
}
.logo {
margin: 0;
font-size: 1.5rem;
font-weight: bold;
}
.header-right {
display: flex;
align-items: center;
gap: 1rem;
}
.language-selector {
display: flex;
align-items: center;
gap: 0.5rem;
}
.language-selector label {
font-size: 0.9rem;
}
.language-selector select {
padding: 0.4rem 0.8rem;
border: none;
border-radius: 4px;
background-color: rgba(255, 255, 255, 0.2);
color: white;
font-size: 0.9rem;
cursor: pointer;
outline: none;
}
.language-selector select option {
color: #333;
background-color: white;
}
/* 响应式设计 */
@media (max-width: 600px) {
.header-container {
flex-direction: column;
gap: 1rem;
padding: 0 10px;
}
.header-right {
width: 100%;
justify-content: center;
}
.logo {
font-size: 1.2rem;
}
}
</style>

View File

@ -0,0 +1,138 @@
<template>
<div class="section" v-if="pendingTransfers.length > 0">
<h2>{{ $t('file_transfer.pending_transfers') }}</h2>
<div class="transfer-list">
<div v-for="transfer in pendingTransfers" :key="transfer.fileId" class="transfer-item">
<div class="transfer-info">
<span class="transfer-name">{{ transfer.name }}</span>
<span class="transfer-size">{{ formatFileSize(transfer.size) }}</span>
<span class="transfer-sender">{{ $t('file_transfer.from') }}: {{ transfer.senderNickname }}</span>
</div>
<div class="transfer-actions">
<button @click="acceptFile(transfer.fileId, transfer.senderId)" class="accept-btn">{{ $t('file_transfer.accept') }}</button>
<button @click="rejectFile(transfer.fileId, transfer.senderId)" class="reject-btn">{{ $t('file_transfer.reject') }}</button>
</div>
</div>
</div>
</div>
</template>
<script setup>
import { ref } from 'vue';
// props
const props = defineProps({
pendingTransfers: {
type: Array,
required: true
}
});
// emit
const emit = defineEmits(['acceptFile', 'rejectFile']);
//
function formatFileSize(bytes) {
if (bytes === 0) return '0 Bytes';
const k = 1024;
const sizes = ['Bytes', 'KB', 'MB', 'GB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return Math.round(bytes / Math.pow(k, i) * 100) / 100 + ' ' + sizes[i];
}
//
function acceptFile(fileId, senderId) {
emit('acceptFile', fileId, senderId);
}
//
function rejectFile(fileId, senderId) {
emit('rejectFile', fileId, senderId);
}
</script>
<style scoped>
.section {
background: white;
padding: 20px;
border-radius: 8px;
margin-bottom: 20px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
.transfer-list {
display: flex;
flex-direction: column;
gap: 15px;
}
.transfer-item {
padding: 15px;
background: #f9f9f9;
border-radius: 4px;
}
.transfer-info {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 10px;
flex-wrap: wrap;
gap: 10px;
}
.transfer-name {
font-weight: bold;
color: #333;
}
.transfer-size {
color: #666;
font-size: 0.9em;
}
.transfer-sender {
padding: 4px 8px;
border-radius: 4px;
font-size: 0.85em;
background: #e3f2fd;
color: #1976d2;
}
.transfer-actions {
display: flex;
gap: 10px;
margin-top: 10px;
}
.accept-btn {
padding: 8px 16px;
background: #4caf50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
transition: all 0.2s ease;
}
.reject-btn {
padding: 8px 16px;
background: #f44336;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
transition: all 0.2s ease;
}
.accept-btn:hover,
.reject-btn:hover {
transform: translateY(-1px);
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}
.accept-btn:active,
.reject-btn:active {
transform: translateY(0);
}
</style>

View File

@ -0,0 +1,84 @@
<template>
<div class="section">
<h2>{{ $t('room.join_room') }}</h2>
<div class="room-controls">
<input v-model="nickname" :placeholder="$t('room.nickname')" class="room-input" />
<input v-model="roomId" :placeholder="$t('room.room_id')" class="room-input" />
<button @click="joinRoom" :disabled="!roomId || !connected">
{{ $t('room.join') }}
</button>
</div>
</div>
</template>
<script setup>
import { ref } from 'vue';
// props
const props = defineProps({
connected: {
type: Boolean,
required: true
}
});
// emit
const emit = defineEmits(['joinRoom']);
//
const roomId = ref('');
const nickname = ref(localStorage.getItem('p2p-nickname') || '');
//
function joinRoom() {
if (roomId.value) {
emit('joinRoom', roomId.value, nickname.value);
}
}
</script>
<style scoped>
.section {
background: white;
padding: 20px;
border-radius: 8px;
margin-bottom: 20px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
.room-controls {
display: flex;
gap: 10px;
}
.room-input {
flex: 1;
padding: 10px;
border: 1px solid #ddd;
border-radius: 4px;
}
button {
padding: 10px 20px;
background: #2196f3;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
transition: all 0.2s ease;
}
button:disabled {
background: #ccc;
cursor: not-allowed;
}
button:hover:not(:disabled) {
transform: translateY(-1px);
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}
button:active:not(:disabled) {
transform: translateY(0);
}
</style>

View File

@ -0,0 +1,151 @@
<template>
<div class="section" v-if="transfers.length > 0">
<h2>{{ $t('file_transfer.transfers') }}</h2>
<div class="transfer-list">
<div v-for="transfer in transfers" :key="transfer.fileId" class="transfer-item">
<div class="transfer-info">
<span class="transfer-name">{{ transfer.name }}</span>
<span class="transfer-size">{{ formatFileSize(transfer.size) }}</span>
<span class="transfer-direction" :class="transfer.direction">{{ $t(`file_transfer.${transfer.direction}`) }}</span>
<span class="transfer-status" :class="transfer.status">{{ $t(`file_transfer.${transfer.status}`) }}</span>
</div>
<div class="progress-bar">
<div class="progress-fill" :style="{ width: transfer.progress + '%' }"></div>
</div>
<span class="progress-text">{{ transfer.progress }}%</span>
</div>
</div>
</div>
</template>
<script setup>
import { ref } from 'vue';
// props
const props = defineProps({
transfers: {
type: Array,
required: true
}
});
//
function formatFileSize(bytes) {
if (bytes === 0) return '0 Bytes';
const k = 1024;
const sizes = ['Bytes', 'KB', 'MB', 'GB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return Math.round(bytes / Math.pow(k, i) * 100) / 100 + ' ' + sizes[i];
}
</script>
<style scoped>
.section {
background: white;
padding: 20px;
border-radius: 8px;
margin-bottom: 20px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
.transfer-list {
display: flex;
flex-direction: column;
gap: 15px;
}
.transfer-item {
padding: 15px;
background: #f9f9f9;
border-radius: 4px;
}
.transfer-info {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 10px;
flex-wrap: wrap;
gap: 10px;
}
.transfer-name {
font-weight: bold;
color: #333;
}
.transfer-size {
color: #666;
font-size: 0.9em;
}
.transfer-direction {
padding: 4px 8px;
border-radius: 4px;
font-size: 0.85em;
text-transform: capitalize;
}
.transfer-direction.incoming {
background: #e3f2fd;
color: #1976d2;
}
.transfer-direction.outgoing {
background: #e8f5e9;
color: #388e3c;
}
.transfer-status {
padding: 4px 8px;
border-radius: 4px;
font-size: 0.85em;
text-transform: capitalize;
}
.transfer-status.sending,
.transfer-status.receiving {
background: #fff3e0;
color: #f57c00;
}
.transfer-status.completed {
background: #e8f5e9;
color: #388e3c;
}
.transfer-status.failed {
background: #ffebee;
color: #d32f2f;
}
.transfer-status.rejected {
background: #ffebee;
color: #d32f2f;
}
.transfer-status.waiting {
background: #fff3e0;
color: #f57c00;
}
.progress-bar {
height: 8px;
background: #e0e0e0;
border-radius: 4px;
overflow: hidden;
margin-bottom: 5px;
}
.progress-fill {
height: 100%;
background: linear-gradient(90deg, #2196f3, #4caf50);
transition: width 0.3s ease;
}
.progress-text {
font-size: 0.85em;
color: #666;
text-align: right;
}
</style>

183
src/components/UserList.vue Normal file
View File

@ -0,0 +1,183 @@
<template>
<div class="section" v-if="roomId">
<h2>{{ $t('room.users_in_room') }}</h2>
<div class="room-info">
<span class="room-id">{{ $t('room.room_id') }}: {{ roomId }}</span>
<span class="user-count">{{ $t('room.users_in_room') }}: {{ roomUsers.length }}</span>
</div>
<div class="user-list">
<div
v-for="user in roomUsers"
:key="user.socketId"
class="user-item"
:class="{ 'current-user': isCurrentUser(user.socketId) }"
>
<span class="user-id">
{{ user.nickname || user.userId }}
<span v-if="isCurrentUser(user.socketId)" class="current-user-tag">(You)</span>
</span>
<div class="user-actions">
<button
@click="connectToUser(user.socketId)"
:disabled="isCurrentUser(user.socketId) || peerConnections.has(user.socketId)"
class="connect-btn"
>
{{ isCurrentUser(user.socketId) ? $t('common.connected') : peerConnections.has(user.socketId) ? $t('file_transfer.connected') : $t('file_transfer.connect') }}
</button>
<button
v-if="peerConnections.has(user.socketId) && !isCurrentUser(user.socketId)"
@click="disconnectFromUser(user.socketId)"
class="disconnect-btn"
>
{{ $t('common.disconnect') }}
</button>
</div>
</div>
</div>
</div>
</template>
<script setup>
import { ref } from 'vue';
// props
const props = defineProps({
roomUsers: {
type: Array,
required: true
},
peerConnections: {
type: Map,
required: true
},
roomId: {
type: String,
default: ''
},
currentSocketId: {
type: String,
default: ''
}
});
// emit
const emit = defineEmits(['connectUser', 'disconnectUser']);
//
function isCurrentUser(socketId) {
return socketId === props.currentSocketId;
}
//
function connectToUser(socketId) {
emit('connectUser', socketId);
}
//
function disconnectFromUser(socketId) {
emit('disconnectUser', socketId);
}
</script>
<style scoped>
.section {
background: white;
padding: 20px;
border-radius: 8px;
margin-bottom: 20px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
.room-info {
display: flex;
gap: 15px;
margin-bottom: 15px;
padding: 10px;
background: #f5f5f5;
border-radius: 4px;
}
.room-id {
font-weight: bold;
color: #2196f3;
}
.user-count {
color: #666;
font-size: 0.9em;
}
.user-list {
display: flex;
flex-direction: column;
gap: 10px;
}
.user-item {
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px;
background: #f9f9f9;
border-radius: 4px;
}
.user-actions {
display: flex;
gap: 8px;
}
.user-item.current-user {
background: #e3f2fd;
border: 1px solid #2196f3;
}
.user-id {
font-family: monospace;
color: #333;
}
.current-user-tag {
color: #2196f3;
font-weight: bold;
margin-left: 5px;
font-size: 0.8em;
}
.connect-btn {
padding: 8px 16px;
background: #2196f3;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
transition: all 0.2s ease;
}
.disconnect-btn {
padding: 8px 16px;
background: #f44336;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
transition: all 0.2s ease;
}
.connect-btn:disabled,
.disconnect-btn:disabled {
background: #ccc;
cursor: not-allowed;
}
.connect-btn:hover:not(:disabled),
.disconnect-btn:hover:not(:disabled) {
transform: translateY(-1px);
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}
.connect-btn:active:not(:disabled),
.disconnect-btn:active:not(:disabled) {
transform: translateY(0);
}
</style>

View File

@ -0,0 +1,332 @@
import { ref } from 'vue';
export function useFileTransfer() {
const transfers = ref([]);
const pendingTransfers = ref([]);
const selectedFile = ref(null);
function handleDataMessage(event, channel, socketId, userId, roomUsers) {
try {
console.log('Raw message from', socketId, ':', event.data);
let data;
// 尝试解析JSON
if (typeof event.data === 'string') {
data = JSON.parse(event.data);
} else {
console.error('Received non-string message:', typeof event.data);
return;
}
console.log('Parsed message data:', data);
console.log('Received message type:', data.type, 'from', socketId);
if (data.type === 'ping') {
console.log('Received ping from:', socketId, ', sending pong');
try {
channel.send(JSON.stringify({ type: 'pong' }));
} catch (error) {
console.error('Error sending pong:', error);
}
} else if (data.type === 'pong') {
console.log('Received pong from:', socketId, ', data channel is ready');
} else if (data.type === 'file-request') {
console.log('Received file request:', data);
const sender = roomUsers.find(u => u.socketId === socketId);
const pendingTransfer = {
fileId: data.fileId,
name: data.name,
size: data.size,
type: data.fileType,
senderId: socketId,
senderNickname: sender?.nickname || sender?.userId || socketId,
receiverId: userId,
direction: 'incoming',
status: 'pending',
receivedSize: 0,
chunks: []
};
pendingTransfers.value.push(pendingTransfer);
} else if (data.type === 'file-accept') {
console.log('File accepted, starting transfer:', data.fileId);
startFileTransfer(data.fileId, socketId, channel);
} else if (data.type === 'file-reject') {
console.log('File rejected:', data.fileId);
const transfer = transfers.value.find(t => t.fileId === data.fileId);
if (transfer) {
transfer.status = 'rejected';
}
} else if (data.type === 'file-start') {
console.log('Received file start:', data);
const transfer = {
fileId: data.fileId,
name: data.name,
size: data.size,
type: data.fileType,
senderId: socketId,
receiverId: userId,
direction: 'incoming',
progress: 0,
status: 'receiving',
receivedSize: 0,
chunks: []
};
transfers.value.push(transfer);
} else if (data.type === 'file-chunk') {
const transfer = transfers.value.find(t => t.fileId === data.fileId);
if (transfer && transfer.status !== 'completed') {
transfer.chunks.push(new Uint8Array(data.chunk));
transfer.receivedSize += data.chunk.length;
transfer.progress = Math.round((transfer.receivedSize / transfer.size) * 100);
console.log('Received chunk:', transfer.receivedSize, '/', transfer.size, '(', transfer.progress, '%)');
}
} else if (data.type === 'file-end') {
const transfer = transfers.value.find(t => t.fileId === data.fileId);
if (transfer && transfer.status !== 'completed') {
transfer.status = 'completed';
console.log('File transfer completed, downloading:', transfer.name);
downloadFile(transfer);
}
} else {
console.warn('Unknown message type:', data.type, 'from', socketId);
}
} catch (error) {
console.error('Error parsing message:', error);
console.log('Raw message data:', event.data);
console.log('Message type:', typeof event.data);
}
}
async function sendFile(socketId, channel, userId) {
if (!selectedFile.value) return;
const fileId = 'file_' + Date.now();
if (!channel) {
alert('No data channel found. Please connect first.');
return;
}
if (channel.readyState !== 'open') {
alert('Data channel not ready. Connection state: ' + channel.readyState);
return;
}
const transfer = {
fileId,
name: selectedFile.value.name,
size: selectedFile.value.size,
type: selectedFile.value.type,
senderId: userId,
receiverId: socketId,
direction: 'outgoing',
progress: 0,
status: 'waiting',
sentSize: 0
};
transfers.value.push(transfer);
console.log('Sending file request:', transfer);
try {
const fileRequest = {
type: 'file-request',
fileId,
name: selectedFile.value.name,
size: selectedFile.value.size,
fileType: selectedFile.value.type
};
console.log('Preparing to send file request:', fileRequest);
console.log('JSON string:', JSON.stringify(fileRequest));
channel.send(JSON.stringify(fileRequest));
console.log('Sent file request message, bufferedAmount:', channel.bufferedAmount);
} catch (error) {
console.error('Error sending file request:', error);
transfer.status = 'failed';
alert('Failed to send file request: ' + error.message);
}
}
async function startFileTransfer(fileId, socketId, channel) {
const transfer = transfers.value.find(t => t.fileId === fileId);
if (!transfer) return;
transfer.status = 'sending';
console.log('Starting file transfer:', transfer);
console.log('Data channel state:', channel.readyState);
console.log('Data channel bufferedAmount:', channel.bufferedAmount);
try {
channel.send(JSON.stringify({
type: 'file-start',
fileId,
name: transfer.name,
size: transfer.size,
fileType: transfer.type
}));
console.log('Sent file-start message');
const chunkSize = 4096; // Reduced chunk size to prevent message size limits
let offset = 0;
let chunkCount = 0;
const sendChunk = async () => {
if (offset >= transfer.size) {
console.log('All chunks sent, sending file-end');
try {
const fileEndMessage = JSON.stringify({
type: 'file-end',
fileId
});
channel.send(fileEndMessage);
console.log('Sent file-end message, bufferedAmount:', channel.bufferedAmount);
} catch (error) {
console.error('Error sending file-end message:', error);
}
transfer.status = 'completed';
console.log('File transfer completed:', fileId, 'Total chunks:', chunkCount);
return;
}
const end = Math.min(offset + chunkSize, transfer.size);
const slice = selectedFile.value.slice(offset, end);
try {
const arrayBuffer = await slice.arrayBuffer();
const uint8Array = new Uint8Array(arrayBuffer);
// 注意JSON.stringify不能直接处理Uint8Array需要转换为普通数组
const chunkData = {
type: 'file-chunk',
fileId,
chunk: Array.from(uint8Array)
};
const jsonString = JSON.stringify(chunkData);
if (channel.bufferedAmount > 16 * 1024 * 1024) {
console.log('Buffer full (' + channel.bufferedAmount + '), waiting...');
setTimeout(sendChunk, 100);
return;
}
console.log('Sending chunk', chunkCount + 1, 'offset:', offset, 'size:', uint8Array.length);
channel.send(jsonString);
console.log('Sent chunk, bufferedAmount:', channel.bufferedAmount);
chunkCount++;
offset = end;
transfer.sentSize = offset;
transfer.progress = Math.round((offset / transfer.size) * 100);
if (offset < transfer.size) {
setTimeout(sendChunk, 10);
} else {
console.log('All chunks sent, sending file-end');
try {
const fileEndMessage = JSON.stringify({
type: 'file-end',
fileId
});
channel.send(fileEndMessage);
console.log('Sent file-end message, bufferedAmount:', channel.bufferedAmount);
} catch (error) {
console.error('Error sending file-end message:', error);
}
transfer.status = 'completed';
console.log('File transfer completed:', fileId, 'Total chunks:', chunkCount);
}
} catch (error) {
console.error('Error sending chunk:', error);
transfer.status = 'failed';
}
};
sendChunk();
} catch (error) {
console.error('Error sending file:', error);
transfer.status = 'failed';
alert('Failed to send file: ' + error.message);
}
}
function acceptFile(fileId, senderSocketId, channel) {
const pendingTransfer = pendingTransfers.value.find(t => t.fileId === fileId);
if (!pendingTransfer) return;
try {
channel.send(JSON.stringify({
type: 'file-accept',
fileId
}));
console.log('Sent file accept message');
pendingTransfers.value = pendingTransfers.value.filter(t => t.fileId !== fileId);
} catch (error) {
console.error('Error accepting file:', error);
alert('Failed to accept file: ' + error.message);
}
}
function rejectFile(fileId, senderSocketId, channel) {
const pendingTransfer = pendingTransfers.value.find(t => t.fileId === fileId);
if (!pendingTransfer) return;
try {
channel.send(JSON.stringify({
type: 'file-reject',
fileId
}));
console.log('Sent file reject message');
pendingTransfers.value = pendingTransfers.value.filter(t => t.fileId !== fileId);
} catch (error) {
console.error('Error rejecting file:', error);
alert('Failed to reject file: ' + error.message);
}
}
function selectFile(fileOrEvent) {
if (fileOrEvent && typeof fileOrEvent === 'object') {
if (fileOrEvent.target && fileOrEvent.target.files) {
// 处理事件对象
selectedFile.value = fileOrEvent.target.files[0];
} else {
// 直接处理文件对象
selectedFile.value = fileOrEvent;
}
}
}
function downloadFile(transfer) {
try {
console.log('Downloading file:', transfer.name, 'with', transfer.chunks.length, 'chunks');
const blob = new Blob(transfer.chunks, { type: transfer.type || 'application/octet-stream' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = transfer.name;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
console.log('File downloaded successfully');
} catch (error) {
console.error('Error downloading file:', error);
alert('Failed to download file: ' + error.message);
}
}
return {
transfers,
pendingTransfers,
selectedFile,
handleDataMessage,
sendFile,
acceptFile,
rejectFile,
selectFile
};
}

View File

@ -0,0 +1,117 @@
import { ref, onMounted, onUnmounted } from 'vue';
import { io } from 'socket.io-client';
import { generateUserId } from '../utils';
function isTauri() {
return window.__TAURI__ !== undefined;
}
export function useSocket() {
const socket = ref(null);
const userId = ref('');
const nickname = ref('');
const connected = ref(false);
const roomUsers = ref([]);
const roomId = ref('');
const serverUrl = ref(localStorage.getItem('p2p-server-url') || 'http://localhost:3000');
onMounted(() => {
userId.value = generateUserId();
nickname.value = localStorage.getItem('p2p-nickname') || '';
connectToServer(serverUrl.value);
});
onUnmounted(() => {
if (socket.value) {
socket.value.disconnect();
}
});
function connectToServer(url) {
if (socket.value) {
socket.value.disconnect();
}
serverUrl.value = url;
localStorage.setItem('p2p-server-url', url);
const socketOptions = {
transports: ['websocket', 'polling'],
reconnection: true,
reconnectionAttempts: 5,
reconnectionDelay: 1000,
reconnectionDelayMax: 5000,
timeout: 10000,
autoConnect: true
};
if (isTauri()) {
socketOptions.withCredentials = true;
socketOptions.extraHeaders = {
'User-Agent': 'Tauri-App'
};
} else {
socketOptions.withCredentials = false;
}
socket.value = io(url, socketOptions);
socket.value.on('connect', () => {
connected.value = true;
console.log('Connected to server:', url);
});
socket.value.on('disconnect', () => {
connected.value = false;
console.log('Disconnected from server');
});
socket.value.on('room-users', (users) => {
roomUsers.value = users;
});
socket.value.on('user-joined', ({ userId: newUserId, socketId, nickname: newNickname }) => {
if (!roomUsers.value.find(u => u.socketId === socketId)) {
roomUsers.value.push({ userId: newUserId, socketId, nickname: newNickname });
}
});
socket.value.on('user-left', ({ userId: leftUserId, socketId }) => {
roomUsers.value = roomUsers.value.filter(u => u.socketId !== socketId);
});
}
function disconnectFromServer() {
if (socket.value) {
socket.value.disconnect();
connected.value = false;
}
}
function joinRoom(newNickname) {
if (roomId.value && socket.value) {
if (newNickname) {
nickname.value = newNickname;
localStorage.setItem('p2p-nickname', newNickname);
}
socket.value.emit('join-room', {
roomId: roomId.value,
userId: userId.value,
nickname: nickname.value
});
}
}
return {
socket,
userId,
nickname,
connected,
roomUsers,
roomId,
serverUrl,
joinRoom,
connectToServer,
disconnectFromServer
};
}

View File

@ -0,0 +1,165 @@
import { ref } from 'vue';
export function useWebRTC() {
const peerConnections = ref(new Map());
const dataChannels = ref(new Map());
const dataChannelReady = ref(new Map());
function createPeerConnection(socket, senderSocketId, signalHandler) {
console.log('Creating peer connection to:', senderSocketId);
const config = {
iceServers: [
{ urls: 'stun:stun.l.google.com:19302' },
{ urls: 'stun:stun1.l.google.com:19302' }
]
};
const pc = new RTCPeerConnection(config);
peerConnections.value.set(senderSocketId, pc);
pc.onicecandidate = (event) => {
if (event.candidate) {
console.log('Sending ICE candidate to:', senderSocketId);
socket.emit('signal', {
targetSocketId: senderSocketId,
signal: { type: 'candidate', candidate: event.candidate }
});
}
};
pc.onconnectionstatechange = () => {
console.log('Connection state with', senderSocketId, ':', pc.connectionState);
};
pc.oniceconnectionstatechange = () => {
console.log('ICE connection state with', senderSocketId, ':', pc.iceConnectionState);
};
const dataChannel = pc.createDataChannel('fileTransfer', {
ordered: true
});
setupDataChannel(dataChannel, senderSocketId, signalHandler);
dataChannels.value.set(senderSocketId, dataChannel);
dataChannelReady.value.set(senderSocketId, false);
return pc;
}
async function handleSignal(socket, senderSocketId, signal, setupDataChannelCallback) {
console.log('Received signal from', senderSocketId, ':', signal.type);
let pc = peerConnections.value.get(senderSocketId);
if (signal.type === 'offer') {
console.log('Processing offer from:', senderSocketId);
const config = {
iceServers: [
{ urls: 'stun:stun.l.google.com:19302' },
{ urls: 'stun:stun1.l.google.com:19302' }
]
};
pc = new RTCPeerConnection(config);
peerConnections.value.set(senderSocketId, pc);
pc.onicecandidate = (event) => {
if (event.candidate) {
console.log('Sending ICE candidate to:', senderSocketId);
socket.emit('signal', {
targetSocketId: senderSocketId,
signal: { type: 'candidate', candidate: event.candidate }
});
}
};
pc.onconnectionstatechange = () => {
console.log('Connection state with', senderSocketId, ':', pc.connectionState);
};
pc.oniceconnectionstatechange = () => {
console.log('ICE connection state with', senderSocketId, ':', pc.iceConnectionState);
};
pc.ondatachannel = (event) => {
console.log('Received data channel from:', senderSocketId);
setupDataChannelCallback(event.channel, senderSocketId);
dataChannels.value.set(senderSocketId, event.channel);
dataChannelReady.value.set(senderSocketId, false);
};
await pc.setRemoteDescription(new RTCSessionDescription(signal.sdp));
const answer = await pc.createAnswer();
await pc.setLocalDescription(answer);
socket.emit('signal', {
targetSocketId: senderSocketId,
signal: { type: 'answer', sdp: answer }
});
} else if (signal.type === 'answer') {
console.log('Processing answer from:', senderSocketId);
if (pc) {
await pc.setRemoteDescription(new RTCSessionDescription(signal.sdp));
}
} else if (signal.type === 'candidate') {
console.log('Processing ICE candidate from:', senderSocketId);
if (pc) {
await pc.addIceCandidate(new RTCIceCandidate(signal.candidate));
}
}
}
function setupDataChannel(channel, socketId, messageHandler) {
channel.binaryType = 'arraybuffer';
channel.onopen = () => {
console.log('Data channel opened with:', socketId, 'readyState:', channel.readyState);
setTimeout(() => {
try {
channel.send(JSON.stringify({ type: 'ping' }));
console.log('Sent ping to:', socketId);
} catch (error) {
console.error('Error sending ping:', error);
}
}, 100);
};
channel.onmessage = (event) => {
messageHandler(event, channel, socketId);
};
channel.onerror = (error) => {
console.error('Data channel error with', socketId, ':', error);
};
channel.onclose = () => {
console.log('Data channel closed with:', socketId);
dataChannelReady.value.delete(socketId);
};
}
function closePeerConnection(socketId) {
const pc = peerConnections.value.get(socketId);
if (pc) {
pc.close();
peerConnections.value.delete(socketId);
}
const dc = dataChannels.value.get(socketId);
if (dc) {
dc.close();
dataChannels.value.delete(socketId);
}
}
return {
peerConnections,
dataChannels,
dataChannelReady,
createPeerConnection,
handleSignal,
setupDataChannel,
closePeerConnection
};
}

16
src/i18n/index.js Normal file
View File

@ -0,0 +1,16 @@
import { createI18n } from 'vue-i18n';
import zhCN from './locales/zh-CN.js';
import enUS from './locales/en-US.js';
// 创建i18n实例
const i18n = createI18n({
legacy: false, // 使用Composition API需要设置为false
locale: 'zh-CN', // 默认语言为中文
fallbackLocale: 'en-US', // 回退语言为英文
messages: {
'zh-CN': zhCN,
'en-US': enUS
}
});
export default i18n;

47
src/i18n/locales/en-US.js Normal file
View File

@ -0,0 +1,47 @@
export default {
common: {
connected: 'Connected',
disconnected: 'Disconnected',
user_id: 'User ID',
p2p_file_transfer: 'P2P File Transfer',
language: 'Language',
chinese: 'Chinese',
english: 'English',
server_url: 'Server URL',
connect: 'Connect',
disconnect: 'Disconnect'
},
room: {
join_room: 'Join Room',
room_id: 'Room ID',
nickname: 'Nickname',
join: 'Join',
leave: 'Leave',
users_in_room: 'Users in Room'
},
file_transfer: {
connect: 'Connect',
connected: 'Connected',
select_file: 'Select File',
send_file: 'Send File',
send_to: 'Send to',
transfers: 'Transfers',
pending_transfers: 'Pending Transfers',
size: 'Size',
direction: 'Direction',
status: 'Status',
progress: 'Progress',
from: 'From',
accept: 'Accept',
reject: 'Reject',
incoming: 'Incoming',
outgoing: 'Outgoing',
sending: 'Sending',
receiving: 'Receiving',
completed: 'Completed',
failed: 'Failed',
rejected: 'Rejected',
waiting: 'Waiting',
open_folder: 'Open Folder'
}
}

47
src/i18n/locales/zh-CN.js Normal file
View File

@ -0,0 +1,47 @@
export default {
common: {
connected: '已连接',
disconnected: '未连接',
user_id: '用户ID',
p2p_file_transfer: 'P2P文件传输',
language: '语言',
chinese: '中文',
english: '英文',
server_url: '服务器地址',
connect: '连接',
disconnect: '断开连接'
},
room: {
join_room: '加入房间',
room_id: '房间ID',
nickname: '昵称',
join: '加入',
leave: '离开',
users_in_room: '房间内用户'
},
file_transfer: {
connect: '连接',
connected: '已连接',
select_file: '选择文件',
send_file: '发送文件',
send_to: '发送给',
transfers: '传输列表',
pending_transfers: '待处理传输',
size: '大小',
direction: '方向',
status: '状态',
progress: '进度',
from: '来自',
accept: '接受',
reject: '拒绝',
incoming: '接收中',
outgoing: '发送中',
sending: '发送中',
receiving: '接收中',
completed: '已完成',
failed: '失败',
rejected: '已拒绝',
waiting: '等待中',
open_folder: '打开文件夹'
}
}

5
src/main.js Normal file
View File

@ -0,0 +1,5 @@
import { createApp } from "vue";
import App from "./App.vue";
import i18n from "./i18n";
createApp(App).use(i18n).mount("#app");

18
src/utils/index.js Normal file
View File

@ -0,0 +1,18 @@
// 生成用户ID
export function generateUserId() {
return 'user_' + Math.random().toString(36).substr(2, 9);
}
// 格式化文件大小
export function formatFileSize(bytes) {
if (bytes === 0) return '0 Bytes';
const k = 1024;
const sizes = ['Bytes', 'KB', 'MB', 'GB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return Math.round(bytes / Math.pow(k, i) * 100) / 100 + ' ' + sizes[i];
}
// 格式化传输速度
export function formatSpeed(bytesPerSecond) {
return formatFileSize(bytesPerSecond) + '/s';
}

38
vite.config.js Normal file
View File

@ -0,0 +1,38 @@
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import path from "path";
const host = process.env.TAURI_DEV_HOST;
// https://vite.dev/config/
export default defineConfig(async () => ({
plugins: [vue()],
// Vite options tailored for Tauri development and only applied in `tauri dev` or `tauri build`
//
// 1. prevent Vite from obscuring rust errors
clearScreen: false,
// 2. tauri expects a fixed port, fail if that port is not available
server: {
port: 1420,
strictPort: true,
host: host || "127.0.0.1",
hmr: host
? {
protocol: "ws",
host,
port: 1421,
}
: undefined,
watch: {
// 3. tell Vite to ignore watching `src-tauri`
ignored: ["**/src-tauri/**"],
},
},
resolve: {
alias: {
'@tauri-apps/api/tauri': path.resolve(__dirname, './src-tauri/mocks/tauri.js'),
'@tauri-apps/api/path': path.resolve(__dirname, './src-tauri/mocks/path.js'),
},
},
}));