Class: Junkie::Webinterface::Interface
- Inherits:
-
Sinatra::Base
- Object
- Sinatra::Base
- Junkie::Webinterface::Interface
- Defined in:
- lib/junkie/webinterface/interface.rb
Overview
Class that represents the web interface for junkie. It is based on WebSockets, so that updates are sent to the connected clients.
Constant Summary collapse
- DEFAULT_CONFIG =
{ port: 8080, }
Class Method Summary collapse
Methods included from Log
Methods included from Config
collect_default_configs, get_config, included
Class Method Details
.publish_encrypted_count ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/junkie/webinterface/interface.rb', line 52 def self.publish_encrypted_count @@channels[:push_episode_count].push(@@encrypted_episodes.length) @@channels[:info].push( { key: "Pending Encrypted Links", desc: "Number of encrypted links that need to be decrypted.", value: @@encrypted_episodes.length, additional: @@encrypted_episodes.values.map { |e| "%s (%s)" % [e.series, e.id] } } ) end |
.setup(channels) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/junkie/webinterface/interface.rb', line 20 def self.setup(channels) @@channels = channels @@config = Config.get_config(self) set :port, @@config[:port] @@stats = Hash.new @@encrypted_episodes = Hash.new # every connected client connects to the following channel, so infos # pushed to this channel are transmitted to the clients @@ws_channel = EM::Channel.new # subscribe to the channel that holds the stats from various parts of # junkie @@channels[:info].subscribe do |info| @@stats[info[:key]] = info @@ws_channel.push(info) end # get new encrypted episode links @@channels[:episodes].subscribe do |episode| next unless episode.status == :encrypted @@encrypted_episodes[episode.uuid] = episode publish_encrypted_count end run! end |