0

我目前正在测试和开发 Muaz khan 的 webrtc firebase 演示。在其中一个使用 Xirsys 的文件中,使用的凭据是 Muaz Khan 的凭据。xirsys 详细信息是版本 v2。目前 Xirsys 使用 V3 版本。我想知道如何将以前的代码更改为新代码。

在演示中工作的前代码是

<script type="text/javascript" src="https://gc.kis.v2.scr.kaspersky-
labs.com/EC7AD6FB-B1E9-9D47-B085-7DB58B77DF98/main.js" charset="UTF-8">
</script><script>
function createCORSRequest(method, url) {
    var xhr = new XMLHttpRequest();
    if ("withCredentials" in xhr) {
        xhr.open(method, url, true);
    } else if (typeof XDomainRequest != "undefined") {
        xhr = new XDomainRequest();
        xhr.open(method, url);
    } else {
         xhr = null;
    }
    return xhr;
}
var url = 'https://service.xirsys.com/ice';
var xhr = createCORSRequest('POST', url);
xhr.onload = function () {
    window.parent.postMessage({
        iceServers: JSON.parse(xhr.responseText).d.iceServers
    }, '*');
};
xhr.onerror = function () {
    console.error('Woops, there was an error making xhr request.');
};
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
window.addEventListener('message', function (event) {
    if (!event.data || typeof event.data !== 'string') return;
    if(event.data == 'get-ice-servers') {
        xhr.send('ident=muazkh&secret=59d93f26-5b89-11e5-babe-
d61aeb366a63&domain=webrtcexperiment-webrtc.netdna-
ssl.com&application=default&room=default&secure=1');
    }
});
</script>

根据新的 Xirsys 文档,它应该是这样的

<!-- JS Get ICE STUN and TURN list -->
<DOCTYPE>
<html>
<head>
   <script 
src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js">
</script>
  <script>
     $( document ).ready( function () {
         $.ajax ({
             url: "https://global.xirsys.net/_turn/muazkh/",
             type: "PUT",
             async: false,
             headers: {
               "Authorization": "Basic " + btoa("muazkh:59d93f26-5b89-11e5-babe-d61aeb366a63")
             },
             success: function (res){
               console.log("ICE List: "+res.v.iceServers);
              }
         });
      })
  </script>
 </head>
<body>
</body>
</html>

我所做的是这个但没有工作

<head><script>
function createCORSRequest(method, url) {
    var xhr = new XMLHttpRequest();
    if ("withCredentials" in xhr) {
        xhr.open(method, url, true);
    } else if (typeof XDomainRequest != "undefined") {
        xhr = new XDomainRequest();
        xhr.open(method, url);
    } else {
        xhr = null;
    }
    return xhr;
}
var url = 'https://global.xirsys.net/_turn/muazkh/default/default';
var xhr = createCORSRequest('PUT', url);
xhr.onload = function () {
    window.parent.postMessage({
        iceServers: JSON.parse(xhr.responseText).v.iceServers
    }, '*');
};
xhr.onerror = function () {
    console.error('Woops, there was an error making xhr request.');
};
xhr.setRequestHeader("Authorization", "muazkh:59d93f26-5b89-11e5-babe-d61aeb366a63");
window.addEventListener('message', function (event) {
    if (!event.data || typeof event.data !== 'string') return;
    if(event.data == 'get-ice-servers') {
        xhr.send();
    }
});
</script>
</head>

将非常感谢这里的任何帮助。谢谢

4

1 回答 1

0

看起来像标题问题。授权标头应使用“基本”身份验证方案。

请将您的 XMLHttpRequest 的“setRequestHeader”更改为:

xhr.setRequestHeader("Authorization", "Basic "+ btoa("muazkh:59d93f26-5b89-11e5-babe-d61aeb366a63") );
于 2017-11-01T17:36:36.990 回答