How to setup sockets for a web-based terminal

Viewed 54

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?

1 Answers

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");
Related