action_channels 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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/action_channels/message_senders/base.rb +4 -0
- data/lib/action_channels/server.rb +33 -14
- data/lib/action_channels/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: abc49cf79165358c0e9c7a33ffa290008db25120
|
4
|
+
data.tar.gz: 8b04ebc3ca9d28b34adb03f6d1929cc6174935a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8d168a249090a17d7da12df4c6c48bbf6c644fb0ddc9da87dc10924af91b692f6b4281b3f9bdc934401bcd583613dccbe0199ab2b47ed3f5d72e652931a7ab1
|
7
|
+
data.tar.gz: 0131f3b388a7e0da7a1f118a523fc860471611ca551f99dc643f3570750f93e63a7090d226230d6286ecb14714ad379072f7dab454d93ea754a39ccdf3b9b12b
|
data/Gemfile.lock
CHANGED
@@ -10,20 +10,7 @@ module ActionChannels
|
|
10
10
|
|
11
11
|
def run
|
12
12
|
NIO::WebSocket.listen port: port do |client|
|
13
|
-
|
14
|
-
ActionChannels.logger.info "Received new message: #{event.data}"
|
15
|
-
|
16
|
-
message = Message.parse_and_setup_author event.data, client
|
17
|
-
process_message message
|
18
|
-
end
|
19
|
-
|
20
|
-
on_close = lambda do |event|
|
21
|
-
ActionChannels.logger.info "Client closed connection."
|
22
|
-
channel_repository.all.each { |channel| channel.remove_client(client) }
|
23
|
-
end
|
24
|
-
|
25
|
-
client.on :message, on_message
|
26
|
-
client.on :close, on_close
|
13
|
+
process_client client
|
27
14
|
end
|
28
15
|
|
29
16
|
ActionChannels.logger.info "Server started on port: #{port}"
|
@@ -33,8 +20,40 @@ module ActionChannels
|
|
33
20
|
@channel_repository ||= ChannelRepository.new
|
34
21
|
end
|
35
22
|
|
23
|
+
def process_client(client)
|
24
|
+
client.on :message, callback_on_message(client)
|
25
|
+
client.on :close, callback_on_close(client)
|
26
|
+
|
27
|
+
client
|
28
|
+
end
|
29
|
+
|
36
30
|
private
|
37
31
|
|
32
|
+
def callback_on_message(client)
|
33
|
+
lambda do |event|
|
34
|
+
begin
|
35
|
+
ActionChannels.logger.info "Received new message: #{event.data}"
|
36
|
+
|
37
|
+
message = Message.parse_and_setup_author event.data, client
|
38
|
+
process_message message
|
39
|
+
rescue Errors::NotParseMessage => exp
|
40
|
+
ActionChannels.logger.error exp.message
|
41
|
+
message_sender.send_error_400 client
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def message_sender
|
47
|
+
@message_sender ||= MessageSenders::WebSocket.new
|
48
|
+
end
|
49
|
+
|
50
|
+
def callback_on_close(client)
|
51
|
+
lambda do |event|
|
52
|
+
ActionChannels.logger.info "Client closed connection."
|
53
|
+
channel_repository.all.each { |channel| channel.remove_client(client) }
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
38
57
|
def process_message(message)
|
39
58
|
channel = channel_repository.find_by_name_or_create message.channel
|
40
59
|
channel.process_message message
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: action_channels
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- German Antsiferov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-02-
|
11
|
+
date: 2018-02-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nio4r-websocket
|