forked from React-Group/interstellar_ai
GetWorker | Removed space
This commit is contained in:
parent
35151b2c53
commit
59005538be
1 changed files with 15 additions and 20 deletions
|
@ -1,37 +1,32 @@
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
|
||||||
let windownameGlobal = ""
|
let windownameGlobal = ""; // Global variable to hold the window name
|
||||||
|
let accesstoken = ""; // Variable to store the access token
|
||||||
|
|
||||||
let accesstoken = ""
|
|
||||||
onmessage = (event) => {
|
onmessage = (event) => {
|
||||||
const { action, access_token, windowname } = event.data
|
const { action, access_token, windowname } = event.data;
|
||||||
accesstoken = access_token
|
accesstoken = access_token;
|
||||||
|
windownameGlobal = windowname;
|
||||||
windownameGlobal = windowname
|
|
||||||
|
|
||||||
if (action === "start") {
|
if (action === "start") {
|
||||||
fetchData()
|
fetchData(); // Start fetching data on 'start' action
|
||||||
} else if (action === "terminate") {
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const fetchData = () => {
|
const fetchData = () => {
|
||||||
|
const apiURL = new URL("http://localhost:5000/interstellar_ai/api/ai_get?access_token=" + accesstoken);
|
||||||
|
apiURL.hostname = windownameGlobal; // Set the hostname
|
||||||
|
|
||||||
const apiURL = new URL("http://localhost:5000/interstellar_ai/api/ai_get?access_token=" + accesstoken)
|
console.log(apiURL.href); // Log the constructed URL
|
||||||
apiURL.hostname = windownameGlobal;
|
|
||||||
|
|
||||||
console.log(apiURL.href)
|
|
||||||
|
|
||||||
axios.get(apiURL.href)
|
axios.get(apiURL.href)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
const data = response.data
|
postMessage(response.data); // Send data back on success
|
||||||
postMessage(data)
|
setTimeout(fetchData, 100); // Schedule next fetch
|
||||||
setTimeout(fetchData, 100)
|
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.log('Error fetching data:', error);
|
console.log('Error fetching data:', error);
|
||||||
postMessage({ error: "failed fetching data" })
|
postMessage({ error: "failed fetching data" }); // Send error message
|
||||||
setTimeout(() => fetchData(), 1000)
|
setTimeout(() => fetchData(), 1000); // Retry after 1 second
|
||||||
})
|
});
|
||||||
}
|
}
|
Loading…
Reference in a new issue