diff options
author | Zhongheng Liu <z.liu@outlook.com.gr> | 2023-12-19 20:27:54 +0200 |
---|---|---|
committer | Zhongheng Liu <z.liu@outlook.com.gr> | 2023-12-19 20:27:54 +0200 |
commit | 486751022cdf5867a5086c63e8dc5001e4284a7d (patch) | |
tree | a3318a7ec8cf55b105f9a0e6857ee350d67c9cf2 | |
parent | 884c5dce980d84fb4afbcfa02e024b5155788311 (diff) | |
download | epq-web-486751022cdf5867a5086c63e8dc5001e4284a7d.tar.gz epq-web-486751022cdf5867a5086c63e8dc5001e4284a7d.tar.bz2 epq-web-486751022cdf5867a5086c63e8dc5001e4284a7d.zip |
started work on frontend message handlers
added type annots to reinforce data structure robustness
started creating Chat.tsx event handlers
-rw-r--r-- | src/Chat/Chat.tsx | 47 | ||||
-rw-r--r-- | src/Chat/ChatMessage.tsx | 23 |
2 files changed, 69 insertions, 1 deletions
diff --git a/src/Chat/Chat.tsx b/src/Chat/Chat.tsx index 4eee36c..be57614 100644 --- a/src/Chat/Chat.tsx +++ b/src/Chat/Chat.tsx @@ -1 +1,46 @@ -import React from "react";
\ No newline at end of file +import React from "react"; +const domain = "localhost" +const port = "8080" +const connectionAddress = `ws://${domain}:${port}` +const Message = ( + { + sender, + text, + objects, + }: + { + sender: string, // TODO Create specific sender object type + text: string, + objects?: Array<any>, + } + ): React.ReactElement => { + + return (<></>) +} +const Chat = (): React.ReactElement => { + const msgWrapperClassName = "msg-wrapper" + const connection = new WebSocket(connectionAddress) + connection.addEventListener("open", (ev: Event) => { + ev.preventDefault() + connection.send("Hello world!") + }) + connection.addEventListener("message", (ev: MessageEvent) => { + ev.preventDefault() + const wrappers = document.getElementsByClassName(msgWrapperClassName) + const data = JSON.parse(ev.data) + for (let index = 0; index < wrappers.length; index++) { + const element: Element | null = wrappers.item(index); + if (!element) { + console.error("msgWrapper class cannot be found! Message not delivered.") + return + } + } + }) + return ( + <div className="chat"> + <div className={msgWrapperClassName}> + </div> + <input></input> + </div> + ) +} diff --git a/src/Chat/ChatMessage.tsx b/src/Chat/ChatMessage.tsx new file mode 100644 index 0000000..5d8069c --- /dev/null +++ b/src/Chat/ChatMessage.tsx @@ -0,0 +1,23 @@ +enum FileType { + FILE_TXT, + DOCUMENT_WORD, + DOCUMENT_PDF, + IMAGE, + EXEC_BINARY, + UNKNOWN, +} +export type Attachment = { + name: string, + uri: string, + sizeBytes: number, + filetype: FileType +} +export type ChatMessage = { + from: string, + fromIP: string, + to: Array<string>, + toIPs: Array<string>, + timestampPosted: number, + message: string, + attachments: Attachment +} |