diff --git a/packages/bruno-app/src/components/RequestPane/WsBody/index.js b/packages/bruno-app/src/components/RequestPane/WsBody/index.js index 818c7b511..41a7d6eee 100644 --- a/packages/bruno-app/src/components/RequestPane/WsBody/index.js +++ b/packages/bruno-app/src/components/RequestPane/WsBody/index.js @@ -51,13 +51,6 @@ const SingleWSMessage = ({ ); }; - const onSend = async () => { - try { - await sendWsRequest(item, collection.uid, content); - } catch (error) { - console.error('Error sending message:', error); - } - }; const onSave = () => dispatch(saveRequest(item.uid, collection.uid)); const onDeleteMessage = () => { diff --git a/packages/bruno-app/src/components/RequestPane/WsQueryUrl/index.js b/packages/bruno-app/src/components/RequestPane/WsQueryUrl/index.js index 875033a0f..9a20c189c 100644 --- a/packages/bruno-app/src/components/RequestPane/WsQueryUrl/index.js +++ b/packages/bruno-app/src/components/RequestPane/WsQueryUrl/index.js @@ -3,14 +3,14 @@ import { IconWebSocket } from 'components/Icons/Grpc'; import classnames from "classnames" import SingleLineEditor from 'components/SingleLineEditor/index'; import { requestUrlChanged } from 'providers/ReduxStore/slices/collections'; -import { saveRequest } from 'providers/ReduxStore/slices/collections/actions'; +import { wsConnectOnly, saveRequest } from 'providers/ReduxStore/slices/collections/actions'; import { useTheme } from 'providers/Theme'; import React, { useEffect, useState } from 'react'; import toast from 'react-hot-toast'; import { useDispatch } from 'react-redux'; import { getPropertyFromDraftOrRequest } from 'utils/collections'; import { isMacOS } from 'utils/common/platform'; -import { closeWsConnection, connectWS, isWsConnectionActive } from 'utils/network/index'; +import { closeWsConnection, isWsConnectionActive } from 'utils/network/index'; import StyledWrapper from './StyledWrapper'; const WsQueryUrl = ({ item, collection, handleRun }) => { @@ -75,7 +75,7 @@ const WsQueryUrl = ({ item, collection, handleRun }) => { const handleConnect = (e) => { setIsConnecting(true) - connectWS(item, collection, undefined, undefined, {connectOnly:true}); + dispatch(wsConnectOnly(item, collection.uid)); }; const onSave = (finalValue) => { diff --git a/packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js b/packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js index 1fb200364..065b55342 100644 --- a/packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js +++ b/packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js @@ -20,7 +20,7 @@ import { transformRequestToSaveToFilesystem } from 'utils/collections'; import { uuid, waitForNextTick } from 'utils/common'; -import { cancelNetworkRequest, sendGrpcRequest, sendNetworkRequest, sendWsRequest } from 'utils/network/index'; +import { cancelNetworkRequest, connectWS, sendGrpcRequest, sendNetworkRequest, sendWsRequest } from 'utils/network/index'; import { callIpc } from 'utils/common/ipc'; import { @@ -242,6 +242,39 @@ export const sendCollectionOauth2Request = (collectionUid, itemUid) => (dispatch }); }; +export const wsConnectOnly = (item, collectionUid) => (dispatch, getState) => { + const state = getState(); + const { globalEnvironments, activeGlobalEnvironmentUid } = state.globalEnvironments; + const collection = findCollectionByUid(state.collections.collections, collectionUid); + + return new Promise(async (resolve, reject) => { + if (!collection) { + return reject(new Error('Collection not found')); + } + + let collectionCopy = cloneDeep(collection); + + const itemCopy = cloneDeep(item); + + const requestUid = uuid(); + itemCopy.requestUid = requestUid; + + const globalEnvironmentVariables = getGlobalEnvironmentVariables({ + globalEnvironments, + activeGlobalEnvironmentUid + }); + collectionCopy.globalEnvironmentVariables = globalEnvironmentVariables; + + const environment = findEnvironmentInCollection(collectionCopy, collectionCopy.activeEnvironmentUid); + + connectWS(itemCopy, collectionCopy, environment, collectionCopy.runtimeVariables, { connectOnly:true }) + .then(resolve) + .catch((err) => { + toast.error(err.message); + }); + }) +} + export const sendRequest = (item, collectionUid) => (dispatch, getState) => { const state = getState(); const { globalEnvironments, activeGlobalEnvironmentUid } = state.globalEnvironments;