From fafa985bde7a458819c416ce7a6f9ef7662af110 Mon Sep 17 00:00:00 2001 From: Zhongheng Liu Date: Thu, 21 Dec 2023 19:42:59 +0200 Subject: [PATCH] finished prototype v1 - removed deprecated files --- src/Chat/Socket.tsx | 61 --------------------------------------------- 1 file changed, 61 deletions(-) delete mode 100644 src/Chat/Socket.tsx 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 = - // 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