testing with internal relay server

This commit is contained in:
Roland Osborne 2023-04-06 11:09:38 -07:00
parent 8d8b6c32e0
commit 0539874b4a

View File

@ -38,10 +38,20 @@ export function useRingContext() {
const iceServers = [ const iceServers = [
{ {
urls: 'turn:35.165.123.117:5001?transport=udp', //urls: 'turn:98.234.232.221:5001?transport=udp',
urls: 'turn:192.168.13.233:5001?transport=udp',
//urls: 'turn:35.165.123.117:5001?transport=udp',
username: 'user', username: 'user',
credential: 'pass' credential: 'pass'
}]; },
{
urls: 'turn:98.234.232.221:5001?transport=udp',
//urls: 'turn:192.168.13.233:5001?transport=udp',
//urls: 'turn:35.165.123.117:5001?transport=udp',
username: 'user',
credential: 'pass'
},
];
const updateState = (value) => { const updateState = (value) => {
setState((s) => ({ ...s, ...value })) setState((s) => ({ ...s, ...value }))
@ -99,11 +109,9 @@ console.log("polite: ", description);
} }
const impolite = async () => { const impolite = async () => {
console.log("IMPOLITE!", processing.current, connected.current);
if (processing.current || !connected.current) { if (processing.current || !connected.current) {
return; return;
} }
console.log("GO");
processing.current = true; processing.current = true;
while (offers.current.length > 0) { while (offers.current.length > 0) {
@ -116,13 +124,11 @@ console.log("GO");
try { try {
if (description == null) { if (description == null) {
console.log(" SENDING NEW IMPOLITE OFFER");
const offer = await pc.current.createOffer(); const offer = await pc.current.createOffer();
await pc.current.setLocalDescription(offer); await pc.current.setLocalDescription(offer);
ws.current.send(JSON.stringify({ description: pc.current.localDescription })); ws.current.send(JSON.stringify({ description: pc.current.localDescription }));
} }
else { else {
console.log("impolite: ", description);
if (description.type === 'offer' && pc.current.signalingState !== 'stable') { if (description.type === 'offer' && pc.current.signalingState !== 'stable') {
continue; continue;
} }
@ -136,6 +142,7 @@ console.log("impolite: ", description);
candidates.current = []; candidates.current = [];
for (let i = 0; i < servers.length; i++) { for (let i = 0; i < servers.length; i++) {
const server = servers[i]; const server = servers[i];
console.log("MY ICE2:", server);
ws.current.send(JSON.stringify(server)); ws.current.send(JSON.stringify(server));
} }
} }
@ -158,9 +165,7 @@ console.log("impolite: ", description);
pc.current = new RTCPeerConnection({ iceServers }); pc.current = new RTCPeerConnection({ iceServers });
pc.current.ontrack = (ev) => { pc.current.ontrack = (ev) => {
console.log("ON TRACK");
if (!stream.current) { if (!stream.current) {
console.log("NEW MEDIA STREAM");
stream.current = new MediaStream(); stream.current = new MediaStream();
updateState({ remoteStream: stream.current }); updateState({ remoteStream: stream.current });
} }
@ -174,15 +179,14 @@ console.log("NEW MEDIA STREAM");
}; };
pc.current.onicecandidate = ({candidate}) => { pc.current.onicecandidate = ({candidate}) => {
if (pc.current.remoteDescription == null) { if (pc.current.remoteDescription == null) {
console.log("QUEING ICE");
candidates.current.push({ candidate }); candidates.current.push({ candidate });
} }
else { else {
console.log("MY ICE", candidate);
ws.current.send(JSON.stringify({ candidate })); ws.current.send(JSON.stringify({ candidate }));
} }
}; };
pc.current.onnegotiationneeded = async () => { pc.current.onnegotiationneeded = async () => {
console.log("NEGOTIATION NEEDED");
offers.current.push(null); offers.current.push(null);
if (policy === 'polite') { if (policy === 'polite') {
polite(); polite();
@ -220,7 +224,6 @@ console.log("NEGOTIATION NEEDED");
// handle messages [impolite] // handle messages [impolite]
try { try {
const signal = JSON.parse(ev.data); const signal = JSON.parse(ev.data);
console.log("ON MESSAGE", signal);
if (signal.status === 'connected') { if (signal.status === 'connected') {
clearRing(); clearRing();
updateState({ callStatus: "connected" }); updateState({ callStatus: "connected" });
@ -246,6 +249,7 @@ console.log("ON MESSAGE", signal);
// return; // return;
// } // }
const candidate = new RTCIceCandidate(signal.candidate); const candidate = new RTCIceCandidate(signal.candidate);
console.log("THEIR ICE:", candidate);
await pc.current.addIceCandidate(candidate); await pc.current.addIceCandidate(candidate);
} }