1
0
Fork 0
forked from External/mediamtx

webrtc: on browsers, display error messages from server (#3448)

This commit is contained in:
Alessandro Ros 2024-06-10 15:41:05 +02:00 committed by GitHub
parent 1911294539
commit 095921dc26
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 19 additions and 8 deletions

View file

@ -311,7 +311,7 @@ func (co *PeerConnection) CreateFullAnswer(
answer, err := co.wr.CreateAnswer(nil) answer, err := co.wr.CreateAnswer(nil)
if err != nil { if err != nil {
if errors.Is(err, webrtc.ErrSenderWithNoCodecs) { if errors.Is(err, webrtc.ErrSenderWithNoCodecs) {
return nil, fmt.Errorf("track codecs are not supported by remote") return nil, fmt.Errorf("codecs not supported by client")
} }
return nil, err return nil, err
} }

View file

@ -409,7 +409,7 @@ const sendLocalCandidates = (candidates) => {
}) })
.then((res) => { .then((res) => {
if (res.status !== 204) { if (res.status !== 204) {
throw new Error('bad status code'); throw new Error(`bad status code ${res.status}`);
} }
}) })
.catch((err) => { .catch((err) => {
@ -464,13 +464,20 @@ const sendOffer = (offer) => {
body: offer, body: offer,
}) })
.then((res) => { .then((res) => {
if (res.status !== 201) { switch (res.status) {
throw new Error('bad status code'); case 201:
break;
case 400:
return res.json().then((e) => { throw new Error(e.error); });
default:
throw new Error(`bad status code ${res.status}`);
} }
sessionUrl = new URL(res.headers.get('location'), window.location.href).toString(); sessionUrl = new URL(res.headers.get('location'), window.location.href).toString();
return res.text();
return res.text()
.then((answer) => onRemoteAnswer(answer));
}) })
.then((answer) => onRemoteAnswer(answer))
.catch((err) => { .catch((err) => {
onError(err.toString(), true); onError(err.toString(), true);
}); });

View file

@ -426,13 +426,17 @@ const sendOffer = (offer) => {
break; break;
case 404: case 404:
throw new Error('stream not found'); throw new Error('stream not found');
case 400:
return res.json().then((e) => { throw new Error(e.error); });
default: default:
throw new Error(`bad status code ${res.status}`); throw new Error(`bad status code ${res.status}`);
} }
sessionUrl = new URL(res.headers.get('location'), window.location.href).toString(); sessionUrl = new URL(res.headers.get('location'), window.location.href).toString();
return res.text();
return res.text()
.then((sdp) => onRemoteAnswer(sdp));
}) })
.then((sdp) => onRemoteAnswer(sdp))
.catch((err) => { .catch((err) => {
onError(err.toString()); onError(err.toString());
}); });