cloudflare / orange

https://demo.orange.cloudflare.dev/
Other
1.56k stars 215 forks source link

Failed to decode body as JSON(addtracks) #42

Closed youfeed closed 6 months ago

youfeed commented 6 months ago

Add a New Track : Adds a media track (audio or video) to an existing session.

rtcFetch(v1/apps/${appId}/sessions/${sessionId}/tracks/new,params,"POST")

function rtcFetch(router,params=false,method='GET'){
    return new Promise((resolve,reject)=>{
      const options = {
        json:true,
        method: method,
        headers: {
            'Accept': 'application/json',
            'Content-Type': 'application/json',
            'Authorization':`Bearer ${appSecret}`
        }
      };
      const req = https.request(`https://rtc.live.cloudflare.com/${router}`,options,res=>{
        var data = '';
        res.on('data', (chuck) => {
          data += chuck;
        });
        res.on('end', () => {
          try { 
            resolve(JSON.parse(data))
          } catch (error) {
            resolve(data)
          }
        });
      });
      req.on('error', (error) => {
        reject(error)
      });
      console.log(router,params)
      params && req.write(JSON.stringify(params));
      req.end();
    })
  }

return

{
"errorCode": "decoding_error",
"errorDescription": "Failed to decode body as JSON",
}

nodejs Send https.request the SDP Are there any special characters?

youfeed commented 6 months ago

params.tracks[].location === local