muaz-khan / DetectRTC

DetectRTC is a tiny JavaScript library that can be used to detect WebRTC features e.g. system having speakers, microphone or webcam, screen capturing is supported, number of audio/video devices etc. https://www.webrtc-experiment.com/DetectRTC/
https://www.webrtc-experiment.com/DetectRTC/
MIT License
664 stars 163 forks source link

websocket error on firefox #90

Closed emreokutan closed 4 years ago

emreokutan commented 4 years ago

With Firefox 77.0.1 (64 bit) when i check websocket support with DetectRTC.checkWebSocketsSupport when disconnecting from websocket on websocket.onmessage in DetectRTC.js file with using websocket.close firefox throws an error saying that:

TypeError: websocket.close is not a function

So the socket connection stays active.

When i tested the behaviour on the same error happens and the reason is firefox WebSocket constructer returns a different referance to the socket object. It is like : Object { websocket: WebSocket, listeners: {…} } but other browsers returns: just a single WebSocket instance.

so on firefox there is no websocket.close but there is websocket.websocket.close. so i changed the code in onmessage function like this:

            if(websocket.close)
                websocket.close();
            else if(websocket.websocket && websocket.websocket.close)
                websocket.websocket.close();

now it is ok to disconnect.

emreokutan commented 4 years ago

well i am not sure about what happened but i have reinstalled the exact same version of firefox and the behaviour has changed! Now the returned websocket instance from constructer is just o single websocket instance and works fine without any changes.