From d8e406d415824c640e104787fbaaae8837ea593b Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Wed, 29 Mar 2023 16:41:16 -0700 Subject: [PATCH] webrtc: reduce debug logging --- common/src/rtc-signaling.ts | 9 ++++++--- plugins/webrtc/package-lock.json | 4 ++-- plugins/webrtc/package.json | 2 +- plugins/webrtc/src/ffmpeg-to-wrtc.ts | 10 +++------- plugins/webrtc/src/main.ts | 4 ++++ plugins/webrtc/src/werift-util.ts | 16 +++++++++------- 6 files changed, 25 insertions(+), 20 deletions(-) diff --git a/common/src/rtc-signaling.ts b/common/src/rtc-signaling.ts index 23e2c586bc..859117e32b 100644 --- a/common/src/rtc-signaling.ts +++ b/common/src/rtc-signaling.ts @@ -250,7 +250,8 @@ export class BrowserSignalingSession implements RTCSignalingSession { function logSendCandidate(console: Console, type: string, session: RTCSignalingSession): RTCSignalingSendIceCandidate { return async (candidate) => { try { - console.log(`${type} trickled candidate:`, candidate.sdpMLineIndex, candidate.candidate); + if (localStorage.getItem('debugLog') === 'true') + console.log(`${type} trickled candidate:`, candidate.sdpMLineIndex, candidate.candidate); await session.addIceCandidate(candidate); } catch (e) { @@ -308,11 +309,13 @@ export async function connectRTCSignalingClients( const offer = await offerClient.createLocalDescription('offer', offerSetup as RTCAVSignalingSetup, disableTrickle ? undefined : answerQueue.queueSendCandidate); - console.log('offer sdp', offer.sdp); + if (localStorage.getItem('debugLog') === 'true') + console.log('offer sdp', offer.sdp); await answerClient.setRemoteDescription(offer, answerSetup as RTCAVSignalingSetup); const answer = await answerClient.createLocalDescription('answer', answerSetup as RTCAVSignalingSetup, disableTrickle ? undefined : offerQueue.queueSendCandidate); - console.log('answer sdp', answer.sdp); + if (localStorage.getItem('debugLog') === 'true') + console.log('answer sdp', answer.sdp); await offerClient.setRemoteDescription(answer, offerSetup as RTCAVSignalingSetup); offerQueue.flush(); answerQueue.flush(); diff --git a/plugins/webrtc/package-lock.json b/plugins/webrtc/package-lock.json index dd8c14237a..f531a13b7c 100644 --- a/plugins/webrtc/package-lock.json +++ b/plugins/webrtc/package-lock.json @@ -1,12 +1,12 @@ { "name": "@scrypted/webrtc", - "version": "0.1.38", + "version": "0.1.39", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@scrypted/webrtc", - "version": "0.1.38", + "version": "0.1.39", "dependencies": { "@scrypted/common": "file:../../common", "@scrypted/sdk": "file:../../sdk", diff --git a/plugins/webrtc/package.json b/plugins/webrtc/package.json index 1acba78e4e..11ea07de7a 100644 --- a/plugins/webrtc/package.json +++ b/plugins/webrtc/package.json @@ -1,6 +1,6 @@ { "name": "@scrypted/webrtc", - "version": "0.1.38", + "version": "0.1.39", "scripts": { "scrypted-setup-project": "scrypted-setup-project", "prescrypted-setup-project": "scrypted-package-json", diff --git a/plugins/webrtc/src/ffmpeg-to-wrtc.ts b/plugins/webrtc/src/ffmpeg-to-wrtc.ts index c4d0a2b625..b08f113b3f 100644 --- a/plugins/webrtc/src/ffmpeg-to-wrtc.ts +++ b/plugins/webrtc/src/ffmpeg-to-wrtc.ts @@ -4,7 +4,7 @@ import { Deferred } from "@scrypted/common/src/deferred"; import sdk, { FFmpegInput, FFmpegTranscodeStream, Intercom, MediaObject, MediaStreamDestination, MediaStreamFeedback, RequestMediaStream, RTCAVSignalingSetup, RTCConnectionManagement, RTCMediaObjectTrack, RTCSignalingOptions, RTCSignalingSession, ScryptedDevice, ScryptedMimeTypes } from "@scrypted/sdk"; import { ScryptedSessionControl } from "./session-control"; import { requiredAudioCodecs, requiredVideoCodec } from "./webrtc-required-codecs"; -import { logIsPrivateIceTransport } from "./werift-util"; +import { isPrivateIceTransport, logIsPrivateIceTransport } from "./werift-util"; import { addVideoFilterArguments } from "@scrypted/common/src/ffmpeg-helpers"; import { connectRTCSignalingClients } from "@scrypted/common/src/rtc-signaling"; @@ -431,10 +431,6 @@ export class WebRTCConnectionManagement implements RTCConnectionManagement { waitConnected(this.pc) .then(() => logIsPrivateIceTransport(this.console, this.pc)).catch(() => {}); - this.pc.signalingStateChange.subscribe(() => { - this.console.log('sig change', this.pc.signalingState); - }) - this.weriftSignalingSession = new WeriftSignalingSession(console, this.pc); } @@ -469,7 +465,7 @@ export class WebRTCConnectionManagement implements RTCConnectionManagement { createTrackForwarder: async (videoTransceiver: RTCRtpTransceiver, audioTransceiver: RTCRtpTransceiver) => { const ret = await createTrackForwarder({ timeStart, - ...logIsPrivateIceTransport(console, this.pc), + ...isPrivateIceTransport(this.pc), requestMediaStream, videoTransceiver, audioTransceiver, @@ -582,7 +578,7 @@ export async function createRTCPeerConnectionSink( clientOffer = true, ) { const clientOptions = await clientSignalingSession.getOptions(); - console.log('remote options', clientOptions); + // console.log('remote options', clientOptions); const connection = new WebRTCConnectionManagement(console, clientSignalingSession, maximumCompatibilityMode, clientOptions, { configuration, diff --git a/plugins/webrtc/src/main.ts b/plugins/webrtc/src/main.ts index 2be47007d1..864317d991 100644 --- a/plugins/webrtc/src/main.ts +++ b/plugins/webrtc/src/main.ts @@ -223,6 +223,10 @@ export class WebRTCPlugin extends AutoenableMixinProvider implements DeviceCreat type: 'textarea', description: "RTCConfiguration that can be used to specify custom TURN and STUN servers. https://gist.github.com/koush/631d38ac8647a86baaac7b22d863f010", }, + debugLog: { + title: 'Debug Log', + type: 'boolean', + } }); bridge: WebRTCBridge; activeConnections = 0; diff --git a/plugins/webrtc/src/werift-util.ts b/plugins/webrtc/src/werift-util.ts index 29657b3c7a..5df8917aee 100644 --- a/plugins/webrtc/src/werift-util.ts +++ b/plugins/webrtc/src/werift-util.ts @@ -42,20 +42,15 @@ export function getWeriftIceServers(configuration: RTCConfiguration): RTCIceServ return ret; } -export function logIsPrivateIceTransport(console: Console, pc: RTCPeerConnection) { +export function isPrivateIceTransport(pc: RTCPeerConnection) { let isPrivate = true; let destinationId: string; for (const ice of pc.iceTransports) { const [address, port] = (ice.connection as any).nominated[1].remoteAddr; if (!destinationId) destinationId = address; - const { turnServer } = ice.connection; isPrivate = isPrivate && ip.isPrivate(address); - console.log('ice transport ip', { - address, - port, - turnServer: !!turnServer, - }); + } console.log('Connection is local network:', isPrivate); const ipv4 = ip.isV4Format(destinationId); @@ -65,3 +60,10 @@ export function logIsPrivateIceTransport(console: Console, pc: RTCPeerConnection destinationId, }; } + +export function logIsPrivateIceTransport(console: Console, pc: RTCPeerConnection) { + const ret = isPrivateIceTransport(pc); + console.log('ice transport', ret); + console.log('Connection is local network:', ret.isPrivate); + return ret; +}