{“ast”:null,“code”:“function _typeof2(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof2 = function _typeof2(obj) { return typeof obj; }; } else { _typeof2 = function _typeof2(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof2(obj); }nn(function (global, factory) {n (typeof exports === "undefined" ? "undefined" : _typeof2(exports)) === "object" && typeof module !== "undefined" ? factory(exports) : typeof define === "function" && define.amd ? define(, factory) : factory(global.ActionCable = {});n})(this, function (exports) {n "use strict";nn var adapters = {n logger: self.console,n WebSocket: self.WebSocketn };n var logger = {n log: function log() {n if (this.enabled) {n var _adapters$logger;nn for (var _len = arguments.length, messages = Array(_len), _key = 0; _key < _len; _key++) {n messages = arguments;n }nn messages.push(Date.now());nn (_adapters$logger = adapters.logger).log.apply(_adapters$logger, ["[ActionCable]"].concat(messages));n }n }n };nn var _typeof = typeof Symbol === "function" && _typeof2(Symbol.iterator) === "symbol" ? function (obj) {n return _typeof2(obj);n } : function (obj) {n return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : _typeof2(obj);n };nn var classCallCheck = function classCallCheck(instance, Constructor) {n if (!(instance instanceof Constructor)) {n throw new TypeError("Cannot call a class as a function");n }n };nn var createClass = function () {n function defineProperties(target, props) {n for (var i = 0; i < props.length; i++) {n var descriptor = props;n descriptor.enumerable = descriptor.enumerable || false;n descriptor.configurable = true;n if ("value" in descriptor) descriptor.writable = true;n Object.defineProperty(target, descriptor.key, descriptor);n }n }nn return function (Constructor, protoProps, staticProps) {n if (protoProps) defineProperties(Constructor.prototype, protoProps);n if (staticProps) defineProperties(Constructor, staticProps);n return Constructor;n };n }();nn var now = function now() {n return new Date().getTime();n };nn var secondsSince = function secondsSince(time) {n return (now() - time) / 1e3;n };nn var clamp = function clamp(number, min, max) {n return Math.max(min, Math.min(max, number));n };nn var ConnectionMonitor = function () {n function ConnectionMonitor(connection) {n classCallCheck(this, ConnectionMonitor);n this.visibilityDidChange = this.visibilityDidChange.bind(this);n this.connection = connection;n this.reconnectAttempts = 0;n }nn ConnectionMonitor.prototype.start = function start() {n if (!this.isRunning()) {n this.startedAt = now();n delete this.stoppedAt;n this.startPolling();n addEventListener("visibilitychange", this.visibilityDidChange);n logger.log("ConnectionMonitor started. pollInterval = " + this.getPollInterval() + " ms");n }n };nn ConnectionMonitor.prototype.stop = function stop() {n if (this.isRunning()) {n this.stoppedAt = now();n this.stopPolling();n removeEventListener("visibilitychange", this.visibilityDidChange);n logger.log("ConnectionMonitor stopped");n }n };nn ConnectionMonitor.prototype.isRunning = function isRunning() {n return this.startedAt && !this.stoppedAt;n };nn ConnectionMonitor.prototype.recordPing = function recordPing() {n this.pingedAt = now();n };nn ConnectionMonitor.prototype.recordConnect = function recordConnect() {n this.reconnectAttempts = 0;n this.recordPing();n delete this.disconnectedAt;n logger.log("ConnectionMonitor recorded connect");n };nn ConnectionMonitor.prototype.recordDisconnect = function recordDisconnect() {n this.disconnectedAt = now();n logger.log("ConnectionMonitor recorded disconnect");n };nn ConnectionMonitor.prototype.startPolling = function startPolling() {n this.stopPolling();n this.poll();n };nn ConnectionMonitor.prototype.stopPolling = function stopPolling() {n clearTimeout(this.pollTimeout);n };nn ConnectionMonitor.prototype.poll = function poll() {n var _this = this;nn this.pollTimeout = setTimeout(function () {n _this.reconnectIfStale();nn _this.poll();n }, this.getPollInterval());n };nn ConnectionMonitor.prototype.getPollInterval = function getPollInterval() {n var _constructor$pollInte = this.constructor.pollInterval,n min = _constructor$pollInte.min,n max = _constructor$pollInte.max,n multiplier = _constructor$pollInte.multiplier;n var interval = multiplier * Math.log(this.reconnectAttempts + 1);n return Math.round(clamp(interval, min, max) * 1e3);n };nn ConnectionMonitor.prototype.reconnectIfStale = function reconnectIfStale() {n if (this.connectionIsStale()) {n logger.log("ConnectionMonitor detected stale connection. reconnectAttempts = " + this.reconnectAttempts + ", pollInterval = " + this.getPollInterval() + " ms, time disconnected = " + secondsSince(this.disconnectedAt) + " s, stale threshold = " + this.constructor.staleThreshold + " s");n this.reconnectAttempts++;nn if (this.disconnectedRecently()) {n logger.log("ConnectionMonitor skipping reopening recent disconnect");n } else {n logger.log("ConnectionMonitor reopening");n this.connection.reopen();n }n }n };nn ConnectionMonitor.prototype.connectionIsStale = function connectionIsStale() {n return secondsSince(this.pingedAt ? this.pingedAt : this.startedAt) > this.constructor.staleThreshold;n };nn ConnectionMonitor.prototype.disconnectedRecently = function disconnectedRecently() {n return this.disconnectedAt && secondsSince(this.disconnectedAt) < this.constructor.staleThreshold;n };nn ConnectionMonitor.prototype.visibilityDidChange = function visibilityDidChange() {n var _this2 = this;nn if (document.visibilityState === "visible") {n setTimeout(function () {n if (_this2.connectionIsStale() || !_this2.connection.isOpen()) {n logger.log("ConnectionMonitor reopening stale connection on visibilitychange. visbilityState = " + document.visibilityState);nn _this2.connection.reopen();n }n }, 200);n }n };nn return ConnectionMonitor;n }();nn ConnectionMonitor.pollInterval = {n min: 3,n max: 30,n multiplier: 5n };n ConnectionMonitor.staleThreshold = 6;n var INTERNAL = {n message_types: {n welcome: "welcome",n disconnect: "disconnect",n ping: "ping",n confirmation: "confirm_subscription",n rejection: "reject_subscription"n },n disconnect_reasons: {n unauthorized: "unauthorized",n invalid_request: "invalid_request",n server_restart: "server_restart"n },n default_mount_path: "/cable",n protocols: ["actioncable-v1-json", "actioncable-unsupported"]n };n var message_types = INTERNAL.message_types,n protocols = INTERNAL.protocols;n var supportedProtocols = protocols.slice(0, protocols.length - 1);n var indexOf = [].indexOf;nn var Connection = function () {n function Connection(consumer) {n classCallCheck(this, Connection);n this.open = this.open.bind(this);n this.consumer = consumer;n this.subscriptions = this.consumer.subscriptions;n this.monitor = new ConnectionMonitor(this);n this.disconnected = true;n }nn Connection.prototype.send = function send(data) {n if (this.isOpen()) {n this.webSocket.send(JSON.stringify(data));n return true;n } else {n return false;n }n };nn Connection.prototype.open = function open() {n if (this.isActive()) {n logger.log("Attempted to open WebSocket, but existing socket is " + this.getState());n return false;n } else {n logger.log("Opening WebSocket, current state is " + this.getState() + ", subprotocols: " + protocols);nn if (this.webSocket) {n this.uninstallEventHandlers();n }nn this.webSocket = new adapters.WebSocket(this.consumer.url, protocols);n this.installEventHandlers();n this.monitor.start();n return true;n }n };nn Connection.prototype.close = function close() {n var _ref = arguments.length > 0 && arguments !== undefined ? arguments : {n allowReconnect: truen },n allowReconnect = _ref.allowReconnect;nn if (!allowReconnect) {n this.monitor.stop();n }nn if (this.isActive()) {n return this.webSocket.close();n }n };nn Connection.prototype.reopen = function reopen() {n logger.log("Reopening WebSocket, current state is " + this.getState());nn if (this.isActive()) {n try {n return this.close();n } catch (error) {n logger.log("Failed to reopen WebSocket", error);n } finally {n logger.log("Reopening WebSocket in " + this.constructor.reopenDelay + "ms");n setTimeout(this.open, this.constructor.reopenDelay);n }n } else {n return this.open();n }n };nn Connection.prototype.getProtocol = function getProtocol() {n if (this.webSocket) {n return this.webSocket.protocol;n }n };nn Connection.prototype.isOpen = function isOpen() {n return this.isState("open");n };nn Connection.prototype.isActive = function isActive() {n return this.isState("open", "connecting");n };nn Connection.prototype.isProtocolSupported = function isProtocolSupported() {n return indexOf.call(supportedProtocols, this.getProtocol()) >= 0;n };nn Connection.prototype.isState = function isState() {n for (var _len = arguments.length, states = Array(_len), _key = 0; _key < _len; _key++) {n states = arguments;n }nn return indexOf.call(states, this.getState()) >= 0;n };nn Connection.prototype.getState = function getState() {n if (this.webSocket) {n for (var state in adapters.WebSocket) {n if (adapters.WebSocket === this.webSocket.readyState) {n return state.toLowerCase();n }n }n }nn return null;n };nn Connection.prototype.installEventHandlers = function installEventHandlers() {n for (var eventName in this.events) {n var handler = this.events.bind(this);n this.webSocket["on" + eventName] = handler;n }n };nn Connection.prototype.uninstallEventHandlers = function uninstallEventHandlers() {n for (var eventName in this.events) {n this.webSocket["on" + eventName] = function () {};n }n };nn return Connection;n }();nn Connection.reopenDelay = 500;n Connection.prototype.events = {n message: function message(event) {n if (!this.isProtocolSupported()) {n return;n }nn var _JSON$parse = JSON.parse(event.data),n identifier = _JSON$parse.identifier,n message = _JSON$parse.message,n reason = _JSON$parse.reason,n reconnect = _JSON$parse.reconnect,n type = _JSON$parse.type;nn switch (type) {n case message_types.welcome:n this.monitor.recordConnect();n return this.subscriptions.reload();nn case message_types.disconnect:n logger.log("Disconnecting. Reason: " + reason);n return this.close({n allowReconnect: reconnectn });nn case message_types.ping:n return this.monitor.recordPing();nn case message_types.confirmation:n return this.subscriptions.notify(identifier, "connected");nn case message_types.rejection:n return this.subscriptions.reject(identifier);nn default:n return this.subscriptions.notify(identifier, "received", message);n }n },n open: function open() {n logger.log("WebSocket onopen event, using '" + this.getProtocol() + "' subprotocol");n this.disconnected = false;nn if (!this.isProtocolSupported()) {n logger.log("Protocol is unsupported. Stopping monitor and disconnecting.");n return this.close({n allowReconnect: falsen });n }n },n close: function close(event) {n logger.log("WebSocket onclose event");nn if (this.disconnected) {n return;n }nn this.disconnected = true;n this.monitor.recordDisconnect();n return this.subscriptions.notifyAll("disconnected", {n willAttemptReconnect: this.monitor.isRunning()n });n },n error: function error() {n logger.log("WebSocket onerror event");n }n };nn var extend = function extend(object, properties) {n if (properties != null) {n for (var key in properties) {n var value = properties;n object = value;n }n }nn return object;n };nn var Subscription = function () {n function Subscription(consumer) {n var params = arguments.length > 1 && arguments !== undefined ? arguments : {};n var mixin = arguments;n classCallCheck(this, Subscription);n this.consumer = consumer;n this.identifier = JSON.stringify(params);n extend(this, mixin);n }nn Subscription.prototype.perform = function perform(action) {n var data = arguments.length > 1 && arguments !== undefined ? arguments : {};n data.action = action;n return this.send(data);n };nn Subscription.prototype.send = function send(data) {n return this.consumer.send({n command: "message",n identifier: this.identifier,n data: JSON.stringify(data)n });n };nn Subscription.prototype.unsubscribe = function unsubscribe() {n return this.consumer.subscriptions.remove(this);n };nn return Subscription;n }();nn var Subscriptions = function () {n function Subscriptions(consumer) {n classCallCheck(this, Subscriptions);n this.consumer = consumer;n this.subscriptions = [];n }nn Subscriptions.prototype.create = function create(channelName, mixin) {n var channel = channelName;n var params = (typeof channel === "undefined" ? "undefined" : _typeof(channel)) === "object" ? channel : {n channel: channeln };n var subscription = new Subscription(this.consumer, params, mixin);n return this.add(subscription);n };nn Subscriptions.prototype.add = function add(subscription) {n this.subscriptions.push(subscription);n this.consumer.ensureActiveConnection();n this.notify(subscription, "initialized");n this.sendCommand(subscription, "subscribe");n return subscription;n };nn Subscriptions.prototype.remove = function remove(subscription) {n this.forget(subscription);nn if (!this.findAll(subscription.identifier).length) {n this.sendCommand(subscription, "unsubscribe");n }nn return subscription;n };nn Subscriptions.prototype.reject = function reject(identifier) {n var _this = this;nn return this.findAll(identifier).map(function (subscription) {n _this.forget(subscription);nn _this.notify(subscription, "rejected");nn return subscription;n });n };nn Subscriptions.prototype.forget = function forget(subscription) {n this.subscriptions = this.subscriptions.filter(function (s) {n return s !== subscription;n });n return subscription;n };nn Subscriptions.prototype.findAll = function findAll(identifier) {n return this.subscriptions.filter(function (s) {n return s.identifier === identifier;n });n };nn Subscriptions.prototype.reload = function reload() {n var _this2 = this;nn return this.subscriptions.map(function (subscription) {n return _this2.sendCommand(subscription, "subscribe");n });n };nn Subscriptions.prototype.notifyAll = function notifyAll(callbackName) {n var _this3 = this;nn for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {n args[_key - 1] = arguments;n }nn return this.subscriptions.map(function (subscription) {n return _this3.notify.apply(_this3, [subscription, callbackName].concat(args));n });n };nn Subscriptions.prototype.notify = function notify(subscription, callbackName) {n for (var _len2 = arguments.length, args = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {n args[_key2 - 2] = arguments;n }nn var subscriptions = void 0;nn if (typeof subscription === "string") {n subscriptions = this.findAll(subscription);n } else {n subscriptions = [subscription];n }nn return subscriptions.map(function (subscription) {n return typeof subscription === "function" ? subscription.apply(subscription, args) : undefined;n });n };nn Subscriptions.prototype.sendCommand = function sendCommand(subscription, command) {n var identifier = subscription.identifier;n return this.consumer.send({n command: command,n identifier: identifiern });n };nn return Subscriptions;n }();nn var Consumer = function () {n function Consumer(url) {n classCallCheck(this, Consumer);n this._url = url;n this.subscriptions = new Subscriptions(this);n this.connection = new Connection(this);n }nn Consumer.prototype.send = function send(data) {n return this.connection.send(data);n };nn Consumer.prototype.connect = function connect() {n return this.connection.open();n };nn Consumer.prototype.disconnect = function disconnect() {n return this.connection.close({n allowReconnect: falsen });n };nn Consumer.prototype.ensureActiveConnection = function ensureActiveConnection() {n if (!this.connection.isActive()) {n return this.connection.open();n }n };nn createClass(Consumer, [{n key: "url",n get: function get$$1() {n return createWebSocketURL(this._url);n }n }]);n return Consumer;n }();nn function createWebSocketURL(url) {n if (typeof url === "function") {n url = url();n }nn if (url && !/^wss?:/i.test(url)) {n var a = document.createElement("a");n a.href = url;n a.href = a.href;n a.protocol = a.protocol.replace("http", "ws");n return a.href;n } else {n return url;n }n }nn function createConsumer() {n var url = arguments.length > 0 && arguments !== undefined ? arguments : getConfig("url") || INTERNAL.default_mount_path;n return new Consumer(url);n }nn function getConfig(name) {n var element = document.head.querySelector("meta[name='action-cable-" + name + "']");nn if (element) {n return element.getAttribute("content");n }n }nn exports.Connection = Connection;n exports.ConnectionMonitor = ConnectionMonitor;n exports.Consumer = Consumer;n exports.INTERNAL = INTERNAL;n exports.Subscription = Subscription;n exports.Subscriptions = Subscriptions;n exports.adapters = adapters;n exports.createWebSocketURL = createWebSocketURL;n exports.logger = logger;n exports.createConsumer = createConsumer;n exports.getConfig = getConfig;n Object.defineProperty(exports, "__esModule", {n value: truen });n});”,“map”:null,“metadata”:{},“sourceType”:“module”}