sprsquish (owner)

Revisions

gist: 111546 Download_button fork
public
Public Clone URL: git://gist.github.com/111546.git
Embed All Files: show embed
Ruby #
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
# A single ruby script that plays ping pong with itself over XMPP
# That's two separate clients connected to the same server using different resource IDs
# Ping will wait until it knows Pong is online, then it'll start the match
 
require 'blather/client/dsl'
$stdout.sync = true
module Ping
  extend Blather::DSL
  def self.run; client.run; end
 
  setup 'echo@jabber.local/ping', 'echo'
 
  status :from => Blather::JID.new('echo@jabber.local/pong') do |s|
    puts "ping!"
    say s.from, 'ping'
  end
 
  message :chat?, :body => 'pong' do |m|
    puts "ping!"
    say m.from, 'ping'
  end
end
 
module Pong
  extend Blather::DSL
  def self.run; client.run; end
 
  setup 'echo@jabber.local/pong', 'echo'
  message :chat?, :body => 'ping' do |m|
    puts "pong!"
    say m.from, 'pong'
  end
end
 
trap(:INT) { EM.stop }
trap(:TERM) { EM.stop }
EM.run do
  Ping.run
  Pong.run
end