aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZhongheng Liu <z.liu@outlook.com.gr>2023-12-21 19:42:59 +0200
committerZhongheng Liu <z.liu@outlook.com.gr>2023-12-21 19:42:59 +0200
commitfafa985bde7a458819c416ce7a6f9ef7662af110 (patch)
treed77663dda7955c22c075442fb581ee158e058a7b
parent8e99d4fa14afc562c969e5fac5c44e97ca4dff29 (diff)
downloadepq-web-fafa985bde7a458819c416ce7a6f9ef7662af110.tar.gz
epq-web-fafa985bde7a458819c416ce7a6f9ef7662af110.tar.bz2
epq-web-fafa985bde7a458819c416ce7a6f9ef7662af110.zip
finished prototype v1 - removed deprecated files
-rw-r--r--src/Chat/Socket.tsx61
1 files changed, 0 insertions, 61 deletions
diff --git a/src/Chat/Socket.tsx b/src/Chat/Socket.tsx
deleted file mode 100644
index cbb4e10..0000000
--- a/src/Chat/Socket.tsx
+++ /dev/null
@@ -1,61 +0,0 @@
-import { Client } from "@stomp/stompjs"
-import { useState } from "react"
-import { Message } from "./Message"
-import { MessageType } from "./types"
-
-const Socket = (
- {
- address,
- user,
- messageCallback,
- }:
- {
- address: string,
- user: string,
- messageCallback: (element: JSX.Element) => {},
- }
-) => {
- const stompClient = new Client({
- brokerURL: address
- })
- const destination = "/app/chat"
- const subscribe = "/sub/chat"
- stompClient.onConnect = (frame) => {
- stompClient.subscribe(subscribe, (message) => {
- console.log(`Collected new message: ${message.body}`);
- const {from, to, content} = JSON.parse(message.body) as MessageType
- const messageElement = <Message sender={from} text={content} />
- // return message to parent
- messageCallback(messageElement)
- })
- }
- stompClient.onWebSocketError = (error) => {
- console.error('Error with websocket', error);
- };
-
- stompClient.onStompError = (frame) => {
- console.error('Broker reported error: ' + frame.headers['message']);
- console.error('Additional details: ' + frame.body);
- };
-
- const send = () => {
- console.log("WebSockets handler invoked.")
-
- const entryElement: HTMLInputElement = document.getElementById("data-entry") as HTMLInputElement
- const messageData =
- {
- from: user,
- to: "everyone",
- content: entryElement.value
- }
- console.log(`STOMP connection status: ${stompClient.connected}`);
-
- stompClient.publish({
- body: JSON.stringify(messageData),
- destination: destination
- })
- }
- stompClient.activate()
- return (<></>)
-}
-export default Socket; \ No newline at end of file