sps_chat 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f61d63062e039d56ad994c289fa4ffd1211d87ae
4
- data.tar.gz: 6276f68c82299e3888176a413b3ea8489df85da0
3
+ metadata.gz: a0f48b2b5a5b99bdf677f2eafc88d6dd4d793817
4
+ data.tar.gz: 31ffa5fbc27e79ae4a53297a0f2ea49dfa33e555
5
5
  SHA512:
6
- metadata.gz: c18425b84d7aa4a3e2d8d01b8915bb7306cf706033d40cee03b863c992bc401327fababdcf7389874f807a591185a984970625077b268e7ad1a43fa662df8900
7
- data.tar.gz: 6083fe2cc9e46f648e5e6f711fa5b1e64ba672813936aadcdbe67b3f091a2005031155fb453f5bb3b382ebdb4f748760e3c6e934297aac48e8d5aa2e9cb89af3
6
+ metadata.gz: 2a9610ece62aa1068d0aa376a5f16b96f4144f49e6ed28f5c25bdca50a6044e8df3cf82d1fedf77d6da606edd49e36f0a486ebe9420679adaffafa80028452df
7
+ data.tar.gz: 96278bf1a54c4fd13eb4a86f5f41c61ecf90f0010950cb3ebb0580e5a6c917fc38f63931dea29ace35e0c85d9aea0c92b1228b185e553d41eb3d14d9aa96830b
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/sps_chat.rb CHANGED
@@ -9,29 +9,36 @@ require 'sps-sub'
9
9
  class SPSChat
10
10
 
11
11
  def initialize(host: 'localhost', port: '8080', \
12
- userid: 'user' + (0..1000).to_a.sample.to_s)
12
+ userid: 'user' + (0..1000).to_a.sample.to_s, room: '')
13
13
 
14
14
  @userid = userid
15
15
 
16
16
  sps = SPSSub.new host: host, port: port, callback: self
17
17
  puts 'connecting ...'
18
18
  sleep 1 # give it a second to connect
19
+
20
+ topic = ['chat']
21
+ topic << room if room.length > 0
22
+
23
+ Thread.new { sps.subscribe topic: (topic + ['#']).join('/') }
19
24
 
20
- Thread.new { sps.subscribe topic: 'chat/#' }
21
25
  @pub = SPSPub.new address: host, port: port
26
+
27
+ topic << userid
28
+ @topic = topic.join('/')
22
29
 
23
30
  end
24
31
 
25
32
  def send(msg)
26
33
 
27
- @pub.notice ("chat/%s: %s" % [@userid, msg])
34
+ @pub.notice ("%s: %s" % [@topic, msg])
28
35
 
29
36
  end
30
37
 
31
38
  # used by the callback routine
32
39
  #
33
40
  def ontopic(topic, msg)
34
-
41
+
35
42
  sender = topic.split('/').last
36
43
  return if sender == @userid
37
44
  onincoming sender, msg
@@ -39,7 +46,9 @@ class SPSChat
39
46
  end
40
47
 
41
48
  def onincoming(sender, msg)
49
+
42
50
  puts "%s: %s" % [sender, msg]
51
+
43
52
  end
44
53
 
45
54
  end
@@ -49,4 +58,4 @@ if __FILE__ == $0 then
49
58
  chat = SPSChat.new port: 8080
50
59
  chat.send 'hello'
51
60
 
52
- end
61
+ end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sps_chat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -31,7 +31,7 @@ cert_chain:
31
31
  lCVLcSK4BUROwuCG5CzgZgqMqPhEPu8W3rU4v6OD1HLgfu7iGHbIAs3gAGRCrJRD
32
32
  VIkRGnNW0mJBFw==
33
33
  -----END CERTIFICATE-----
34
- date: 2015-05-16 00:00:00.000000000 Z
34
+ date: 2016-04-16 00:00:00.000000000 Z
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: sps-sub
@@ -100,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
100
  version: '0'
101
101
  requirements: []
102
102
  rubyforge_project:
103
- rubygems_version: 2.4.6
103
+ rubygems_version: 2.4.8
104
104
  signing_key:
105
105
  specification_version: 4
106
106
  summary: A simple chat client which sends and receives messages through the SimplePubSub
metadata.gz.sig CHANGED
Binary file