hello,
my project is to create a chrome extention who make a notification when a streamer is on live.
so i have a script who check every 10sc if it’s the case :
check(); setInterval(function () {check(); }, 10000);
async function check() {
let storage = await getStorageData();
const streamData = await getStreamData();
if (streamData && streamData.type === 'live') {
chrome.browserAction.setIcon({path: config.images.icon_on_64});
if (storage.notifications && !await streamIsOpen()) {
if (storage.notified || (new Date()) - storage.notified > 60 * 60 * 1000) {
if (config.notification.message === '') config.notification.message = streamData.title;
chrome.notifications.create(config.notification);
chrome.storage.local.set({notified: new Date()});
}
}
} else {
chrome.browserAction.setIcon({path: config.images.icon_off_64});
chrome.storage.local.set({sent: null});
}}
this one have 2 objectif : find if the live is on and if it’s on change the icon of the extention
but the return of the streamData is empty .
for this i use some functions :
async function OAuth() {
return await new Promise(resolve => {
$.ajax({
type: 'POST',
url: `https://id.twitch.tv/oauth2/token?client_id=${config.client_id}&client_secret=${config.client_secret}&grant_type=client_credentials`,
success: res => resolve(res || null),
error: err => resolve(null),
})
});}
this one for Oauth who take some info on a config.js
and , normaly, create an acces_token
and my getstreamdata function
async function getStreamData() {
return await new Promise(resolve => {
$.ajax({
dataType: 'json',
headers: {'Client-ID': config.client_id, 'Authorization': 'Bearer ' + config.access_token},
url: "https://api.twitch.tv/helix/streams?user_login=" + config.channel_name,
success: stream =>
stream && stream.data && stream.data[0]
? resolve(stream.data[0])
: resolve(null),
error: err => resolve(null),
});
});}
it’s my first time on APi and JS and don’t know how to solve it.
sorry for my realy bad english and ty for the future help