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:
parent
9c9838927a
commit
3653f5eefc
1 changed files with 11 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue