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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 47477c38541523e99f3f25349df665d30742f6068b75e24c45ea546a41a98906
|
|
4
|
+
data.tar.gz: 05031e7593eb8a22c0949c5fcdb2e51bba9670cb2631ed842d2c3b8fe8e54d13
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
|
35
|
-
|
|
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
|
|
101
|
+
this.subscribed?.clear()
|
|
101
102
|
}
|
|
102
103
|
|
|
103
104
|
processTurboStream(stream, data) {
|
data/lib/turbo_cable/version.rb
CHANGED