the-forest/client/node_modules/.cache/babel-loader/b587e2efc3a903ee8be7065c39b605d268f07510bf2b1c3e17b090905c20c4f4.json
2024-09-17 20:35:18 -04:00

1 line
6.0 KiB
JSON

{"ast":null,"code":"/* global __webpack_dev_server_client__ */\n\nimport WebSocketClient from \"./clients/WebSocketClient.js\";\nimport { log } from \"./utils/log.js\";\n\n// this WebsocketClient is here as a default fallback, in case the client is not injected\n/* eslint-disable camelcase */\nvar Client =\n// 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;\n\n// 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\nexport var client = null;\n\n/**\n * @param {string} url\n * @param {{ [handler: string]: (data?: any, params?: any) => any }} handlers\n * @param {number} [reconnect]\n */\nvar socket = function initSocket(url, handlers, reconnect) {\n client = new Client(url);\n client.onOpen(function () {\n retries = 0;\n if (typeof reconnect !== \"undefined\") {\n maxRetries = reconnect;\n }\n });\n client.onClose(function () {\n if (retries === 0) {\n handlers.close();\n }\n\n // Try to reconnect.\n client = null;\n\n // After 10 retries stop trying, to prevent logspam.\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 if (handlers[message.type]) {\n handlers[message.type](message.data, message.params);\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/shoofle/Projects/the-forest/node_modules/webpack-dev-server/client/socket.js"],"sourcesContent":["/* global __webpack_dev_server_client__ */\n\nimport WebSocketClient from \"./clients/WebSocketClient.js\";\nimport { log } from \"./utils/log.js\";\n\n// this WebsocketClient is here as a default fallback, in case the client is not injected\n/* eslint-disable camelcase */\nvar Client =\n// 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;\n\n// 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\nexport var client = null;\n\n/**\n * @param {string} url\n * @param {{ [handler: string]: (data?: any, params?: any) => any }} handlers\n * @param {number} [reconnect]\n */\nvar socket = function initSocket(url, handlers, reconnect) {\n client = new Client(url);\n client.onOpen(function () {\n retries = 0;\n if (typeof reconnect !== \"undefined\") {\n maxRetries = reconnect;\n }\n });\n client.onClose(function () {\n if (retries === 0) {\n handlers.close();\n }\n\n // Try to reconnect.\n client = null;\n\n // After 10 retries stop trying, to prevent logspam.\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 if (handlers[message.type]) {\n handlers[message.type](message.data, message.params);\n }\n });\n};\nexport default socket;"],"mappings":"AAAA;;AAEA,OAAOA,eAAe,MAAM,8BAA8B;AAC1D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