From 2b2379de12df31823882be77df172389523f55b7 Mon Sep 17 00:00:00 2001 From: winlin Date: Sun, 10 Apr 2022 16:39:56 +0800 Subject: [PATCH] RTC: Refine player sdk, reject with xhr. --- trunk/research/players/js/srs.sdk.js | 36 ++++++++++++++-------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/trunk/research/players/js/srs.sdk.js b/trunk/research/players/js/srs.sdk.js index ef75a1419..29c37178c 100644 --- a/trunk/research/players/js/srs.sdk.js +++ b/trunk/research/players/js/srs.sdk.js @@ -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}) @@ -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})