File: app.rb

package info (click to toggle)
ruby-faye 1.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 1,792 kB
  • sloc: javascript: 14,833; ruby: 5,068; makefile: 30
file content (41 lines) | stat: -rw-r--r-- 813 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
require 'sinatra'
require 'faye'
require 'permessage_deflate'

ROOT_DIR = File.expand_path('../..', __FILE__)
set :root, ROOT_DIR
set :logging, false

get '/' do
  File.read(ROOT_DIR + '/public/index.html')
end

get '/post' do
  env['faye.client'].publish('/mentioning/*', {
    :user => 'sinatra',
    :message => params[:message]
  })
  params[:message]
end

App = Faye::RackAdapter.new(Sinatra::Application,
  :mount   => '/bayeux',
  :timeout => 25
)

App.add_websocket_extension(PermessageDeflate)

def App.log(message)
end

App.on(:subscribe) do |client_id, channel|
  puts "[  SUBSCRIBE] #{ client_id } -> #{ channel }"
end

App.on(:unsubscribe) do |client_id, channel|
  puts "[UNSUBSCRIBE] #{ client_id } -> #{ channel }"
end

App.on(:disconnect) do |client_id|
  puts "[ DISCONNECT] #{ client_id }"
end