wip entities
This commit is contained in:
@@ -7,54 +7,62 @@
|
||||
/* web sockets with socket.io
|
||||
*/
|
||||
import { socket, user } from './Chat_socket.svelte';
|
||||
// import { init_socket, socket, user } from './Socket';
|
||||
import { msgs } from './Store_msg.js';
|
||||
|
||||
// async function socket_actions()
|
||||
// {
|
||||
//
|
||||
// await init_socket();
|
||||
|
||||
// pbm: sometimes socket is still undefined here
|
||||
socket.on('connect', function(){
|
||||
console.log("socket.io connected");
|
||||
});
|
||||
socket.on('disconnect', function(){
|
||||
console.log("socket.io disconnected");
|
||||
});
|
||||
socket.on('connect_error', function(){
|
||||
console.log("socket.io connect_error");
|
||||
});
|
||||
socket.on('connect_timeout', function(){
|
||||
console.log("socket.io connect_timeout");
|
||||
});
|
||||
socket.on('error', function(){
|
||||
console.log("socket.io error");
|
||||
});
|
||||
socket.on('reconnect', function(){
|
||||
console.log("socket.io reconnect");
|
||||
});
|
||||
socket.on('reconnect_attempt', function(){
|
||||
console.log("socket.io reconnect_attempt");
|
||||
});
|
||||
socket.on('reconnecting', function(){
|
||||
console.log("socket.io reconnecting");
|
||||
});
|
||||
socket.on('reconnect_error', function(){
|
||||
console.log("socket.io reconnect_error");
|
||||
});
|
||||
socket.on('reconnect_failed', function(){
|
||||
console.log("socket.io reconnect_failed");
|
||||
});
|
||||
socket.on('ping', function(){
|
||||
console.log("socket.io ping");
|
||||
});
|
||||
socket.on('pong', function(){
|
||||
console.log("socket.io pong");
|
||||
});
|
||||
// pbm: sometimes socket is still undefined here
|
||||
socket.on('connect', function(){
|
||||
console.log("socket.io connected");
|
||||
});
|
||||
socket.on('disconnect', function(){
|
||||
console.log("socket.io disconnected");
|
||||
});
|
||||
socket.on('connect_error', function(){
|
||||
console.log("socket.io connect_error");
|
||||
});
|
||||
socket.on('connect_timeout', function(){
|
||||
console.log("socket.io connect_timeout");
|
||||
});
|
||||
socket.on('error', function(){
|
||||
console.log("socket.io error");
|
||||
});
|
||||
socket.on('reconnect', function(){
|
||||
console.log("socket.io reconnect");
|
||||
});
|
||||
socket.on('reconnect_attempt', function(){
|
||||
console.log("socket.io reconnect_attempt");
|
||||
});
|
||||
socket.on('reconnecting', function(){
|
||||
console.log("socket.io reconnecting");
|
||||
});
|
||||
socket.on('reconnect_error', function(){
|
||||
console.log("socket.io reconnect_error");
|
||||
});
|
||||
socket.on('reconnect_failed', function(){
|
||||
console.log("socket.io reconnect_failed");
|
||||
});
|
||||
socket.on('ping', function(){
|
||||
console.log("socket.io ping");
|
||||
});
|
||||
socket.on('pong', function(){
|
||||
console.log("socket.io pong");
|
||||
});
|
||||
|
||||
socket.on('message', function(from, message)
|
||||
{
|
||||
console.log("received msg:", message, from);
|
||||
if (from === user.username)
|
||||
from = "me";
|
||||
msgs.update(msgs => [...msgs, { content: message, name: from }]);
|
||||
});
|
||||
socket.on('message', function(from, message)
|
||||
{
|
||||
console.log("received msg:", message, from);
|
||||
if (from === user.username)
|
||||
from = "me";
|
||||
msgs.update(msgs => [...msgs, { content: message, name: from }]);
|
||||
});
|
||||
// };
|
||||
|
||||
// socket_actions();
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
@@ -5,17 +5,20 @@
|
||||
export let layout = "";
|
||||
export let back = "";
|
||||
|
||||
function handleSubmit(evt)
|
||||
async function handleSubmit(evt)
|
||||
{
|
||||
let formIsValid = evt.target.checkValidity();
|
||||
console.log("----- formIsValid:");
|
||||
console.log(formIsValid);
|
||||
|
||||
if (formIsValid)
|
||||
{
|
||||
fetch('/api/v2/chat/create', {
|
||||
const formData = new FormData(evt.target);
|
||||
console.log(formData);
|
||||
const response = await fetch('/api/v2/chat/join', {
|
||||
method: 'POST',
|
||||
body: evt.target,
|
||||
})
|
||||
//headers: { 'Content-Type': 'multipart/form-data' },
|
||||
body: formData,
|
||||
});
|
||||
console.log(await response.json());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,20 +55,20 @@
|
||||
<form on:submit|preventDefault={handleSubmit}>
|
||||
<!-- name: -->
|
||||
<label for="chat_name"><p>new room name :</p></label>
|
||||
<input id="chat_name" required>
|
||||
<input id="chat_name" name="room_name" required>
|
||||
<!-- [ ] pubic -->
|
||||
<input id="chat_public" type="radio" name="chat_create_type" checked>
|
||||
<input id="chat_public" type="radio" name="room_type" value="public" checked>
|
||||
<label for="chat_public" class="_radio"><p>public</p></label>
|
||||
<!-- [ ] private -->
|
||||
<input id="chat_private" type="radio" name="chat_create_type">
|
||||
<input id="chat_private" type="radio" name="room_type" value="private">
|
||||
<label for="chat_private" class="_radio"><p>private</p></label>
|
||||
<!-- [ ] protected -->
|
||||
<input id="chat_protected" class="__check_change_next" type="radio" name="chat_create_type">
|
||||
<input id="chat_protected" class="__check_change_next" type="radio" name="room_type" value="protected">
|
||||
<label for="chat_protected" class="_radio"><p>protected</p></label>
|
||||
<!-- [x] protected -->
|
||||
<div class="__to_show">
|
||||
<label for="chat_pswd"><p>choose a password :</p></label>
|
||||
<input id="chat_pswd" type="password" placeholder="minimum 8 characters" minlength="8">
|
||||
<input id="chat_pswd" type="password" placeholder="minimum 8 characters" minlength="8" name="password">
|
||||
</div>
|
||||
<input type="submit" value="⮡">
|
||||
</form>
|
||||
|
||||
25
srcs/requirements/svelte/api_front/src/pieces/chat/Socket.ts
Normal file
25
srcs/requirements/svelte/api_front/src/pieces/chat/Socket.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
|
||||
import io from 'socket.io-client';
|
||||
export let user;
|
||||
export let socket;
|
||||
|
||||
const address = `http://${process.env.WEBSITE_HOST}:${process.env.WEBSITE_PORT}`;
|
||||
|
||||
export function init_socket()
|
||||
{
|
||||
fetch(`${address}/api/v2/user`)
|
||||
.then((resp) => resp.json())
|
||||
.then((data) =>
|
||||
{
|
||||
user = data;
|
||||
socket = io(address,
|
||||
{
|
||||
path: '/chat',
|
||||
query:
|
||||
{
|
||||
username: user.username,
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user