Skip to content

Commit

Permalink
Use released Turbo version
Browse files Browse the repository at this point in the history
  • Loading branch information
afcapel committed Nov 23, 2023
1 parent ec710c7 commit 3199f7a
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 20 deletions.
59 changes: 43 additions & 16 deletions app/assets/javascripts/turbo.js
Original file line number Diff line number Diff line change
Expand Up @@ -4060,14 +4060,14 @@ var turbo_es2017Esm = Object.freeze({
let consumer;

async function getConsumer() {
return consumer || setConsumer(createConsumer().then(setConsumer));
return consumer || setConsumer(createConsumer$1().then(setConsumer));
}

function setConsumer(newConsumer) {
return consumer = newConsumer;
}

async function createConsumer() {
async function createConsumer$1() {
const {createConsumer: createConsumer} = await Promise.resolve().then((function() {
return index;
}));
Expand All @@ -4083,7 +4083,7 @@ var cable = Object.freeze({
__proto__: null,
getConsumer: getConsumer,
setConsumer: setConsumer,
createConsumer: createConsumer,
createConsumer: createConsumer$1,
subscribeTo: subscribeTo
});

Expand Down Expand Up @@ -4309,6 +4309,8 @@ ConnectionMonitor.staleThreshold = 6;

ConnectionMonitor.reconnectionBackoffRate = .15;

var ConnectionMonitor$1 = ConnectionMonitor;

var INTERNAL = {
message_types: {
welcome: "welcome",
Expand All @@ -4320,7 +4322,8 @@ var INTERNAL = {
disconnect_reasons: {
unauthorized: "unauthorized",
invalid_request: "invalid_request",
server_restart: "server_restart"
server_restart: "server_restart",
remote: "remote"
},
default_mount_path: "/cable",
protocols: [ "actioncable-v1-json", "actioncable-unsupported" ]
Expand All @@ -4337,7 +4340,7 @@ class Connection {
this.open = this.open.bind(this);
this.consumer = consumer;
this.subscriptions = this.consumer.subscriptions;
this.monitor = new ConnectionMonitor(this);
this.monitor = new ConnectionMonitor$1(this);
this.disconnected = true;
}
send(data) {
Expand All @@ -4353,11 +4356,12 @@ class Connection {
logger.log(`Attempted to open WebSocket, but existing socket is ${this.getState()}`);
return false;
} else {
logger.log(`Opening WebSocket, current state is ${this.getState()}, subprotocols: ${protocols}`);
const socketProtocols = [ ...protocols, ...this.consumer.subprotocols || [] ];
logger.log(`Opening WebSocket, current state is ${this.getState()}, subprotocols: ${socketProtocols}`);
if (this.webSocket) {
this.uninstallEventHandlers();
}
this.webSocket = new adapters.WebSocket(this.consumer.url, protocols);
this.webSocket = new adapters.WebSocket(this.consumer.url, socketProtocols);
this.installEventHandlers();
this.monitor.start();
return true;
Expand All @@ -4369,7 +4373,7 @@ class Connection {
if (!allowReconnect) {
this.monitor.stop();
}
if (this.isActive()) {
if (this.isOpen()) {
return this.webSocket.close();
}
}
Expand Down Expand Up @@ -4399,6 +4403,9 @@ class Connection {
isActive() {
return this.isState("open", "connecting");
}
triedToReconnect() {
return this.monitor.reconnectAttempts > 0;
}
isProtocolSupported() {
return indexOf.call(supportedProtocols, this.getProtocol()) >= 0;
}
Expand Down Expand Up @@ -4438,6 +4445,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();

Expand All @@ -4452,7 +4462,16 @@ Connection.prototype.events = {

case message_types.confirmation:
this.subscriptions.confirmSubscription(identifier);
return this.subscriptions.notify(identifier, "connected");
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);
Expand Down Expand Up @@ -4487,6 +4506,8 @@ Connection.prototype.events = {
}
};

var Connection$1 = Connection;

const extend = function(object, properties) {
if (properties != null) {
for (let key in properties) {
Expand Down Expand Up @@ -4556,10 +4577,12 @@ class SubscriptionGuarantor {
}
}

var SubscriptionGuarantor$1 = SubscriptionGuarantor;

class Subscriptions {
constructor(consumer) {
this.consumer = consumer;
this.guarantor = new SubscriptionGuarantor(this);
this.guarantor = new SubscriptionGuarantor$1(this);
this.subscriptions = [];
}
create(channelName, mixin) {
Expand Down Expand Up @@ -4636,7 +4659,8 @@ class Consumer {
constructor(url) {
this._url = url;
this.subscriptions = new Subscriptions(this);
this.connection = new Connection(this);
this.connection = new Connection$1(this);
this.subprotocols = [];
}
get url() {
return createWebSocketURL(this._url);
Expand All @@ -4657,6 +4681,9 @@ class Consumer {
return this.connection.open();
}
}
addSubProtocol(subprotocol) {
this.subprotocols = [ ...this.subprotocols, subprotocol ];
}
}

function createWebSocketURL(url) {
Expand All @@ -4674,7 +4701,7 @@ function createWebSocketURL(url) {
}
}

function createConsumer$1(url = getConfig("url") || INTERNAL.default_mount_path) {
function createConsumer(url = getConfig("url") || INTERNAL.default_mount_path) {
return new Consumer(url);
}

Expand All @@ -4687,17 +4714,17 @@ function getConfig(name) {

var index = Object.freeze({
__proto__: null,
Connection: Connection,
ConnectionMonitor: ConnectionMonitor,
Connection: Connection$1,
ConnectionMonitor: ConnectionMonitor$1,
Consumer: Consumer,
INTERNAL: INTERNAL,
Subscription: Subscription,
Subscriptions: Subscriptions,
SubscriptionGuarantor: SubscriptionGuarantor,
SubscriptionGuarantor: SubscriptionGuarantor$1,
adapters: adapters,
createWebSocketURL: createWebSocketURL,
logger: logger,
createConsumer: createConsumer$1,
createConsumer: createConsumer,
getConfig: getConfig
});

Expand Down
Loading

0 comments on commit 3199f7a

Please sign in to comment.