joewalnes / reconnecting-websocket

A small decorator for the JavaScript WebSocket API that automatically reconnects
MIT License
4.21k stars 968 forks source link

No support IE. #29

Open tjl1979 opened 9 years ago

tjl1979 commented 9 years ago

IE don't support addEventListener. IE use attachEvent.

How to fixed?

joewalnes commented 9 years ago

All versions of IE that have WebSockets also support addEventListener. Which version of IE are you seeing the issue with? Can you post the error message.

JamesThorpe commented 9 years ago

I'm also seeing an error in IE (11) - I'll update with the specific error message later, but it was to do with firing custom events on the internally created div element

JamesThorpe commented 9 years ago

It turns out you can't create new events in IE using:

new Event('connecting')

Doing so throws "Object doesn't support this action". I've moved beyond the connecting part to the same error in onopen by replacing the event code in connect with:

var ev = document.createEvent("Event");
ev.initEvent('connecting', false, false);
eventTarget.dispatchEvent(ev);

Not sure at this point if it's cross browser (probably not knowing IE) or if browser detection will be needed to run the correct code.

JamesThorpe commented 9 years ago

Looks like it should be ok in other browsers, based on this and this SO answer which says:

    if(document.createEvent){
        //...
    }else if(document.createEventObject){// IE < 9
        //...
    }

implying that createEvent is fine in IE9 and above, and other browsers. As you've commented above, this is only targetted versions of IE that support websockets, so this should be fine to use across the board I think

JamesThorpe commented 9 years ago

Ok, glad I checked before forking and attempting a fix - seems there's already a pull request for exactly this issue :)

joewalnes commented 9 years ago

Just merged that pull request