one-way communication without frontent :)
This commit is contained in:
		@@ -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);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user