mirror of
https://github.com/wu736139669/hapi.git
synced 2026-08-05 06:24:37 +00:00
fix(web): use explicit Manager+socket for terminal namespace connection (#433)
The convenience `io()` function misparses the `/terminal` path
component as part of the Engine.IO endpoint in some browser
environments, producing requests to `/terminal/socket.io/` instead
of `/socket.io/`. Using `new Manager(baseUrl)` + `manager.socket('/terminal')`
separates the transport URL from the namespace unambiguously.
Closes #251
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { useCallback, useEffect, useRef, useState } from 'react'
|
||||
import { io, type Socket } from 'socket.io-client'
|
||||
import { Manager, type Socket } from 'socket.io-client'
|
||||
|
||||
type TerminalConnectionState =
|
||||
| { status: 'idle' }
|
||||
@@ -116,8 +116,7 @@ export function useTerminalSocket(options: UseTerminalSocketOptions): {
|
||||
return
|
||||
}
|
||||
|
||||
const socket = io(`${baseUrlRef.current}/terminal`, {
|
||||
auth: { token },
|
||||
const manager = new Manager(baseUrlRef.current, {
|
||||
path: '/socket.io/',
|
||||
reconnection: true,
|
||||
reconnectionAttempts: Infinity,
|
||||
@@ -126,6 +125,9 @@ export function useTerminalSocket(options: UseTerminalSocketOptions): {
|
||||
transports: ['polling', 'websocket'],
|
||||
autoConnect: false
|
||||
})
|
||||
const socket = manager.socket('/terminal', {
|
||||
auth: { token }
|
||||
})
|
||||
|
||||
socketRef.current = socket
|
||||
setState({ status: 'connecting' })
|
||||
|
||||
Reference in New Issue
Block a user