Using Relay and/or Running the WebIDE locally

Posted on
  • Hi,

    I got my Puck.JS today and wanted to get right into programming without waiting for my bluetooth dongle to arrive. So I tried to use the relay function.

    Unfortunately I could not get it to work though. It always stopped with the message "Starting Websocket connection" on the phone. I tried it with my Nexus 5X on Android 7.1.1 and Chrome 57.0.2987.132.

    I then tried to start up the server on my own computer to potentially see what went wrong node server.js did not server anything under /relay and I also read that it only supports one session at a time, which would probably cause problems with the relaying anyways.

    With the python server twisted I managed to server the root directory with ssl including the /relay subdirectory using twistd -no web --https=4444 --path=.. But I could not figure out if there is a websocket relay server included or if there is a default one that I should be running.

    I also tried setting var WS_HOST = 'wss://espruino.com:8443'; with the UI hosted from my computer. With that and the following code added to relay.js, I got the output Encountered an error: {"isTrusted": true}. Which didn't yield any additional insights and might just be due to Cross-Origin restrictions.

    socket.addEventListener('error', function (error) {
      term("Encountered an error: "+JSON.stringify(error));
    });
    

    Any pointers on how to properly run a local setup or maybe get the relay on espruino.com working are much appreciated.

    On a related note: @Gordon Did you try or think about using peer-to-peer communication using WebRTC instead of websockets for the communication between the browsers? That way there might not be a need for a websocket server.

  • Hi,

    I'm afraid the relay doesn't work offline (the relay isn't part of the server) - you'd need to use the relay that's on the Espruino website. It's very hard to host locally because you'll need to serve the IDE and also WebSockets via HTTPS with a certified key.

    I think I found the problem and fixed it now, so could you give it a try again at the normal addresses? The SSL keys needed to be updated whenever the letsencrypt keys were renewed.

    My understanding with WebRTC was that you still need an online service to broker the connection between the two clients? It'd be great if it could be done without that though, or with a third party. Have you used it?

  • Thank you for fixing the relay. I was able to upload a scripts and communicate with the Puck through it successfully. I might still, out of curiosity, try to set up a working version on my local machine using a self signed certificate.

    In regards to WebRTC. You have to broker the connection yes, but this is (theoretically) possible, without using a dedicated server. There is a demo which just provides you with the signaling payload and you can use what ever way you want to transfer it to the other client. Based upon that someone created a demo for signaling via QR-Code, which unfortunately doesn't work for me.

    But even if the websocket connection is still used for the signaling, it might be an option to do the rest of the communication via p2p. The benefit could be faster communication with the Puck and it would not require additional communication with the server, after the channel is created, so it could provide more stability if you want to use the relay somewhere, where you don't have a fast or stable internet connection.

  • Hmm, WebRTC sounds like it would be a great way to, for example, stream sensor values to a client (f.e. accelerometer from Espruino to Chrome tab).

    Do you guys have WebRTC running in Espruino?

  • No - I think you might be the first person to mention it. I don't think you'd find it any faster than something like Websockets though?

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Using Relay and/or Running the WebIDE locally

Posted by Avatar for cryptobias @cryptobias

Actions