presetup client for server api calls for webrtc calls
This commit is contained in:
@@ -353,6 +353,21 @@ public partial class MainPage : ContentPage
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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#!");
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|
||||||
@@ -158,7 +168,6 @@ async function joinChannelCall() {
|
|||||||
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
|
||||||
@@ -228,6 +262,20 @@ async function channelCallJoin()
|
|||||||
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);
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user