y-rb_actioncable 0.1.2 → 0.1.4

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
  SHA256:
3
- metadata.gz: 9aee5ffece065c56362b59a6f7514bbe4e6177d0ea2d782ec1e3bb485cd05a53
4
- data.tar.gz: 709e1c51409f66f3134049dbf555db7c6c94bab0f1a66a629d3174051c186f0b
3
+ metadata.gz: 6f06116e8fced707775ecdbc580d8b46b7ae6f0a0e2e55042b94785da6765516
4
+ data.tar.gz: e6a8acf34ac91161f2b270459a9155bafeed09398c578d08c344051ee173573a
5
5
  SHA512:
6
- metadata.gz: b16e36125a01866c74585b92580a6391c86f264f44a8cfbd308da0edf48f9d9855f2e464b494c6286eed47a67f7f3655c405b5bd728304e5c6653948e5f03dfb
7
- data.tar.gz: d6463f08ecefb4ddfcb629e58cf6e385df9f090eefdf3a9bf1928327bb3bbaf67de8a90650e41e93a98fcaa483e0a75f05938d4f593f1a855e36123c58044ff2
6
+ metadata.gz: bb45227353a4f55e880908a59abf2ca9e8afd1f61eb011eed431bc4a64db4acae033bea610b230691134eceaa981015a6fddac7ba34e83eaaf20f64065431092
7
+ data.tar.gz: b35bfce523b71dd05af4f714707e5a13623b95332021dbab705b4bd27703e747324bbfd7051ccdea868415f7048cc6c87c62db1779c09bb04272d83a88dac9eb
data/README.md CHANGED
@@ -60,13 +60,8 @@ class SyncChannel < ApplicationCable::Channel
60
60
  include Y::Actioncable::Sync
61
61
 
62
62
  def subscribed
63
- stream_from("document-1", coder: ActiveSupport::JSON) do |message|
64
- # integrate updates in the y-rb document
65
- integrate(message)
66
- end
67
-
68
- # negotiate initial state with client
69
- initiate
63
+ # initiate sync & subscribe to updates, with optional persistence mechanism
64
+ sync_from("document-1")
70
65
  end
71
66
 
72
67
  def receive(message)
@@ -87,7 +87,10 @@ module Y
87
87
 
88
88
  # do not transmit message back to current connection if the connection
89
89
  # is the origin of the message
90
- transmit(message) if origin != connection.connection_identifier
90
+ connection_identifier = connection.connection_identifier
91
+ return if connection_identifier.present? && origin == connection_identifier
92
+
93
+ transmit(message)
91
94
  end
92
95
 
93
96
  # Sync for given model. This is a utility method that simplifies the setup
@@ -150,7 +153,7 @@ module Y
150
153
  # we broadcast to all connected clients, but provide the
151
154
  # connection_identifier as origin so that the [#integrate] method is
152
155
  # able to filter sending back the update to its origin.
153
- self.class.broadcast(
156
+ ActionCable.server.broadcast(
154
157
  broadcasting,
155
158
  { update: update, origin: connection.connection_identifier }
156
159
  )
@@ -197,8 +200,7 @@ module Y
197
200
  # "issue_channel:id:1"
198
201
  def canonical_channel_key
199
202
  @canonical_channel_key ||= begin
200
- pairs = JSON.parse!(identifier)
201
- params_part = pairs.map do |k, v|
203
+ params_part = channel_identifier.map do |k, v|
202
204
  "#{k.to_s.parameterize}-#{v.to_s.parameterize}"
203
205
  end
204
206
 
@@ -257,6 +259,14 @@ module Y
257
259
  def doc
258
260
  @doc ||= Y::Doc.new
259
261
  end
262
+
263
+ private
264
+
265
+ def channel_identifier
266
+ return ["test", identifier] if Rails.env.test?
267
+
268
+ JSON.parse(identifier)
269
+ end
260
270
  end
261
271
  end
262
272
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Y
4
4
  module Actioncable
5
- VERSION = "0.1.2"
5
+ VERSION = "0.1.4"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: y-rb_actioncable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hannes Moser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-25 00:00:00.000000000 Z
11
+ date: 2023-02-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -96,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
96
96
  - !ruby/object:Gem::Version
97
97
  version: '0'
98
98
  requirements: []
99
- rubygems_version: 3.4.4
99
+ rubygems_version: 3.4.5
100
100
  signing_key:
101
101
  specification_version: 4
102
102
  summary: An ActionCable companion for Y.js clients.