Flotype / now

NowJS makes it easy to build real-time web apps using JavaScript
http://www.nowjs.com
MIT License
1.91k stars 175 forks source link

IE8 Socket.IO Bug? #74

Closed ghost closed 13 years ago

ghost commented 13 years ago

When now.js(v0.5.3) is done loading in IE8, I get this error:

Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)
Timestamp: Tue, 26 Apr 2011 11:08:14 UTC

Message: 'io' is undefined
Line: 911
Char: 5
Code: 0
URI: http://192.168.1.11:9000/nowjs/now.js

Any ideas how to fix that?

Thanks!

ericz commented 13 years ago

Hi LawSimply,

I couldn't reproduce the bug on IE8 or 7. If you open the debug window (F12) and click the script tab, are there any additional error messages printed?

nsmeta commented 13 years ago

ericz, thanks for the reply!

It doesn't show any additional errors but it points to this code:

(function(){
  var dependencies = ["/socket.io/socket.io.js"];
  var dependenciesLoaded = 0;

  var nowJSScriptLoaded = function(){
    dependenciesLoaded++;
    if(dependenciesLoaded !== dependencies.length) {
      return;
    }

    nowUtil.debug("isIE", isIE);

    socket = new io.Socket('localhost', {port: 9000}); // According to IE, this line here is the cause.
    socket.connect();
    socket.on('connect', function(){
      var client = socket;
      client.sessionId = SERVER_ID;
      nowLib.handleNewConnection(client);
      nowCore.emit('connect');
    });
  };

  for(var i in dependencies){
    if(dependencies.hasOwnProperty(i)){
      var fileref=document.createElement('script');
      fileref.setAttribute("type","text/javascript");
      fileref.setAttribute("src", "http://localhost:9000"+dependencies[i]);
      fileref.onload = nowJSScriptLoaded;
      if(isIE) {
        fileref.onreadystatechange = function () {
          if(fileref.readyState === "loaded") {
            nowJSScriptLoaded();
          }
        };
      }
      document.getElementsByTagName("head")[0].appendChild(fileref);
    }
  }
}());
nsmeta commented 13 years ago

Alright. So I've added the script tag before including now.js, pointing to socket.io:

<script type="text/javascript" src="/socket.io/socket.io.js"></script>

And the error is gone.

UPDATE: It seems that now.ready event won't be fired, even after adding socket.io explicitly. Though I have solved this problem for myself by replacing those functions with old ajax calls(at this time, I was using now.js for remote function calling, not for realtime stuff anyways). I guess, if no one else is having this problem then there could be something wrong with my code. Anyway. I appreciate your help and Now.js is what makes me want to use Node.js even more. Keep up the awesome work! -- LawSimply

ericz commented 13 years ago

Thanks man but this is very strange. I can't seem to replicate it unfortunately

dvv commented 13 years ago

Wonder why dependencies being an array, we iterate over it via for in. This can be the clue

ericz commented 13 years ago

@dvv I have fixed that in latest master. Not sure if it'll fix original issue (possible, if array prototype was being extended)