Class: SPSChat
- Inherits:
-
SPSDuplex
- Object
- SPSDuplex
- SPSChat
- Defined in:
- lib/sps_chat.rb
Instance Method Summary collapse
-
#initialize(host: 'localhost', port: '8080', userid: 'user' + (0..1000).to_a.sample.to_s, room: '') ⇒ SPSChat
constructor
A new instance of SPSChat.
- #onincoming(sender, msg, typing = false) ⇒ Object
-
#ontopic(topic, msg) ⇒ Object
used by the callback routine.
- #typing(c) ⇒ Object
Constructor Details
#initialize(host: 'localhost', port: '8080', userid: 'user' + (0..1000).to_a.sample.to_s, room: '') ⇒ SPSChat
Returns a new instance of SPSChat.
10 11 12 13 14 15 16 17 |
# File 'lib/sps_chat.rb', line 10 def initialize(host: 'localhost', port: '8080', \ userid: 'user' + (0..1000).to_a.sample.to_s, room: '') @userid = userid super(host: host, port: port, topic: 'chat', sub_topic: '#', pub_topic: userid) end |
Instance Method Details
#onincoming(sender, msg, typing = false) ⇒ Object
41 42 43 44 45 |
# File 'lib/sps_chat.rb', line 41 def onincoming(sender, msg, typing=false) puts "%s: %s" % [sender, msg] end |
#ontopic(topic, msg) ⇒ Object
used by the callback routine
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/sps_chat.rb', line 27 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) ⇒ Object
19 20 21 22 23 |
# File 'lib/sps_chat.rb', line 19 def typing(c) @pub.notice ("%s/typing: %s" % [@topic, c]) end |