Class: RokuBuilder::Navigator
- Extended by:
- Plugin
- Defined in:
- lib/roku_builder/plugins/navigator.rb
Overview
Navigation methods
Class Method Summary collapse
Instance Method Summary collapse
-
#init ⇒ Object
Setup navigation commands.
-
#nav(options:, device: nil) ⇒ Boolean
Send a navigation command to the roku device.
- #navigate(options:) ⇒ Object
-
#screen(options:) ⇒ Boolean
Show the commands for one of the roku secret screens.
-
#screens(options:) ⇒ Object
Show avaiable roku secret screens.
-
#type(options:, device: nil) ⇒ Boolean
Type text on the roku device.
Methods included from Plugin
commands, dependencies, parse_options, validate
Methods inherited from Util
Constructor Details
This class inherits a constructor from RokuBuilder::Util
Class Method Details
.commands ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/roku_builder/plugins/navigator.rb', line 9 def self.commands { nav: {device: true}, navigate: {device: true}, type: {device: true}, screen: {device: true}, screens: {} } end |
.parse_options(parser:, options:) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/roku_builder/plugins/navigator.rb', line 19 def self.(parser:, options:) parser.separator("Commands:") parser.on("-N", "--nav CMD", "Send the given command to the roku") do |n| [:nav] = n end parser.on("--navigate", "Run interactive navigator") do [:navigate] = true end parser.on("-y", "--type TEXT", "Type the given text on the roku device") do |t| [:type] = t end parser.on("--screen SCREEN", "Show a screen") do |s| [:screen] = s end parser.on("--screens", "Show possible screens") do [:screens] = true end end |
Instance Method Details
#init ⇒ Object
Setup navigation commands
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/roku_builder/plugins/navigator.rb', line 39 def init() @commands = { home: "Home", rew: "Rev", ff: "Fwd", play: "Play", select: "Select", left: "Left", right: "Right", down: "Down", up: "Up", back: "Back", replay: "InstantReplay", info: "Info", backspace: "Backspace", search: "Search", enter: "Enter", volumedown: "VolumeDown", volumeup: "VolumeUp", mute: "VolumeMute", channelup: "ChannelUp", channeldown: "ChannelDown", tuner: "InputTuner", hdmi1: "InputHDMI1", hdmi2: "InputHDMI2", hdmi3: "InputHDMI3", hdmi4: "InputHDMI4", avi: "InputAVI" } @screens = { platform: [:home, :home, :home, :home, :home, :ff, :play, :rew, :play, :ff], secret: [:home, :home, :home, :home, :home, :ff, :ff, :ff, :rew, :rew], secret2: [:home, :home, :home, :home, :home, :up, :right, :down, :left, :up], channels: [:home, :home, :home, :up, :up, :left, :right, :left, :right, :left], developer: [:home, :home, :home, :up, :up, :right, :left, :right, :left, :right], wifi: [:home, :home, :home, :home, :home, :up, :down, :up, :down, :up], antenna: [:home, :home, :home, :home, :home, :ff, :down, :rew, :down, :ff], bitrate: [:home, :home, :home, :home, :home, :rew, :rew, :rew, :ff, :ff], network: [:home, :home, :home, :home, :home, :right, :left, :right, :left, :right], reboot: [:home, :home, :home, :home, :home, :up, :rew, :rew, :ff, :ff] } @runable = [ :secret, :channels ] mappings_init end |
#nav(options:, device: nil) ⇒ Boolean
Send a navigation command to the roku device
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/roku_builder/plugins/navigator.rb', line 73 def nav(options:, device: nil) get_device(device: device, no_lock: true) do |device| commands = [:nav].split(/, */).map{|c| c.to_sym} commands.each do |command| unless @commands.has_key?(command) raise ExecutionError, "Unknown Navigation Command" end multipart_connection(port: 8060, device: device) do |conn| path = "/keypress/#{@commands[command]}" @logger.debug("Send Command: "+path) response = conn.post path raise ExecutionError, "Navigation Failed" unless response.success? end end end end |
#navigate(options:) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/roku_builder/plugins/navigator.rb', line 105 def navigate(options:) get_device(no_lock: true) do |device| running = true @logger.info("Key Mappings:") @mappings.each_value {|key| @logger.info(sprintf("%13s -> %s", key[1], @commands[key[0].to_sym])) } @logger.info(sprintf("%13s -> %s", "Ctrl + c", "Exit")) while running char = read_char @logger.debug("Char: #{char.inspect}") if char == "\u0003" running = false else Thread.new(char, device) {|character,device| handle_navigate_input(character, device)} end end end end |
#screen(options:) ⇒ Boolean
Show the commands for one of the roku secret screens
129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/roku_builder/plugins/navigator.rb', line 129 def screen(options:) type = [:screen].to_sym unless @screens.has_key?(type) raise ExecutionError, "Unknown Screen" end if @runable.include?(type) nav(options: {nav: @screens[type].join(", ")}) else @logger.unknown("Cannot run command automatically") display_screen_command(type) end end |
#screens(options:) ⇒ Object
Show avaiable roku secret screens
143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/roku_builder/plugins/navigator.rb', line 143 def screens(options:) logger = ::Logger.new(STDOUT) logger.formatter = proc {|_severity, _datetime, _progname, msg| "%s\n\r" % [msg] } logger.unknown("----------------------------------------------------------------------") @screens.keys.each {|screen| logger.unknown(sprintf("%10s: %s", screen.to_s, get_screen_command(screen))) logger.unknown("----------------------------------------------------------------------") } end |
#type(options:, device: nil) ⇒ Boolean
Type text on the roku device
93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/roku_builder/plugins/navigator.rb', line 93 def type(options:, device: nil) multipart_connection(port: 8060, device: device, no_lock: true) do |conn| [:type].split(//).each do |c| path = "/keypress/LIT_#{CGI::escape(c)}" @logger.debug("Send Letter: "+path) response = conn.post path return false unless response.success? end return true end end |