Skip to content

Commit

Permalink
webrtc: reduce debug logging
Browse files Browse the repository at this point in the history
  • Loading branch information
koush committed Mar 29, 2023
1 parent 4529872 commit d8e406d
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 20 deletions.
9 changes: 6 additions & 3 deletions common/src/rtc-signaling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions plugins/webrtc/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion plugins/webrtc/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
10 changes: 3 additions & 7 deletions plugins/webrtc/src/ffmpeg-to-wrtc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions plugins/webrtc/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 9 additions & 7 deletions plugins/webrtc/src/werift-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}

0 comments on commit d8e406d

Please sign in to comment.