openpixelcontrol
openpixelcontrol copied to clipboard
add web-socket support for gl_server?
Is this possible? It would make debugging/making front end webpage stuff a lot easier.
Agreed! I'm trying this now...I'm getting "Client connected" from the gl_server, so that part works. Upon further investigation I see that the sockets used by gl_server may see the initial handshake, but won't be able to do the special websockets stuff without a supporting library.
Javascript:
var ws = new WebSocket("ws://localhost:7890");
ws.onopen = function () {
var packet = new Uint8Array([ 0,0,0,9, 255,0,0, 0,255,0, 0,0,255 ]);
ws.send(packet.buffer);
};
Actually, I got this working with the help of websockify! It does exactly what's missing: acts as a websocket server for the browser, but sends the traffic to the standard socket the gl_server expects.
/path/to/websockify> ./websockify.py 7890 localhost:7891
/path/to/openpixelcontrol> bin/gl_server -l layouts/mylayout.json -p 7891
Two gotchas:
- websockify needs the second arg of the WebSocket() constructor to be
['binary', 'base64']. Fine for gl_server, but fadecandy's server (which I'm using in "production") can only handle['fcserver']. - Also fadecandy-only: OPC needs the 3rd and 4th bytes to define packet length, but fadecandy doesn't think that's necessary so it outputs a NOTICE to the log when they're non-zero. Appears to work fine, though.
cc @scanlime