Method: Tinder::Room#listen
- Defined in:
- lib/vendor/tinder/lib/tinder/room.rb
#listen ⇒ Object
Listen for new messages in the room, yielding them to the provided block as they arrive. Each message is a hash with:
-
:body: the body of the message -
:user: Campfire user, which is itself a hash, of:-
:id: User id -
:name: User name -
:email_address: Email address -
:admin: Boolean admin flag -
:created_at: User creation timestamp -
:type: User type (e.g. Member)
-
-
:id: Campfire message id -
:type: Campfire message type -
:room_id: Campfire room id -
:created_at: Message creation timestamproom.listen do |m|
room.speak "Go away!" if m[:body] =~ /Java/iend
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/vendor/tinder/lib/tinder/room.rb', line 124 def listen raise "no block provided" unless block_given? require 'twitter/json_stream' join # you have to be in the room to listen auth = connection.[:basic_auth] = { :host => "streaming.#{Connection::HOST}", :path => room_url_for(:live), :auth => "#{auth[:username]}:#{auth[:password]}", :timeout => 2 } EventMachine::run do stream = Twitter::JSONStream.connect() stream.each_item do || = HashWithIndifferentAccess.new(JSON.parse()) [:user] = user(.delete(:user_id)) [:created_at] = Time.parse([:created_at]) yield() end end end |