nornagon / saxi

Tools & library for driving the AxiDraw pen plotter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Some buttons do not work with ws >= 8.0.0

alexrudd2 opened this issue · comments

commented

The current version is ^7.4.6, which is fine.

However, upgrading to ^8.0.0 breaks the Pen Up and Pen Down buttons. Tests don't catch it, and there are no errors in the console. So avoid that upgrade for now. :)

ff5eac is good; 0ea983 is bad

commented

Here's the relevant code:

saxi/src/server.ts

Lines 35 to 40 in b1996eb

wss.on("connection", (ws) => {
clients.push(ws);
ws.on("message", (message) => {
if (typeof message === "string") {
const msg = JSON.parse(message);
switch (msg.c) {

By adding some logging statements, I found that the type of message changed.

ws@8.13.0
received: {"c":"setPenHeight","p":{"height":13650,"rate":1000}}
type object

ws@7.5.9
received: {"c":"setPenHeight","p":{"height":13650,"rate":1000}}
type string

commented

This was websockets/ws@e173423c

  • Text messages and close reasons are no longer decoded to strings. They are
    passed as Buffers to the listeners of their respective events. The listeners
    of the 'message' event now take a boolean argument specifying whether or not
    the message is binary (e173423).

    Existing code can be migrated by decoding the buffer explicitly.

    websocket.on('message', function message(data, isBinary) {
      const message = isBinary ? data : data.toString();
      // Continue as before.
    });
    
    websocket.on('close', function close(code, data) {
      const reason = data.toString();
      // Continue as before.
    });