Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Console.js does not show the output from commands #41

Open
KennyFig opened this issue Sep 10, 2023 · 3 comments
Open

Console.js does not show the output from commands #41

KennyFig opened this issue Sep 10, 2023 · 3 comments

Comments

@KennyFig
Copy link

I've noticed that there's an issue with console.js where it doesn't read the new way opensim handles the responses

@MelanieT
Copy link
Collaborator

The console protocol is fatally flawed, I should never have tried to shoehorn a console into plain http. The better way available now would be to use websockets.

@KennyFig
Copy link
Author

I do have a temporary fix for this issue but am struggling trying to push my commit for a pull request.

@KennyFig
Copy link
Author

KennyFig commented Sep 10, 2023

It's an issue with the ReadResponses function. My band-aid fix can be seen below.

function ReadResponses(console, xml, status) {
  ShowStatus(console, status);
  if (xml) {
    Output(TRACE, "[ReadResponses:".concat(console.name, "] Processing response"));
    elements = xml.getElementsByTagName('Line');
    if (elements) {
      ScrollBottom.Save(console, element.MESSAGES);
      UpdateScrollback(elements.length);
      for (var i = 0; i < elements.length; ++i) {
        var lineNode = elements[i];
        //var lines = lineNode.firstChild.nodeValue.split('\n');
        //var parts = lines.shift().split(':');
        var parts;
        var line;
        var level = xml.getElementsByTagName('Level');
        if(lineNode.firstChild != null){
          parts = lineNode.firstChild.nodeValue.split(':');
          line = parts.join(':');
          if (line.substr(1, 2) == '++') { // Prompt
            if (line.substr(0, 1) == '+') {
              // Normal prompt is used as title
              SetTitle(console, line.substr(3));
            }
            else {
              // Interactive prompt for requesting input
              ShowPrompt(console, line.substr(3));
            }
            UpdateScrollback(1); Output(TRACE, "[ReadResponses:".concat(console.name, "] '", line, "'"), true);
            continue;
          }
          else if (line.length >= 1024) {
            UpdateScrollback(1); Output(TRACE, "[ReadResponses:".concat(console.name, "] Long line with ", line.length, " bytes"), true);
          }
          var matches = line.match(LinePattern);
          //line = new Array();
          if (matches) {
            line = new Array();
            // Timestamp
            line[0] = document.createTextNode(matches[1]);
            // Module name
            line[1] = document.createElement('span');
            line[1].setAttribute('style', 'color:' + Colors.GetForString(matches[2]));
            line[1].appendChild(document.createTextNode(matches[2]));
            // Colon & whitespace
            line[2] = document.createTextNode(matches[3]);
            // Message
            line[3] = document.createElement('span');
            line[3].setAttribute('class', level);
            line[3].appendChild(document.createTextNode(matches[4]));
          }
        }
        else{
          parts = lineNode;
          line = parts;
        }
        if (console.prompt)
          HidePrompt(console, true);
        //if (lines.length)
        //  UpdateScrollback(lines.length);
        //for (var l in lines)
        //  line.push(document.createTextNode(lines[l]));
        Output(MSG + " " + console.name, line, true);
      }
      ScrollBottom.Restore(console, element.MESSAGES);
    }
  }
  if (console.sessionId) {
    try {
      void AjaxSend(console.serviceURL.concat('/ReadResponses/', console.sessionId, '/'), '',
        function(xml, status) { ReadResponses(console, xml, status); },
        console.consoleRequest);
    }
    catch (e) {
      NoConnection(console);
    }          
  }
  if (wifi && (console.name == ID.DEFAULT_CONSOLE))
    if (++wifi.heartbeatCounter >= wifi.HEARTBEAT_THRESHOLD) {
      // Keep session active
      wifi.heartbeatCounter = 0;
      Output(TRACE, "[ReadResponses:".concat(console.name, "] Wifi Heartbeat"));
      void AjaxSend(location.protocol.concat('//', location.host, location.pathname, 'heartbeat/', location.search));
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants