From 92ed15e8735ae391d3eb742415772b9a3d40fc1c Mon Sep 17 00:00:00 2001 From: Giacomo Vacca Date: Fri, 16 Aug 2024 12:09:58 +0200 Subject: [PATCH] WIP, refactor set local description --- packages/common/src/webrtc/BaseCall.ts | 36 ++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/packages/common/src/webrtc/BaseCall.ts b/packages/common/src/webrtc/BaseCall.ts index e6b5dadc..ae008e3c 100644 --- a/packages/common/src/webrtc/BaseCall.ts +++ b/packages/common/src/webrtc/BaseCall.ts @@ -621,12 +621,18 @@ export default abstract class BaseCall implements IWebRTCCall { } private _onIceSdp(data: RTCSessionDescription) { + console.log('________________ _onIceSdp ___________') if (this._iceTimeout) { clearTimeout(this._iceTimeout) } this._iceTimeout = null this._iceDone = true const { sdp, type } = data + + + console.log('________ SDP: ', sdp) + + if (sdp.indexOf('candidate') === -1) { this._requestAnotherLocalDescription() return @@ -663,15 +669,19 @@ export default abstract class BaseCall implements IWebRTCCall { this._iceDone = false instance.onicecandidate = event => { if (this._iceDone) { + console.log('______iceDone, returning...') return } - if (this._iceTimeout === null) { - this._iceTimeout = setTimeout(() => this._onIceSdp(instance.localDescription), 1000) - } + // if (this._iceTimeout === null) { + // console.log('______ set timeout for iceTimeout _____') + // this._iceTimeout = setTimeout(() => this._onIceSdp(instance.localDescription), 1000) + // } if (event.candidate) { - logger.info('IceCandidate:', event.candidate) + logger.info('IceCandidate: address: ', event.candidate.address, ' - port: ', event.candidate.port, ' - type:', event.candidate.type) } else { - this._onIceSdp(instance.localDescription) + console.log('_________onicecandidate - doing nothing_______') + // console.log('______calling onIceSdp with local description:', instance.localDescription?.sdp) + // this._onIceSdp(instance.localDescription) } } @@ -687,6 +697,22 @@ export default abstract class BaseCall implements IWebRTCCall { instance.addEventListener('addstream', (event: MediaStreamEvent) => { this.options.remoteStream = event.stream }) + + instance.addEventListener('icegatheringstatechange', (ev) => { + switch (instance.iceGatheringState) { + case 'new': + console.log('_______new_______') + break + case 'gathering': + console.log('_______gathering_______') + break + case 'complete': + console.log('_______complete_______ calling _onIceSdp with SDP: ', instance.localDescription?.sdp) + this._onIceSdp(instance.localDescription) + break + } + }) + } private _checkConferenceSerno = (serno: number) => {