one-way communication without frontent :)

This commit is contained in:
2025-02-05 16:55:45 +03:00
parent 3a742b1f34
commit 81ae05c583
4 changed files with 120 additions and 53 deletions

View File

@@ -1,6 +1,29 @@
function getCookie(name) {
const value = `; ${document.cookie}`;
const parts = value.split(`; ${name}=`);
if (parts.length === 2) return parts.pop().split(';').shift();
}
$(document).ready(() => {
//prod
// const socket = new WebSocket('wss://auth.foxarmy.org');
//dev
const socket = new WebSocket('ws://localhost:3000');
socket.onmessage = message => {
console.log(message)
}
const sendData = async () => {
alert(1);
const jwt = getCookie("jwt");
const author = await (await fetch(`/api/getUsername`)).json()
const content = $("#chat-input").val();
const message = {
jwt, author, content
};
socket.send(JSON.stringify(message));
}
$("#send-message-button").click(sendData);