1
0

Testing audio

Signed-off-by: James Ketrenos <james_eikona@ketrenos.com>
This commit is contained in:
James Ketrenos 2022-03-14 19:29:02 -07:00
parent 2182d9b0c1
commit 221dd0e726
2 changed files with 35 additions and 19 deletions

View File

@ -80,15 +80,21 @@ const MediaAgent = () => {
offerToReceiveAudio: true, offerToReceiveAudio: true,
offerToReceiveVideo: false offerToReceiveVideo: false
}, },
iceServers: [ iceServers: [ {
{ urls: "stun:stun.l.google.com:19302" }, /* urls: "stun:stun.l.google.com:19302" }, {
{ urls: "stun:stun.stunprotocol.org:3478" } urls: "stun:stun.stunprotocol.org:3478" }, { */
] // urls: "turn:ketrenos.com:3478",
// username: "ketra",
// credential: "ketran"
urls: "turn:numb.viagenie.ca",
username: "james_viagenie@ketrenos.com",
credential: "1!viagenie"
} ]
}, { }, {
/* this will no longer be needed by chrome /* this will no longer be needed by chrome
* eventually (supposedly), but is necessary * eventually (supposedly), but is necessary
* for now to get firefox to talk to chrome */ * for now to get firefox to talk to chrome */
optional: [{DtlsSrtpKeyAgreement: true}] //optional: [{DtlsSrtpKeyAgreement: true}]
}); });
peers[peer_id] = { peers[peer_id] = {
@ -99,8 +105,19 @@ const MediaAgent = () => {
console.log(`media-agent - addPeer - remote`, peers); console.log(`media-agent - addPeer - remote`, peers);
setPeers(Object.assign({}, peers)); setPeers(Object.assign({}, peers));
connection.addEventListener('icecandidateerror', (event) => {
if (event.errorCode === 701) {
if (connection.icegatheringstate === 'gathering') {
console.log(`Unable to reach host: ${event.url}`);
} else {
console.error(`media-agent - icecandidateerror - `, event.url, event.errorText);
}
}
});
connection.onicecandidate = (event) => { connection.onicecandidate = (event) => {
if (!event.candidate) { if (!event.candidate) {
console.error(`media-agent - icecanditate - gathering is complete: ${connection.connectinoState}`);
return; return;
} }
/* If a srflx candidate was found, notify that the STUN server works! */ /* If a srflx candidate was found, notify that the STUN server works! */
@ -114,14 +131,13 @@ const MediaAgent = () => {
console.log("The TURN server is reachable !"); console.log("The TURN server is reachable !");
} }
console.log(`media-agent - onicecandidate - `, event.candidate);
sendMessage({ sendMessage({
type: 'relayICECandidate', type: 'relayICECandidate',
config: { config: {
peer_id: peer_id, peer_id,
ice_candidate: { candidate: event.candidate
sdpMLineIndex: event.candidate.sdpMLineIndex,
candidate: event.candidate.candidate
}
} }
}); });
}; };
@ -147,7 +163,7 @@ const MediaAgent = () => {
sendMessage({ sendMessage({
type: 'relaySessionDescription', type: 'relaySessionDescription',
config: { config: {
'peer_id': peer_id, peer_id,
'session_description': local_description 'session_description': local_description
} }
}); });
@ -222,7 +238,7 @@ const MediaAgent = () => {
setPeers(Object.assign({}, peers)); setPeers(Object.assign({}, peers));
}; };
const iceCandidate = ({ peer_id, ice_candidate }) => { const iceCandidate = ({ peer_id, candidate }) => {
/** /**
* The offerer will send a number of ICE Candidate blobs to the * The offerer will send a number of ICE Candidate blobs to the
* answerer so they can begin trying to find the best path to one * answerer so they can begin trying to find the best path to one
@ -233,12 +249,12 @@ const MediaAgent = () => {
console.error(`media-agent - iceCandidate - No peer for ${peer_id}`, peers); console.error(`media-agent - iceCandidate - No peer for ${peer_id}`, peers);
return; return;
} }
peer.connection.addIceCandidate(new RTCIceCandidate(ice_candidate)) peer.connection.addIceCandidate(new RTCIceCandidate(candidate))
.then(() => { .then(() => {
if (debug) console.log(`media-agent - iceCandidate - Successfully added Ice Candidate for ${peer_id}`); if (debug) console.log(`media-agent - iceCandidate - Successfully added Ice Candidate for ${peer_id}`);
}) })
.catch((error) => { .catch((error) => {
console.error(error, peer, ice_candidate); console.error(error, peer, candidate);
}); });
}; };

View File

@ -3373,13 +3373,13 @@ router.ws("/ws/:id", async (ws, req) => {
return; return;
} }
const { peer_id, ice_candidate } = data.config; const { peer_id, candidate } = data.config;
if (debug.audio) console.log(`${short}:${id} <- relayICECandidate ${getName(session)} to ${peer_id}`, if (debug.audio) console.log(`${short}:${id} <- relayICECandidate ${getName(session)} to ${peer_id}`,
ice_candidate); candidate);
message = JSON.stringify({ message = JSON.stringify({
type: 'iceCandidate', type: 'iceCandidate',
data: {'peer_id': getName(session), 'ice_candidate': ice_candidate } data: {'peer_id': getName(session), 'candidate': candidate }
}); });
if (peer_id in audio[id]) { if (peer_id in audio[id]) {