www: fix setting error statuses in some situations

This commit is contained in:
Mathieu Duponchelle 2021-11-23 21:10:27 +01:00
parent 7ce0ef5b88
commit 3052884bdc

View file

@ -93,7 +93,6 @@ function Session(our_id, peer_id, closed_callback) {
this.setError = function(text) { this.setError = function(text) {
console.error(text); console.error(text);
console.log(this);
var span = document.getElementById("status-" + this.our_id); var span = document.getElementById("status-" + this.our_id);
span.textContent = text; span.textContent = text;
span.classList.add('error'); span.classList.add('error');
@ -114,22 +113,30 @@ function Session(our_id, peer_id, closed_callback) {
}); });
}; };
this.onRemoteDescriptionSet = function() {
this.setStatus("Remote SDP set");
this.setStatus("Got SDP offer");
this.peer_connection.createAnswer()
.then(this.onLocalDescription.bind(this)).catch(this.setError);
}
// SDP offer received from peer, set remote description and create an answer // SDP offer received from peer, set remote description and create an answer
this.onIncomingSDP = function(sdp) { this.onIncomingSDP = function(sdp) {
this.peer_connection.setRemoteDescription(sdp).then(() => { var thiz = this;
this.setStatus("Remote SDP set"); this.peer_connection.setRemoteDescription(sdp)
if (sdp.type != "offer") .then(this.onRemoteDescriptionSet.bind(this))
return; .catch(function(e) {
this.setStatus("Got SDP offer"); thiz.setError(e)
this.peer_connection.createAnswer() });
.then(this.onLocalDescription.bind(this)).catch(this.setError);
}).catch(this.setError);
}; };
// ICE candidate received from peer, add it to the peer connection // ICE candidate received from peer, add it to the peer connection
this.onIncomingICE = function(ice) { this.onIncomingICE = function(ice) {
var candidate = new RTCIceCandidate(ice); var candidate = new RTCIceCandidate(ice);
this.peer_connection.addIceCandidate(candidate).catch(this.setError); var thiz = this;
this.peer_connection.addIceCandidate(candidate).catch(function(e) {
thiz.setError(e)
});
}; };
this.onServerMessage = function(event) { this.onServerMessage = function(event) {