Вы должны включить асинхронный тег даже в функцию карты:
file.map(async source => {
var videoPosition = 0;
var sigkey = "sigkey";
var formBody = new FormData();
formBody.set('ver', "1.2");
formBody.set('key', "key");
formBody.set('video_id', file[videoPosition].file);
formBody.set('user_id', "1234");
formBody.set('format', "json");
formBody.set('ip', "");
formBody.set('tts', "0");
formBody.set('nonce', Math.round((new Date()).getTime() / 1000));
var sign_fields = [formBody.get('video_id'), formBody.get('user_id'), formBody.get('ip'), formBody.get('tts'), formBody.get('ver'), formBody.get('key'), formBody.get('nonce')];
var data = sign_fields.join(':');
var signature = hmacsha256(data, sigkey);
formBody.set('sig', signature);
var formBodyStringified = new URLSearchParams(formBody).toString();
const resJson = await fetch(Config.api.livebox, {
method: 'POST',
body: formBodyStringified,
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
}
}).then(res => res.json());
Или вы можете использовать Promise.all :
const fetchList = file.map(source => {
var videoPosition = 0;
var sigkey = "sigkey";
var formBody = new FormData();
formBody.set('ver', "1.2");
formBody.set('key', "key");
formBody.set('video_id', file[videoPosition].file);
formBody.set('user_id', "1234");
formBody.set('format', "json");
formBody.set('ip', "");
formBody.set('tts', "0");
formBody.set('nonce', Math.round((new Date()).getTime() / 1000));
var sign_fields = [formBody.get('video_id'), formBody.get('user_id'), formBody.get('ip'), formBody.get('tts'), formBody.get('ver'), formBody.get('key'), formBody.get('nonce')];
var data = sign_fields.join(':');
var signature = hmacsha256(data, sigkey);
formBody.set('sig', signature);
var formBodyStringified = new URLSearchParams(formBody).toString();
const request = fetch(Config.api.livebox, {
method: 'POST',
body: formBodyStringified,
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
}
}).then(res => res.json());
return request;
});
const resJsons = Promise.all(fetchList);
resJsons.forEach(resJson => {
const finalJsonUrl = 'https:' + resJson.hls;
this.setState({ videoSource: finalJsonUrl });
...
}