You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 line
6.0 KiB

2 years ago
{"ast":null,"code":"/* global __webpack_dev_server_client__ */\nimport WebSocketClient from \"./clients/WebSocketClient.js\";\nimport { log } from \"./utils/log.js\"; // this WebsocketClient is here as a default fallback, in case the client is not injected\n\n/* eslint-disable camelcase */\n\nvar Client = // eslint-disable-next-line no-nested-ternary\ntypeof __webpack_dev_server_client__ !== \"undefined\" ? typeof __webpack_dev_server_client__.default !== \"undefined\" ? __webpack_dev_server_client__.default : __webpack_dev_server_client__ : WebSocketClient;\n/* eslint-enable camelcase */\n\nvar retries = 0;\nvar maxRetries = 10; // Initialized client is exported so external consumers can utilize the same instance\n// It is mutable to enforce singleton\n// eslint-disable-next-line import/no-mutable-exports\n\nexport var client = null;\n/**\n * @param {string} url\n * @param {{ [handler: string]: (data?: any, params?: any) => any }} handlers\n * @param {number} [reconnect]\n */\n\nvar socket = function initSocket(url, handlers, reconnect) {\n client = new Client(url);\n client.onOpen(function () {\n retries = 0;\n\n if (typeof reconnect !== \"undefined\") {\n maxRetries = reconnect;\n }\n });\n client.onClose(function () {\n if (retries === 0) {\n handlers.close();\n } // Try to reconnect.\n\n\n client = null; // After 10 retries stop trying, to prevent logspam.\n\n if (retries < maxRetries) {\n // Exponentially increase timeout to reconnect.\n // Respectfully copied from the package `got`.\n // eslint-disable-next-line no-restricted-properties\n var retryInMs = 1000 * Math.pow(2, retries) + Math.random() * 100;\n retries += 1;\n log.info(\"Trying to reconnect...\");\n setTimeout(function () {\n socket(url, handlers, reconnect);\n }, retryInMs);\n }\n });\n client.onMessage(\n /**\n * @param {any} data\n */\n function (data) {\n var message = JSON.parse(data);\n\n if (handlers[message.type]) {\n handlers[message.type](message.data, message.params);\n }\n });\n};\n\nexport default socket;","map":{"version":3,"names":["WebSocketClient","log","Client","__webpack_dev_server_client__","default","retries","maxRetries","client","socket","initSocket","url","handlers","reconnect","onOpen","onClose","close","retryInMs","Math","pow","random","info","setTimeout","onMessage","data","message","JSON","parse","type","params"],"sources":["/Users/mahdi/Documents/work/programming/barnameNegar/arbaeenWebApp/node_modules/webpack-dev-server/client/socket.js"],"sourcesContent":["/* global __webpack_dev_server_client__ */\nimport WebSocketClient from \"./clients/WebSocketClient.js\";\nimport { log } from \"./utils/log.js\"; // this WebsocketClient is here as a default fallback, in case the client is not injected\n\n/* eslint-disable camelcase */\n\nvar Client = // eslint-disable-next-line no-nested-ternary\ntypeof __webpack_dev_server_client__ !== \"undefined\" ? typeof __webpack_dev_server_client__.default !== \"undefined\" ? __webpack_dev_server_client__.default : __webpack_dev_server_client__ : WebSocketClient;\n/* eslint-enable camelcase */\n\nvar retries = 0;\nvar maxRetries = 10; // Initialized client is exported so external consumers can utilize the same instance\n// It is mutable to enforce singleton\n// eslint-disable-next-line import/no-mutable-exports\n\nexport var client = null;\n/**\n * @param {string} url\n * @param {{ [handler: string]: (data?: any, params?: any) => any }} handlers\n * @param {number} [reconnect]\n */\n\nvar socket = function initSocket(url, handlers, reconnect) {\n client = new Client(url);\n client.onOpen(function () {\n retries = 0;\n\n if (typeof reconnect !== \"undefined\") {\n maxRetries = reconnect;\n }\n });\n client.onClose(function () {\n if (retries === 0) {\n handlers.close();\n } // Try to reconnect.\n\n\n client = null; // After 10 retries stop trying, to prevent logspam.\n\n if (retries < maxRetries) {\n // Exponentially increase timeout to reconnect.\n