2023-11-02 17:16:15 +00:00
|
|
|
// Socket IO - Communication
|
|
|
|
|
|
|
|
var socketLink = null
|
|
|
|
|
|
|
|
fetch('/internal/socketlink', {
|
|
|
|
method: "GET"
|
|
|
|
}).then(link => {socketLink = link})
|
|
|
|
|
|
|
|
const socket = io(socketLink);
|
|
|
|
|
|
|
|
socket.on("connect", () => {
|
|
|
|
console.log("Connecté au serveur par le Socket avec l'ID : " + socket.id)
|
|
|
|
});
|
|
|
|
|
2024-01-07 22:27:49 +00:00
|
|
|
socket.on("disconnect", (log) => {
|
2023-11-02 17:16:15 +00:00
|
|
|
window.location.href = "/"
|
|
|
|
})
|
|
|
|
|
|
|
|
function get(request) {
|
|
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
|
|
|
socket.emit("GET/" + request)
|
|
|
|
console.log("Envoi de la requête GET : " + request)
|
|
|
|
|
|
|
|
socket.once("ANSWER/GET/" + request, (answer) => {
|
|
|
|
|
|
|
|
console.log("Réponse pour la requête : " + request)
|
|
|
|
|
|
|
|
resolve(answer)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-11-03 13:25:39 +00:00
|
|
|
function post(request, value) {
|
|
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
|
|
|
socket.emit("POST/" + request, value)
|
|
|
|
console.log("Envoi de la requête POST : " + request)
|
|
|
|
|
|
|
|
socket.once("ANSWER/POST/" + request, (answer) => {
|
|
|
|
|
|
|
|
console.log("Réponse pour la requête : " + request)
|
|
|
|
|
|
|
|
resolve(answer)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-11-02 17:16:15 +00:00
|
|
|
function getSocket() {
|
|
|
|
|
|
|
|
return socket
|
|
|
|
}
|