code: function startRecorderServer(config, onReady, onCommand, onEnd){
      var server = http.createServer(function(req, res){
          if(req.url === '/proxy.pac'){
              var wdproxy = config.wdproxy;
              if(wdproxy){
                  res.writeHead(200, { 'Content-Type': 'text/plain' });
                  var pacContent = 'function FindProxyForURL(url, host){if(!/^(127.0.0.1|localhost)$/.test(host))return "PROXY '+config.wdproxy+'";\r\nreturn "DIRECT"}';
                  res.end(pacContent);
              }
              else{
                  res.end('No wdproxy finded!');
              }
          }
      });
      server.listen(0, function(){
          var serverPort = server.address().port;
          console.log('');
          console.log(__('recorder_server_listen_on').green, serverPort);
          onReady(serverPort);
      });
      wsServer = new WebSocketServer({
          httpServer: server,
          autoAcceptConnections: true
      });
      wsServer.on('connect', function(connection) {
          wsConnection = connection;
          sendWsMessage('config', config);
          connection.on('message', function(message) {
              var message = message.utf8Data;
              try{
                  message = JSON.parse(message);
              }
              catch(e){};
              var type = message.type;
              switch(type){
                  case 'saveCmd':
                      onCommand(message.data);
                      break;
                  case 'save':
                      onCommand({
                          cmd: 'end'
                      });
                      setTimeout(function(){
                          wsConnection && wsConnection.close();
                          server.close(function(){
                              onEnd(true);
                          });
                      }, 500);
                      break;
                  case 'end':
                      onCommand({
                          cmd: 'end'
                      });
                      setTimeout(function(){
                          wsConnection && wsConnection.close();
                          server.close(function(){
                              onEnd(false);
                          });
                      }, 500);
                      break;
              }
          });
          connection.on('close', function(reasonCode, description) {
              wsConnection = null;
          });
      });
  }
docs: start recorder server