-
Notifications
You must be signed in to change notification settings - Fork 354
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(VncConsole): Introduce VncConsole component #288
Merged
+387
−485
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,20 @@ | ||
.vnc-console { | ||
padding-right: 0px; | ||
padding-left: 0px; | ||
|
||
.vnc-console-connecting { | ||
background-color: @color-pf-green; | ||
} | ||
.vnc-console-disconnected { | ||
background-color: @color-pf-red; | ||
} | ||
.toolbar-pf { | ||
border-bottom: none; | ||
} | ||
.toolbar-pf-results { | ||
padding-top: 10px; | ||
} | ||
.toolbar-pf-action-right .dropdown-menu { | ||
min-width: 102px; /* avoid overflow if DropdownButton is used under Toolbar.RightContent */ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { DropdownButton, MenuItem, noop } from 'patternfly-react'; | ||
|
||
const VncActions = ({ textSendShortcut, textCtrlAltDel, onCtrlAltDel }) => ( | ||
<DropdownButton | ||
bsStyle="default" | ||
title={textSendShortcut} | ||
id="console-send-shortcut" | ||
onClick={noop} | ||
> | ||
<MenuItem eventKey="1" onClick={onCtrlAltDel}> | ||
{textCtrlAltDel} | ||
</MenuItem> | ||
</DropdownButton> | ||
); | ||
|
||
VncActions.propTypes = { | ||
onCtrlAltDel: PropTypes.func, | ||
|
||
textCtrlAltDel: PropTypes.string, | ||
textSendShortcut: PropTypes.string | ||
}; | ||
|
||
VncActions.defaultProps = { | ||
onCtrlAltDel: noop, | ||
|
||
textCtrlAltDel: 'Ctrl+Alt+Del', | ||
textSendShortcut: 'Send Key' | ||
}; | ||
|
||
export default VncActions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* eslint-disable import/no-extraneous-dependencies */ | ||
import React from 'react'; | ||
import { shallow, mount } from 'enzyme'; | ||
import VncActions from './VncActions'; | ||
|
||
test('placeholder render test', () => { | ||
const view = shallow(<VncActions />); | ||
expect(view).toMatchSnapshot(); | ||
}); | ||
|
||
test('VncActions renders correctly component hierarchy', () => { | ||
const view = shallow( | ||
<VncActions | ||
textSendShortcut="My Send Shortcut description" | ||
textCtrlAltDel="foobar" | ||
onCtrlAltDel={jest.fn()} | ||
/> | ||
); | ||
expect(view).toMatchSnapshot(); | ||
}); | ||
|
||
test('VncActions renders correctly html', () => { | ||
const view = shallow( | ||
<VncActions | ||
textSendShortcut="My Send Shortcut description" | ||
textCtrlAltDel="foobar" | ||
onCtrlAltDel={jest.fn()} | ||
/> | ||
); | ||
expect(view.html()).toMatchSnapshot(); | ||
}); | ||
|
||
test('VncActions calls ctrl+alt+del action', () => { | ||
const onCtrlAltDel = jest.fn(); | ||
|
||
const wrapper = mount( | ||
<VncActions | ||
textSendShortcut="My Send Shortcut description" | ||
textCtrlAltDel="CtrlAltDel" | ||
onCtrlAltDel={onCtrlAltDel} | ||
/> | ||
); | ||
|
||
const button = wrapper.find('a[role="menuitem"]'); | ||
expect(button).toHaveLength(1); | ||
button.simulate('click'); | ||
expect(onCtrlAltDel).toHaveBeenCalledTimes(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,196 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
const propTypes = {}; | ||
const defaultProps = {}; | ||
import * as NovncLog from '@novnc/novnc/core/util/logging'; | ||
import RFB from '@novnc/novnc/core/rfb'; | ||
|
||
const VncConsole = () => <div>VncConsole</div>; | ||
import classNames from 'classnames'; | ||
import { Toolbar, noop } from 'patternfly-react'; | ||
|
||
VncConsole.propTypes = propTypes; | ||
VncConsole.defaultProps = defaultProps; | ||
import VncActions from './VncActions'; | ||
|
||
const CONNECTING = 'connecting'; | ||
const CONNECTED = 'connected'; | ||
const DISCONNECTED = 'disconnected'; | ||
|
||
/* eslint no-console: ["warn", { allow: ["error"] }] */ | ||
|
||
class VncConsole extends React.Component { | ||
state = { status: CONNECTING }; | ||
|
||
componentDidMount() { | ||
const { | ||
host, | ||
port, | ||
path, | ||
encrypt, | ||
resizeSession, | ||
viewOnly, | ||
shared, | ||
credentials, | ||
repeaterID, | ||
vncLogging, | ||
onInitFailed | ||
} = this.props; | ||
|
||
NovncLog.init_logging(vncLogging); | ||
try { | ||
const protocol = encrypt ? 'wss' : 'ws'; | ||
const url = `${protocol}://${host}:${port}/${path}`; | ||
|
||
const options = { | ||
repeaterID, | ||
shared, | ||
credentials | ||
}; | ||
|
||
this.rfb = new RFB(this.novncElem, url, options); | ||
this.rfb.addEventListener('connect', this.onConnected); | ||
this.rfb.addEventListener('disconnect', this.onDisconnected); | ||
this.rfb.addEventListener('securityfailure', this.onSecurityFailure); | ||
this.rfb.viewOnly = viewOnly; | ||
this.rfb.scaleViewport = false; // if the remote session is smaller than HTML container, the view will be centered | ||
this.rfb.resizeSession = resizeSession; | ||
} catch (e) { | ||
onInitFailed && onInitFailed(e); | ||
this.rfb = undefined; | ||
} | ||
} | ||
|
||
onConnected = () => { | ||
this.setState({ status: CONNECTED }); | ||
}; | ||
|
||
onCtrlAltDel = e => { | ||
if (this.rfb) { | ||
this.rfb.sendCtrlAltDel(); | ||
this.focusVnc(e); | ||
} | ||
}; | ||
|
||
onDisconnected = e => { | ||
this.setState({ status: DISCONNECTED }); | ||
this.props.onDisconnected(e); | ||
}; | ||
|
||
onSecurityFailure = e => { | ||
this.setState({ status: DISCONNECTED }); | ||
this.props.onSecurityFailure(e); | ||
}; | ||
|
||
setNovncElem = e => { | ||
this.novncElem = e; | ||
}; | ||
|
||
focusVnc = e => { | ||
if (e && e.target && e.target.blur) { | ||
e.target.blur(); | ||
} | ||
this.novncElem && this.novncElem.focus(); | ||
}; | ||
|
||
render() { | ||
const { | ||
textDisconnected, | ||
textConnecting, | ||
textSendShortcut, | ||
textCtrlAltDel | ||
} = this.props; | ||
|
||
let status = null; | ||
let rightContent = null; | ||
switch (this.state.status) { | ||
case CONNECTED: | ||
rightContent = ( | ||
<Toolbar.RightContent> | ||
<VncActions | ||
onCtrlAltDel={this.onCtrlAltDel} | ||
textSendShortcut={textSendShortcut} | ||
textCtrlAltDel={textCtrlAltDel} | ||
/> | ||
</Toolbar.RightContent> | ||
); | ||
break; | ||
case DISCONNECTED: | ||
status = ( | ||
<div className="vnc-console-disconnected">{textDisconnected}</div> | ||
); | ||
break; | ||
case CONNECTING: | ||
default: | ||
status = <div className="vnc-console-connecting">{textConnecting}</div>; | ||
} | ||
|
||
if (!this.novncStaticComponent) { | ||
// create just once | ||
this.novncStaticComponent = <div ref={this.setNovncElem} />; | ||
} | ||
|
||
return ( | ||
<Toolbar className={classNames('vnc-console', this.props.topClassName)}> | ||
{this.props.children} | ||
{rightContent} | ||
<Toolbar.Results> | ||
{status} | ||
{this.novncStaticComponent} | ||
</Toolbar.Results> | ||
</Toolbar> | ||
); | ||
} | ||
} | ||
|
||
VncConsole.propTypes = { | ||
children: PropTypes.node /** Children nodes */, | ||
|
||
host: PropTypes.string.isRequired /** FQDN or IP to connect to */, | ||
port: PropTypes.string /** TCP Port */, | ||
path: PropTypes.string /** host:port/path */, | ||
encrypt: | ||
PropTypes.bool /** For all following, see: https://github.com/novnc/noVNC/blob/master/docs/API.md */, | ||
resizeSession: | ||
PropTypes.bool /** Change remote session size according to local HTML container */, | ||
viewOnly: PropTypes.bool, | ||
shared: PropTypes.bool, | ||
credentials: | ||
PropTypes.object /** { username: '', password: '', target: ''} */, | ||
repeaterID: PropTypes.string, | ||
vncLogging: PropTypes.string /** log-level for noVNC */, | ||
|
||
topClassName: PropTypes.string /** Enable customization */, | ||
|
||
onDisconnected: PropTypes.func /** Callback. VNC server disconnected. */, | ||
onInitFailed: PropTypes.func /** Initialization of RFB failed */, | ||
onSecurityFailure: PropTypes.func /** Handshake failed */, | ||
|
||
textConnecting: PropTypes.string /** For localization */, | ||
textDisconnected: PropTypes.string, | ||
textSendShortcut: PropTypes.string, | ||
textCtrlAltDel: PropTypes.string | ||
}; | ||
|
||
VncConsole.defaultProps = { | ||
children: null, | ||
|
||
port: '80', | ||
path: '', | ||
encrypt: false, | ||
resizeSession: true, | ||
viewOnly: false, | ||
shared: false, | ||
credentials: undefined, | ||
repeaterID: '', | ||
vncLogging: 'warn', | ||
|
||
topClassName: '', | ||
|
||
onDisconnected: noop, | ||
onInitFailed: noop, | ||
onSecurityFailure: noop, | ||
|
||
textConnecting: 'Connecting', | ||
textDisconnected: 'Disconnected', | ||
textSendShortcut: undefined /** Default value defined in VncActions */, | ||
textCtrlAltDel: undefined /** Default value defined in VncActions */ | ||
}; | ||
|
||
export default VncConsole; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this can be moved to
packages/console/package.json
dependencies now i believe.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry - this is only used in tests. Nevermind ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, jest tests are configured once per project