-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfaye.ru
More file actions
52 lines (41 loc) · 1.27 KB
/
faye.ru
File metadata and controls
52 lines (41 loc) · 1.27 KB
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
42
43
44
45
46
47
48
49
50
51
52
require 'faye'
Faye::WebSocket.load_adapter('thin')
bayeux = Faye::RackAdapter.new(:port => 3053, :mount => '/faye', :timeout => 25)
# report handshake
bayeux.on(:handshake) do |client_id|
puts " " + client_id + " connected."
end
# report disconnect
bayeux.on(:disconnect) do |client_id|
puts " " + client_id + " disconnected."
end
# report publish
bayeux.on(:publish) do |client_id, channel, data|
# client_id maybe null
id = ""
if client_id.nil?
id = "client(NIL)" # id is always NIL from what I've been seeing.
else
id = "client(" + client_id + ")"
end
puts " " + id + " published some data in channel: " + channel + "."
end
# report subscription
bayeux.on(:subscribe) do |client_id, channel|
puts " " + client_id + " subscribed to channel: " + channel + "."
# broadcast subscription
#bayeux.get_client.publish(channel, {
# 'type' => 'user_subscribe',
# 'client_id' => client_id
#})
end
# report un-subscription
bayeux.on(:unsubscribe) do |client_id, channel|
puts " " + client_id + " un-subscribed from channel: " + channel + "."
# broadcast unsubscription
#bayeux.get_client.publish(channel, {
# 'type' => 'user_unsubscribe',
# 'client_id' => client_id
#})
end
run bayeux