Encryption Sent, Encrpytion Decoded, Offer Sent, Offer Recieved, JS -> C# / C# -> JS Broke (some disconnect here) SendRtcSignalToJsAsync
This commit is contained in:
@@ -164,58 +164,43 @@ async function joinChannelCall() {
|
||||
LogMessage("Current username: " + currentUsername);
|
||||
LogMessage("Current channel: " + currentChannelId);
|
||||
|
||||
const isActive = await window.HybridWebView.InvokeDotNet("JoinRtcChannel");
|
||||
const peerConnection = await ensurePeerConnectionForUser(currentUsername);
|
||||
await window.HybridWebView.InvokeDotNet("JoinRtcChannel");
|
||||
await ensureLocalMedia();
|
||||
|
||||
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)])
|
||||
const rawParticipants = await window.HybridWebView.InvokeDotNet("GetRtcParticipants");
|
||||
const participants = typeof rawParticipants === "string"
|
||||
? JSON.parse(rawParticipants)
|
||||
: rawParticipants;
|
||||
|
||||
const rawParticipants = await window.HybridWebView.InvokeDotNet("GetRtcParticipants");
|
||||
const participants = typeof rawParticipants === "string" ? JSON.parse(rawParticipants) : rawParticipants;
|
||||
LogMessage("Participants: " + JSON.stringify(participants));
|
||||
|
||||
LogMessage("Participants: " + JSON.stringify(participants)); // TODO: Remove
|
||||
const otherUsers = participants.filter(username => username !== currentUsername);
|
||||
|
||||
for (const username of participants) {
|
||||
if (username === currentUsername) continue;
|
||||
|
||||
const pc = await ensurePeerConnectionForUser(username);
|
||||
|
||||
const offer = await pc.createOffer();
|
||||
await pc.setLocalDescription(offer);
|
||||
|
||||
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}`);
|
||||
}
|
||||
if (otherUsers.length === 0) {
|
||||
LogMessage("Joined call as first participant. Waiting for others...");
|
||||
return;
|
||||
}
|
||||
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)
|
||||
}
|
||||
|
||||
for (const username of otherUsers) {
|
||||
const pc = await ensurePeerConnectionForUser(username);
|
||||
|
||||
const offer = await pc.createOffer();
|
||||
await pc.setLocalDescription(offer);
|
||||
|
||||
const payload = {
|
||||
type: "rtc_offer",
|
||||
from: currentUsername,
|
||||
to: username,
|
||||
channelId: currentChannelId,
|
||||
sdp: offer.sdp,
|
||||
isInitiator: true
|
||||
};
|
||||
|
||||
await window.HybridWebView.InvokeDotNet("SendRtcSignal", [JSON.stringify(payload)]);
|
||||
LogMessage(`Sent offer to ${username}`);
|
||||
}
|
||||
}
|
||||
|
||||
async function channelCallJoin(activeCall)
|
||||
{
|
||||
// LogMessage("Active call: " + activeCall);
|
||||
@@ -337,6 +322,11 @@ async function handleRtcSignal(rawJson) {
|
||||
|
||||
if (!msg.from || msg.from === currentUsername) return;
|
||||
|
||||
if (msg.to && msg.to !== currentUsername) {
|
||||
LogMessage(`Ignoring signal meant for ${msg.to}`);
|
||||
return;
|
||||
}
|
||||
|
||||
const pc = await ensurePeerConnectionForUser(msg.from);
|
||||
|
||||
if (msg.type === "rtc_offer") {
|
||||
@@ -390,6 +380,8 @@ async function handleRtcSignal(rawJson) {
|
||||
}
|
||||
}
|
||||
|
||||
window.handleRtcSignal = handleRtcSignal;
|
||||
|
||||
async function loadDevices() {
|
||||
try {
|
||||
const devices = await navigator.mediaDevices.enumerateDevices();
|
||||
@@ -510,8 +502,6 @@ function removeRemoteTile(username) {
|
||||
}
|
||||
}
|
||||
|
||||
window.handleRtcSignal = handleRtcSignal;
|
||||
|
||||
window.addEventListener("HybridWebViewMessageReceived", function (e) {
|
||||
LogMessage("Raw message: " + e.detail.message);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user