class SPSChat

Public Class Methods

new(host: 'localhost', port: '8080', \ userid: 'user' + (0..1000).to_a.sample.to_s, room: '', \ interactive: true) click to toggle source
Calls superclass method
# File lib/sps_chat.rb, line 10
def initialize(host: 'localhost', port: '8080', \
                userid: 'user' + (0..1000).to_a.sample.to_s, room: '', \
               interactive: true)

  @userid = userid    
  super(host: host, port: port, topic: 'chat',
        sub_topic: '#', pub_topic: userid, interactive: interactive)

end

Public Instance Methods

onincoming(sender, msg, typing=false) click to toggle source
# File lib/sps_chat.rb, line 42
def onincoming(sender, msg, typing=false)
  
  puts "%s: %s" % [sender, msg]
  
end
ontopic(topic, msg) click to toggle source

used by the callback routine

# File lib/sps_chat.rb, line 28
def ontopic(topic, msg)

  typing = false
  
  a = topic.split('/')
  sender = a.pop
  (sender = a.pop; typing = true) if sender == 'typing'

  return if sender == @userid
  
  typing ? onincoming(sender, msg, true) : onincoming(sender, msg)

end
typing(c) click to toggle source
# File lib/sps_chat.rb, line 20
def typing(c)
  
  @pub.notice ("%s/typing: %s" % [@topic, c])
  
end