hotsock-turbo 0.1.0 → 0.2.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/README.md +26 -2
- data/lib/hotsock/turbo/config.rb +2 -1
- data/lib/hotsock/turbo/streams_channel.rb +8 -0
- data/lib/hotsock/turbo/streams_helper.rb +1 -1
- data/lib/hotsock/turbo/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: aa8e10033b8676f3818b4c8988046b24f410258c07f0632cd4082e9a1ed9865d
|
|
4
|
+
data.tar.gz: 575ebb35a85d1bc5ab915b6ab83c32dba6bdb542cd36c8fde03c6ad21a38946b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 443b7bae1effc3d21e06d5d1249cf8d93fda03a38f8876eacc60d9d414360887e8b20d88689a508a7b181124493bdd2ca8af2b81750fbeafc8324903bec3aa4d
|
|
7
|
+
data.tar.gz: b29f910dd278d6143812b0ab65ebbb01deb75dbde72614084880e10be081a1a1450fe7730d443a119f9e4230f09191275f100143f0d43525fb2177121f82f1c9
|
data/README.md
CHANGED
|
@@ -64,14 +64,26 @@ import "@hotsock/hotsock-js"
|
|
|
64
64
|
import "hotsock-turbo"
|
|
65
65
|
```
|
|
66
66
|
|
|
67
|
+
### Mount the Engine
|
|
68
|
+
|
|
69
|
+
Add to your `config/routes.rb`:
|
|
70
|
+
|
|
71
|
+
```ruby
|
|
72
|
+
mount Hotsock::Turbo::Engine => "/hotsock"
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
This provides a `POST /hotsock/connect` endpoint that returns connection tokens for the WebSocket client.
|
|
76
|
+
|
|
67
77
|
## Configuration
|
|
68
78
|
|
|
69
79
|
Create an initializer at `config/initializers/hotsock_turbo.rb`:
|
|
70
80
|
|
|
71
81
|
```ruby
|
|
72
82
|
Hotsock::Turbo.configure do |config|
|
|
73
|
-
# Required: Path to
|
|
74
|
-
|
|
83
|
+
# Required: Path to the engine's connect endpoint (or your own custom
|
|
84
|
+
# endpoint). This path must accept a POST request and return a JSON object
|
|
85
|
+
# with a `token` field that contains a connect-scoped JWT. {"token":"ey..."}
|
|
86
|
+
config.connect_token_path = "/hotsock/connect"
|
|
75
87
|
|
|
76
88
|
# Required: Your Hotsock WebSocket URL
|
|
77
89
|
config.wss_url = "wss://your-hotsock-instance.example.com"
|
|
@@ -96,6 +108,7 @@ end
|
|
|
96
108
|
| `log_level` | `"warn"` | JavaScript client log level (`"debug"`, `"info"`, `"warn"`, `"error"`) |
|
|
97
109
|
| `parent_controller` | `"ApplicationController"` | Base controller for generated routes |
|
|
98
110
|
| `override_turbo_broadcastable` | `false` | When `true`, overrides standard Turbo broadcast methods to use Hotsock |
|
|
111
|
+
| `suppress_broadcasts` | `false` | When `true`, suppresses all Hotsock turbo broadcasts globally |
|
|
99
112
|
|
|
100
113
|
## Usage
|
|
101
114
|
|
|
@@ -273,6 +286,17 @@ message.broadcast_replace_later_to(board)
|
|
|
273
286
|
|
|
274
287
|
### Suppressing Broadcasts
|
|
275
288
|
|
|
289
|
+
#### Global Suppression (Test Environments)
|
|
290
|
+
|
|
291
|
+
Disable all broadcasts globally, useful for test environments where you don't want to require a Hotsock configuration:
|
|
292
|
+
|
|
293
|
+
```ruby
|
|
294
|
+
# config/environments/test.rb
|
|
295
|
+
Hotsock::Turbo.config.suppress_broadcasts = true
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
#### Block-based Suppression
|
|
299
|
+
|
|
276
300
|
Temporarily disable broadcasts within a block:
|
|
277
301
|
|
|
278
302
|
```ruby
|
data/lib/hotsock/turbo/config.rb
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
module Hotsock
|
|
4
4
|
module Turbo
|
|
5
5
|
class Config
|
|
6
|
-
attr_accessor :parent_controller, :connect_token_path, :wss_url, :log_level, :override_turbo_broadcastable
|
|
6
|
+
attr_accessor :parent_controller, :connect_token_path, :wss_url, :log_level, :override_turbo_broadcastable, :suppress_broadcasts
|
|
7
7
|
|
|
8
8
|
def initialize
|
|
9
9
|
@parent_controller = "ApplicationController"
|
|
@@ -11,6 +11,7 @@ module Hotsock
|
|
|
11
11
|
@wss_url = nil
|
|
12
12
|
@log_level = "warn"
|
|
13
13
|
@override_turbo_broadcastable = false
|
|
14
|
+
@suppress_broadcasts = false
|
|
14
15
|
end
|
|
15
16
|
end
|
|
16
17
|
end
|
|
@@ -74,6 +74,8 @@ module Hotsock
|
|
|
74
74
|
end
|
|
75
75
|
|
|
76
76
|
def self.broadcast_to(stream_or_streamable, content, options = {})
|
|
77
|
+
return if Hotsock::Turbo.config.suppress_broadcasts
|
|
78
|
+
|
|
77
79
|
unless enabled?
|
|
78
80
|
fail "Turbo Streams is not enabled. Please install turbo-rails to use this method."
|
|
79
81
|
end
|
|
@@ -145,11 +147,15 @@ module Hotsock
|
|
|
145
147
|
end
|
|
146
148
|
|
|
147
149
|
def self.broadcast_refresh_later_to(*streamables, request_id: nil)
|
|
150
|
+
return if Hotsock::Turbo.config.suppress_broadcasts
|
|
151
|
+
|
|
148
152
|
stream_name = serialize_broadcasting(streamables)
|
|
149
153
|
Hotsock::Turbo::BroadcastRefreshJob.perform_later(stream_name, request_id: request_id)
|
|
150
154
|
end
|
|
151
155
|
|
|
152
156
|
def self.broadcast_action_later_to(*streamables, action:, target: nil, targets: nil, attributes: {}, **rendering)
|
|
157
|
+
return if Hotsock::Turbo.config.suppress_broadcasts
|
|
158
|
+
|
|
153
159
|
stream_name = serialize_broadcasting(streamables)
|
|
154
160
|
Hotsock::Turbo::ActionBroadcastJob.perform_later(
|
|
155
161
|
stream_name,
|
|
@@ -194,6 +200,8 @@ module Hotsock
|
|
|
194
200
|
end
|
|
195
201
|
|
|
196
202
|
def self.broadcast_render_later_to(*streamables, **rendering)
|
|
203
|
+
return if Hotsock::Turbo.config.suppress_broadcasts
|
|
204
|
+
|
|
197
205
|
stream_name = serialize_broadcasting(streamables)
|
|
198
206
|
Hotsock::Turbo::BroadcastJob.perform_later(stream_name, **rendering)
|
|
199
207
|
end
|
|
@@ -27,7 +27,7 @@ module Hotsock
|
|
|
27
27
|
def create_subscription_token(channel_name)
|
|
28
28
|
Hotsock.issue_token(
|
|
29
29
|
scope: "subscribe",
|
|
30
|
-
channels: {channel_name => {
|
|
30
|
+
channels: {channel_name => {omitFromSubCount: true, subscribe: true}},
|
|
31
31
|
uid:,
|
|
32
32
|
exp: 1.week.from_now.to_i
|
|
33
33
|
)
|