module SonyCameraRemoteAPI::SSDP
Module providing SSDP
function to discover camera (Device discovery)
Constants
Public Instance Methods
parse_device_description(dd)
click to toggle source
Parse device description and get endpoint URLs
# File lib/sony_camera_remote_api/ssdp.rb, line 51 def parse_device_description(dd) dd_xml = Nokogiri::XML(dd) raise DeviceDescriptionInvalid if dd_xml.nil? dd_xml.remove_namespaces! camera_name = dd_xml.css('device friendlyName').inner_text services = dd_xml.css('device X_ScalarWebAPI_Service') endpoints = {} services.each do |sv| service_type = sv.css('X_ScalarWebAPI_ServiceType').inner_text endpoints[service_type] = File.join(sv.css('X_ScalarWebAPI_ActionList_URL').inner_text, service_type) end # endpoints['liveview'] = dd_xml.css('device X_ScalarWebAPI_LiveView_URL').inner_text # endpoints.delete_if { |k, v| v.blank? } log.info "model-name: #{camera_name}" log.debug 'endpoints:' endpoints.each do |e| log.debug " #{e}" end endpoints end
ssdp_search()
click to toggle source
Perform SSDP
discover to find camera on network. @return [Hash] Endpoint URLs
# File lib/sony_camera_remote_api/ssdp.rb, line 26 def ssdp_search log.info 'Trying SSDP discover...' try = 1 while true do response = Frisky::SSDP.search SSDP_SEARCH_TARGET if response.present? break elsif try < SSDP_SEARCH_RETRY try += 1 log.warn "SSDP discover failed, retrying... (#{try}/#{SSDP_SEARCH_RETRY})" sleep(SSDP_RETRY_INTERVAL) else raise DeviceNotFound, 'Cannot find camera API server. Please confirm network connection is correct.' end end log.info 'SSDP discover succeeded.' # get device description dd = HTTPClient.new.get_content(response[0][:location]) # puts dd parse_device_description(dd) end