Browse Source

front channels

master
Pheuw1 2 years ago
parent
commit
c93f9d020b
  1. 25
      .env_sample
  2. 35
      front/volume/src/components/Channels.svelte
  3. 5
      front/volume/src/components/Chat.svelte

25
.env_sample

@ -1,25 +0,0 @@
POSTGRES_HOST=postgres
POSTGRES_PORT=5432
POSTGRES_USER=postgres_usr
POSTGRES_PASSWORD=postgres_pw
POSTGRES_DB=transcendence
PGADMIN_DEFAULT_EMAIL=admin@pg.com
PGADMIN_DEFAULT_PASSWORD=admin
MAIL_USER=vaganiwast@gmail.com
MAIL_PASSWORD=
FRONT_FPS=144
HOST=localhost
FRONT_PORT=80
BACK_PORT=3001
HASH_SALT=10
JWT_SECRET=test
JWT_EXPIRATION_TIME=900
FT_OAUTH_CLIENT_ID=
FT_OAUTH_CLIENT_SECRET=
FT_OAUTH_CALLBACK_URL=http://$HOST:$BACK_PORT/log/inReturn

35
front/volume/src/components/Channels.svelte

@ -23,13 +23,17 @@
}); });
}; };
let channels: Array<ChannelsType> = []; const getChannels = async () => {
onMount(async () => {
const res = await fetch(API_URL + "/channels", { const res = await fetch(API_URL + "/channels", {
credentials: "include", credentials: "include",
mode: "cors", mode: "cors",
}); });
if (res.ok) channels = await res.json(); if (res.ok) channels = await res.json();
};
let channels: Array<ChannelsType> = [];
onMount(async () => {
getChannels()
}); });
//--------------------------------------------------------------------------------/ //--------------------------------------------------------------------------------/
@ -46,11 +50,25 @@
//--------------------------------------------------------------------------------/ //--------------------------------------------------------------------------------/
const createChannel = async () => { const createChannel = async () => {
const name = prompt("Enter a name for the new channel:"); let name, friend;
if (channelMode === "direct") {
friend = prompt("Invite a friend to your channel:");
const response = await fetch(API_URL + "/users/" + friend + "/byname", {
credentials: "include",
method: "GET",
mode: "cors",});
if (!response.ok) {
alert("Error getting user infos");
return
}
}
else name = prompt("Enter a name for the new channel:");
if (name) { if (name) {
let password = ""; let password = "";
if (channelMode !== "direct") if (channelMode === "private")
password = prompt("Enter a password for the new channel:"); password = prompt("Enter a password for the new channel:");
if (friend !== undefined) name = "💬 " + $store.username + "/" + friend;
else name = "🚪 " + name;
const response = await fetch(API_URL + "/channels", { const response = await fetch(API_URL + "/channels", {
credentials: "include", credentials: "include",
method: "POST", method: "POST",
@ -62,7 +80,8 @@
name: name, name: name,
owner: $store.ftId, owner: $store.ftId,
password: password, password: password,
isPrivate: channelMode === "private", isPrivate: channelMode === "private" || channelMode === "direct",
direct: friend,
}), }),
}); });
if (response.ok) { if (response.ok) {
@ -70,6 +89,12 @@
} else { } else {
alert("Error creating channel"); alert("Error creating channel");
} }
const res = await fetch(API_URL + "/channels", {
credentials: "include",
mode: "cors",
});
if (res.ok) channels = await res.json();
getChannels()
} }
}; };

5
front/volume/src/components/Chat.svelte

@ -33,7 +33,10 @@
}); });
onDestroy(() => { onDestroy(() => {
socket.emit("leaveChannel"); io.emit("LeaveChanel", async (response) => {
console.log(response.status);
});
io.disconnect();
}); });
//--------------------------------------------------------------------------------/ //--------------------------------------------------------------------------------/

Loading…
Cancel
Save