12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- 'use strict';
- var Client = typeof __webpack_dev_server_client__ !== 'undefined' ? __webpack_dev_server_client__ :
- require('./clients/SockJSClient');
- var retries = 0;
- var client = null;
- var socket = function initSocket(url, handlers) {
- client = new Client(url);
- client.onOpen(function () {
- retries = 0;
- });
- client.onClose(function () {
- if (retries === 0) {
- handlers.close();
- }
- client = null;
- if (retries <= 10) {
-
-
-
- var retryInMs = 1000 * Math.pow(2, retries) + Math.random() * 100;
- retries += 1;
- setTimeout(function () {
- socket(url, handlers);
- }, retryInMs);
- }
- });
- client.onMessage(function (data) {
- var msg = JSON.parse(data);
- if (handlers[msg.type]) {
- handlers[msg.type](msg.data);
- }
- });
- };
- module.exports = socket;
|