A step in the right direction

This commit is contained in:
2026-04-21 01:14:44 -04:00
parent a2608ffab9
commit 4f6bbcf6e2
3 changed files with 76 additions and 31 deletions

View File

@@ -161,37 +161,81 @@ async function joinChannelCall() {
LogMessage("Current username: " + currentUsername);
LogMessage("Current channel: " + currentChannelId);
await window.HybridWebView.InvokeDotNet("JoinRtcChannel");
const isActive = await window.HybridWebView.InvokeDotNet("JoinRtcChannel");
const peerConnection = await ensurePeerConnectionForUser(currentUsername);
await ensureLocalMedia();
const rawParticipants = await window.HybridWebView.InvokeDotNet("GetRtcParticipants");
const participants = typeof rawParticipants === "string"
? JSON.parse(rawParticipants)
: rawParticipants;
if (isActive) {
const rawJson = await window.HybridWebView.InvokeDotNet("GetRtcOffer");
const offer = typeof rawJson === "string" ? JSON.parse(rawJson) : rawJson;
await peerConnection.setRemoteDescription(offer);
const answer = await peerConnection.createAnswer();
await peerConnection.setRemoteDescription(answer);
await window.HybridWebView.InvokeDotNet("WriteRtcAnswer", [JSON.stringify(answer)])
LogMessage("Participants: " + JSON.stringify(participants)); // TODO: Remove
const rawParticipants = await window.HybridWebView.InvokeDotNet("GetRtcParticipants");
const participants = typeof rawParticipants === "string" ? JSON.parse(rawParticipants) : rawParticipants;
for (const username of participants) {
if (username === currentUsername) continue;
LogMessage("Participants: " + JSON.stringify(participants)); // TODO: Remove
const pc = await ensurePeerConnectionForUser(username);
for (const username of participants) {
if (username === currentUsername) continue;
const offer = await pc.createOffer();
await pc.setLocalDescription(offer);
const pc = await ensurePeerConnectionForUser(username);
const payload = {
type: "rtc_offer",
from: currentUsername,
to: username,
channelId: currentChannelId,
sdp: offer.sdp
};
const offer = await pc.createOffer();
await pc.setLocalDescription(offer);
await window.HybridWebView.InvokeDotNet("SendRtcSignal", [JSON.stringify(payload)]);
LogMessage(`Sent offer to ${username}`);
const payload = {
type: "rtc_offer",
from: currentUsername,
to: username,
channelId: currentChannelId,
sdp: offer.sdp
};
await window.HybridWebView.InvokeDotNet("SendRtcSignal", [JSON.stringify(payload)]);
LogMessage(`Sent offer to ${username}`);
}
}
else
{
try {
LogMessage(currentUsername + " attempted to join inactive channel. Making new call.")
const offer = await peerConnection.createOffer();
await peerConnection.setLocalDescription(offer);
await window.HybridWebView.InvokeDotNet("WriteRtcOffer", [JSON.stringify(offer)]);
LogMessage(`Joining call with media offer: ${JSON.stringify(offer)}`);
}
catch (error) {
LogMessage(error)
}
}
}
async function channelCallJoin(activeCall)
{
// LogMessage("Active call: " + activeCall);
await ensurePeerConnectionForUser(currentUsername);
if (activeCall)
{
const rawJson = await window.HybridWebView.InvokeDotNet("GetRtcOffer");
const offer = typeof rawJson === "string" ? JSON.parse(rawJson) : rawJson;
await peerConnection.setRemoteDescription(offer);
const answer = await peerConnection.createAnswer();
await peerConnection.setLocalDescription(answer);
// LogMessage("Joining call with media answer: " + JSON.stringify(answer));
// LogMessage("Calling C# WriteRtcAnswer with: " + JSON.stringify(answer));
await window.HybridWebView.InvokeDotNet("WriteRtcAnswer", [JSON.stringify(answer)]);
}
else
{
const offer = await peerConnection.createOffer();
await peerConnection.setLocalDescription(offer);
await window.HybridWebView.InvokeDotNet("WriteRtcOffer", [JSON.stringify(offer)]);
}
}
async function ensurePeerConnectionForUser(username) {
if (peerConnections[username]) return peerConnections[username];