Skip to content

Commit

Permalink
RTC: Refine player sdk, reject with xhr.
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Apr 10, 2022
1 parent b3baa88 commit 2b2379d
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions trunk/research/players/js/srs.sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,17 @@ function SrsRtcPublisherAsync() {
};
console.log("Generated offer: ", data);

const http = new XMLHttpRequest();
http.onload = function() {
if (http.readyState !== http.DONE) return;
if (http.status !== 200) return reject(http);
const data = JSON.parse(http.responseText);
const xhr = new XMLHttpRequest();
xhr.onload = function() {
if (xhr.readyState !== xhr.DONE) return;
if (xhr.status !== 200) return reject(xhr);
const data = JSON.parse(xhr.responseText);
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);
http.setRequestHeader('Content-type', 'application/json');
http.send(JSON.stringify(data));
xhr.open('POST', conf.apiUrl, true);
xhr.setRequestHeader('Content-type', 'application/json');
xhr.send(JSON.stringify(data));
});
await self.pc.setRemoteDescription(
new RTCSessionDescription({type: 'answer', sdp: session.sdp})
Expand Down Expand Up @@ -311,17 +311,17 @@ function SrsRtcPlayerAsync() {
};
console.log("Generated offer: ", data);

const http = new XMLHttpRequest();
http.onload = function() {
if (http.readyState !== http.DONE) return;
if (http.status !== 200) return reject(http);
const data = JSON.parse(http.responseText);
const xhr = new XMLHttpRequest();
xhr.onload = function() {
if (xhr.readyState !== xhr.DONE) return;
if (xhr.status !== 200) return reject(xhr);
const data = JSON.parse(xhr.responseText);
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);
http.setRequestHeader('Content-type', 'application/json');
http.send(JSON.stringify(data));
xhr.open('POST', conf.apiUrl, true);
xhr.setRequestHeader('Content-type', 'application/json');
xhr.send(JSON.stringify(data));
});
await self.pc.setRemoteDescription(
new RTCSessionDescription({type: 'answer', sdp: session.sdp})
Expand Down

0 comments on commit 2b2379d

Please sign in to comment.