From 795c54343a02d9b50a4a9e15a6cdf05ae70e74c5 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Sun, 22 Oct 2023 20:51:08 +0100 Subject: [PATCH] android, desktop: reduce browser call logs, check Worker availability directly (#3256) --- .../commonMain/resources/assets/www/call.js | 23 +++++++++---------- .../resources/assets/www/desktop/ui.js | 6 ++--- packages/simplex-chat-webrtc/src/call.ts | 21 +++++++++-------- .../simplex-chat-webrtc/src/desktop/ui.ts | 6 ++--- 4 files changed, 28 insertions(+), 28 deletions(-) diff --git a/apps/multiplatform/common/src/commonMain/resources/assets/www/call.js b/apps/multiplatform/common/src/commonMain/resources/assets/www/call.js index fd574d022..62c9ca7fb 100644 --- a/apps/multiplatform/common/src/commonMain/resources/assets/www/call.js +++ b/apps/multiplatform/common/src/commonMain/resources/assets/www/call.js @@ -84,10 +84,8 @@ const processCommand = (function () { if (delay) clearTimeout(delay); resolved = true; - console.log("LALAL resolveIceCandidates", JSON.stringify(candidates)); - //const ipv6Elem = candidates.find((item) => item.candidate.includes("raddr ::")) - //candidates = ipv6Elem != undefined ? candidates.filter((elem) => elem == ipv6Elem) : candidates - //console.log("LALAL resolveIceCandidates2", JSON.stringify(candidates)) + // console.log("resolveIceCandidates", JSON.stringify(candidates)) + console.log("resolveIceCandidates"); const iceCandidates = serialize(candidates); candidates = []; resolve(iceCandidates); @@ -95,7 +93,8 @@ const processCommand = (function () { function sendIceCandidates() { if (candidates.length === 0) return; - console.log("LALAL sendIceCandidates", JSON.stringify(candidates)); + // console.log("sendIceCandidates", JSON.stringify(candidates)) + console.log("sendIceCandidates"); const iceCandidates = serialize(candidates); candidates = []; sendMessageToNative({ resp: { type: "ice", iceCandidates } }); @@ -217,7 +216,7 @@ const processCommand = (function () { iceCandidates: await activeCall.iceCandidates, capabilities: { encryption }, }; - console.log("LALALs", JSON.stringify(resp)); + // console.log("offer response", JSON.stringify(resp)) break; } case "offer": @@ -233,7 +232,7 @@ const processCommand = (function () { const { media, aesKey, iceServers, relay } = command; activeCall = await initializeCall(getCallConfig(!!aesKey, iceServers, relay), media, aesKey); const pc = activeCall.connection; - console.log("LALALo", JSON.stringify(remoteIceCandidates)); + // console.log("offer remoteIceCandidates", JSON.stringify(remoteIceCandidates)) await pc.setRemoteDescription(new RTCSessionDescription(offer)); const answer = await pc.createAnswer(); await pc.setLocalDescription(answer); @@ -245,7 +244,7 @@ const processCommand = (function () { iceCandidates: await activeCall.iceCandidates, }; } - console.log("LALALo", JSON.stringify(resp)); + // console.log("answer response", JSON.stringify(resp)) break; case "answer": if (!pc) { @@ -260,7 +259,7 @@ const processCommand = (function () { else { const answer = parse(command.answer); const remoteIceCandidates = parse(command.iceCandidates); - console.log("LALALa", JSON.stringify(remoteIceCandidates)); + // console.log("answer remoteIceCandidates", JSON.stringify(remoteIceCandidates)) await pc.setRemoteDescription(new RTCSessionDescription(answer)); addIceCandidates(pc, remoteIceCandidates); resp = { type: "ok" }; @@ -333,7 +332,7 @@ const processCommand = (function () { function addIceCandidates(conn, iceCandidates) { for (const c of iceCandidates) { conn.addIceCandidate(new RTCIceCandidate(c)); - console.log("LALAL addIceCandidates", JSON.stringify(c)); + // console.log("addIceCandidates", JSON.stringify(c)) } } async function setupMediaStreams(call) { @@ -356,8 +355,8 @@ const processCommand = (function () { if (useWorker && !call.worker) { const workerCode = `const callCrypto = (${callCryptoFunction.toString()})(); (${workerFunction.toString()})()`; call.worker = new Worker(URL.createObjectURL(new Blob([workerCode], { type: "text/javascript" }))); - call.worker.onerror = ({ error, filename, lineno, message }) => console.log(JSON.stringify({ error, filename, lineno, message })); - call.worker.onmessage = ({ data }) => console.log(JSON.stringify({ message: data })); + call.worker.onerror = ({ error, filename, lineno, message }) => console.log({ error, filename, lineno, message }); + // call.worker.onmessage = ({data}) => console.log(JSON.stringify({message: data})) } } } diff --git a/apps/multiplatform/common/src/commonMain/resources/assets/www/desktop/ui.js b/apps/multiplatform/common/src/commonMain/resources/assets/www/desktop/ui.js index 73c33ae91..2514a2411 100644 --- a/apps/multiplatform/common/src/commonMain/resources/assets/www/desktop/ui.js +++ b/apps/multiplatform/common/src/commonMain/resources/assets/www/desktop/ui.js @@ -1,12 +1,12 @@ "use strict"; // Override defaults to enable worker on Chrome and Safari -useWorker = window.safari !== undefined || navigator.userAgent.indexOf("Chrome") != -1; +useWorker = typeof window.Worker !== "undefined"; // Create WebSocket connection. const socket = new WebSocket(`ws://${location.host}`); socket.addEventListener("open", (_event) => { console.log("Opened socket"); sendMessageToNative = (msg) => { - console.log("Message to server: ", msg); + console.log("Message to server"); socket.send(JSON.stringify(msg)); }; }); @@ -14,7 +14,7 @@ socket.addEventListener("message", (event) => { const parsed = JSON.parse(event.data); reactOnMessageFromServer(parsed); processCommand(parsed); - console.log("Message from server: ", event.data); + console.log("Message from server"); }); socket.addEventListener("close", (_event) => { console.log("Closed socket"); diff --git a/packages/simplex-chat-webrtc/src/call.ts b/packages/simplex-chat-webrtc/src/call.ts index a6f036eb3..2a55b2671 100644 --- a/packages/simplex-chat-webrtc/src/call.ts +++ b/packages/simplex-chat-webrtc/src/call.ts @@ -285,7 +285,8 @@ const processCommand = (function () { function resolveIceCandidates() { if (delay) clearTimeout(delay) resolved = true - console.log("LALAL resolveIceCandidates", JSON.stringify(candidates)) + // console.log("resolveIceCandidates", JSON.stringify(candidates)) + console.log("resolveIceCandidates") const iceCandidates = serialize(candidates) candidates = [] resolve(iceCandidates) @@ -293,7 +294,8 @@ const processCommand = (function () { function sendIceCandidates() { if (candidates.length === 0) return - console.log("LALAL sendIceCandidates", JSON.stringify(candidates)) + // console.log("sendIceCandidates", JSON.stringify(candidates)) + console.log("sendIceCandidates") const iceCandidates = serialize(candidates) candidates = [] sendMessageToNative({resp: {type: "ice", iceCandidates}}) @@ -417,7 +419,7 @@ const processCommand = (function () { iceCandidates: await activeCall.iceCandidates, capabilities: {encryption}, } - console.log("LALALs", JSON.stringify(resp)) + // console.log("offer response", JSON.stringify(resp)) break } case "offer": @@ -431,7 +433,7 @@ const processCommand = (function () { const {media, aesKey, iceServers, relay} = command activeCall = await initializeCall(getCallConfig(!!aesKey, iceServers, relay), media, aesKey) const pc = activeCall.connection - console.log("LALALo", JSON.stringify(remoteIceCandidates)) + // console.log("offer remoteIceCandidates", JSON.stringify(remoteIceCandidates)) await pc.setRemoteDescription(new RTCSessionDescription(offer)) const answer = await pc.createAnswer() await pc.setLocalDescription(answer) @@ -443,7 +445,7 @@ const processCommand = (function () { iceCandidates: await activeCall.iceCandidates, } } - console.log("LALALo", JSON.stringify(resp)) + // console.log("answer response", JSON.stringify(resp)) break case "answer": if (!pc) { @@ -455,7 +457,7 @@ const processCommand = (function () { } else { const answer: RTCSessionDescriptionInit = parse(command.answer) const remoteIceCandidates: RTCIceCandidateInit[] = parse(command.iceCandidates) - console.log("LALALa", JSON.stringify(remoteIceCandidates)) + // console.log("answer remoteIceCandidates", JSON.stringify(remoteIceCandidates)) await pc.setRemoteDescription(new RTCSessionDescription(answer)) addIceCandidates(pc, remoteIceCandidates) resp = {type: "ok"} @@ -523,7 +525,7 @@ const processCommand = (function () { function addIceCandidates(conn: RTCPeerConnection, iceCandidates: RTCIceCandidateInit[]) { for (const c of iceCandidates) { conn.addIceCandidate(new RTCIceCandidate(c)) - console.log("LALAL addIceCandidates", JSON.stringify(c)) + // console.log("addIceCandidates", JSON.stringify(c)) } } @@ -546,9 +548,8 @@ const processCommand = (function () { if (useWorker && !call.worker) { const workerCode = `const callCrypto = (${callCryptoFunction.toString()})(); (${workerFunction.toString()})()` call.worker = new Worker(URL.createObjectURL(new Blob([workerCode], {type: "text/javascript"}))) - call.worker.onerror = ({error, filename, lineno, message}: ErrorEvent) => - console.log(JSON.stringify({error, filename, lineno, message})) - call.worker.onmessage = ({data}) => console.log(JSON.stringify({message: data})) + call.worker.onerror = ({error, filename, lineno, message}: ErrorEvent) => console.log({error, filename, lineno, message}) + // call.worker.onmessage = ({data}) => console.log(JSON.stringify({message: data})) } } } diff --git a/packages/simplex-chat-webrtc/src/desktop/ui.ts b/packages/simplex-chat-webrtc/src/desktop/ui.ts index ea681b4eb..f72adffd9 100644 --- a/packages/simplex-chat-webrtc/src/desktop/ui.ts +++ b/packages/simplex-chat-webrtc/src/desktop/ui.ts @@ -1,5 +1,5 @@ // Override defaults to enable worker on Chrome and Safari -useWorker = (window as any).safari !== undefined || navigator.userAgent.indexOf("Chrome") != -1 +useWorker = typeof window.Worker !== "undefined" // Create WebSocket connection. const socket = new WebSocket(`ws://${location.host}`) @@ -7,7 +7,7 @@ const socket = new WebSocket(`ws://${location.host}`) socket.addEventListener("open", (_event) => { console.log("Opened socket") sendMessageToNative = (msg: WVApiMessage) => { - console.log("Message to server: ", msg) + console.log("Message to server") socket.send(JSON.stringify(msg)) } }) @@ -16,7 +16,7 @@ socket.addEventListener("message", (event) => { const parsed = JSON.parse(event.data) reactOnMessageFromServer(parsed) processCommand(parsed) - console.log("Message from server: ", event.data) + console.log("Message from server") }) socket.addEventListener("close", (_event) => {