[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