using admin set ice relay

This commit is contained in:
Roland Osborne 2023-04-13 13:49:51 -07:00
parent de043e1f36
commit dd34a17268
3 changed files with 24 additions and 26 deletions

View File

@ -181,8 +181,8 @@ export function useAppContext(websocket) {
setAppRevision(activity.revision);
}
if (activity.ring) {
const { cardId, callId, calleeToken } = activity.ring;
ringContext.actions.ring(cardId, callId, calleeToken);
const { cardId, callId, calleeToken, iceUrl, iceUsername, icePassword } = activity.ring;
ringContext.actions.ring(cardId, callId, calleeToken, iceUrl, iceUsername, icePassword);
}
}
catch (err) {

View File

@ -37,16 +37,6 @@ export function useRingContext() {
const connected = useRef(false);
const candidates = useRef([]);
const iceServers = [
{
//urls: 'turn:98.234.232.221:5001?transport=udp',
urls: 'turn:44.238.207.157:3478?transport=udp',
//urls: 'turn:35.165.123.117:5001?transport=udp',
username: 'user',
credential: 'pass'
},
];
const updateState = (value) => {
setState((s) => ({ ...s, ...value }))
}
@ -144,9 +134,11 @@ export function useRingContext() {
processing.current = false;
}
const transmit = async (policy) => {
const transmit = async (policy, ice) => {
pc.current = new RTCPeerConnection({ iceServers });
console.log("TRANSMIT:", ice);
pc.current = new RTCPeerConnection({ iceServers: ice });
pc.current.ontrack = (ev) => {
if (!stream.current) {
stream.current = new MediaStream();
@ -192,7 +184,9 @@ export function useRingContext() {
}
}
const connect = async (policy, node, token, clearRing, clearAlive) => {
const connect = async (policy, node, token, clearRing, clearAlive, ice) => {
console.log("ICE CONNECT", ice);
// connect signal socket
connected.current = false;
@ -216,7 +210,7 @@ export function useRingContext() {
updateState({ callStatus: "connected" });
if (policy === 'polite') {
connected.current = true;
transmit('polite');
transmit('polite', ice);
polite();
}
}
@ -267,7 +261,7 @@ export function useRingContext() {
ws.current.send(JSON.stringify({ AppToken: token }));
if (policy === 'impolite') {
connected.current = true;
transmit('impolite');
transmit('impolite', ice);
impolite();
}
}
@ -290,9 +284,9 @@ export function useRingContext() {
clearToken: () => {
access.current = null;
},
ring: (cardId, callId, calleeToken) => {
ring: (cardId, callId, calleeToken, iceUrl, iceUsername, icePassword) => {
const key = `${cardId}:${callId}`
const call = ringing.current.get(key) || { cardId, calleeToken, callId }
const call = ringing.current.get(key) || { cardId, calleeToken, callId, iceUrl, iceUsername, icePassword }
call.expires = Date.now() + EXPIRE;
ringing.current.set(key, call);
updateState({ ringing: ringing.current });
@ -324,11 +318,13 @@ export function useRingContext() {
}
}
},
accept: async (cardId, callId, contactNode, contactToken, calleeToken) => {
accept: async (cardId, callId, contactNode, contactToken, calleeToken, iceUrl, iceUsername, icePassword) => {
if (calling.current) {
throw new Error("active session");
}
const ice = [{ urls: iceUrl, username: iceUsername, credential: icePassword }];
const key = `${cardId}:${callId}`
const call = ringing.current.get(key);
if (call) {
@ -337,7 +333,7 @@ export function useRingContext() {
updateState({ ringing: ringing.current, callStatus: "connecting", cardId });
calling.current = { callId, contactNode, contactToken, host: false };
await connect('impolite', contactNode, calleeToken, () => {}, () => {});
await connect('impolite', contactNode, calleeToken, () => {}, () => {}, ice);
}
},
end: async () => {
@ -408,7 +404,8 @@ export function useRingContext() {
updateState({ callStatus: "ringing", cardId });
calling.current = { callId: id, host: true };
await connect('polite', window.location.host, callerToken, () => clearInterval(ringInterval), () => clearInterval(aliveInterval));
const ice = [{ urls: iceUrl, username: iceUsername, credential: icePassword }];
await connect('polite', window.location.host, callerToken, () => clearInterval(ringInterval), () => clearInterval(aliveInterval), ice);
},
enableVideo: async () => {
if (!accessVideo.current) {

View File

@ -55,14 +55,14 @@ export function useSession() {
const expired = Date.now();
ring.state.ringing.forEach(call => {
if (call.expires > expired && !call.status) {
const { callId, cardId, calleeToken } = call;
const { callId, cardId, calleeToken, iceUrl, iceUsername, icePassword } = call;
const contact = card.state.cards.get(cardId);
if (contact) {
const { imageSet, name, handle, node, guid } = contact.data.cardProfile || {};
const { token } = contact.data.cardDetail;
const contactToken = `${guid}.${token}`;
const img = imageSet ? card.actions.getCardImageUrl(cardId) : null;
ringing.push({ cardId, img, name, handle, contactNode: node, callId, contactToken, calleeToken });
ringing.push({ cardId, img, name, handle, contactNode: node, callId, contactToken, calleeToken, iceUrl, iceUsername, icePassword });
}
}
});
@ -166,8 +166,9 @@ export function useSession() {
await ring.actions.decline(cardId, contactNode, contactToken, callId);
},
accept: async (call) => {
const { cardId, callId, contactNode, contactToken, calleeToken } = call;
await ring.actions.accept(cardId, callId, contactNode, contactToken, calleeToken);
console.log("ACCEPTING:", call);
const { cardId, callId, contactNode, contactToken, calleeToken, iceUrl, iceUsername, icePassword } = call;
await ring.actions.accept(cardId, callId, contactNode, contactToken, calleeToken, iceUrl, iceUsername, icePassword);
},
end: async () => {
await ring.actions.end();