iceservers with auth.

This commit is contained in:
Miroslav Šedivý 2021-03-17 15:47:50 +01:00
parent 4d967f03d0
commit 662cb53982
3 changed files with 15 additions and 9 deletions

View File

@ -18,6 +18,12 @@ export interface WebRTCStats {
height: number height: number
} }
export interface ICEServer {
urls: string
username: string
credential: string
}
export interface NekoWebRTCEvents { export interface NekoWebRTCEvents {
connecting: () => void connecting: () => void
connected: () => void connected: () => void
@ -66,7 +72,7 @@ export class NekoWebRTC extends EventEmitter<NekoWebRTCEvents> {
this._log.debug(`adding remote ICE candidate`, candidate) this._log.debug(`adding remote ICE candidate`, candidate)
} }
public async connect(sdp: string, lite: boolean, servers: string[]): Promise<string> { public async connect(sdp: string, iceServers: ICEServer[]): Promise<string> {
this._log.info(`connecting`) this._log.info(`connecting`)
if (!this.supported) { if (!this.supported) {
@ -79,11 +85,10 @@ export class NekoWebRTC extends EventEmitter<NekoWebRTCEvents> {
this.emit('connecting') this.emit('connecting')
this._peer = new RTCPeerConnection() this._peer = new RTCPeerConnection({ iceServers })
if (lite !== true) {
this._peer = new RTCPeerConnection({ if (iceServers.length == 0) {
iceServers: [{ urls: servers }], this._log.warn(`iceservers are empty`)
})
} }
this._peer.onconnectionstatechange = (event) => { this._peer.onconnectionstatechange = (event) => {

View File

@ -385,7 +385,7 @@
switch (event) { switch (event) {
case 'signal/provide': case 'signal/provide':
try { 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 }) this.websocket.send('signal/answer', { sdp })
} catch (e) {} } catch (e) {}
break break

View File

@ -1,3 +1,5 @@
import { ICEServer } from '../internal/webrtc'
export interface Message { export interface Message {
event: string | undefined event: string | undefined
payload: any payload: any
@ -34,8 +36,7 @@ export interface SystemDisconnect {
export interface SignalProvide { export interface SignalProvide {
event: string | undefined event: string | undefined
sdp: string sdp: string
lite: boolean iceservers: ICEServer[]
ice: string[]
video: string video: string
videos: string[] videos: string[]
} }