@rails/actioncable 6.1.4-1 → 7.0.0-rc1
Sign up to get free protection for your applications and to get access to all the features.
- package/app/assets/javascripts/action_cable.js +229 -256
- package/app/assets/javascripts/actioncable.esm.js +491 -0
- package/app/assets/javascripts/actioncable.js +489 -0
- package/package.json +7 -10
- package/src/connection.js +1 -0
- package/src/connection_monitor.js +14 -15
- package/src/index.js +2 -0
- package/src/index_with_name_deprecation.js +2 -0
- package/src/subscription_guarantor.js +50 -0
- package/src/subscriptions.js +18 -2
package/src/subscriptions.js
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
import Subscription from "./subscription"
|
2
|
+
import SubscriptionGuarantor from "./subscription_guarantor"
|
3
|
+
import logger from "./logger"
|
2
4
|
|
3
5
|
// Collection class for creating (and internally managing) channel subscriptions.
|
4
6
|
// The only method intended to be triggered by the user is ActionCable.Subscriptions#create,
|
@@ -13,6 +15,7 @@ import Subscription from "./subscription"
|
|
13
15
|
export default class Subscriptions {
|
14
16
|
constructor(consumer) {
|
15
17
|
this.consumer = consumer
|
18
|
+
this.guarantor = new SubscriptionGuarantor(this)
|
16
19
|
this.subscriptions = []
|
17
20
|
}
|
18
21
|
|
@@ -29,7 +32,7 @@ export default class Subscriptions {
|
|
29
32
|
this.subscriptions.push(subscription)
|
30
33
|
this.consumer.ensureActiveConnection()
|
31
34
|
this.notify(subscription, "initialized")
|
32
|
-
this.
|
35
|
+
this.subscribe(subscription)
|
33
36
|
return subscription
|
34
37
|
}
|
35
38
|
|
@@ -50,6 +53,7 @@ export default class Subscriptions {
|
|
50
53
|
}
|
51
54
|
|
52
55
|
forget(subscription) {
|
56
|
+
this.guarantor.forget(subscription)
|
53
57
|
this.subscriptions = (this.subscriptions.filter((s) => s !== subscription))
|
54
58
|
return subscription
|
55
59
|
}
|
@@ -60,7 +64,7 @@ export default class Subscriptions {
|
|
60
64
|
|
61
65
|
reload() {
|
62
66
|
return this.subscriptions.map((subscription) =>
|
63
|
-
this.
|
67
|
+
this.subscribe(subscription))
|
64
68
|
}
|
65
69
|
|
66
70
|
notifyAll(callbackName, ...args) {
|
@@ -80,6 +84,18 @@ export default class Subscriptions {
|
|
80
84
|
(typeof subscription[callbackName] === "function" ? subscription[callbackName](...args) : undefined))
|
81
85
|
}
|
82
86
|
|
87
|
+
subscribe(subscription) {
|
88
|
+
if (this.sendCommand(subscription, "subscribe")) {
|
89
|
+
this.guarantor.guarantee(subscription)
|
90
|
+
}
|
91
|
+
}
|
92
|
+
|
93
|
+
confirmSubscription(identifier) {
|
94
|
+
logger.log(`Subscription confirmed ${identifier}`)
|
95
|
+
this.findAll(identifier).map((subscription) =>
|
96
|
+
this.guarantor.forget(subscription))
|
97
|
+
}
|
98
|
+
|
83
99
|
sendCommand(subscription, command) {
|
84
100
|
const {identifier} = subscription
|
85
101
|
return this.consumer.send({command, identifier})
|