Skip to content

Commit a75cd4b

Browse files
authored
[grid] UI Liveview disconnect noVNC websocket when closing dialog (#14598)
1 parent c7daf73 commit a75cd4b

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

Diff for: javascript/grid-ui/src/components/LiveView/LiveView.tsx

+9-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
import React, { useEffect, useState } from 'react'
18+
import React, { useEffect, useState, useImperativeHandle, forwardRef } from 'react'
1919
import RFB from '@novnc/novnc/core/rfb'
2020
import PasswordDialog from './PasswordDialog'
2121
import MuiAlert, { AlertProps } from '@mui/material/Alert'
@@ -28,7 +28,7 @@ const Alert = React.forwardRef<HTMLDivElement, AlertProps>(function Alert (
2828
return <MuiAlert elevation={6} ref={ref} variant='filled' {...props} />
2929
})
3030

31-
function LiveView (props) {
31+
const LiveView = forwardRef((props, ref) => {
3232
let canvas: any = null
3333

3434
const [open, setOpen] = useState(false)
@@ -49,6 +49,10 @@ function LiveView (props) {
4949
setRfb(null)
5050
}
5151

52+
useImperativeHandle(ref, () => ({
53+
disconnect
54+
}))
55+
5256
const connect = () => {
5357
disconnect()
5458

@@ -109,6 +113,7 @@ function LiveView (props) {
109113
}
110114

111115
const handlePasswordDialogClose = () => {
116+
disconnect()
112117
props.onClose()
113118
}
114119

@@ -132,6 +137,7 @@ function LiveView (props) {
132137
return
133138
}
134139
setOpenErrorAlert(false)
140+
disconnect()
135141
props.onClose()
136142
}
137143

@@ -176,6 +182,6 @@ function LiveView (props) {
176182
</Snackbar>
177183
</div>
178184
)
179-
}
185+
})
180186

181187
export default LiveView

Diff for: javascript/grid-ui/src/components/RunningSessions/RunningSessions.tsx

+11-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
import React, { useState } from 'react'
18+
import React, { useState, useRef } from 'react'
1919
import Table from '@mui/material/Table'
2020
import TableBody from '@mui/material/TableBody'
2121
import TableCell from '@mui/material/TableCell'
@@ -177,6 +177,14 @@ function RunningSessions (props) {
177177
const [rowsPerPage, setRowsPerPage] = useState(10)
178178
const [searchFilter, setSearchFilter] = useState('')
179179
const [searchBarHelpOpen, setSearchBarHelpOpen] = useState(false)
180+
const liveViewRef = useRef(null)
181+
182+
const handleDialogClose = () => {
183+
if (liveViewRef.current) {
184+
liveViewRef.current.disconnect()
185+
}
186+
setRowLiveViewOpen('')
187+
}
180188

181189
const handleRequestSort = (event: React.MouseEvent<unknown>,
182190
property: keyof SessionData) => {
@@ -379,14 +387,15 @@ function RunningSessions (props) {
379387
sx={{ height: '600px' }}
380388
>
381389
<LiveView
390+
ref={liveViewRef}
382391
url={row.vnc as string}
383392
scaleViewport
384393
onClose={() => setRowLiveViewOpen('')}
385394
/>
386395
</DialogContent>
387396
<DialogActions>
388397
<Button
389-
onClick={() => setRowLiveViewOpen('')}
398+
onClick={handleDialogClose}
390399
color='primary'
391400
variant='contained'
392401
>

0 commit comments

Comments
 (0)