Add Coturn TURN server
This commit is contained in:
1 parent
752d0cf3af
commit
c3ca3e1752
13 files changed
+309
-11
No files matched your search
@@ -1,7 +1,7 @@
|
||||
<script setup>
|
||||
import { computed, onBeforeUnmount, ref } from 'vue';
|
||||
import NetworkSettings from './NetworkSettings.vue';
|
||||
import { acceptAnswerCode, createAnswerCode, createOfferCode, createPeerConnection, getFingerprints, MAX_SIGNAL_LENGTH, STUN_PROVIDERS } from '../lib/webrtc.js';
|
||||
import { acceptAnswerCode, createAnswerCode, createOfferCode, createPeerConnection, fetchTurnOptions, iceConfiguration, getFingerprints, MAX_SIGNAL_LENGTH, STUN_PROVIDERS } from '../lib/webrtc.js';
|
||||
import { FILE_LIMIT, MEMORY_LIMIT, Transfer, validateMetadata } from '../lib/transfer.js';
|
||||
|
||||
const props = defineProps({ sending: Boolean });
|
||||
@@ -18,7 +18,9 @@ const incoming = ref(null);
|
||||
const downloadUrl = ref('');
|
||||
const choosing = ref(false);
|
||||
const dragover = ref(false);
|
||||
const settings = ref({ stunChoice: 'google', customStun: '', allowTurn: false, turnUrl: '', username: '', credential: '' });
|
||||
const iceEndpoint = import.meta.env.VITE_ICE_ENDPOINT || '';
|
||||
const defaultStun = import.meta.env.VITE_STUN_URL || '';
|
||||
const settings = ref({ stunChoice: defaultStun ? 'custom' : 'google', customStun: defaultStun, allowTurn: false, managedTurn: !!iceEndpoint, turnUrl: '', username: '', credential: '' });
|
||||
const canSaveToDisk = typeof window.showSaveFilePicker === 'function';
|
||||
let active = null;
|
||||
let copyTimer;
|
||||
@@ -109,7 +111,8 @@ function start() {
|
||||
stunUrl: chosen.stunChoice === 'custom' ? chosen.customStun.trim() || null : STUN_PROVIDERS.find(p => p.id === chosen.stunChoice)?.url ?? null,
|
||||
turnUrl: chosen.turnUrl.trim(),
|
||||
};
|
||||
const pc = createPeerConnection(options);
|
||||
// Fetch managed credentials before gathering, while retaining normal cancellation.
|
||||
const pc = createPeerConnection(iceEndpoint && options.managedTurn ? { ...options, allowTurn: false } : options);
|
||||
const session = { pc, options, file: file.value, controller: new AbortController(), transfer: null };
|
||||
active = session;
|
||||
session.timer = setTimeout(() => fail(session, new Error('Connection timed out. Start again with new codes.')), 5 * 60 * 1000);
|
||||
@@ -133,6 +136,9 @@ async function createCode() {
|
||||
validateMetadata({ name: file.value.name, size: file.value.size, mime: file.value.type || '' });
|
||||
}
|
||||
session = start();
|
||||
const configured = await fetchTurnOptions(session.options, iceEndpoint, { signal: session.controller.signal });
|
||||
if (active !== session) return;
|
||||
session.pc.setConfiguration(iceConfiguration(configured));
|
||||
const options = { ...session.options, signal: session.controller.signal };
|
||||
if (props.sending) attach(session, session.pc.createDataChannel('hellcon-v2'));
|
||||
const code = props.sending ? await createOfferCode(session.pc, options) : await createAnswerCode(session.pc, pasted, options);
|
||||
|
||||
Reference in new issue
Block a user