Skip to content

Commit 869a86b

Browse files
authored
fix: Fix issues relate to connection (#74)
# Description - STUN/TURN servers will reset on new version release - Fix the issue where wrong target will cause server to crash Fixes #73 ## Type of change Please delete options that are not relevant. - [x] Bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] This change requires a documentation update ## Checklist - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my code - [x] I have commented my code, particularly in hard-to-understand areas - [x] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [ ] Any dependent changes have been merged and published in downstream modules
2 parents 60ef276 + 0c299c7 commit 869a86b

File tree

10 files changed

+58
-44
lines changed

10 files changed

+58
-44
lines changed

CHANGELOG.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,21 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## [3.1.18] - 2025-03-12
6+
7+
### Changed
8+
9+
- STUN/TURN servers will reset on new version release
10+
11+
### Fixed
12+
13+
- Fix the issue where wrong target will cause server to crash
14+
515
## [3.1.17] - 2025-03-11
616

717
### Fixed
818

9-
- Fixed the issue where auto download is disabled in certain browsers
19+
- Fix the issue where auto download is disabled in certain browsers
1020

1121
## [3.1.16] - 2025-02-14
1222

SECURITY.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ We release patches for security vulnerabilities in the following versions:
66

77
| Part | Version | Supported |
88
| ------ | ------- | ------------------ |
9-
| Server | 3.0.x | :white_check_mark: |
10-
| Server | < 3.0 | :x: |
9+
| Server | 3.1.x | :white_check_mark: |
10+
| Server | < 3.1 | :x: |
1111
| Client | 3.1.x | :white_check_mark: |
1212
| Client | < 3.1 | :x: |
1313

client/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "client",
3-
"version": "3.1.17",
3+
"version": "3.1.18",
44
"private": true,
55
"type": "module",
66
"scripts": {

client/src/const.ts

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,19 @@ export const defaultMaxConnectionNumber: number = 10
44

55
export const defaultIceServers: IceServer[] = [
66
{
7-
urls: 'stun:stun.l.google.com:19302',
8-
},
9-
{
10-
urls: 'stun:stun.l.google.com:5349',
11-
},
12-
{
13-
urls: 'stun:stun1.l.google.com:3478',
14-
},
15-
{
16-
urls: 'stun:stun1.l.google.com:5349',
17-
},
18-
{
19-
urls: 'stun:stun2.l.google.com:19302',
20-
},
21-
{
22-
urls: 'stun:stun2.l.google.com:5349',
23-
},
24-
{
25-
urls: 'stun:stun3.l.google.com:3478',
26-
},
27-
{
28-
urls: 'stun:stun3.l.google.com:5349',
7+
urls: 'turn:103.124.107.241:3478',
8+
username: 'easytransfer',
9+
credential: 'sharesimplyandstayanonymous',
2910
},
3011
{
31-
urls: 'stun:stun4.l.google.com:19302',
12+
urls: 'stun:stun.relay.metered.ca:80',
3213
},
3314
{
34-
urls: 'stun:stun4.l.google.com:5349',
15+
urls: 'turn:global.relay.metered.ca:80',
16+
username: 'cf841207b56ebddc17948dde',
17+
credential: '0dGvvEm7eq2UaqlW',
3518
},
3619
{
37-
urls: 'turn:103.124.107.241:3478',
38-
username: 'easytransfer',
39-
credential: 'sharesimplyandstayanonymous',
20+
urls: 'stun:stun.l.google.com:19302',
4021
},
4122
]

client/src/stores/connect.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ export const useConnectStore = defineStore('connect', () => {
6565
}
6666

6767
function handleServerMsg() {
68+
socket?.on('error', (error: string) => {
69+
console.error(`[ERROR] ${error}`)
70+
isConnecting.value = false
71+
isConnectSuccess.value = false
72+
})
73+
6874
socket?.on('success', (id: string) => {
6975
clientId.value = id
7076
registered.value = true

client/src/stores/setting.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,27 +50,31 @@ export const useSettingStore = defineStore('setting', () => {
5050
})
5151

5252
// maxConnectionNumber
53+
const maxConnectionNumberStorageName =
54+
'maxConnectionNumber-' + (process.package_version as string)
5355
const maxConnectionNumber: Ref<number> = ref(defaultMaxConnectionNumber)
5456

55-
if (localStorage.getItem('maxConnectionNumber')) {
57+
if (localStorage.getItem(maxConnectionNumberStorageName)) {
5658
maxConnectionNumber.value = JSON.parse(
57-
localStorage.getItem('maxConnectionNumber') as string,
59+
localStorage.getItem(maxConnectionNumberStorageName) as string,
5860
)
5961
}
6062

6163
watch(maxConnectionNumber, () => {
6264
localStorage.setItem(
63-
'maxConnectionNumber',
65+
maxConnectionNumberStorageName,
6466
JSON.stringify(maxConnectionNumber.value),
6567
)
6668
})
6769

6870
// iceServers
71+
const iceServersStorageName =
72+
'iceServers-' + (process.package_version as string)
6973
const iceServers: Ref<IceServer[]> = ref(defaultIceServers)
7074

71-
if (localStorage.getItem('iceServers')) {
75+
if (localStorage.getItem(iceServersStorageName)) {
7276
const existingIceServers = JSON.parse(
73-
localStorage.getItem('iceServers') as string,
77+
localStorage.getItem(iceServersStorageName) as string,
7478
)
7579
const newIceServers = [...iceServers.value, ...existingIceServers]
7680
const uniqueIceServers = Array.from(
@@ -80,7 +84,10 @@ export const useSettingStore = defineStore('setting', () => {
8084
}
8185

8286
watch(iceServers, () => {
83-
localStorage.setItem('iceServers', JSON.stringify(iceServers.value))
87+
localStorage.setItem(
88+
iceServersStorageName,
89+
JSON.stringify(iceServers.value),
90+
)
8491
})
8592

8693
return {

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "file-transfer-server",
3-
"version": "3.0.2",
3+
"version": "3.1.0",
44
"description": "Server for file transfer",
55
"main": "dist/server.js",
66
"type": "module",

server/server.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,17 @@ io.on("connection", (socket: Socket) => {
5555
"offer",
5656
(sdp: RTCSessionDescriptionInit, srcId: string, targetId: string) => {
5757
console.log("[offer] ", srcId, " --> ", targetId);
58-
clients[targetId].emit("offer", sdp, srcId, maxConnectionNumbers[srcId]);
58+
try {
59+
clients[targetId].emit(
60+
"offer",
61+
sdp,
62+
srcId,
63+
maxConnectionNumbers[srcId],
64+
);
65+
} catch (error) {
66+
console.error("[error] ", error);
67+
clients[srcId].emit("error", "Target client not found");
68+
}
5969
},
6070
);
6171

0 commit comments

Comments
 (0)