feat(chatModal): add getWebSocketUrl function to generate WebSocket URL based on chatId and environment

This commit adds a new function called getWebSocketUrl to the ChatModal component. This function generates a WebSocket URL based on the chatId and environment. It determines whether to use the "ws" or "wss" protocol based on whether the current protocol is secure or not. It also determines the host based on whether the environment is development or production. This function will be used to establish a WebSocket connection to the server.
This commit is contained in:
anovazzi1 2023-06-15 15:53:56 -03:00
commit 3653f5eefc

View file

@ -111,6 +111,17 @@ export default function ChatModal({
}
}
function getWebSocketUrl(chatId, isDevelopment = false) {
const isSecureProtocol = window.location.protocol === "https:";
const webSocketProtocol = isSecureProtocol ? "wss" : "ws";
const host = isDevelopment ? "localhost:7860" : window.location.host;
const chatEndpoint = `/api/v1/chat/${chatId}`;
return `${
isDevelopment ? "ws" : webSocketProtocol
}://${host}${chatEndpoint}`;
}
function handleWsMessage(data: any) {
if (Array.isArray(data)) {
//set chat history