mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-23 07:38:16 +00:00
sendrecv/js: Improve more logging and errors
This commit is contained in:
parent
9cc57d2dd1
commit
ea8e960e29
1 changed files with 16 additions and 6 deletions
|
@ -44,15 +44,15 @@ function getVideoElement() {
|
||||||
|
|
||||||
function setStatus(text) {
|
function setStatus(text) {
|
||||||
console.log(text);
|
console.log(text);
|
||||||
span = document.getElementById("status")
|
var span = document.getElementById("status")
|
||||||
// Don't set the status if it already contains an error
|
// Don't set the status if it already contains an error
|
||||||
if (!span.classList.contains('error'))
|
if (!span.classList.contains('error'))
|
||||||
span.textContent = text;
|
span.textContent = text;
|
||||||
}
|
}
|
||||||
|
|
||||||
function setError(text) {
|
function setError(text) {
|
||||||
console.log(text);
|
console.error(text);
|
||||||
span = document.getElementById("status")
|
var span = document.getElementById("status")
|
||||||
span.textContent = text;
|
span.textContent = text;
|
||||||
span.classList.add('error');
|
span.classList.add('error');
|
||||||
}
|
}
|
||||||
|
@ -71,7 +71,6 @@ function resetVideo() {
|
||||||
|
|
||||||
// SDP offer received from peer, set remote description and create an answer
|
// SDP offer received from peer, set remote description and create an answer
|
||||||
function onIncomingSDP(sdp) {
|
function onIncomingSDP(sdp) {
|
||||||
console.log("Incoming SDP is "+ JSON.stringify(sdp));
|
|
||||||
peer_connection.setRemoteDescription(sdp).then(() => {
|
peer_connection.setRemoteDescription(sdp).then(() => {
|
||||||
setStatus("Remote SDP set");
|
setStatus("Remote SDP set");
|
||||||
if (sdp.type != "offer")
|
if (sdp.type != "offer")
|
||||||
|
@ -97,7 +96,6 @@ function onLocalDescription(desc) {
|
||||||
|
|
||||||
// ICE candidate received from peer, add it to the peer connection
|
// ICE candidate received from peer, add it to the peer connection
|
||||||
function onIncomingICE(ice) {
|
function onIncomingICE(ice) {
|
||||||
console.log("Incoming ICE: " + JSON.stringify(ice));
|
|
||||||
var candidate = new RTCIceCandidate(ice);
|
var candidate = new RTCIceCandidate(ice);
|
||||||
peer_connection.addIceCandidate(candidate).catch(setError);
|
peer_connection.addIceCandidate(candidate).catch(setError);
|
||||||
}
|
}
|
||||||
|
@ -140,6 +138,7 @@ function onServerMessage(event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function onServerClose(event) {
|
function onServerClose(event) {
|
||||||
|
setStatus('Disconnected from server');
|
||||||
resetVideo();
|
resetVideo();
|
||||||
|
|
||||||
if (peer_connection) {
|
if (peer_connection) {
|
||||||
|
@ -158,8 +157,15 @@ function onServerError(event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getLocalStream() {
|
function getLocalStream() {
|
||||||
|
var constraints;
|
||||||
var textarea = document.getElementById('constraints');
|
var textarea = document.getElementById('constraints');
|
||||||
var constraints = JSON.parse(textarea.value);
|
try {
|
||||||
|
constraints = JSON.parse(textarea.value);
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
setError('ERROR parsing constraints: ' + e.message + ', using default constraints');
|
||||||
|
constraints = default_constraints;
|
||||||
|
}
|
||||||
console.log(JSON.stringify(constraints));
|
console.log(JSON.stringify(constraints));
|
||||||
|
|
||||||
// Add local stream
|
// Add local stream
|
||||||
|
@ -176,6 +182,10 @@ function websocketServerConnect() {
|
||||||
setError("Too many connection attempts, aborting. Refresh page to try again");
|
setError("Too many connection attempts, aborting. Refresh page to try again");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// Clear errors in the status span
|
||||||
|
var span = document.getElementById("status");
|
||||||
|
span.classList.remove('error');
|
||||||
|
span.textContent = '';
|
||||||
// Populate constraints
|
// Populate constraints
|
||||||
var textarea = document.getElementById('constraints');
|
var textarea = document.getElementById('constraints');
|
||||||
if (textarea.value == '')
|
if (textarea.value == '')
|
||||||
|
|
Loading…
Reference in a new issue