Sha256: ffb3f8774e48b97c3318e2249c62bafd5d91b2f2b78c74e20ceadfdad5f60b2e

Contents?: true

Size: 1.54 KB

Versions: 12

Compression:

Stored size: 1.54 KB

Contents

#!/usr/bin/env ruby

require 'bundler/setup'
require 'eventmachine'
require 'em-websocket'
require 'thin'
require 'trollop'

require './config/boot'

opts = Trollop.options do
  version "Smartkiosk::Client #{Smartkiosk::Client::VERSION}"
  banner "Smartkiosk client application"
  opt :log, "Log file to use", type: String
end

Smartkiosk::Client::Logging.destination = opts[:log] if opts[:log]
Smartkiosk::Client::Logging.init

EventMachine.run do
  #
  # Serving front
  #
  Thin::Server.start '0.0.0.0', 3001 do
    map '/assets' do
      run Application.sprockets
    end
    use Smartkiosk::Client::Logging::Middleware
    run Application
  end

  #
  # Serving WebSockets
  #
  @front_orders = EM::Channel.new

  EventMachine.add_periodic_timer 1 do
    @front_orders.push ['state', Terminal.state].to_json
  end

  EventMachine.add_periodic_timer 5 do
    @front_orders.push ['modified_at', Terminal.modified_at].to_json
  end

  Smartware.subscribe do |message|
    if message.key == "modem.accounting"
      message.acknowlege

      p message

      SessionRecord.create(started_at: message[0],
                           upstream: message[1],
                           downstream: message[2],
                           time: message[3])
    else
      @front_orders.push ["smartware.#{message.key}", message.args].to_json
    end
  end

  EventMachine::WebSocket.run(:host => '0.0.0.0', :port => 3002) do |ws|
    ws.onopen {
      sid = @front_orders.subscribe { |msg| ws.send msg }

      ws.onclose {
        @front_orders.unsubscribe(sid)
      }
    }
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
smartkiosk-client-0.1.14 bin/smartkiosk-client
smartkiosk-client-0.1.13 bin/smartkiosk-client
smartkiosk-client-0.1.12 bin/smartkiosk-client
smartkiosk-client-0.1.11 bin/smartkiosk-client
smartkiosk-client-0.1.10 bin/smartkiosk-client
smartkiosk-client-0.1.9 bin/smartkiosk-client
smartkiosk-client-0.1.8 bin/smartkiosk-client
smartkiosk-client-0.1.7 bin/smartkiosk-client
smartkiosk-client-0.1.6 bin/smartkiosk-client
smartkiosk-client-0.1.5 bin/smartkiosk-client
smartkiosk-client-0.1.4 bin/smartkiosk-client
smartkiosk-client-0.1.3 bin/smartkiosk-client