Class: LastFM::Client::TelnetClient

Inherits:
LastFM::Client show all
Defined in:
lib/lastfm.rb

Instance Attribute Summary

Attributes inherited from LastFM::Client

#current_song

Instance Method Summary collapse

Methods inherited from LastFM::Client

#display_current_song, #divider, #flush_output_buffer, #help, #parse_command, #play, #prompt, #skip, #stop, #tune

Constructor Details

#initialize(lastfm, audio_output, port) ⇒ TelnetClient

Returns a new instance of TelnetClient.



279
280
281
282
# File 'lib/lastfm.rb', line 279

def initialize(lastfm, audio_output, port)
  @port = port
  super(lastfm, audio_output)
end

Instance Method Details

#startObject



283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
# File 'lib/lastfm.rb', line 283

def start
  server = TCPServer.new('localhost', @port)
  puts
  puts "Starting last.fm telnet server on port #{@port}.

Other computers can log in and control the lastfm stream on this 
computer simultaneously.

For a better experience, try logging in using rlwrap 
(which provides readline support)."
  display_current_song
  while session=server.accept
    puts "A telnet session has just started."
    Thread.new(session) do |my_session|
      my_session.print prompt
      while req = my_session.gets
        puts "\n"
        puts divider
        puts "TELNET REQUEST"
        req = req.split(" ")
        if req[0] =~ /^q/ # quit
          my_session.close
          break
        end
        command = req.shift
        parse_command(command, req) 
        puts divider
        print prompt
        $stdout.flush
        my_session.print flush_output_buffer

        unless command =~ /^h/
          my_session.print "\n" 
          my_session.print prompt 
        end
      end
      puts "A telnet session just ended."
    end
  end
end