|
|
@ -1,4 +1,5 @@ |
|
|
|
import RFB from '@novnc/novnc/core/rfb'; |
|
|
|
import RFB from '@novnc/novnc/core/rfb'; |
|
|
|
|
|
|
|
import Websock from '@novnc/novnc/core/websock'; |
|
|
|
import { useEffect } from 'react'; |
|
|
|
import { useEffect } from 'react'; |
|
|
|
|
|
|
|
|
|
|
|
const rfbConnect: RfbConnectFunction = ({ |
|
|
|
const rfbConnect: RfbConnectFunction = ({ |
|
|
@ -9,6 +10,8 @@ const rfbConnect: RfbConnectFunction = ({ |
|
|
|
focusOnClick = false, |
|
|
|
focusOnClick = false, |
|
|
|
onConnect, |
|
|
|
onConnect, |
|
|
|
onDisconnect, |
|
|
|
onDisconnect, |
|
|
|
|
|
|
|
onWsClose, |
|
|
|
|
|
|
|
onWsError, |
|
|
|
qualityLevel = 6, |
|
|
|
qualityLevel = 6, |
|
|
|
resizeSession = true, |
|
|
|
resizeSession = true, |
|
|
|
rfb, |
|
|
|
rfb, |
|
|
@ -45,6 +48,23 @@ const rfbConnect: RfbConnectFunction = ({ |
|
|
|
if (onDisconnect) { |
|
|
|
if (onDisconnect) { |
|
|
|
rfb.current.addEventListener('disconnect', onDisconnect); |
|
|
|
rfb.current.addEventListener('disconnect', onDisconnect); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* eslint-disable no-underscore-dangle */ |
|
|
|
|
|
|
|
const ws: typeof Websock = rfb.current._sock; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const socketClose = ws._eventHandlers.close; |
|
|
|
|
|
|
|
const socketError = ws._eventHandlers.error; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ws.on('close', (e?: WebsockCloseEvent) => { |
|
|
|
|
|
|
|
socketClose(e); |
|
|
|
|
|
|
|
onWsClose?.call(null, e); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ws.on('error', (e: Event) => { |
|
|
|
|
|
|
|
socketError(e); |
|
|
|
|
|
|
|
onWsError?.call(null, e); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
/* eslint-enable no-underscore-dangle */ |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const rfbDisconnect: RfbDisconnectFunction = (rfb) => { |
|
|
|
const rfbDisconnect: RfbDisconnectFunction = (rfb) => { |
|
|
@ -58,6 +78,8 @@ const VncDisplay = (props: VncDisplayProps): JSX.Element => { |
|
|
|
const { |
|
|
|
const { |
|
|
|
onConnect, |
|
|
|
onConnect, |
|
|
|
onDisconnect, |
|
|
|
onDisconnect, |
|
|
|
|
|
|
|
onWsClose, |
|
|
|
|
|
|
|
onWsError, |
|
|
|
rfb, |
|
|
|
rfb, |
|
|
|
rfbConnectArgs, |
|
|
|
rfbConnectArgs, |
|
|
|
rfbScreen, |
|
|
|
rfbScreen, |
|
|
@ -73,6 +95,8 @@ const VncDisplay = (props: VncDisplayProps): JSX.Element => { |
|
|
|
const args: RfbConnectArgs = { |
|
|
|
const args: RfbConnectArgs = { |
|
|
|
onConnect, |
|
|
|
onConnect, |
|
|
|
onDisconnect, |
|
|
|
onDisconnect, |
|
|
|
|
|
|
|
onWsClose, |
|
|
|
|
|
|
|
onWsError, |
|
|
|
rfb, |
|
|
|
rfb, |
|
|
|
rfbScreen, |
|
|
|
rfbScreen, |
|
|
|
url, |
|
|
|
url, |
|
|
@ -83,7 +107,16 @@ const VncDisplay = (props: VncDisplayProps): JSX.Element => { |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
rfbDisconnect(rfb); |
|
|
|
rfbDisconnect(rfb); |
|
|
|
} |
|
|
|
} |
|
|
|
}, [initUrl, onConnect, onDisconnect, rfb, rfbConnectArgs, rfbScreen]); |
|
|
|
}, [ |
|
|
|
|
|
|
|
initUrl, |
|
|
|
|
|
|
|
onConnect, |
|
|
|
|
|
|
|
onDisconnect, |
|
|
|
|
|
|
|
onWsClose, |
|
|
|
|
|
|
|
onWsError, |
|
|
|
|
|
|
|
rfb, |
|
|
|
|
|
|
|
rfbConnectArgs, |
|
|
|
|
|
|
|
rfbScreen, |
|
|
|
|
|
|
|
]); |
|
|
|
|
|
|
|
|
|
|
|
useEffect( |
|
|
|
useEffect( |
|
|
|
() => () => { |
|
|
|
() => () => { |
|
|
|