mirror of
https://github.com/vacp2p/de-mls.git
synced 2026-01-08 22:57:57 -05:00
* start building waku for group_chat * replace test * replace test * fix building issue on m2 * continue waku integration * add admin trait * update cfg * update code * replace cli to ws * add docker for each instance * fully working process for joining to the group * update readme * Add Waku and WebSocket actors for message processing and group management - Introduced `WakuActor` for handling message sending and group subscriptions using Waku protocol. - Implemented `Group` actor for managing group creation, member addition/removal, and message processing. - Added `WsActor` for WebSocket communication, enabling user connections and message handling. - Defined message structures for processing and sending messages within the Waku and WebSocket contexts. - Enhanced error handling and logging for message operations. * Refactor Waku and WebSocket integration for improved message handling - Updated `WakuActor` to return a vector of `WakuContentTopic` upon subscription, enhancing group topic management. - Introduced `AppState` struct to centralize application state, including Waku actor reference and content topics. - Refactored main loop to utilize `AppState`, improving message flow between Waku and WebSocket actors. - Enhanced message handling in `WsActor` to support `MessageToPrint`, allowing for structured message sending. - Improved error handling and logging throughout the message processing pipeline. * Refactor Waku message handling and clean up unused code * Refactor and remove unused components from the project - Deleted the `sc_key_store` module and its associated files, streamlining the codebase. - Removed unused Docker and Git configuration files, enhancing project clarity. - Cleaned up `.gitignore` and `.dockerignore` to reflect current project structure. - Updated `Cargo.toml` files to remove references to deleted modules and dependencies. - Refactored Waku and WebSocket actors to improve message handling and group management. - Enhanced error handling and logging throughout the message processing pipeline. - Adjusted frontend input styling for better user experience. * Update CI workflow to use 'main' branch and add support for manual triggers * Enhance Waku integration and documentation - Added instructions for running a test Waku node in the README. - Refactored Waku message handling in `ds_waku.rs` to improve content topic management and error handling. - Updated `Cargo.toml` dependencies for better compatibility and removed unused entries. - Improved error handling in `DeliveryServiceError` for Waku node operations. - Cleaned up CI workflow by commenting out unused test jobs. - Enhanced logging in tests for better traceability of message flows. * Update CI workflow to include Go setup for testing - Added steps to the CI configuration to set up Go version 1.20.x for user tests. - Ensured consistent environment setup across different jobs in the CI pipeline. * Update package versions to 1.0.0 in Cargo.toml files for the main project and 'ds' module * Update README to include note on frontend implementation based on Chatr
118 lines
3.4 KiB
Svelte
118 lines
3.4 KiB
Svelte
<script lang="ts">
|
|
import {onMount, onDestroy} from "svelte";
|
|
import {user, channel, eth_private_key, group, createNewRoom} from "../../lib/stores/user";
|
|
import {goto} from '$app/navigation';
|
|
import {env} from '$env/dynamic/public'
|
|
import toast from "svelte-french-toast";
|
|
import { json } from "@sveltejs/kit";
|
|
|
|
let status = "🔴";
|
|
let statusTip = "Disconnected";
|
|
let message = "";
|
|
let messages: any[] = [];
|
|
let socket: WebSocket;
|
|
let interval: number;
|
|
let delay = 2000;
|
|
let timeout = false;
|
|
$: {
|
|
if (interval || (!timeout && interval)) {
|
|
clearInterval(interval);
|
|
}
|
|
|
|
if (timeout == true) {
|
|
interval = setInterval(() => {
|
|
if (delay < 30_000) delay = delay * 2;
|
|
console.log("reconnecting in:", delay)
|
|
connect();
|
|
}, delay)
|
|
}
|
|
}
|
|
|
|
function connect() {
|
|
socket = new WebSocket(`${env.PUBLIC_WEBSOCKET_URL}/ws`)
|
|
socket.addEventListener("open", () => {
|
|
status = "🟢"
|
|
statusTip = "Connected";
|
|
timeout = false;
|
|
socket.send(JSON.stringify({
|
|
eth_private_key: $eth_private_key,
|
|
group_id: $group,
|
|
should_create: $createNewRoom,
|
|
}));
|
|
})
|
|
|
|
socket.addEventListener("close", () => {
|
|
status = "🔴";
|
|
statusTip = "Disconnected";
|
|
if (timeout == false) {
|
|
delay = 2000;
|
|
timeout = true;
|
|
}
|
|
})
|
|
|
|
socket.addEventListener('message', function (event) {
|
|
if (event.data == "Username already taken.") {
|
|
toast.error(event.data)
|
|
goto("/");
|
|
} else {
|
|
messages = [...messages, event.data]
|
|
}
|
|
})
|
|
}
|
|
|
|
onMount(() => {
|
|
if ($eth_private_key.length < 1 || $group.length < 1 ) {
|
|
toast.error("Something went wrong!")
|
|
goto("/");
|
|
} else {
|
|
connect()
|
|
}
|
|
}
|
|
)
|
|
|
|
onDestroy(() => {
|
|
if (socket) {
|
|
socket.close()
|
|
}
|
|
if (interval) {
|
|
clearInterval(interval)
|
|
}
|
|
timeout = false
|
|
})
|
|
|
|
const sendMessage = () => {
|
|
socket.send(JSON.stringify({
|
|
message: message,
|
|
group_id: $group,
|
|
}));
|
|
message = "";
|
|
};
|
|
const clear_messages = () => {
|
|
messages = [];
|
|
};
|
|
|
|
|
|
</script>
|
|
<div class="title flex justify-between">
|
|
<h1 class="text-3xl font-bold cursor-default">Chat Room <span class="tooltip" data-tip="{statusTip}">{status}</span>
|
|
</h1>
|
|
<button class="btn btn-accent" on:click={clear_messages}>clear</button>
|
|
</div>
|
|
<div class="card h-96 flex-grow bg-base-300 shadow-xl my-10">
|
|
<div class="card-body">
|
|
<div class="flex flex-col overflow-y-auto max-h-80 scroll-smooth">
|
|
{#each messages as msg}
|
|
<div class="my-2">{msg}</div>
|
|
{/each}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="message-box flex justify-end">
|
|
<form on:submit|preventDefault={sendMessage}>
|
|
<input placeholder="Message" class="input input-bordered input-primary w-[51rem] bg-base-200 mb-2"
|
|
bind:value={message}>
|
|
<button class="btn btn-primary w-full sm:w-auto btn-wide">Send</button>
|
|
</form>
|
|
</div>
|