Ho letto diverse altre domande su un problema correlato, ma nessuno ha risposto alla mia domanda. Ho un problema strano in cui sono in grado di utilizzare WebRTC per chat audio da Chrome a Firefox ma non da Firefox a Chrome.WebRTC funziona con Chrome ma non con Firefox
Fondamentalmente, quando un utente desidera chat audio, fa clic su un pulsante #audioChatBtn
, che utilizza getUserMedia()
per configurare uno streaming. Il fatto è che, facendo clic su #audioChatBtn
da Firefox non si attiva la richiamata onaddstream
su Chrome, ma facendo clic sul pulsante da Chrome si attiva onaddstream
in Firefox. Pertanto, posso chat audio da Chrome a Firefox, ma non viceversa. Ho cercato di capirlo per diverse ore, ma spero che forse qualcuno qui abbia una risposta.
fonte pertinente:
var configuration = {
'iceServers': [
{ url: 'stun:stun.l.google.com:19302' },
{ url: 'stun:stun1.l.google.com:19302' },
{ url: 'stun:stun2.l.google.com:19302' },
{ url: 'stun:stun3.l.google.com:19302' },
{ url: 'stun:stun4.l.google.com:19302' }
]
};
var pc = RTCPeerConnection(configuration);
var myStream = null;
var currentAudioIndex = 0; // Number of created channels
var myAudioEnabled = false;
// send any ice candidates to the other peer
pc.onicecandidate = function (evt) {
if (evt.candidate)
$(document).trigger("persistState", { mode: 'rtc', 'candidate': evt.candidate });
};
// let the 'negotiationneeded' event trigger offer generation
pc.onnegotiationneeded = function() {
pc.createOffer(localDescCreated, logError);
}
// once remote stream arrives, play it in the audio element
pc.onaddstream = function (evt) {
console.log('creating and binding audio');
var idx = (currentAudioIndex++);
var audioElement = $('#audio' + idx);
if (audioElement.length == 0) {
var audio = $('<audio id="audio' + idx + '" autoplay>');
$('body').append(audio);
audioElement = $('#audio' + idx);
}
var audioObject = audioElement[0];
attachMediaStream(audioObject, evt.stream);
};
function localDescCreated(desc) {
pc.setLocalDescription(desc, function() {
$(document).trigger("persistState", { mode: 'rtc', 'sdp': pc.localDescription });
}, logError);
}
function logError(e) {
bootbox.alert("Audio chat could not be started.");
}
function hasGetUserMedia() {
return !!(navigator.getUserMedia || navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia || navigator.msGetUserMedia);
}
server.onPersist = function(msg) {
if (msg.mode == "rtc") {
if (msg.sdp)
pc.setRemoteDescription(new RTCSessionDescription(msg.sdp), function() {
// if we received an offer, we need to answer
if (pc.remoteDescription.type == 'offer')
pc.createAnswer(localDescCreated, logError);
}, logError);
else
pc.addIceCandidate(new RTCIceCandidate(msg.candidate));
}
}
// On click, start audio chat from this user.
$('#audioChatBtn').click(function() {
if (!hasGetUserMedia()) {
bootbox.alert('Audio conferencing is not supported by your browser. (Currently only supported by Chrome, Firefox, and Opera web browsers.)');
return;
}
if (myAudioEnabled) {
myStream.stop();
displayAlert('Streaming closed', 'Audio chat is off');
$('#audioChatBtn').removeClass('btn-success').addClass('btn-primary');
} else {
getUserMedia({ video: false, audio: true }, function (localMediaStream) {
myStream = localMediaStream;
pc.addStream(localMediaStream);
displayAlert('Streaming...', 'Audio chat is enabled');
$('#audioChatBtn').removeClass('btn-primary').addClass('btn-success');
}, logError);
}
myAudioEnabled = !myAudioEnabled;
});
quello che ho provato
- Provato utilizzando
'optional': [{ 'DtlsSrtpKeyAgreement': 'true' }]
nella configurazione dopo aver letto this question - provato a generare un nuovo RTCPeerConnection() ogni richiesta
- provato utilizzando le funzioni del browser nativo invece di adapter.js.
- Explored Web Audio API, invece di
getUserMedia()
Caro downvoter, la ragione per cui hai fornito conferma che la domanda "deve includere il comportamento desiderato, un problema specifico o un errore e il codice più breve necessario per riprodurlo nella domanda stessa". La mia domanda include tutti questi elementi. – arao6
Fuori questione, voglio implementare webRTC ma è possibile rendere utente1 contatto utente2 se entrambi hanno i loro ID invece di caricare .shopping tutti gli utenti connessi al server? – Awena
forse [peer.js] (http://peerjs.com/) sarà più facile da usare, quindi reinventare la ruota? –