简体   繁体   中英

How to setup sockets for a web-based terminal

I'm currently working on a project and want to implement a web-based terminal in the node-red-dashboard. I've already set up xterm and wetty. The problem I got is my small knowledge about sockets. Currently I'm trying to link wetty with xterm but it wont work.

<link rel="stylesheet" href="/xterm/css/xterm.css" />
<script src="/xterm/lib/xterm.js"></script>
<script src="/xterm-addon-attach/lib/xterm-addon-attach.js"></script>
<div id="terminal"></div>
<script>
    const socketio = context.global.get("socket.io");
        //const sockett = new nett.Socket('3001');
    const socket1 = io("ws://localhost:3001");
    var term = new Terminal();
    var attachAddon = new AttachAddon(socket1);
    term.loadAddon(attachAddon);
    term.open(document.getElementById('terminal'));
    term.write('Raspberry $ ');
</script>

Wetty is hosted on port 3001 and I want to link it to a node at the same machine. What am I doing wrong?

You can't access the context from within a NR Dashboard template node like that, because it's running in the browser not the NR backend.

And since the NR Dashboard already uses Socket.IO there should be no need to try and load it again.

Delete the following line:

const socketio = context.global.get("socket.io");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM