I have implemented webrtc in 2 browsers that physically work on one local machine (one browser I will call as "local", another - "remote"). The browser - Firefox 112.0.1, TURN, STUN servers are not used.
All strings (offer, answer, ice candidates) are transferred from one to another browser manually (slow transfer - via copy and paste). "Remote" gets an offer from the "local" and processes it by rtc2_RegisterRemoteOffer
(see code below). This function creates answer of the "remote". Then: (1) the negotiationneeded
event fired on the "remote", (2) because of (1) "remote" creates offer and generates it's own ice candidates (up to here neither "local" nor "remote" ice candidates I didn't transfer to each other). (3) Then after few seconds on the "remote" iceconnectionstate
fired with the status failed
.
The questions are:
- What may be a reason of
iceconnectionstate
getsfailed
- see (3) ? - Could this happen because I didn't have enough time to send any ice candidate from the "local" to the "remote" after sending offer ?
- Is the case (2) - is correct behavior ? Should the "remote" create your own answer when it processes the answer of the "local" ?
- If it shouldn't (question 3), then how the "remote" should correctly process it's own
negotiationneeded
event ?
The code of the "rtc2_RegisterRemoteOffer"
function rtc2_RegisterRemoteOffer(remoteOfferText) {
// Register an offer of a remote machine..
// Input:
// - remoteOfferText - string - offer text.
let stateStr = webRtc.peerConnection.signalingState;
let logMsg = "rtc2_RegisterRemoteOffer is called. State = " + stateStr;
DisplayLogMessage(logMsg);
console.log(logMsg);
console.log("==remoteOfferText==" + remoteOfferText);
console.log(remoteOfferText);
remoteOfferObj = {type: "offer", sdp: remoteOfferText};
let remoteDescr = null;
try {
remoteDescr = new RTCSessionDescription(remoteOfferObj);
}
catch (e) {
remoteDescr = null;
DisplayErrMessage("Can't create SDP. Errmsg = " + e.message);
}
if (remoteDescr === null) {
// error - do nothing
DisplayErrMessage("remoteDescr === null !!!");
}
else {
// set remote description
let remotedescrPromise = webRtc.peerConnection.setRemoteDescription(remoteDescr)
.then(function Resolve_rdp() {
let msg = "rtc2_RegisterRemoteOffer.setRemoteDescription -- fulfilled";
DisplayLogMessage(msg);
console.log("===> ", msg);
},
function Reject_rdp(e) {
let msg ="rt2c_RegisterRemoteOffer.setRemoteDescription REJECTED. Msg = " + e.message;
DisplayErrMessage(msg);
console.log("===> ", msg);
}
); // let remotedescrPromise =
stateStr = webRtc.peerConnection.signalingState;
DisplayLogMessage("rtc2_RegisterRemoteOffer - Creating answer for the remote. State = " + stateStr);
// create an answer to the remote offer
let answerTextPromise = webRtc.peerConnection.createAnswer().then(
// resolve
function resolve_createAnswer(answer) {
// answer is generated
stateStr = webRtc.peerConnection.signalingState;
let msg = "rtc2_RegisterRemoteOffer.createAnswer - resolved. State = " + stateStr;
DisplayLogMessage(msg);
console.log(msg);
// (***) HERE I get:
// rtc2_RegisterRemoteOffer.createAnswer - resolved. State = have-remote-offer
// set the answer as the local description
webRtc.peerConnection.setLocalDescription(answer,
function resolve_setLocalDescription_answer() {
// resolve -- local description is set
console.log("===> ", "rtc2_RegisterRemoteOffer.SetLocalDescription fulfilled.");
// ----------------------------------------------------
// (***) HERE I get: the message above
},
function reject_setLocalDescription_answer() {
// resolve -- local description is set
console.log("ERROR = (setLocalDescription in rtc_RegisterRemoteOffer) is REJECTED");
}
);
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Display local answer for the remote
PutLocalAnswerText(answer.sdp);
DisplayStatus("Send answer to a remote");
// --- try to add local audio/video tracks to the remote ---
let tracksAdded = rtc2_addTracks();
if (tracksAdded) {
// our tracks sent to the remote
let msg = "rtc2_RegisterRemoteOffer_Our tracks sent on remote answer.";
DisplayLogMessage(msg);
console.log(msg);
}
else {
// can't access <mediaDevices>
let msg = "ERR1 - rtc_RegisterRemoteOffer_Our tracks WERE NOT sent on remote answer.";
DisplayErrMessage(msg);
console.log(msg);
}
},
function reject_createAnswer(e) {
let msg = "rt2c_RegisterRemoteOffer.createAnswer - REJECTED. Msg = " + e.message +
" State = " + stateStr;
DisplayErrMessage(msg);
console.log(msg);
}
);
} // if (remoteDescr === null) else
} // function rtc2_RegisterRemoteOffer
The offer of the "local"
v=0
o=mozilla...THIS_IS_SDPARTA-99.0 672388715268626096 0 IN IP4 0.0.0.0
s=-
t=0 0
a=sendrecv
a=fingerprint:sha-256 65:F6:31:2A:FF:DD:7C:E1:89:83:C6:F1:8C:61:25:8F:E4:AD:0A:B6:8A:A7:D0:A3:0E:E0:DF:C8:99:5F:85:73
a=group:BUNDLE 0
a=ice-options:trickle
a=msid-semantic:WMS *
m=application 9 UDP/DTLS/SCTP webrtc-datachannel
c=IN IP4 0.0.0.0
a=sendrecv
a=ice-pwd:e0e9063fdcde2bd9f4c3068accca0907
a=ice-ufrag:4386e8e0
a=mid:0
a=setup:actpass
a=sctp-port:5000
a=max-message-size:1073741823
Via Active questions tagged javascript - Stack Overflow https://ift.tt/JdeyXA2
Comments
Post a Comment