feat: websocket part1 (estudo)

This commit is contained in:
2025-03-03 21:23:35 -03:00
parent 76d2d4a879
commit 3a7cbfc413
115 changed files with 17856 additions and 33 deletions

View File

@@ -1,3 +1,38 @@
const websocket = new WebSocket('ws://localhost:8765');
websocket.addEventListener('open', (event) => {
console.log('Conectado ao servidor WebSocket');
});
websocket.addEventListener('message', (event) => {
const data = JSON.parse(event.data);
if (data.local === 'cozinha' && data.tipo === 'add'){
const novoElemento = document.createElement('div');
novoElemento.innerHTML = data.message;
var fila = document.getElementById('Fila').appendChild(novoElemento);
texto = new SpeechSynthesisUtterance(data.speak);
window.speechSynthesis.speak(texto);
console.log('Mensagem recebida:', data.local);
}
else if (data.local === 'cozinha' && data.tipo === 'edit'){
var card = document.getElementById('obs-'+data.id).innerHTML = data.message
console.log('Mensagem recebida:', data.local);
}
});
websocket.addEventListener('error', (event) => {
console.error('Erro no WebSocket:', event);
});
websocket.addEventListener('close', (event) => {
console.log("conexão fechada");
});
function menuShow() {
let menuMobile = document.querySelector('.mobile-menu');
if (menuMobile.classList.contains('open')) {

View File

@@ -1,5 +1,6 @@
function openModal() {
textField = document.getElementById('search-product')
textField.value = '';
@@ -220,8 +221,8 @@ function showToastAdd(message, type ,duration = 3000) {
}
function addProductComanda(productId,comandaId, cuisine) {
obs = document.getElementById('obs');
console.log(obs.value);
console.log(cuisine);
// console.log(obs.value);
// console.log(cuisine);
if(cuisine == 'ggg'){
var obs = openModalObs();
@@ -239,7 +240,9 @@ function addProductComanda(productId,comandaId, cuisine) {
var listProductsBalcaoElement = document.getElementById("list-products-comanda");
listProductsBalcaoElement.innerHTML = text;
})
// websocket.send(JSON.stringify({ type: 'broadcast', message: '<div class="m-card" style="background-color: rgb(253, 69, 69);"><h4>Tapioca de ovo</h4><h4>sem ovo </h4><h4>Joao - mesa 07</h4><h4> Atendente: Lucas </h4><h4> 25/02/2025 20:03</h4><button class="btn-primary" >Preparar</button></div>'
//}));
showToastAdd('Produto adicionado com sucesso!😁','success');
}
@@ -258,11 +261,21 @@ function taxa(){
}
}
document.getElementById('taxa').addEventListener("change", taxa);
// document.getElementById('taxa').addEventListener("change", taxa);
// document.getElementById('productForm').addEventListener('submit', function(event) {
// event.preventDefault();
// });
// hx-get="{% url 'addProduct' product.id comanda.id %} " hx-trigger="click" hx-target="#list-products-comanda"
// Enviar uma mensagem (exemplo - broadcast):
// websocket.send(JSON.stringify({ type: 'broadcast', message: 'Olá do cliente!' }));
//enviar uma mensagem (exemplo - echo):
// websocket.send(JSON.stringify({"type": "echo", "message": "Olá Mundo!"}))
//enviar uma mensagem (exemplo - test):
// websocket.send(JSON.stringify({"type": "test"}))

View File

@@ -1,4 +1,3 @@
// document.cookie = `fila=0`;
function reloadPage(){
setTimeout(function() {
@@ -99,9 +98,9 @@ function notificacao(){
}
setInterval(()=> {
notificacao()
}, 10000)
// setInterval(()=> {
// notificacao()
// }, 10000)