turbo_cable 1.0.0 → 1.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 30c119c76d7a8582b017756899eeee0fcdd1ffddbb2e2b1e521c65a1f62dbe52
4
- data.tar.gz: 1fd9541c95cd5e00c770e827b3ada328052d8e5a988322d22f1bb4577d1db7f4
3
+ metadata.gz: 47477c38541523e99f3f25349df665d30742f6068b75e24c45ea546a41a98906
4
+ data.tar.gz: 05031e7593eb8a22c0949c5fcdb2e51bba9670cb2631ed842d2c3b8fe8e54d13
5
5
  SHA512:
6
- metadata.gz: ac0e5d7562e5bc03e2d8bf1d396ed0c16d894cf70aeb91573be29c19ed91e82fb90f28fbc5e584386cd10915362bb5640e605c2401a8a7b4d23912f785d6c993
7
- data.tar.gz: 9ad4dbe3b6dd0b7b68c6de10ad3e38fc45480974b1fd26de5dd9db158a5ad1c9d10d3a079ba5a14a4b9c04e873612c76cf1939a7a27d7f0e14752f1a878ef00a
6
+ metadata.gz: b58628908580e011dc6d7e2fc57bd6f4e37a129500e9cb5725d3f2bbe45b95d6cabc09687cb03da5c39cfb220c3d2247bd86876bdd4654f86c92deb78cf1de9e
7
+ data.tar.gz: 0241c1d82f8cf1aa6fe3882c3c4103002978e22f08ad509e72c413c11f565faf9eda1096b3e01b251a1bc24819838a066677e88901b1cfdd4186f9c88958d7da
data/README.md CHANGED
@@ -191,6 +191,33 @@ ENV['TURBO_CABLE_BROADCAST_URL'] = 'http://localhost:3000/_broadcast'
191
191
  - **Thruster/nginx proxy**: When `PORT` is set to the proxy port, not the Rails server port
192
192
  - **Never needed**: When `PORT` correctly points to your Rails server (like with Navigator/configurator.rb)
193
193
 
194
+ ### WebSocket URL (Optional)
195
+
196
+ By default, the Stimulus controller connects to `ws://[current-host]/cable`. For custom routing or multi-region deployments, you can specify the WebSocket URL via the standard Rails helper:
197
+
198
+ ```erb
199
+ <!-- In your layout -->
200
+ <head>
201
+ <%= action_cable_meta_tag %>
202
+ </head>
203
+ ```
204
+
205
+ This generates `<meta name="action-cable-url" content="...">` using your configured `config.action_cable.url`.
206
+
207
+ **Example use cases:**
208
+ - **Multi-region deployments**: Route to region-specific endpoints (e.g., `wss://example.com/regions/us-east/cable`)
209
+ - **Reverse proxies**: Use custom paths configured in your proxy (e.g., Navigator, nginx)
210
+ - **Custom routing**: Any non-standard WebSocket endpoint path
211
+
212
+ Configure the URL in your environment config:
213
+
214
+ ```ruby
215
+ # config/environments/production.rb
216
+ config.action_cable.url = "wss://example.com/regions/#{ENV['FLY_REGION']}/cable"
217
+ ```
218
+
219
+ The Stimulus controller will use this meta tag if present, otherwise fall back to the default `/cable` endpoint on the current host.
220
+
194
221
  ## Migration from Action Cable
195
222
 
196
223
  **⚠️ First, verify your deployment architecture supports TurboCable.** If you have multiple Rails instances serving the same app (Heroku dynos, AWS containers, Kubernetes pods, load-balanced VPS), TurboCable won't work for you. See "When NOT to Use" above.
@@ -30,9 +30,10 @@ export default class extends Controller {
30
30
 
31
31
  console.debug("Subscribing to streams:", Array.from(this.streams))
32
32
 
33
- // Create WebSocket connection
34
- const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:'
35
- this.ws = new WebSocket(`${protocol}//${window.location.host}/cable`)
33
+ // Create WebSocket connection using the cable URL from meta tag
34
+ const cableUrlMeta = document.querySelector('meta[name="action-cable-url"]')
35
+ const cableUrl = cableUrlMeta?.content || `${window.location.protocol === 'https:' ? 'wss:' : 'ws:'}//${window.location.host}/cable`
36
+ this.ws = new WebSocket(cableUrl)
36
37
  this.subscribed = new Set()
37
38
 
38
39
  this.ws.onopen = () => {
@@ -97,7 +98,7 @@ export default class extends Controller {
97
98
  })
98
99
  this.ws.close()
99
100
  }
100
- this.subscribed.clear()
101
+ this.subscribed?.clear()
101
102
  }
102
103
 
103
104
  processTurboStream(stream, data) {
@@ -1,3 +1,3 @@
1
1
  module TurboCable
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turbo_cable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Ruby