1

我用 docker 启动 KMS+OPENVIDU 服务器。当我使用 JQ ajax 时,一切都适用于 Web 组件:

例如(这很好用):

   $.ajax({
          type: "POST",
          url: OPENVIDU_SERVER_URL + "/api/sessions",
          data: JSON.stringify({ customSessionId: sessionId }),
          headers: {
            "Authorization": "Basic " + btoa("OPENVIDUAPP:" + OPENVIDU_SERVER_SECRET),
            "Content-Type": "application/json"
          },
          success: response => resolve(response.data.id),
          error: (error) => {
            if (error.status === 409) {
              resolve(sessionId);
            } else {
              console.warn('No connection to OpenVidu Server. This may be a certificate error at ' + OPENVIDU_SERVER_URL);
              if (window.confirm('No connection to OpenVidu Server. This may be a certificate error at \"' + OPENVIDU_SERVER_URL + '\"\n\nClick OK to navigate and accept it. ' +
                'If no certificate warning is shown, then check that your OpenVidu Server is up and running at "' + OPENVIDU_SERVER_URL + '"')) {
                location.assign(OPENVIDU_SERVER_URL + '/accept-certificate');
              }
            }
          }
        })

如果我把 fetch (native javascript) :

      var myPromise = fetch(this.ovServerUrl + '/api/sessions', {
        method: 'POST',
        // mode: 'cors',
        // credentials: 'same-origin',
        // redirect: 'follow',
        body: JSON.stringify(
          { customSessionId: sessionId }
        ),
        headers: {
          'Content-Type': 'application/json',
          'Authorization': 'Basic ' + btoa('OPENVIDUAPP:' + this.ovSecret)
        }
      })


      return myPromise.then(response => {
        console.log('return resolve !response', response)
        console.log('return resolve !response.data.id! ', response.data.id)
        return response.id
      })

我得到了回应,但没有response.id

好像 :

body: (...)
bodyUsed: false
headers: Headers {}
ok: true
redirected: false
status: 200
statusText: ""
type: "cors"
url: "https://MY_DOMAIN:4443/api/sessions"

有什么建议吗?

4

0 回答 0