jimmywarting / wemo-client

JavaScript client library for controlling and subscribing to Wemo Devices
MIT License
132 stars 40 forks source link

Ignore invalid responses #41

Closed gregbradley closed 8 years ago

gregbradley commented 8 years ago

I was getting some errors discovery devices. Found a device that was responding with unexpected JSON syntax (see below). As this is not a Belkin device just going to ignore rather than add additional handling.

{
    "n1:root": {
        "$": {
            "xmlns:n1": "urn:schemas-upnp-org:device-1-0"
        },
        "specVersion": {
            "major": "1",
            "minor": "0"
        },
        "device": {
            "deviceType": "urn:roku-com:device:player:1-0",
            "friendlyName": "Mac mini",
            "manufacturer": "Roku",
            "manufacturerURL": "http://www.roku.com",
            "modelDescription": "Roku Streaming Player Network Media",
            "modelName": "Roku 3",
            "modelNumber": "4200X",
            "modelURL": "http://www.roku.com",
            "serialNumber": "12345678900",
            "UDN": "uuid:43a4d300-59b7-4ef7-b75a-2d9e24301688",
            "serviceList": {
                "service": {
                    "serviceType": "urn:roku-com:service:ecp:1",
                    "serviceId": "urn:roku-com:serviceId:ecp1-0",
                    "controlURL": "",
                    "eventSubURL": "",
                    "SCPDURL": "ecp_SCPD.xml"
                }
            }
        }
    }
}
codecov-io commented 8 years ago

Current coverage is 89.96% (diff: 100%)

Merging #41 into master will not change coverage

@@             master        #41   diff @@
==========================================
  Files             2          2          
  Lines           269        269          
  Methods          57         57          
  Messages          0          0          
  Branches         43         43          
==========================================
  Hits            242        242          
  Misses           27         27          
  Partials          0          0          

Powered by Codecov. Last update 6b55226...f973204

timonreinhard commented 8 years ago

While this is good safeguard in general, I'd prefer filtering out such unwanted devices in https://github.com/timonreinhard/wemo-client/blob/master/index.js#L57 already to address the root cause. Any chance you can check msg to come from a Wemo device?

timonreinhard commented 8 years ago

I addressed your issue by filtering the SSDP responses (aea39838007af278405635adc60c40e8ef5c06b0) so with current master you shouldn't run again in a situation where the client tries to connect to your Roku player or anything else that isn't a Wemo.