]>
Commit | Line | Data |
---|---|---|
5f8b5df0 DM |
1 | Ext.define('PVE.noVncConsole', { |
2 | extend: 'Ext.panel.Panel', | |
3 | alias: 'widget.pveNoVncConsole', | |
4 | ||
5 | nodename: undefined, | |
5f8b5df0 | 6 | vmid: undefined, |
b945c7c1 TM |
7 | cmd: undefined, |
8 | ||
9 | consoleType: undefined, // lxc, kvm, shell, cmd | |
9f02743e DC |
10 | xtermjs: false, |
11 | ||
78bfd48a | 12 | layout: 'fit', |
c7218ab3 | 13 | border: false, |
b135fd08 | 14 | |
78bfd48a | 15 | initComponent: function() { |
5f8b5df0 DM |
16 | var me = this; |
17 | ||
18 | if (!me.nodename) { | |
19 | throw "no node name specified"; | |
20 | } | |
21 | ||
22 | if (!me.consoleType) { | |
23 | throw "no console type specified"; | |
24 | } | |
25 | ||
b945c7c1 | 26 | if (!me.vmid && me.consoleType !== 'shell' && me.consoleType !== 'cmd') { |
5f8b5df0 DM |
27 | throw "no VM ID specified"; |
28 | } | |
b135fd08 | 29 | |
5f8b5df0 DM |
30 | // always use same iframe, to avoid running several noVnc clients |
31 | // at same time (to avoid performance problems) | |
8058410f | 32 | var box = Ext.create('Ext.ux.IFrame', { itemid: "vncconsole" }); |
5f8b5df0 | 33 | |
9f02743e | 34 | var type = me.xtermjs ? 'xtermjs' : 'novnc'; |
5f8b5df0 | 35 | Ext.apply(me, { |
5f8b5df0 DM |
36 | items: box, |
37 | listeners: { | |
c7218ab3 | 38 | activate: function() { |
9199d171 TL |
39 | let sp = Ext.state.Manager.getProvider(); |
40 | if (Ext.isFunction(me.beforeLoad)) { | |
41 | me.beforeLoad(); | |
42 | } | |
43 | let queryDict = { | |
b945c7c1 TM |
44 | console: me.consoleType, // kvm, lxc, upgrade or shell |
45 | vmid: me.vmid, | |
46 | node: me.nodename, | |
47 | cmd: me.cmd, | |
9199d171 | 48 | 'cmd-opts': me.cmdOpts, |
635cc133 | 49 | resize: sp.get('novnc-scaling', 'scale'), |
b945c7c1 TM |
50 | }; |
51 | queryDict[type] = 1; | |
52 | PVE.Utils.cleanEmptyObjectKeys(queryDict); | |
53 | var url = '/?' + Ext.Object.toQueryString(queryDict); | |
5f8b5df0 | 54 | box.load(url); |
f6710aac TL |
55 | }, |
56 | }, | |
b135fd08 | 57 | }); |
5f8b5df0 DM |
58 | |
59 | me.callParent(); | |
ff605c35 TL |
60 | |
61 | me.on('afterrender', function() { | |
62 | me.focus(); | |
63 | }); | |
c17ecca2 SR |
64 | }, |
65 | ||
5d7c0d97 | 66 | reload: function() { |
c17ecca2 | 67 | // reload IFrame content to forcibly reconnect VNC/xterm.js to VM |
5d7c0d97 | 68 | var box = this.down('[itemid=vncconsole]'); |
c17ecca2 | 69 | box.getWin().location.reload(); |
f6710aac | 70 | }, |
5f8b5df0 DM |
71 | }); |
72 |