android, desktop: reduce browser call logs, check Worker availability directly (#3256)
This commit is contained in:
parent
f026a38a75
commit
795c54343a
@ -84,10 +84,8 @@ const processCommand = (function () {
|
|||||||
if (delay)
|
if (delay)
|
||||||
clearTimeout(delay);
|
clearTimeout(delay);
|
||||||
resolved = true;
|
resolved = true;
|
||||||
console.log("LALAL resolveIceCandidates", JSON.stringify(candidates));
|
// console.log("resolveIceCandidates", JSON.stringify(candidates))
|
||||||
//const ipv6Elem = candidates.find((item) => item.candidate.includes("raddr ::"))
|
console.log("resolveIceCandidates");
|
||||||
//candidates = ipv6Elem != undefined ? candidates.filter((elem) => elem == ipv6Elem) : candidates
|
|
||||||
//console.log("LALAL resolveIceCandidates2", JSON.stringify(candidates))
|
|
||||||
const iceCandidates = serialize(candidates);
|
const iceCandidates = serialize(candidates);
|
||||||
candidates = [];
|
candidates = [];
|
||||||
resolve(iceCandidates);
|
resolve(iceCandidates);
|
||||||
@ -95,7 +93,8 @@ const processCommand = (function () {
|
|||||||
function sendIceCandidates() {
|
function sendIceCandidates() {
|
||||||
if (candidates.length === 0)
|
if (candidates.length === 0)
|
||||||
return;
|
return;
|
||||||
console.log("LALAL sendIceCandidates", JSON.stringify(candidates));
|
// console.log("sendIceCandidates", JSON.stringify(candidates))
|
||||||
|
console.log("sendIceCandidates");
|
||||||
const iceCandidates = serialize(candidates);
|
const iceCandidates = serialize(candidates);
|
||||||
candidates = [];
|
candidates = [];
|
||||||
sendMessageToNative({ resp: { type: "ice", iceCandidates } });
|
sendMessageToNative({ resp: { type: "ice", iceCandidates } });
|
||||||
@ -217,7 +216,7 @@ const processCommand = (function () {
|
|||||||
iceCandidates: await activeCall.iceCandidates,
|
iceCandidates: await activeCall.iceCandidates,
|
||||||
capabilities: { encryption },
|
capabilities: { encryption },
|
||||||
};
|
};
|
||||||
console.log("LALALs", JSON.stringify(resp));
|
// console.log("offer response", JSON.stringify(resp))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "offer":
|
case "offer":
|
||||||
@ -233,7 +232,7 @@ const processCommand = (function () {
|
|||||||
const { media, aesKey, iceServers, relay } = command;
|
const { media, aesKey, iceServers, relay } = command;
|
||||||
activeCall = await initializeCall(getCallConfig(!!aesKey, iceServers, relay), media, aesKey);
|
activeCall = await initializeCall(getCallConfig(!!aesKey, iceServers, relay), media, aesKey);
|
||||||
const pc = activeCall.connection;
|
const pc = activeCall.connection;
|
||||||
console.log("LALALo", JSON.stringify(remoteIceCandidates));
|
// console.log("offer remoteIceCandidates", JSON.stringify(remoteIceCandidates))
|
||||||
await pc.setRemoteDescription(new RTCSessionDescription(offer));
|
await pc.setRemoteDescription(new RTCSessionDescription(offer));
|
||||||
const answer = await pc.createAnswer();
|
const answer = await pc.createAnswer();
|
||||||
await pc.setLocalDescription(answer);
|
await pc.setLocalDescription(answer);
|
||||||
@ -245,7 +244,7 @@ const processCommand = (function () {
|
|||||||
iceCandidates: await activeCall.iceCandidates,
|
iceCandidates: await activeCall.iceCandidates,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
console.log("LALALo", JSON.stringify(resp));
|
// console.log("answer response", JSON.stringify(resp))
|
||||||
break;
|
break;
|
||||||
case "answer":
|
case "answer":
|
||||||
if (!pc) {
|
if (!pc) {
|
||||||
@ -260,7 +259,7 @@ const processCommand = (function () {
|
|||||||
else {
|
else {
|
||||||
const answer = parse(command.answer);
|
const answer = parse(command.answer);
|
||||||
const remoteIceCandidates = parse(command.iceCandidates);
|
const remoteIceCandidates = parse(command.iceCandidates);
|
||||||
console.log("LALALa", JSON.stringify(remoteIceCandidates));
|
// console.log("answer remoteIceCandidates", JSON.stringify(remoteIceCandidates))
|
||||||
await pc.setRemoteDescription(new RTCSessionDescription(answer));
|
await pc.setRemoteDescription(new RTCSessionDescription(answer));
|
||||||
addIceCandidates(pc, remoteIceCandidates);
|
addIceCandidates(pc, remoteIceCandidates);
|
||||||
resp = { type: "ok" };
|
resp = { type: "ok" };
|
||||||
@ -333,7 +332,7 @@ const processCommand = (function () {
|
|||||||
function addIceCandidates(conn, iceCandidates) {
|
function addIceCandidates(conn, iceCandidates) {
|
||||||
for (const c of iceCandidates) {
|
for (const c of iceCandidates) {
|
||||||
conn.addIceCandidate(new RTCIceCandidate(c));
|
conn.addIceCandidate(new RTCIceCandidate(c));
|
||||||
console.log("LALAL addIceCandidates", JSON.stringify(c));
|
// console.log("addIceCandidates", JSON.stringify(c))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async function setupMediaStreams(call) {
|
async function setupMediaStreams(call) {
|
||||||
@ -356,8 +355,8 @@ const processCommand = (function () {
|
|||||||
if (useWorker && !call.worker) {
|
if (useWorker && !call.worker) {
|
||||||
const workerCode = `const callCrypto = (${callCryptoFunction.toString()})(); (${workerFunction.toString()})()`;
|
const workerCode = `const callCrypto = (${callCryptoFunction.toString()})(); (${workerFunction.toString()})()`;
|
||||||
call.worker = new Worker(URL.createObjectURL(new Blob([workerCode], { type: "text/javascript" })));
|
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.onerror = ({ error, filename, lineno, message }) => console.log({ error, filename, lineno, message });
|
||||||
call.worker.onmessage = ({ data }) => console.log(JSON.stringify({ message: data }));
|
// call.worker.onmessage = ({data}) => console.log(JSON.stringify({message: data}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
// Override defaults to enable worker on Chrome and Safari
|
// 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.
|
// Create WebSocket connection.
|
||||||
const socket = new WebSocket(`ws://${location.host}`);
|
const socket = new WebSocket(`ws://${location.host}`);
|
||||||
socket.addEventListener("open", (_event) => {
|
socket.addEventListener("open", (_event) => {
|
||||||
console.log("Opened socket");
|
console.log("Opened socket");
|
||||||
sendMessageToNative = (msg) => {
|
sendMessageToNative = (msg) => {
|
||||||
console.log("Message to server: ", msg);
|
console.log("Message to server");
|
||||||
socket.send(JSON.stringify(msg));
|
socket.send(JSON.stringify(msg));
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
@ -14,7 +14,7 @@ socket.addEventListener("message", (event) => {
|
|||||||
const parsed = JSON.parse(event.data);
|
const parsed = JSON.parse(event.data);
|
||||||
reactOnMessageFromServer(parsed);
|
reactOnMessageFromServer(parsed);
|
||||||
processCommand(parsed);
|
processCommand(parsed);
|
||||||
console.log("Message from server: ", event.data);
|
console.log("Message from server");
|
||||||
});
|
});
|
||||||
socket.addEventListener("close", (_event) => {
|
socket.addEventListener("close", (_event) => {
|
||||||
console.log("Closed socket");
|
console.log("Closed socket");
|
||||||
|
@ -285,7 +285,8 @@ const processCommand = (function () {
|
|||||||
function resolveIceCandidates() {
|
function resolveIceCandidates() {
|
||||||
if (delay) clearTimeout(delay)
|
if (delay) clearTimeout(delay)
|
||||||
resolved = true
|
resolved = true
|
||||||
console.log("LALAL resolveIceCandidates", JSON.stringify(candidates))
|
// console.log("resolveIceCandidates", JSON.stringify(candidates))
|
||||||
|
console.log("resolveIceCandidates")
|
||||||
const iceCandidates = serialize(candidates)
|
const iceCandidates = serialize(candidates)
|
||||||
candidates = []
|
candidates = []
|
||||||
resolve(iceCandidates)
|
resolve(iceCandidates)
|
||||||
@ -293,7 +294,8 @@ const processCommand = (function () {
|
|||||||
|
|
||||||
function sendIceCandidates() {
|
function sendIceCandidates() {
|
||||||
if (candidates.length === 0) return
|
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)
|
const iceCandidates = serialize(candidates)
|
||||||
candidates = []
|
candidates = []
|
||||||
sendMessageToNative({resp: {type: "ice", iceCandidates}})
|
sendMessageToNative({resp: {type: "ice", iceCandidates}})
|
||||||
@ -417,7 +419,7 @@ const processCommand = (function () {
|
|||||||
iceCandidates: await activeCall.iceCandidates,
|
iceCandidates: await activeCall.iceCandidates,
|
||||||
capabilities: {encryption},
|
capabilities: {encryption},
|
||||||
}
|
}
|
||||||
console.log("LALALs", JSON.stringify(resp))
|
// console.log("offer response", JSON.stringify(resp))
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
case "offer":
|
case "offer":
|
||||||
@ -431,7 +433,7 @@ const processCommand = (function () {
|
|||||||
const {media, aesKey, iceServers, relay} = command
|
const {media, aesKey, iceServers, relay} = command
|
||||||
activeCall = await initializeCall(getCallConfig(!!aesKey, iceServers, relay), media, aesKey)
|
activeCall = await initializeCall(getCallConfig(!!aesKey, iceServers, relay), media, aesKey)
|
||||||
const pc = activeCall.connection
|
const pc = activeCall.connection
|
||||||
console.log("LALALo", JSON.stringify(remoteIceCandidates))
|
// console.log("offer remoteIceCandidates", JSON.stringify(remoteIceCandidates))
|
||||||
await pc.setRemoteDescription(new RTCSessionDescription(offer))
|
await pc.setRemoteDescription(new RTCSessionDescription(offer))
|
||||||
const answer = await pc.createAnswer()
|
const answer = await pc.createAnswer()
|
||||||
await pc.setLocalDescription(answer)
|
await pc.setLocalDescription(answer)
|
||||||
@ -443,7 +445,7 @@ const processCommand = (function () {
|
|||||||
iceCandidates: await activeCall.iceCandidates,
|
iceCandidates: await activeCall.iceCandidates,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log("LALALo", JSON.stringify(resp))
|
// console.log("answer response", JSON.stringify(resp))
|
||||||
break
|
break
|
||||||
case "answer":
|
case "answer":
|
||||||
if (!pc) {
|
if (!pc) {
|
||||||
@ -455,7 +457,7 @@ const processCommand = (function () {
|
|||||||
} else {
|
} else {
|
||||||
const answer: RTCSessionDescriptionInit = parse(command.answer)
|
const answer: RTCSessionDescriptionInit = parse(command.answer)
|
||||||
const remoteIceCandidates: RTCIceCandidateInit[] = parse(command.iceCandidates)
|
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))
|
await pc.setRemoteDescription(new RTCSessionDescription(answer))
|
||||||
addIceCandidates(pc, remoteIceCandidates)
|
addIceCandidates(pc, remoteIceCandidates)
|
||||||
resp = {type: "ok"}
|
resp = {type: "ok"}
|
||||||
@ -523,7 +525,7 @@ const processCommand = (function () {
|
|||||||
function addIceCandidates(conn: RTCPeerConnection, iceCandidates: RTCIceCandidateInit[]) {
|
function addIceCandidates(conn: RTCPeerConnection, iceCandidates: RTCIceCandidateInit[]) {
|
||||||
for (const c of iceCandidates) {
|
for (const c of iceCandidates) {
|
||||||
conn.addIceCandidate(new RTCIceCandidate(c))
|
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) {
|
if (useWorker && !call.worker) {
|
||||||
const workerCode = `const callCrypto = (${callCryptoFunction.toString()})(); (${workerFunction.toString()})()`
|
const workerCode = `const callCrypto = (${callCryptoFunction.toString()})(); (${workerFunction.toString()})()`
|
||||||
call.worker = new Worker(URL.createObjectURL(new Blob([workerCode], {type: "text/javascript"})))
|
call.worker = new Worker(URL.createObjectURL(new Blob([workerCode], {type: "text/javascript"})))
|
||||||
call.worker.onerror = ({error, filename, lineno, message}: ErrorEvent) =>
|
call.worker.onerror = ({error, filename, lineno, message}: ErrorEvent) => console.log({error, filename, lineno, message})
|
||||||
console.log(JSON.stringify({error, filename, lineno, message}))
|
// call.worker.onmessage = ({data}) => console.log(JSON.stringify({message: data}))
|
||||||
call.worker.onmessage = ({data}) => console.log(JSON.stringify({message: data}))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// Override defaults to enable worker on Chrome and Safari
|
// 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.
|
// Create WebSocket connection.
|
||||||
const socket = new WebSocket(`ws://${location.host}`)
|
const socket = new WebSocket(`ws://${location.host}`)
|
||||||
@ -7,7 +7,7 @@ const socket = new WebSocket(`ws://${location.host}`)
|
|||||||
socket.addEventListener("open", (_event) => {
|
socket.addEventListener("open", (_event) => {
|
||||||
console.log("Opened socket")
|
console.log("Opened socket")
|
||||||
sendMessageToNative = (msg: WVApiMessage) => {
|
sendMessageToNative = (msg: WVApiMessage) => {
|
||||||
console.log("Message to server: ", msg)
|
console.log("Message to server")
|
||||||
socket.send(JSON.stringify(msg))
|
socket.send(JSON.stringify(msg))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -16,7 +16,7 @@ socket.addEventListener("message", (event) => {
|
|||||||
const parsed = JSON.parse(event.data)
|
const parsed = JSON.parse(event.data)
|
||||||
reactOnMessageFromServer(parsed)
|
reactOnMessageFromServer(parsed)
|
||||||
processCommand(parsed)
|
processCommand(parsed)
|
||||||
console.log("Message from server: ", event.data)
|
console.log("Message from server")
|
||||||
})
|
})
|
||||||
|
|
||||||
socket.addEventListener("close", (_event) => {
|
socket.addEventListener("close", (_event) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user