action_cable_client 1.1.0 → 1.2.0
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/CHANGELOG.md +5 -2
- data/README.md +29 -0
- data/lib/action_cable_client.rb +49 -10
- data/lib/action_cable_client/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bf3e80558eb6d0f95a7231691b4418cf8db5477f
|
4
|
+
data.tar.gz: 86148eae1c47b441775874811d55a9b330482e88
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a681d1dd7de3ca8530f36a2998ceab0cf6fbbdc890f914ccb81db8670535dd28520cda5ced1a80fdd3f54702819c23b664835e753669bcca9e2a71f3d4ea64c
|
7
|
+
data.tar.gz: 0b5170f14d921eaaf7d244806b9b8083fc58563fd7f382257c1aee936a4b77a94c9734f8794c139550ebe668375cff8145ec960af2d6471ec1ff37f2777748b0
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -53,6 +53,35 @@ Action Cable Client Demo on YouTube (1:41)
|
|
53
53
|
|
54
54
|
[Here is a set of files in a gist](https://gist.github.com/NullVoxPopuli/edfcbbe91a7877e445cbde84c7f05b37) that demonstrate how different `action_cable_client`s can communicate with eachother.
|
55
55
|
|
56
|
+
## The Action Cable Protocol
|
57
|
+
|
58
|
+
There really isn't that much to this gem. :-)
|
59
|
+
|
60
|
+
1. Connect to the Action Cable URL
|
61
|
+
2. After the connection succeeds, send a subscribe message
|
62
|
+
- The subscribe message JSON should look like this
|
63
|
+
- `{"command":"subscribe","identifier":"{\"channel\":\"MeshRelayChannel\"}"}`
|
64
|
+
- You should receive a message like this:
|
65
|
+
- `{"identifier"=>"{\"channel\":\"MeshRelayChannel\"}", "type"=>"confirm_subscription"}`
|
66
|
+
3. Once subscribed, you can send messages.
|
67
|
+
- Make sure that the command string matches the data-handling method name on your ActionCable server.
|
68
|
+
- Your message JSON should look like this:
|
69
|
+
- `{"command":"message","identifier":"{\"channel\":\"MeshRelayChannel\"}","data":"{\"to\":\"user1\",\"message\":\"hello from user2\",\"action\":\"chat\"}"}`
|
70
|
+
- Received messages should look about the same
|
71
|
+
|
72
|
+
4. Notes:
|
73
|
+
- Every message sent to the server has a `command` and `identifier` key.
|
74
|
+
- The channel value must match the `name` of the channel class on the ActionCable server.
|
75
|
+
- `identifier` and `data` are redundantly jsonified. So, for example (in ruby):
|
76
|
+
```ruby
|
77
|
+
payload = {
|
78
|
+
command: 'command text',
|
79
|
+
identifier: { channel: 'MeshRelayChannel' }.to_json,
|
80
|
+
data: { to: 'user', message: 'hi' }.to_json
|
81
|
+
}.to_json
|
82
|
+
```
|
83
|
+
|
84
|
+
|
56
85
|
## Contributing
|
57
86
|
|
58
87
|
1. Fork it ( https://github.com/NullVoxPopuli/action_cable_client/fork )
|
data/lib/action_cable_client.rb
CHANGED
@@ -75,17 +75,9 @@ class ActionCableClient
|
|
75
75
|
# end
|
76
76
|
def received(skip_pings = true)
|
77
77
|
_websocket_client.stream do |message|
|
78
|
-
|
79
|
-
json = JSON.parse(string)
|
80
|
-
|
81
|
-
if is_ping?(json)
|
82
|
-
check_for_subscribe_confirmation(json) unless subscribed?
|
83
|
-
yield(json) unless skip_pings
|
84
|
-
else
|
78
|
+
handle_received_message(message, skip_pings) do |json|
|
85
79
|
yield(json)
|
86
80
|
end
|
87
|
-
|
88
|
-
deplete_queue if _queued_send
|
89
81
|
end
|
90
82
|
end
|
91
83
|
|
@@ -105,6 +97,53 @@ class ActionCableClient
|
|
105
97
|
|
106
98
|
private
|
107
99
|
|
100
|
+
|
101
|
+
# @param [WebSocket::Frame::Incoming::Client] message - the websockt message object
|
102
|
+
# This object is from the websocket-ruby gem:
|
103
|
+
# https://github.com/imanel/websocket-ruby/blob/master/lib/websocket/frame/incoming/client.rb
|
104
|
+
#
|
105
|
+
# [9] pry(#<ActionCableClient>)> ap message.methods - Object.instance_methods
|
106
|
+
#
|
107
|
+
# [ 0] <<(data) WebSocket::Frame::Incoming::Client (WebSocket::Frame::Incoming)
|
108
|
+
# [ 1] code() WebSocket::Frame::Incoming::Client (WebSocket::Frame::Base)
|
109
|
+
# [ 2] code=(arg1) WebSocket::Frame::Incoming::Client (WebSocket::Frame::Base)
|
110
|
+
# [ 3] data() WebSocket::Frame::Incoming::Client (WebSocket::Frame::Base)
|
111
|
+
# [ 4] data=(arg1) WebSocket::Frame::Incoming::Client (WebSocket::Frame::Base)
|
112
|
+
# [ 5] decoded?() WebSocket::Frame::Incoming::Client (WebSocket::Frame::Incoming)
|
113
|
+
# [ 6] error() WebSocket::Frame::Incoming::Client (WebSocket::Frame::Base)
|
114
|
+
# [ 7] error=(arg1) WebSocket::Frame::Incoming::Client (WebSocket::ExceptionHandler)
|
115
|
+
# [ 8] error?() WebSocket::Frame::Incoming::Client (WebSocket::Frame::Base)
|
116
|
+
# [ 9] incoming_masking?() WebSocket::Frame::Incoming::Client
|
117
|
+
# [10] initialize_with_rescue(*args) WebSocket::Frame::Incoming::Client (WebSocket::Frame::Base)
|
118
|
+
# [11] next(*args) WebSocket::Frame::Incoming::Client (WebSocket::Frame::Incoming)
|
119
|
+
# [12] next_with_rescue(*args) WebSocket::Frame::Incoming::Client (WebSocket::Frame::Incoming)
|
120
|
+
# [13] next_without_rescue() WebSocket::Frame::Incoming::Client (WebSocket::Frame::Incoming)
|
121
|
+
# [14] outgoing_masking?() WebSocket::Frame::Incoming::Client
|
122
|
+
# [15] support_type?() WebSocket::Frame::Incoming::Client (WebSocket::Frame::Base)
|
123
|
+
# [16] supported_frames() WebSocket::Frame::Incoming::Client (WebSocket::Frame::Base)
|
124
|
+
# [17] type() WebSocket::Frame::Incoming::Client (WebSocket::Frame::Base)
|
125
|
+
# [18] version() WebSocket::Frame::Incoming::Client (WebSocket::Frame::Base)
|
126
|
+
#
|
127
|
+
# None of this really seems that importont, other than `data`
|
128
|
+
#
|
129
|
+
# @param [Boolean] skip_pings - by default, messages
|
130
|
+
# with the identifier '_ping' are skipped
|
131
|
+
def handle_received_message(message, skip_pings = true)
|
132
|
+
string = message.data
|
133
|
+
json = JSON.parse(string)
|
134
|
+
|
135
|
+
if is_ping?(json)
|
136
|
+
check_for_subscribe_confirmation(json) unless subscribed?
|
137
|
+
yield(json) unless skip_pings
|
138
|
+
else
|
139
|
+
# TODO: do we want to yield any additional things?
|
140
|
+
# maybe just make it extensible?
|
141
|
+
yield(json)
|
142
|
+
end
|
143
|
+
|
144
|
+
deplete_queue if _queued_send
|
145
|
+
end
|
146
|
+
|
108
147
|
# {"identifier" => "_ping","type" => "confirm_subscription"}
|
109
148
|
def check_for_subscribe_confirmation(message)
|
110
149
|
message_type = message[Message::TYPE_KEY]
|
@@ -120,7 +159,7 @@ class ActionCableClient
|
|
120
159
|
|
121
160
|
def subscribe
|
122
161
|
msg = _message_factory.create(Commands::SUBSCRIBE)
|
123
|
-
|
162
|
+
send_msg(msg.to_json)
|
124
163
|
end
|
125
164
|
|
126
165
|
def deplete_queue
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: action_cable_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- L. Preston Sego III
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -129,5 +129,5 @@ rubyforge_project:
|
|
129
129
|
rubygems_version: 2.5.1
|
130
130
|
signing_key:
|
131
131
|
specification_version: 4
|
132
|
-
summary: ActionCableClient-1.
|
132
|
+
summary: ActionCableClient-1.2.0
|
133
133
|
test_files: []
|