Skip to content

Commit

Permalink
Potential fix for ws issue
Browse files Browse the repository at this point in the history
  • Loading branch information
AlemTuzlak committed Nov 18, 2024
1 parent a095126 commit 6576489
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 79 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@
"react-d3-tree": "^3.6.2",
"react-diff-viewer-continued": "^3.3.1",
"react-hotkeys-hook": "^4.5.0",
"react-use-websocket": "^4.8.1",
"tailwind-merge": "^1.14.0"
}
}
57 changes: 1 addition & 56 deletions src/client/hooks/useRemixForgeSocket.ts
Original file line number Diff line number Diff line change
@@ -1,60 +1,5 @@
import { useState } from "react"
import useWebSocket from "react-use-websocket"

enum ReadyState {
UNINSTANTIATED = -1,
CONNECTING = 0,
OPEN = 1,
CLOSING = 2,
CLOSED = 3,
}
import { useSettingsContext, useTerminalContext } from "../context/useRDTContext.js"

const RETRY_COUNT = 2

export const useRemixForgeSocket = (options?: any) => {
const { settings, setSettings } = useSettingsContext()
const { terminals, toggleTerminalLock, setProcessId } = useTerminalContext()
const { shouldConnectWithForge, port } = settings
const [retryCount, setRetryCount] = useState(0)
const opts: any = {
...options,
share: true,
shouldReconnect: () => true,
reconnectAttempts: RETRY_COUNT,
reconnectInterval: 0,
onClose: (e: any) => {
// connection closed by remix forge
if (e.code === 1005) {
setSettings({ shouldConnectWithForge: false })
setRetryCount(0)
for (const terminal of terminals) {
toggleTerminalLock(terminal.id, false)
setProcessId(terminal.id, undefined)
}

return
}
if (retryCount < RETRY_COUNT) {
return setRetryCount(retryCount + 1)
}
setSettings({ shouldConnectWithForge: false })
},
}

const properties = useWebSocket(`ws://localhost:${port}`, opts, shouldConnectWithForge)

const connectionStatus = {
[ReadyState.CONNECTING]: "Connecting",
[ReadyState.OPEN]: "Open",
[ReadyState.CLOSING]: "Closing",
[ReadyState.CLOSED]: "Closed",
[ReadyState.UNINSTANTIATED]: "Uninstantiated",
}[properties.readyState]
const isConnected = properties.readyState === ReadyState.OPEN
const isConnecting = properties.readyState === ReadyState.CONNECTING

return { ...properties, connectionStatus, isConnected, isConnecting }
return { sendJsonMessage: (obj: any) => {}, isConnected: false, isConnecting: false }
}

interface RemixForgeMessage extends Record<string, unknown> {
Expand Down
23 changes: 1 addition & 22 deletions src/client/layout/Tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,12 @@ const Tab = ({
}

const Tabs = ({ plugins, setIsOpen }: TabsProps) => {
const { settings, setSettings } = useSettingsContext()
const { settings } = useSettingsContext()
const { htmlErrors } = useHtmlErrors()
const { setPersistOpen } = usePersistOpen()
const { activeTab } = settings
const { isConnected, isConnecting } = useRemixForgeSocket()
const { visibleTabs } = useTabs(isConnected, isConnecting, plugins)
const shouldShowConnectToForge = !isConnected || isConnecting
const scrollRef = useHorizontalScroll()
const { setDetachedWindowOwner, detachedWindowOwner, detachedWindow } = useDetachedWindowControls()
const handleDetachment = () => {
Expand Down Expand Up @@ -117,26 +116,6 @@ const Tabs = ({ plugins, setIsOpen }: TabsProps) => {
/>
))}
<div className={clsx("mt-auto flex w-full flex-col items-center")}>
{shouldShowConnectToForge && (
<Tab
tab={{
id: "connect",
name: isConnecting ? "Connecting to Forge..." : "Connect to Remix Forge",
requiresForge: false,
hideTimeline: false,
component: <></>,
icon: <Icon name="Radio" size="md" />,
}}
className={twMerge(
clsx(
isConnecting && "pointer-events-none animate-pulse cursor-default",
"mt-auto w-full ",
detachedWindow ? "mr-0" : ""
)
)}
onClick={() => setSettings({ shouldConnectWithForge: true })}
/>
)}
{!detachedWindow && setIsOpen && (
<>
{!detachedWindowOwner && (
Expand Down

0 comments on commit 6576489

Please sign in to comment.