Skip to content

Commit 377447e

Browse files
committed
Remove the kind parameter
1 parent e1f1e02 commit 377447e

File tree

6 files changed

+24
-22
lines changed

6 files changed

+24
-22
lines changed

Gemfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
source :rubygems
2-
32
gemspec

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,24 @@ Board for LinuxFr.org
22
=====================
33

44
Users of the LinuxFr.org website can chat on a space called the board
5-
(« la tribune » in french). This was an experiment for notifying the users
5+
(« la tribune » in french). This is an experiment for notifying the users
66
when something is said with Server-Sent Event / EventSource.
77

8-
For the moment, I won't use it because:
8+
For the moment, there are some difficulties:
99

10-
- the current board daemon works
1110
- I was hoping to simplify largely its logic, but it's not the case
11+
→ maybe, it will be better if I also refactor code in the Rails part
1212
- Goliath can't listen on UNIX socket
13+
→ it's no longer the case (fixed in the git repository)
1314
- EventSource is not supported by most browsers
14-
and I'm not very confident in the polyfills for it
15+
→ I need to try the polyfills
1516

1617

1718
See also
1819
--------
1920

20-
* [Git repository](http://github.com/nono/board-see-LinuxFr.org)
21+
* [Git repository](http://github.com/nono/board-sse-LinuxFr.org)
22+
* [Current board](https://github.com/nono/Board-LinuxFr.org)
2123

2224

2325
Copyright

board-linuxfr.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# encoding: utf-8
2-
require './lib/board-linuxfr/version'
2+
require './lib/board-linuxfr'
33

44
Gem::Specification.new do |s|
55
s.name = "board-linuxfr"

lib/board-linuxfr.rb

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
require "goliath"
22
require "yajl"
3-
require "board-linuxfr/redis_plugin"
43

54

65
class BoardLinuxfr < Goliath::API
6+
autoload :Cache, "board-linuxfr/cache"
7+
autoload :RedisPlugin, "board-linuxfr/redis_plugin"
8+
autoload :VERSION, "board-linuxfr/version"
9+
710
plugin RedisPlugin
811

912
def response(env)
1013
env.logger.debug "New client: #{env['PATH_INFO']}"
11-
send_msg = ->(msg) {
12-
env.logger.debug " -> #{msg}"
13-
env.stream_send("data: #{msg}\nid: #{msg[:id]}\n\n")
14+
send_msg = ->(args) {
15+
id, msg = *args
16+
env.logger.info " -> #{id}. #{msg}"
17+
env.stream_send("data: #{args.last}\nid: #{args.first}\n\n")
1418
}
15-
event_id = env['HTTP_LAST_EVENT_ID']
16-
chan_name = env['PATH_INFO'].delete('/b/')
19+
event_id = env['HTTP_LAST_EVENT_ID']
20+
chan_name = env['PATH_INFO'].split('/', 3).last
21+
env.logger.info "chan_name = #{chan_name.inspect}"
1722
env['cache'] = status[:cache][chan_name]
1823
env['chan'] = status[:channels][chan_name]
1924
env['sid'] = env['chan'].subscribe &send_msg

lib/board-linuxfr/cache.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
require "goliath/api"
2-
3-
4-
class BoardLinuxfr < Goliath::API
1+
class BoardLinuxfr
52
class Cache
63
CAPACITY = 10
74

lib/board-linuxfr/redis_plugin.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
require "board-linuxfr/cache"
66

77

8-
class BoardLinuxfr < Goliath::API
8+
class BoardLinuxfr
99
class RedisPlugin
10-
1110
def initialize(port, config, status, logger)
1211
logger.info "Initializing the Redis plugin"
1312
@logger = logger
@@ -24,10 +23,10 @@ def run
2423
end
2524

2625
on.pmessage do |pattern, chan, msg|
27-
_, chan, id, kind = *chan.split('/')
28-
@logger.info "New message: [#{chan}] #{id}. #{kind}> #{msg}"
26+
_, chan, id = *chan.split('/')
27+
@logger.info "New message: [#{chan.inspect}] #{id}. #{msg}"
2928
[@chans, @cache].each do |storage|
30-
storage[chan].push(id: id, kind: kind, msg: msg)
29+
storage[chan].push [id, msg]
3130
end
3231
end
3332

0 commit comments

Comments
 (0)