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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2a86a68b94af2eef6fcb59c71974a5906905c130
4
- data.tar.gz: f24eb7b22f1eeafe33183e2686f591a427bf0801
3
+ metadata.gz: abc49cf79165358c0e9c7a33ffa290008db25120
4
+ data.tar.gz: 8b04ebc3ca9d28b34adb03f6d1929cc6174935a9
5
5
  SHA512:
6
- metadata.gz: 65665230caaa80943f0d94cd0e561403fb71cbec5b9aae2bfb8bf3446109595c2e91e07bae8c59300eb1eacb557cad59a8c1ac180ee34ff6a637919c042d4dfb
7
- data.tar.gz: 3f74d7b19fe79a651d50cfb57e8f437f7bf1f140dbadf0e605dddb9def7eec3ff19342cd711331d5d4a842d54797f0b7501f4e42da3ce1f86fbd66edb30e29f0
6
+ metadata.gz: d8d168a249090a17d7da12df4c6c48bbf6c644fb0ddc9da87dc10924af91b692f6b4281b3f9bdc934401bcd583613dccbe0199ab2b47ed3f5d72e652931a7ab1
7
+ data.tar.gz: 0131f3b388a7e0da7a1f118a523fc860471611ca551f99dc643f3570750f93e63a7090d226230d6286ecb14714ad379072f7dab454d93ea754a39ccdf3b9b12b
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- action_channels (0.0.1)
4
+ action_channels (0.1.1)
5
5
  nio4r-websocket
6
6
 
7
7
  GEM
@@ -3,6 +3,10 @@ module ActionChannels
3
3
  class Base
4
4
  def do_send(receiver, message)
5
5
  end
6
+
7
+ def send_error_400(receiver)
8
+ do_send receiver, Message.new(channel: '', type: 'bad_request')
9
+ end
6
10
  end
7
11
  end
8
12
  end
@@ -10,20 +10,7 @@ module ActionChannels
10
10
 
11
11
  def run
12
12
  NIO::WebSocket.listen port: port do |client|
13
- on_message = lambda do |event|
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
@@ -1,3 +1,3 @@
1
1
  module ActionChannels
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
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.0
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-12 00:00:00.000000000 Z
11
+ date: 2018-02-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nio4r-websocket