Skip to content

Commit

Permalink
[grid] UI Liveview disconnect noVNC websocket when closing dialog
Browse files Browse the repository at this point in the history
Signed-off-by: Viet Nguyen Duc <[email protected]>
  • Loading branch information
VietND96 committed Oct 14, 2024
1 parent c7daf73 commit 5295bea
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
12 changes: 9 additions & 3 deletions javascript/grid-ui/src/components/LiveView/LiveView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.

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

function LiveView (props) {
const LiveView = forwardRef((props, ref) => {
let canvas: any = null

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

useImperativeHandle(ref, () => ({
disconnect
}))

const connect = () => {
disconnect()

Expand Down Expand Up @@ -109,6 +113,7 @@ function LiveView (props) {
}

const handlePasswordDialogClose = () => {
disconnect()
props.onClose()
}

Expand All @@ -132,6 +137,7 @@ function LiveView (props) {
return
}
setOpenErrorAlert(false)
disconnect()
props.onClose()
}

Expand Down Expand Up @@ -176,6 +182,6 @@ function LiveView (props) {
</Snackbar>
</div>
)
}
})

export default LiveView
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.

import React, { useState } from 'react'
import React, { useState, useRef } from 'react'
import Table from '@mui/material/Table'
import TableBody from '@mui/material/TableBody'
import TableCell from '@mui/material/TableCell'
Expand Down Expand Up @@ -177,6 +177,14 @@ function RunningSessions (props) {
const [rowsPerPage, setRowsPerPage] = useState(10)
const [searchFilter, setSearchFilter] = useState('')
const [searchBarHelpOpen, setSearchBarHelpOpen] = useState(false)
const liveViewRef = useRef(null)

const handleDialogClose = () => {
if (liveViewRef.current) {
liveViewRef.current.disconnect()
}
setRowLiveViewOpen('')
}

const handleRequestSort = (event: React.MouseEvent<unknown>,
property: keyof SessionData) => {
Expand Down Expand Up @@ -379,14 +387,15 @@ function RunningSessions (props) {
sx={{ height: '600px' }}
>
<LiveView
ref={liveViewRef}
url={row.vnc as string}
scaleViewport
onClose={() => setRowLiveViewOpen('')}
/>
</DialogContent>
<DialogActions>
<Button
onClick={() => setRowLiveViewOpen('')}
onClick={handleDialogClose}
color='primary'
variant='contained'
>
Expand Down

0 comments on commit 5295bea

Please sign in to comment.