presetup client for server api calls for webrtc calls

This commit is contained in:
2026-04-02 13:51:26 -04:00
parent cb59cc4409
commit 92db27edc4
3 changed files with 74 additions and 10 deletions

View File

@@ -352,7 +352,22 @@ public partial class MainPage : ContentPage
ViewSwapped.Text = "Swap to Message View"; ViewSwapped.Text = "Swap to Message View";
} }
} }
public void JoinRtcChannel()
{
//TODO: get bool value for if channel ID has an active call
//TODO: Join RTC using current channel ID
}
public void WriteRtcOffer(string json)
{
RTCOffer? offer = JsonSerializer.Deserialize<RTCOffer>(json);
}
private class RTCOffer
{
private string type { get; set; }
private string sdp { get; set; }
}
private void OnSendMessageButtonClicked(object sender, EventArgs e) private void OnSendMessageButtonClicked(object sender, EventArgs e)
{ {
hybridWebView.SendRawMessage($"Hello from C#!"); hybridWebView.SendRawMessage($"Hello from C#!");

View File

@@ -1,12 +1,13 @@
@import url('https://fonts.googleapis.com/css2?family=Syne+Mono&display=swap'); @import url('https://fonts.googleapis.com/css2?family=Anonymous+Pro');
body { body {
font-family: 'Syne Mono', monospace; font-family: 'Anonymous Pro', monospace;
-webkit-font-smoothing: antialiased; -webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale; -moz-osx-font-smoothing: grayscale;
text-align: center; text-align: center;
color: #2c3e50; color: #2c3e50;
margin: 80px 10px; margin: 80px 10px;
background-color: #666666;
} }
video { video {

View File

@@ -4,6 +4,17 @@ let currentUsername = null;
let currentChannelId = null; let currentChannelId = null;
let availableCameras = []; let availableCameras = [];
let availableMics = []; let availableMics = [];
const configuration = {
iceServers:[
{
urls:[
'stun:stun1.l.google.com:19302',
'stun:stun2.l.google.com:19302',
],
},
],
iceCandidatePoolSize: 10,
}
window.setUsername = function(name) { window.setUsername = function(name) {
currentUsername = name; currentUsername = name;
@@ -86,7 +97,6 @@ async function ensurePeerConnection() {
LogMessage("ICE gathering state: " + peerConnection.iceGatheringState); LogMessage("ICE gathering state: " + peerConnection.iceGatheringState);
}; };
} }
async function ensureLocalMedia() { async function ensureLocalMedia() {
if (localStream) return; if (localStream) return;
@@ -157,8 +167,7 @@ async function joinChannelCall() {
LogMessage("Current username: " + currentUsername); LogMessage("Current username: " + currentUsername);
LogMessage("Current channel: " + currentChannelId); LogMessage("Current channel: " + currentChannelId);
//TODO: Update Server DB to hold bool if channel has an active call //TODO: Update Server DB to hold bool if channel has an active call
//TODO: First check if channel already has an active offer, if it does join with an answer, otherwise make a new offer //TODO: First check if channel already has an active offer, if it does join with an answer, otherwise make a new offer
try { try {
if (!currentChannelId) { if (!currentChannelId) {
LogMessage("No current channel set."); LogMessage("No current channel set.");
@@ -183,9 +192,34 @@ async function joinChannelCall() {
} }
} }
async function channelCallJoin()
async function ensurePeerConnection2()
{ {
const activeCall = true; //TODO: Read Surreal DB with channel id for active call if (peerConnection) return;
peerConnection = new RTCPeerConnection(configuration);
peerConnection.addEventListener('icegatheringstatechange', () => {
console.log(
`ICE gathering state changed: ${peerConnection.iceGatheringState}`);
});
peerConnection.addEventListener('connectionstatechange', () => {
console.log(`Connection state change: ${peerConnection.connectionState}`);
});
peerConnection.addEventListener('signalingstatechange', () => {
console.log(`Signaling state change: ${peerConnection.signalingState}`);
});
peerConnection.addEventListener('iceconnectionstatechange ', () => {
console.log(
`ICE connection state change: ${peerConnection.iceConnectionState}`);
});
}
async function channelCallJoin(activeCall, channelId)
{
await ensurePeerConnection2();
if (activeCall) if (activeCall)
{ {
@@ -214,8 +248,8 @@ async function channelCallJoin()
} }
} }
const roomRef = "id"; //TODO: Add offer to SurrealDB on server await window.HybridWebView.InvokeDotNet("WriteRtcOffer", [JSON.stringify(offer)]);
const roomId = roomRef.id;
//TODO: Write roomId to surreal DB with channel id as active call //TODO: Write roomId to surreal DB with channel id as active call
//TODO: Add callback function for when call is answered to replace following code block //TODO: Add callback function for when call is answered to replace following code block
@@ -227,6 +261,20 @@ async function channelCallJoin()
const answer = new RTCSessionDescription(data.answer) const answer = new RTCSessionDescription(data.answer)
await peerConnection.setRemoteDescription(answer); await peerConnection.setRemoteDescription(answer);
} }
});
localStream.getTracks().forEach(track => {
peerConnection.addTrack(track, localStream);
});
//TODO: collect ICE candidates
peerConnection.addEventListener('track', event => {
LogMessage("Received track: " + event.streams[0]);
event.streams[0].getTracks().forEach(track => {
LogMessage(`Add a track to the remoteStream: ${track}`);
remoteStream.addTrack(track);
});
}); });
} }