fix(xo-lite/console): get console URL from XAPI

This commit is contained in:
Pierre Donias
2021-03-09 14:03:56 +01:00
parent dbb3f74ab0
commit 3a0af4e7e0
2 changed files with 30 additions and 10 deletions

View File

@@ -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'],
})
},
},
}),

View File

@@ -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)
}
}