small changes and clean comments

This commit is contained in:
simplonco
2023-01-05 10:26:09 +01:00
parent e16dc56314
commit 286d79ed06
6 changed files with 34 additions and 41 deletions

View File

@@ -9,6 +9,7 @@
import { socket, user } from './Chat_socket.svelte';
import { msgs } from './Store_msg.js';
// pbm: sometimes socket is still undefined here
socket.on('connect', function(){
console.log("socket.io connected");
@@ -47,13 +48,12 @@
console.log("socket.io pong");
});
socket.on('message', (from, message) => {
socket.on('message', function(from, message)
{
console.log("received msg:", message, from);
if (from === user.username)
from = "me";
//msgs = [...msgs, { content: message, name: from }];
msgs.update(msgs => [...msgs, { content: message, name: from }]);
//add_msg(name, message);
});
</script>

View File

@@ -3,7 +3,7 @@
import Button from './Chat_button.svelte';
import Msg from './Chat_msg.svelte';
import { socket, user } from './Chat_socket.svelte';
import { socket } from './Chat_socket.svelte';
import { msgs } from './Store_msg.js';
export let layout = "";
@@ -11,13 +11,9 @@
let msg = "";
let text_area;
//let msgs = [];
function add_msg(from, message)
function add_local_msg(from, message)
{
if (from === user.username)
from = "me";
//msgs = [...msgs, { content: message, name: from }];
msgs.update(msgs => [...msgs, { content: message, name: from }]);
}
@@ -26,7 +22,7 @@
msg = msg.trim();
if (msg.length > 0) {
socket.emit('message', msg);
add_msg("me", msg);
add_local_msg("me", msg);
}
msg = "";

View File

@@ -1,5 +1,7 @@
import { writable } from 'svelte/store';
export let user = writable({});
export let socket = writable({});
export let msgs = writable([]);