-1

[EDIT] The description of my post was bad, sorry for my English, I start again. What I mean is when I make a request ajax rest to api opentok from localhost, I have this error:

Failed to load https://api.opentok.com/v2/project//broadcast: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://localhost:8081' is therefore not allowed access.

And this code represents the ajax query:

var dataLiveStreamRequestBody = {
                      "sessionId": sessionId,
                      "layout": {
                        "type": "bestfit",
                      },
                      "maxDuration": 5400,
                      "outputs": {
                        "hls": {},
                        "rtmp": [{
                          "id": "<adresse_ip>",
                          "serverUrl": "rtmp://<adresse_ip>/<streamname>/toto",
                          "streamName": "<stream-name>"
                        }]
                      },
                      "resolution": "640x480"
                    };



                $.ajax({
                  contentType: 'application/json',
                  data: JSON.stringify(dataLiveStreamRequestBody),
                  dataType: 'json',
                  beforeSend: function(xhr){
                    xhr.setRequestHeader('X-OPENTOK-AUTH', '<token>');
                    xhr.setRequestHeader('Accept', 'application/json');
                  },
                  success: function(data){
                      console.log("live streaming broadcast succeeded");
                  },
                  error: function(){
                      console.log("live streaming broadcast failed");
                  },
                  type: 'POST',
                  url: 'https://api.opentok.com/v2/project/'+ apiKey +'/broadcast'
                });

I followed the instructions on this page: https://tokbox.com/developer/rest/#start_broadcast

Fanga
  • 3
  • 4

2 Answers2

0

Tokbox QA staff here.

Not sure what you're trying to do, but maybe this can help:

https://tokbox.com/developer/rest/#start_broadcast

On the other hand, that IP 127.0.0.1:8081 does not look very well, because it's an internal address. Where does that IP come from?

0

TokBox Developer Evangelist here.

You should be making the startBroadcast call from your server because the call requires the X-OPENTOK-AUTH header which is generated using your apiKey and apiSecret. The apiSecret should not be exposed on the client side because it's used to generate OpenTok sessions and tokens.

Also, here's a StackOverflow answer that explains what to do when you run into that Access-Control-Allow-Originissue : Response to preflight request doesn't pass access control check

Manik
  • 1,427
  • 9
  • 17
  • Thanks, indeed the problem was related at "Access-Control-Allow-Origin", your issue had the solution. – Fanga Jun 21 '18 at 12:53