Sha256: 661a0a3f4d0b7e5ac8874d6ac12fd5166925f6062857d1005737998e26268cf8

Contents?: true

Size: 860 Bytes

Versions: 2

Compression:

Stored size: 860 Bytes

Contents

require 'sinatra/base'
require 'sinatra/reloader'
require 'faye'

# https://github.com/DanKnox/websocket-rails/issues/85
Faye::WebSocket.load_adapter('thin')

module DoubanFMHotkey
  class Server < Sinatra::Base

    configure :development do
      register Sinatra::Reloader
    end

    dir = File.dirname(File.expand_path(__FILE__))

    set :views,  "#{dir}/server/views"

    if respond_to? :public_folder
      set :public_folder, "#{dir}/server/public"
    else
      set :public, "#{dir}/server/public"
    end

    set :static, true

    use Faye::RackAdapter, :mount => '/faye'

    before do
      @client = Faye::Client.new('http://0.0.0.0:1988/faye')
    end

    get '/' do
      erb :index
    end

    %w{skip pause love ban info}.each do |cmd|
      get "/#{cmd}" do
        @client.publish('/hotkey', {cmd: cmd})
      end
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
douban_fm_hotkey-1.2.1 lib/douban_fm_hotkey/server.rb
douban_fm_hotkey-1.2.0 lib/douban_fm_hotkey/server.rb