Sha256: 6e7e845dfb9d1c8fe383663c95aed041bd5ade03132c68d6456e8938ff04bd38
Contents?: true
Size: 944 Bytes
Versions: 2
Compression:
Stored size: 944 Bytes
Contents
require 'lib/em-websocket' require 'twitter/json_stream' require 'json' # # broadcast all ruby related tweets to all connected users! # username = ARGV.shift password = ARGV.shift raise "need username and password" if !username or !password EventMachine.run { @channel = EM::Channel.new @twitter = Twitter::JSONStream.connect( :path => '/1/statuses/filter.json?track=ruby', :auth => "#{username}:#{password}" ) @twitter.each_item do |status| status = JSON.parse(status) @channel.push "#{status['user']['screen_name']}: #{status['text']}" end EventMachine::WebSocket.start(:host => "0.0.0.0", :port => 8080, :debug => true) do |ws| ws.onopen { @sid = @channel.subscribe { |msg| ws.send msg } @channel.push "#{@sid} connected!" } ws.onmessage { |msg| @channel.push "<#{@sid}>: #{msg}" } ws.onclose { @channel.unsubscribe(@sid) } end puts "Server started" }
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
em-websocket-0.0.6 | examples/multicast.rb |
em-websocket-0.0.5 | examples/multicast.rb |