Skip to content

Commit

Permalink
android, desktop: reduce browser call logs, check Worker availability…
Browse files Browse the repository at this point in the history
… directly (#3256)
  • Loading branch information
epoberezkin committed Oct 22, 2023
1 parent f026a38 commit 795c543
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 28 deletions.

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

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

21 changes: 11 additions & 10 deletions packages/simplex-chat-webrtc/src/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,15 +285,17 @@ 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)
}

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}})
Expand Down Expand Up @@ -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":
Expand All @@ -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)
Expand All @@ -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) {
Expand All @@ -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"}
Expand Down Expand Up @@ -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))
}
}

Expand All @@ -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}))
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions packages/simplex-chat-webrtc/src/desktop/ui.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// 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}`)

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))
}
})
Expand All @@ -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) => {
Expand Down

0 comments on commit 795c543

Please sign in to comment.