presetup client for server api calls for webrtc calls
This commit is contained in:
@@ -4,6 +4,17 @@ let currentUsername = null;
|
||||
let currentChannelId = null;
|
||||
let availableCameras = [];
|
||||
let availableMics = [];
|
||||
const configuration = {
|
||||
iceServers:[
|
||||
{
|
||||
urls:[
|
||||
'stun:stun1.l.google.com:19302',
|
||||
'stun:stun2.l.google.com:19302',
|
||||
],
|
||||
},
|
||||
],
|
||||
iceCandidatePoolSize: 10,
|
||||
}
|
||||
|
||||
window.setUsername = function(name) {
|
||||
currentUsername = name;
|
||||
@@ -86,7 +97,6 @@ async function ensurePeerConnection() {
|
||||
LogMessage("ICE gathering state: " + peerConnection.iceGatheringState);
|
||||
};
|
||||
}
|
||||
|
||||
async function ensureLocalMedia() {
|
||||
if (localStream) return;
|
||||
|
||||
@@ -157,8 +167,7 @@ async function joinChannelCall() {
|
||||
LogMessage("Current username: " + currentUsername);
|
||||
LogMessage("Current channel: " + currentChannelId);
|
||||
//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 {
|
||||
if (!currentChannelId) {
|
||||
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)
|
||||
{
|
||||
@@ -214,8 +248,8 @@ async function channelCallJoin()
|
||||
}
|
||||
}
|
||||
|
||||
const roomRef = "id"; //TODO: Add offer to SurrealDB on server
|
||||
const roomId = roomRef.id;
|
||||
await window.HybridWebView.InvokeDotNet("WriteRtcOffer", [JSON.stringify(offer)]);
|
||||
|
||||
//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
|
||||
@@ -227,6 +261,20 @@ async function channelCallJoin()
|
||||
const answer = new RTCSessionDescription(data.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