You are reading a single comment by @Injecteer and its replies. Click here to read the full conversation.
  • Ok, I nailed the problem. My code doesn't work with the latest remote version of ws module -> http://www.espruino.com/modules/ws.js.

    Luckily I have a local (slightly modified) version of the ws-module (without the crypto module), and with this one the code from above works as before!

    Gordon, can you please modify the following lines in the ws module?

    function WebSocket(host, options) {
      this.socket = null;
      options = options || {};
      this.host = host;
      this.port = options.port || 80;
      this.protocolVersion = options.protocolVersion || 13;
      this.origin = options.origin || 'Espruino';
      this.keepAlive = options.keepAlive * 1000 || 60000;
      this.masking = options.masking!==undefined ? options.masking : true;
      this.path = options.path || "/";
      this.protocol = options.protocol;
      this.lastData = "";
      this.key = buildKey();
      this.connected = false || options.connected;
      this.headers = options.headers || {};
    }
    
    WebSocket.prototype.handshake = function () {
      var socketHeader = [
        "GET " + this.path + " HTTP/1.1",
        "Host: " + this.host,
        "Upgrade: websocket",
        "Connection: Upgrade",
        "Sec-WebSocket-Key: " + this.key.source,
        "Sec-WebSocket-Version: " + this.protocolVersion,
        "Origin: " + this.origin
      ];
      if (this.protocol)
        socketHeader.push("Sec-WebSocket-Protoco­l: "+this.protocol);
      
      for( var key in this.headers ){
        if( this.headers.hasOwnProperty( key ) )
          socketHeader.push( key + ": " + this.headers[ key ] );
      }
    
      this.socket.write(socketHeader.join("\r\­n")+"\r\n\r\n");
    };
    

    so that I can further test my stuff the new ws code

About

Avatar for Injecteer @Injecteer started