fix(xo-lite/console): get console URL from XAPI
This commit is contained in:
@@ -12,17 +12,26 @@ const Console = [
|
||||
container: React.createRef(),
|
||||
}),
|
||||
effects: {
|
||||
initialize: function (this: EffectContext) {
|
||||
initialize: async function (this: EffectContext) {
|
||||
const { vmId } = this.props
|
||||
const { objectsByType, xapi } = this.state
|
||||
const consoles = objectsByType
|
||||
.get('VM')
|
||||
.get(vmId)
|
||||
.$consoles.filter((vmConsole: { protocol: string }) => vmConsole.protocol === 'rfb')
|
||||
|
||||
if (consoles.length === 0) {
|
||||
throw new Error('Could not find VM console')
|
||||
}
|
||||
|
||||
const url = new URL(consoles[0].location)
|
||||
url.protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:'
|
||||
url.searchParams.set('session_id', xapi.sessionId)
|
||||
|
||||
// eslint-disable-next-line no-new
|
||||
new RFB(
|
||||
this.state.container.current,
|
||||
`ws://${this.state.xapiHostname}/console?uuid=${this.props.vmId}&session_id=${
|
||||
this.state.xapi.sessionId
|
||||
}`,
|
||||
{
|
||||
wsProtocols: ['binary'],
|
||||
}
|
||||
)
|
||||
new RFB(this.state.container.current, url, {
|
||||
wsProtocols: ['binary'],
|
||||
})
|
||||
},
|
||||
},
|
||||
}),
|
||||
|
||||
@@ -113,4 +113,15 @@ export default class XapiConnection {
|
||||
console.error(err)
|
||||
}
|
||||
}
|
||||
|
||||
call(method: string, ...args: string[]): void {
|
||||
const { _xapi, connected } = this
|
||||
if (!connected) {
|
||||
throw new Error('Not connected to XAPI')
|
||||
}
|
||||
|
||||
console.log('args:', args)
|
||||
console.log('method:', method)
|
||||
return _xapi.call(method, ...args)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user