mirror of https://github.com/rails/rails
Fix #45738
This commit is contained in:
parent
876977d0ad
commit
3a6ab41595
|
@ -197,7 +197,7 @@
|
|||
isActive() {
|
||||
return this.isState("open", "connecting");
|
||||
}
|
||||
reconnectAttempted() {
|
||||
triedToReconnect() {
|
||||
return this.monitor.reconnectAttempts > 0;
|
||||
}
|
||||
isProtocolSupported() {
|
||||
|
@ -237,6 +237,9 @@
|
|||
const {identifier: identifier, message: message, reason: reason, reconnect: reconnect, type: type} = JSON.parse(event.data);
|
||||
switch (type) {
|
||||
case message_types.welcome:
|
||||
if (this.triedToReconnect()) {
|
||||
this.reconnectAttempted = true;
|
||||
}
|
||||
this.monitor.recordConnect();
|
||||
return this.subscriptions.reload();
|
||||
|
||||
|
@ -251,9 +254,16 @@
|
|||
|
||||
case message_types.confirmation:
|
||||
this.subscriptions.confirmSubscription(identifier);
|
||||
return this.subscriptions.notify(identifier, "connected", {
|
||||
reconnected: this.reconnectAttempted()
|
||||
});
|
||||
if (this.reconnectAttempted) {
|
||||
this.reconnectAttempted = false;
|
||||
return this.subscriptions.notify(identifier, "connected", {
|
||||
reconnected: true
|
||||
});
|
||||
} else {
|
||||
return this.subscriptions.notify(identifier, "connected", {
|
||||
reconnected: false
|
||||
});
|
||||
}
|
||||
|
||||
case message_types.rejection:
|
||||
return this.subscriptions.reject(identifier);
|
||||
|
|
|
@ -203,7 +203,7 @@ class Connection {
|
|||
isActive() {
|
||||
return this.isState("open", "connecting");
|
||||
}
|
||||
reconnectAttempted() {
|
||||
triedToReconnect() {
|
||||
return this.monitor.reconnectAttempts > 0;
|
||||
}
|
||||
isProtocolSupported() {
|
||||
|
@ -245,6 +245,9 @@ Connection.prototype.events = {
|
|||
const {identifier: identifier, message: message, reason: reason, reconnect: reconnect, type: type} = JSON.parse(event.data);
|
||||
switch (type) {
|
||||
case message_types.welcome:
|
||||
if (this.triedToReconnect()) {
|
||||
this.reconnectAttempted = true;
|
||||
}
|
||||
this.monitor.recordConnect();
|
||||
return this.subscriptions.reload();
|
||||
|
||||
|
@ -259,9 +262,16 @@ Connection.prototype.events = {
|
|||
|
||||
case message_types.confirmation:
|
||||
this.subscriptions.confirmSubscription(identifier);
|
||||
return this.subscriptions.notify(identifier, "connected", {
|
||||
reconnected: this.reconnectAttempted()
|
||||
});
|
||||
if (this.reconnectAttempted) {
|
||||
this.reconnectAttempted = false;
|
||||
return this.subscriptions.notify(identifier, "connected", {
|
||||
reconnected: true
|
||||
});
|
||||
} else {
|
||||
return this.subscriptions.notify(identifier, "connected", {
|
||||
reconnected: false
|
||||
});
|
||||
}
|
||||
|
||||
case message_types.rejection:
|
||||
return this.subscriptions.reject(identifier);
|
||||
|
|
|
@ -197,7 +197,7 @@
|
|||
isActive() {
|
||||
return this.isState("open", "connecting");
|
||||
}
|
||||
reconnectAttempted() {
|
||||
triedToReconnect() {
|
||||
return this.monitor.reconnectAttempts > 0;
|
||||
}
|
||||
isProtocolSupported() {
|
||||
|
@ -237,6 +237,9 @@
|
|||
const {identifier: identifier, message: message, reason: reason, reconnect: reconnect, type: type} = JSON.parse(event.data);
|
||||
switch (type) {
|
||||
case message_types.welcome:
|
||||
if (this.triedToReconnect()) {
|
||||
this.reconnectAttempted = true;
|
||||
}
|
||||
this.monitor.recordConnect();
|
||||
return this.subscriptions.reload();
|
||||
|
||||
|
@ -251,9 +254,16 @@
|
|||
|
||||
case message_types.confirmation:
|
||||
this.subscriptions.confirmSubscription(identifier);
|
||||
return this.subscriptions.notify(identifier, "connected", {
|
||||
reconnected: this.reconnectAttempted()
|
||||
});
|
||||
if (this.reconnectAttempted) {
|
||||
this.reconnectAttempted = false;
|
||||
return this.subscriptions.notify(identifier, "connected", {
|
||||
reconnected: true
|
||||
});
|
||||
} else {
|
||||
return this.subscriptions.notify(identifier, "connected", {
|
||||
reconnected: false
|
||||
});
|
||||
}
|
||||
|
||||
case message_types.rejection:
|
||||
return this.subscriptions.reject(identifier);
|
||||
|
|
|
@ -81,7 +81,7 @@ class Connection {
|
|||
return this.isState("open", "connecting")
|
||||
}
|
||||
|
||||
reconnectAttempted() {
|
||||
triedToReconnect() {
|
||||
return this.monitor.reconnectAttempts > 0
|
||||
}
|
||||
|
||||
|
@ -129,6 +129,9 @@ Connection.prototype.events = {
|
|||
const {identifier, message, reason, reconnect, type} = JSON.parse(event.data)
|
||||
switch (type) {
|
||||
case message_types.welcome:
|
||||
if (this.triedToReconnect()) {
|
||||
this.reconnectAttempted = true
|
||||
}
|
||||
this.monitor.recordConnect()
|
||||
return this.subscriptions.reload()
|
||||
case message_types.disconnect:
|
||||
|
@ -138,7 +141,12 @@ Connection.prototype.events = {
|
|||
return this.monitor.recordPing()
|
||||
case message_types.confirmation:
|
||||
this.subscriptions.confirmSubscription(identifier)
|
||||
return this.subscriptions.notify(identifier, "connected", {reconnected: this.reconnectAttempted()})
|
||||
if (this.reconnectAttempted) {
|
||||
this.reconnectAttempted = false
|
||||
return this.subscriptions.notify(identifier, "connected", {reconnected: true})
|
||||
} else {
|
||||
return this.subscriptions.notify(identifier, "connected", {reconnected: false})
|
||||
}
|
||||
case message_types.rejection:
|
||||
return this.subscriptions.reject(identifier)
|
||||
default:
|
||||
|
|
|
@ -14,8 +14,9 @@ module("ActionCable.Subscription", () => {
|
|||
|
||||
consumerTest("#connected callback", ({server, consumer, assert, done}) => {
|
||||
const subscription = consumer.subscriptions.create("chat", {
|
||||
connected() {
|
||||
connected({reconnected}) {
|
||||
assert.ok(true)
|
||||
assert.notOk(reconnected)
|
||||
done()
|
||||
}
|
||||
})
|
||||
|
@ -26,13 +27,12 @@ module("ActionCable.Subscription", () => {
|
|||
consumerTest("#connected callback (handling reconnects)", ({server, consumer, connection, monitor, assert, done}) => {
|
||||
const subscription = consumer.subscriptions.create("chat", {
|
||||
connected({reconnected}) {
|
||||
assert.ok(true, reconnected)
|
||||
assert.ok(reconnected)
|
||||
done()
|
||||
}
|
||||
})
|
||||
|
||||
monitor.reconnectAttempts = 1
|
||||
assert.ok(connection.reconnectAttempted())
|
||||
server.broadcastTo(subscription, {message_type: "welcome"})
|
||||
server.broadcastTo(subscription, {message_type: "confirmation"})
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue