Add server lists to edit
This commit is contained in:
1 parent
08b9f659c2
commit
85ccdbfc03
4 files changed
+151
-11
No files matched your search
+13
-6
@@ -2,9 +2,9 @@ import { createApp } from 'vue';
|
||||
import App from './App.vue';
|
||||
import './style.css';
|
||||
|
||||
export const TRACKERS = ['wss://tracker.webtorrent.dev', 'wss://open.ftorrent.com'];
|
||||
export const DEFAULT_TRACKERS = ['wss://tracker.webtorrent.dev', 'wss://open.ftorrent.com'];
|
||||
|
||||
export const STUN_SERVERS = [
|
||||
export const DEFAULT_STUN_SERVERS = [
|
||||
'stun:stun.pagequit.net:3478',
|
||||
'stun:stun.cloudflare.com:3478',
|
||||
'stun:stun.l.google.com:19302',
|
||||
@@ -12,7 +12,12 @@ export const STUN_SERVERS = [
|
||||
];
|
||||
|
||||
// Without STUN only local addresses are offered: works on the same network or VPN, contacts nobody.
|
||||
export const settings = { stun: true };
|
||||
// Read whenever a connection or tracker socket is created, so changes apply to the next one.
|
||||
export const settings = {
|
||||
stun: true,
|
||||
stunServers: [...DEFAULT_STUN_SERVERS],
|
||||
trackers: [...DEFAULT_TRACKERS],
|
||||
};
|
||||
|
||||
const CHUNK_SIZE = 16 * 1024;
|
||||
const MAX_BUFFERED = 1024 * 1024;
|
||||
@@ -40,7 +45,9 @@ export type Events = {
|
||||
};
|
||||
|
||||
function createPeerConnection() {
|
||||
return new RTCPeerConnection({ iceServers: settings.stun ? [{ urls: STUN_SERVERS }] : [] });
|
||||
// An empty urls list is a syntax error.
|
||||
const stun = settings.stun && settings.stunServers.length;
|
||||
return new RTCPeerConnection({ iceServers: stun ? [{ urls: settings.stunServers }] : [] });
|
||||
}
|
||||
|
||||
function randomBinary(length: number) {
|
||||
@@ -420,7 +427,7 @@ export async function sendViaTracker(file: File, events: Events) {
|
||||
});
|
||||
}
|
||||
|
||||
for (const url of TRACKERS) {
|
||||
for (const url of settings.trackers) {
|
||||
const ws = new WebSocket(url);
|
||||
ws.onopen = () => {
|
||||
announce(ws, hash, peerId, { left: 0, event: 'started' });
|
||||
@@ -489,7 +496,7 @@ export async function receiveViaTracker(code: string, events: Events) {
|
||||
});
|
||||
}
|
||||
|
||||
for (const url of TRACKERS) offer(url);
|
||||
for (const url of settings.trackers) offer(url);
|
||||
}
|
||||
|
||||
// Mounted last: App.vue imports the core from this module.
|
||||
|
||||
Reference in new issue
Block a user