From 662cb53982c0f0aef55993285931cde56c8eb524 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Wed, 17 Mar 2021 15:47:50 +0100 Subject: [PATCH] iceservers with auth. --- src/component/internal/webrtc.ts | 17 +++++++++++------ src/component/main.vue | 2 +- src/component/types/messages.ts | 5 +++-- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/component/internal/webrtc.ts b/src/component/internal/webrtc.ts index 7895d68e..c78d4f87 100644 --- a/src/component/internal/webrtc.ts +++ b/src/component/internal/webrtc.ts @@ -18,6 +18,12 @@ export interface WebRTCStats { height: number } +export interface ICEServer { + urls: string + username: string + credential: string +} + export interface NekoWebRTCEvents { connecting: () => void connected: () => void @@ -66,7 +72,7 @@ export class NekoWebRTC extends EventEmitter { this._log.debug(`adding remote ICE candidate`, candidate) } - public async connect(sdp: string, lite: boolean, servers: string[]): Promise { + public async connect(sdp: string, iceServers: ICEServer[]): Promise { this._log.info(`connecting`) if (!this.supported) { @@ -79,11 +85,10 @@ export class NekoWebRTC extends EventEmitter { this.emit('connecting') - this._peer = new RTCPeerConnection() - if (lite !== true) { - this._peer = new RTCPeerConnection({ - iceServers: [{ urls: servers }], - }) + this._peer = new RTCPeerConnection({ iceServers }) + + if (iceServers.length == 0) { + this._log.warn(`iceservers are empty`) } this._peer.onconnectionstatechange = (event) => { diff --git a/src/component/main.vue b/src/component/main.vue index 24fdef73..041b5754 100644 --- a/src/component/main.vue +++ b/src/component/main.vue @@ -385,7 +385,7 @@ switch (event) { case 'signal/provide': try { - let sdp = await this.webrtc.connect(payload.sdp, payload.lite, payload.ice) + let sdp = await this.webrtc.connect(payload.sdp, payload.iceservers) this.websocket.send('signal/answer', { sdp }) } catch (e) {} break diff --git a/src/component/types/messages.ts b/src/component/types/messages.ts index 98c1366f..95e5d050 100644 --- a/src/component/types/messages.ts +++ b/src/component/types/messages.ts @@ -1,3 +1,5 @@ +import { ICEServer } from '../internal/webrtc' + export interface Message { event: string | undefined payload: any @@ -34,8 +36,7 @@ export interface SystemDisconnect { export interface SignalProvide { event: string | undefined sdp: string - lite: boolean - ice: string[] + iceservers: ICEServer[] video: string videos: string[] }