最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Integrate guacamole-common-js in my react application - Stack Overflow

programmeradmin2浏览0评论

I wanna use guacamole-mon-js in my React application and already set up guaca in docker and guacamole client by guacamole-lite. I have successfully seen the view from plain HTML and javascript. However, I could not render it in React JSX. Here is my code:

import Guacamole from "guacamole-mon-js";

let guaca = new Guacamole.Client(new Guacamole.WebSocketTunnel(webSocketFullUrl));
guaca.onerror = function (error) {
    alert(error);
};
guaca.connect();

// Disconnect on close
window.onunload = function () {
     guaca.disconnect();
}

let display = document.getElementById("display");
display.appendChild(guaca.getDisplay().getElement());

And to render it:

React.createElement("div", {id, "display"})

I also try with Ref like follow but still not works:


constructor(props) {
    super(props);
    this.displayRef = React.createRef();
    this.guacaRef = React.createRef();
}


this.guacaRef.current = new Guacamole.Client(new Guacamole.WebSocketTunnel(webSocketFullUrl));
this.guacaRef.current.onerror = function (error) {
    alert(error);
};
this.guacaRef.current.connect();

// Disconnect on close
window.onunload = function () {
    this.guacaRef.current.disconnect();
}

this.displayRef.current.appendChild(this.guacaRef.current.getDisplay().getElement());

To render it:

 <div ref={displayRef}/>

I'm new to it and any help will be appreciated.

I wanna use guacamole-mon-js in my React application and already set up guaca in docker and guacamole client by guacamole-lite. I have successfully seen the view from plain HTML and javascript. However, I could not render it in React JSX. Here is my code:

import Guacamole from "guacamole-mon-js";

let guaca = new Guacamole.Client(new Guacamole.WebSocketTunnel(webSocketFullUrl));
guaca.onerror = function (error) {
    alert(error);
};
guaca.connect();

// Disconnect on close
window.onunload = function () {
     guaca.disconnect();
}

let display = document.getElementById("display");
display.appendChild(guaca.getDisplay().getElement());

And to render it:

React.createElement("div", {id, "display"})

I also try with Ref like follow but still not works:


constructor(props) {
    super(props);
    this.displayRef = React.createRef();
    this.guacaRef = React.createRef();
}


this.guacaRef.current = new Guacamole.Client(new Guacamole.WebSocketTunnel(webSocketFullUrl));
this.guacaRef.current.onerror = function (error) {
    alert(error);
};
this.guacaRef.current.connect();

// Disconnect on close
window.onunload = function () {
    this.guacaRef.current.disconnect();
}

this.displayRef.current.appendChild(this.guacaRef.current.getDisplay().getElement());

To render it:

 <div ref={displayRef}/>

I'm new to it and any help will be appreciated.

Share Improve this question asked May 10, 2020 at 17:10 IvanaIvana 1152 silver badges11 bronze badges 1
  • Could you please point me towards correct direction for getting - webSocketFullUrl Using - guacamole-lite with VNC – Pawan Singh Commented Mar 8, 2022 at 11:17
Add a ment  | 

2 Answers 2

Reset to default 4

Seems like the reason is kind of stupid... the default style for guacamole canvas rendering is {z-index: -1}. When adding up to 1, it renders properly.

As @Ivana stated, necessary to change z-index

const element = guaca.getDisplay().getElement();
const canvas = $(element).find(`canvas`);
for(let c of canvas) {
  $(c).css(`z-index`, 10)
};
发布评论

评论列表(0)

  1. 暂无评论