Module: Roku::Discover
- Defined in:
- lib/roku/discover.rb
Defined Under Namespace
Classes: DeviceNotFound
Constant Summary collapse
- MULTICAST_ADDR =
'239.255.255.250'.freeze
- BIND_ADDR =
'0.0.0.0'.freeze
- PORT =
1900
- REQUEST =
"M-SEARCH * HTTP/1.1\n" \ "Host: 239.255.255.250:1900\n" \ "Man: \"ssdp:discover\"\n" \ "ST: roku:ecp\n\n".freeze
Class Method Summary collapse
Class Method Details
.await_response ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/roku/discover.rb', line 34 def await_response Timeout.timeout(10) do loop do response, = socket.recvfrom(1024) if response.include?('LOCATION') && response.include?('200 OK') return response end end end end |
.search ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/roku/discover.rb', line 18 def search bind socket.send(REQUEST, 0, MULTICAST_ADDR, PORT) begin parse_address(await_response) rescue Timeout::Error raise DeviceNotFound, "Roku's automatic device discovery failed. If you continue " \ "to receive this message, you should try restarting your " \ "router, and you may want to manually configure this. You " \ "can do this by finding the device's IP via your router " \ "and setting the ROKU_HOST environment variable to " \ "\"http://{{device-ip}}:8060\"." end end |