dexiecable 3.0.1 → 4.0.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/README.md +5 -11
- data/lib/dexiecable/active_record_ext.rb +18 -0
- data/lib/dexiecable/concern.rb +1 -20
- data/lib/dexiecable/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: dc8d12fc20298e1698ef329c2003cfab1a5e6508577f9542dd03a24e8d7d88ec
|
|
4
|
+
data.tar.gz: 36c9682301446b416bc5528431e934c93c1902adac0a64f9f3dce6d2f87d4328
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 41476f7e6f642abceefc394cf9686572c5dea7e35db568b43d7fbc76b44a5e076783c091f9caff74839bcc66c6db1521f4f467b2847662e1a95e5675496b49f5
|
|
7
|
+
data.tar.gz: a10831e0fe6271f3630520b595d5f4554fbf80fcfaccdd1766b832d8425eaaf5bc71610e5785d2be7fe5e6c0450b605bee9ce75e6360aff59553c81668f6a090
|
data/README.md
CHANGED
|
@@ -106,7 +106,7 @@ import { subscribe } from "dexiecable";
|
|
|
106
106
|
import { db } from "./db";
|
|
107
107
|
|
|
108
108
|
const subscription = subscribe(db);
|
|
109
|
-
// Stream tokens come from the server:
|
|
109
|
+
// Stream tokens come from the server: target.to_stream_token
|
|
110
110
|
subscription.addStream(streamToken);
|
|
111
111
|
```
|
|
112
112
|
|
|
@@ -135,23 +135,17 @@ class DexieChannel < ApplicationCable::Channel
|
|
|
135
135
|
end
|
|
136
136
|
```
|
|
137
137
|
|
|
138
|
-
Stream tokens are signed with the application secret, so a client can only subscribe to streams the server has issued for it:
|
|
138
|
+
Stream tokens are signed with the application secret, so a client can only subscribe to streams the server has issued for it. Generate one on the record itself:
|
|
139
139
|
|
|
140
140
|
```ruby
|
|
141
|
-
|
|
142
|
-
```
|
|
143
|
-
|
|
144
|
-
For an ActiveRecord model it returns a signed GlobalID (Rails' `signed_id`):
|
|
145
|
-
|
|
146
|
-
```ruby
|
|
147
|
-
DexieChannel.stream_token_for(current_user)
|
|
141
|
+
current_user.to_stream_token
|
|
148
142
|
# => "signed global id"
|
|
149
143
|
```
|
|
150
144
|
|
|
151
145
|
Tokens never expire by default. Pass `expires_in:` or `expires_at:` to limit a token's lifetime:
|
|
152
146
|
|
|
153
147
|
```ruby
|
|
154
|
-
|
|
148
|
+
current_user.to_stream_token(expires_in: 1.day)
|
|
155
149
|
```
|
|
156
150
|
|
|
157
151
|
An expired token, or one whose record no longer exists, is rejected. Only plain strings are treated as public stream names.
|
|
@@ -322,7 +316,7 @@ class Message < ApplicationRecord
|
|
|
322
316
|
end
|
|
323
317
|
```
|
|
324
318
|
|
|
325
|
-
Broadcasts go out over `DexieChannel`, the channel DexieCable provides. On the client, subscribe to it and add the stream token returned by `
|
|
319
|
+
Broadcasts go out over `DexieChannel`, the channel DexieCable provides. On the client, subscribe to it and add the stream token returned by `record.to_stream_token`:
|
|
326
320
|
|
|
327
321
|
```js
|
|
328
322
|
const subscription = subscribe(db);
|
|
@@ -117,6 +117,24 @@ module DexieCable
|
|
|
117
117
|
end
|
|
118
118
|
end
|
|
119
119
|
|
|
120
|
+
# Returns a signed token the client passes to +subscription.addStream+ to
|
|
121
|
+
# receive this record's stream. Tokens never expire by default; pass
|
|
122
|
+
# +expires_in:+ (a duration) or +expires_at:+ (a time) to limit their
|
|
123
|
+
# lifetime.
|
|
124
|
+
def to_stream_token(expires_at: nil, expires_in: nil)
|
|
125
|
+
options = { for: STREAM_TOKEN_PURPOSE }
|
|
126
|
+
|
|
127
|
+
if expires_at
|
|
128
|
+
options[:expires_at] = expires_at
|
|
129
|
+
elsif expires_in
|
|
130
|
+
options[:expires_in] = expires_in
|
|
131
|
+
else
|
|
132
|
+
options[:expires_at] = nil # never expire
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
to_sgid_param(**options)
|
|
136
|
+
end
|
|
137
|
+
|
|
120
138
|
private
|
|
121
139
|
|
|
122
140
|
def resolve_channels(via = nil)
|
data/lib/dexiecable/concern.rb
CHANGED
|
@@ -25,7 +25,7 @@ module DexieCable
|
|
|
25
25
|
# The client subscribes to that channel and adds streams dynamically:
|
|
26
26
|
#
|
|
27
27
|
# subscribe(db) # subscribes to "DexieChannel"
|
|
28
|
-
# subscription.addStream(
|
|
28
|
+
# subscription.addStream(current_user.to_stream_token)
|
|
29
29
|
# subscription.addStream("feed") # plain strings are public streams
|
|
30
30
|
#
|
|
31
31
|
extend ActiveSupport::Concern
|
|
@@ -68,25 +68,6 @@ module DexieCable
|
|
|
68
68
|
{}
|
|
69
69
|
end
|
|
70
70
|
end
|
|
71
|
-
|
|
72
|
-
# Returns a signed token for +target+ (a record). Send it to the client,
|
|
73
|
-
# which passes it to +subscription.addStream+.
|
|
74
|
-
#
|
|
75
|
-
# Tokens never expire by default. Pass +expires_in:+ (a duration) or
|
|
76
|
-
# +expires_at:+ (a time) to limit a token's lifetime.
|
|
77
|
-
def stream_token_for(target, expires_at: nil, expires_in: nil)
|
|
78
|
-
options = { for: STREAM_TOKEN_PURPOSE }
|
|
79
|
-
|
|
80
|
-
if expires_at
|
|
81
|
-
options[:expires_at] = expires_at
|
|
82
|
-
elsif expires_in
|
|
83
|
-
options[:expires_in] = expires_in
|
|
84
|
-
else
|
|
85
|
-
options[:expires_at] = nil # never expire
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
target.to_sgid_param(**options)
|
|
89
|
-
end
|
|
90
71
|
end
|
|
91
72
|
|
|
92
73
|
# Build a query against a Dexie table, transmitted to all subscribers
|
data/lib/dexiecable/version.rb
CHANGED