1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-02-13 03:41:55 +00:00

RTC: Refine player sdk, reject with xhr.

This commit is contained in:
winlin 2022-04-10 16:39:56 +08:00
parent b3baa888ee
commit 2b2379de12

View file

@ -78,17 +78,17 @@ function SrsRtcPublisherAsync() {
}; };
console.log("Generated offer: ", data); console.log("Generated offer: ", data);
const http = new XMLHttpRequest(); const xhr = new XMLHttpRequest();
http.onload = function() { xhr.onload = function() {
if (http.readyState !== http.DONE) return; if (xhr.readyState !== xhr.DONE) return;
if (http.status !== 200) return reject(http); if (xhr.status !== 200) return reject(xhr);
const data = JSON.parse(http.responseText); const data = JSON.parse(xhr.responseText);
console.log("Got answer: ", data); console.log("Got answer: ", data);
return data.code ? reject(data) : resolve(data); return data.code ? reject(xhr) : resolve(data);
} }
http.open('POST', conf.apiUrl, true); xhr.open('POST', conf.apiUrl, true);
http.setRequestHeader('Content-type', 'application/json'); xhr.setRequestHeader('Content-type', 'application/json');
http.send(JSON.stringify(data)); xhr.send(JSON.stringify(data));
}); });
await self.pc.setRemoteDescription( await self.pc.setRemoteDescription(
new RTCSessionDescription({type: 'answer', sdp: session.sdp}) new RTCSessionDescription({type: 'answer', sdp: session.sdp})
@ -311,17 +311,17 @@ function SrsRtcPlayerAsync() {
}; };
console.log("Generated offer: ", data); console.log("Generated offer: ", data);
const http = new XMLHttpRequest(); const xhr = new XMLHttpRequest();
http.onload = function() { xhr.onload = function() {
if (http.readyState !== http.DONE) return; if (xhr.readyState !== xhr.DONE) return;
if (http.status !== 200) return reject(http); if (xhr.status !== 200) return reject(xhr);
const data = JSON.parse(http.responseText); const data = JSON.parse(xhr.responseText);
console.log("Got answer: ", data); console.log("Got answer: ", data);
return data.code ? reject(data) : resolve(data); return data.code ? reject(xhr) : resolve(data);
} }
http.open('POST', conf.apiUrl, true); xhr.open('POST', conf.apiUrl, true);
http.setRequestHeader('Content-type', 'application/json'); xhr.setRequestHeader('Content-type', 'application/json');
http.send(JSON.stringify(data)); xhr.send(JSON.stringify(data));
}); });
await self.pc.setRemoteDescription( await self.pc.setRemoteDescription(
new RTCSessionDescription({type: 'answer', sdp: session.sdp}) new RTCSessionDescription({type: 'answer', sdp: session.sdp})