anycable 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -0
- data/CHANGELOG.md +15 -1
- data/lib/anycable/rpc_handler.rb +27 -56
- data/lib/anycable/socket.rb +43 -0
- data/lib/anycable/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 26a8ddbb776d6aa172c87b764baaf5a50e99c4b8
|
4
|
+
data.tar.gz: '0139cc0a3fd8e545ec262262ec37451bb0e5403c'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 55c331b5be0551543aeb12ad5332155b2301d72858b31dc03f3e87698538232f6427a69ca5e1c38c7ca1e054447da7526e648c27149b30d7ee81db130a6dc497
|
7
|
+
data.tar.gz: ef3dc2181c6f8fe1b4e73fcca29e177daf3fc16d00f22b6107be423410b1e0b574e307f5f96d530d11c46e0f3a286a6897b86dc08b24c2881e0df3c6b69baf2b
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,20 @@
|
|
1
1
|
# Change log
|
2
2
|
|
3
|
-
## 0.4.
|
3
|
+
## 0.4.1 (2017-01-24)
|
4
|
+
|
5
|
+
- Introduce _fake_ socket instance to handle transmissions and streams. ([@palkan][])
|
6
|
+
|
7
|
+
- Make commands handling more abstract. ([@palkan][])
|
8
|
+
|
9
|
+
We now do not explicitly call channels action but use the only one entrypoing for all commands:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
connection.handle_channel_command(identifier, command, data)
|
13
|
+
```
|
14
|
+
|
15
|
+
This method should return `true` if command was successful and `false` otherwise.
|
16
|
+
|
17
|
+
## 0.4.0 (2017-01-22)
|
4
18
|
|
5
19
|
- Refactor RPC API. ([@palkan][])
|
6
20
|
|
data/lib/anycable/rpc_handler.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
require 'anycable/socket'
|
2
3
|
require 'anycable/rpc/rpc'
|
3
4
|
require 'anycable/rpc/rpc_services'
|
4
5
|
|
5
|
-
# rubocop:disable Metrics/
|
6
|
+
# rubocop:disable Metrics/AbcSize
|
6
7
|
# rubocop:disable Metrics/MethodLength
|
7
8
|
module Anycable
|
8
9
|
# RPC service handler
|
@@ -11,17 +12,19 @@ module Anycable
|
|
11
12
|
def connect(request, _unused_call)
|
12
13
|
logger.debug("RPC Connect: #{request}")
|
13
14
|
|
14
|
-
|
15
|
+
socket = build_socket(env: rack_env(request))
|
16
|
+
|
17
|
+
connection = factory.create(socket)
|
15
18
|
|
16
19
|
connection.handle_open
|
17
20
|
|
18
|
-
if
|
21
|
+
if socket.closed?
|
19
22
|
Anycable::ConnectionResponse.new(status: Anycable::Status::ERROR)
|
20
23
|
else
|
21
24
|
Anycable::ConnectionResponse.new(
|
22
25
|
status: Anycable::Status::SUCCESS,
|
23
26
|
identifiers: connection.identifiers_json,
|
24
|
-
transmissions:
|
27
|
+
transmissions: socket.transmissions
|
25
28
|
)
|
26
29
|
end
|
27
30
|
end
|
@@ -29,8 +32,10 @@ module Anycable
|
|
29
32
|
def disconnect(request, _unused_call)
|
30
33
|
logger.debug("RPC Disonnect: #{request}")
|
31
34
|
|
35
|
+
socket = build_socket(env: rack_env(request))
|
36
|
+
|
32
37
|
connection = factory.create(
|
33
|
-
|
38
|
+
socket,
|
34
39
|
identifiers: request.identifiers,
|
35
40
|
subscriptions: request.subscriptions
|
36
41
|
)
|
@@ -45,68 +50,30 @@ module Anycable
|
|
45
50
|
def command(message, _unused_call)
|
46
51
|
logger.debug("RPC Command: #{message}")
|
47
52
|
|
48
|
-
|
49
|
-
end
|
53
|
+
socket = build_socket
|
50
54
|
|
51
|
-
private
|
52
|
-
|
53
|
-
def run_command(message)
|
54
55
|
connection = factory.create(
|
56
|
+
socket,
|
55
57
|
identifiers: message.connection_identifiers
|
56
58
|
)
|
57
59
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
else
|
63
|
-
Anycable::CommandResponse.new(
|
64
|
-
status: Anycable::Status::ERROR
|
65
|
-
)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def handle_subscribe(_msg, connection, channel)
|
70
|
-
channel.handle_subscribe
|
71
|
-
if channel.subscription_rejected?
|
72
|
-
Anycable::CommandResponse.new(
|
73
|
-
status: Anycable::Status::ERROR,
|
74
|
-
disconnect: connection.closed?,
|
75
|
-
transmissions: connection.transmissions
|
76
|
-
)
|
77
|
-
else
|
78
|
-
Anycable::CommandResponse.new(
|
79
|
-
status: Anycable::Status::SUCCESS,
|
80
|
-
disconnect: connection.closed?,
|
81
|
-
stop_streams: channel.stop_streams?,
|
82
|
-
streams: channel.streams,
|
83
|
-
transmissions: connection.transmissions
|
84
|
-
)
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
def handle_unsubscribe(_mgs, connection, channel)
|
89
|
-
channel.handle_unsubscribe
|
90
|
-
|
91
|
-
Anycable::CommandResponse.new(
|
92
|
-
status: Anycable::Status::SUCCESS,
|
93
|
-
disconnect: connection.closed?,
|
94
|
-
stop_streams: true,
|
95
|
-
transmissions: connection.transmissions
|
60
|
+
result = connection.handle_channel_command(
|
61
|
+
message.identifier,
|
62
|
+
message.command,
|
63
|
+
message.data
|
96
64
|
)
|
97
|
-
end
|
98
65
|
|
99
|
-
def handle_message(msg, connection, channel)
|
100
|
-
channel.handle_action(msg.data)
|
101
66
|
Anycable::CommandResponse.new(
|
102
|
-
status: Anycable::Status::SUCCESS,
|
103
|
-
disconnect:
|
104
|
-
stop_streams:
|
105
|
-
streams:
|
106
|
-
transmissions:
|
67
|
+
status: result ? Anycable::Status::SUCCESS : Anycable::Status::ERROR,
|
68
|
+
disconnect: socket.closed?,
|
69
|
+
stop_streams: socket.stop_streams?,
|
70
|
+
streams: socket.streams,
|
71
|
+
transmissions: socket.transmissions
|
107
72
|
)
|
108
73
|
end
|
109
74
|
|
75
|
+
private
|
76
|
+
|
110
77
|
# Build env from path
|
111
78
|
def rack_env(request)
|
112
79
|
uri = URI.parse(request.path)
|
@@ -124,6 +91,10 @@ module Anycable
|
|
124
91
|
}
|
125
92
|
end
|
126
93
|
|
94
|
+
def build_socket(**options)
|
95
|
+
Anycable::Socket.new(**options)
|
96
|
+
end
|
97
|
+
|
127
98
|
def logger
|
128
99
|
Anycable.logger
|
129
100
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Anycable
|
3
|
+
# Socket mock to be used with application connection
|
4
|
+
class Socket
|
5
|
+
attr_reader :transmissions, :env
|
6
|
+
|
7
|
+
def initialize(env: nil)
|
8
|
+
@transmissions = []
|
9
|
+
@env = env
|
10
|
+
end
|
11
|
+
|
12
|
+
def transmit(websocket_message)
|
13
|
+
transmissions << websocket_message
|
14
|
+
end
|
15
|
+
|
16
|
+
def stream(broadcasting)
|
17
|
+
streams << broadcasting
|
18
|
+
end
|
19
|
+
|
20
|
+
def streams
|
21
|
+
@streams ||= []
|
22
|
+
end
|
23
|
+
|
24
|
+
def close
|
25
|
+
@closed = true
|
26
|
+
@transmissions.clear
|
27
|
+
@streams&.clear
|
28
|
+
@stop_all_streams = true
|
29
|
+
end
|
30
|
+
|
31
|
+
def closed?
|
32
|
+
@closed == true
|
33
|
+
end
|
34
|
+
|
35
|
+
def stop_all_streams
|
36
|
+
@stop_all_streams = true
|
37
|
+
end
|
38
|
+
|
39
|
+
def stop_streams?
|
40
|
+
@stop_all_streams == true
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/anycable/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: anycable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- palkan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: anyway_config
|
@@ -175,6 +175,7 @@ files:
|
|
175
175
|
- lib/anycable/rpc/rpc_services.rb
|
176
176
|
- lib/anycable/rpc_handler.rb
|
177
177
|
- lib/anycable/server.rb
|
178
|
+
- lib/anycable/socket.rb
|
178
179
|
- lib/anycable/version.rb
|
179
180
|
- protos/rpc.proto
|
180
181
|
homepage: http://github.com/anycable/anycable
|