(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.DHWs = factory()); }(this, (function () { 'use strict'; /** * @description 处理客户端登陆、登出、保活。版本相关逻辑 * @author 178730 * @date 2021-04-27 */ var account = { /** * @description 登录客户端 */ loginClient() { this.loginEnd = false; this.loginStartTime = Date.now(); const config = this.config; let { appName, appId, browser: { name, version, platform } } = config; // 登陆确保有appName if (!appName) { this.loginEnd = true; return false; } const params = { appName, params: { browser: name, version, platform }, appId }; this.postMessage('register', params); }, /** * @description 注销客户端 */ logoutClient() { console.log("注销客户端"); const config = this.config; const { appName, appId } = config; this.postMessage('unregister', { appName, appId }); this.config.appName = ''; }, }; /** * @description 处理浏览器位置和DOM对象方法 * @author 178730 * @date 2021-04-27 */ /** * @description 检测浏览器缩放比例 */ function detectZoom() { var ratio = 0, screen = window.screen, ua = navigator.userAgent.toLowerCase(); if (window.devicePixelRatio !== undefined) { ratio = window.devicePixelRatio; } else if (~ua.indexOf('msie')) { if (screen['deviceXDPI'] && screen['logicalXDPI']) { ratio = screen['deviceXDPI'] / screen['logicalXDPI']; } } else if (window.outerWidth !== undefined && window.innerWidth !== undefined) { ratio = window.outerWidth / window.innerWidth; } if (ratio) { ratio = Math.round(ratio * 100); } return ratio; } /** * @description 检测浏览器是否有Y轴滚动条 */ function hasScrollbarY() { return (getDocument().body.scrollHeight > (window.innerHeight || getDocument().documentElement.clientHeight)); } /** * @description 检测浏览器是否有X轴滚动条 */ function hasScrollbarX() { return (getDocument().body.scrollWidth > (window.innerWidth || getDocument().documentElement.clientWidth)); } /** * @description 获取浏览器滚动条宽度 */ function getScrollbarWidth() { var scrollDiv = getDocument().createElement('div'); scrollDiv.style.cssText = 'width: 99px; height: 99px; overflow: scroll; position: absolute; top: -9999px;'; getDocument().body.appendChild(scrollDiv); var scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth; getDocument().body.removeChild(scrollDiv); return scrollbarWidth; } /** * @description 获取当前浏览器缩放和滚动条信息 */ function getScrollInfo() { let ratio = detectZoom(); let scrollX = window.pageXOffset; let scrollY = window.pageYOffset; var hasscrollbary = hasScrollbarY(); var hasscrollbarx = hasScrollbarX(); var scrollbarWidth = getScrollbarWidth(); let scrollXH = hasscrollbarx ? scrollbarWidth : 0; let scrollYW = hasscrollbary ? scrollbarWidth : 0; return { ratio, scrollX, scrollY, scrollXH, scrollYW }; } /** * @description 根据domId检测Dom是否有宽和高的属性 * @param {Obeject} domId 元素ID */ function checkDomExit(domId, log = true) { let defaultDomInfo = { x: 0, y: 0, width: 0, height: 0 }; const domTarget = getDocument().getElementById(domId); if (!domTarget) { log && console.log(`ws-can not find dom by id ${domId}`); return defaultDomInfo; } const domInfo = (domTarget.getClientRects() && domTarget.getClientRects()[0]); if (!domInfo) { // 若找不到DOM元素,报错 log && console.warn(`ws-can not find domInfo by id ${domId}, please check dom exited`); return defaultDomInfo; } return domInfo; } /** * @description 判断当前是否在iframe之中 */ function isIframe() { return self.frameElement && self.frameElement.tagName == "IFRAME"; } /** * @description 获取当前的document对象,兼容iframe处理 * 存在iframe,实例在top,目标窗口在子层,需要级联 */ function getDocument() { let _document = window.document; // 判断是否在iframe里面 if (isIframe()) { // 存在navigator if (top['$nav']) { // 通过navigator获取dom const iframe = top['$nav'].getIframeByPath(); if (iframe) { _document = iframe.contentWindow.document; } else { throw new Error('can not find document in iframe by @psi/navigator'); } } else { // iframe嵌入,且没有@psi/navigator throw new Error('not support in iframe that without @psi/navigator'); } } return _document; } /** * @description 通过元素ID获取DOM对象 * @param {Obeject} domId 元素ID */ function getDomById(domId) { console.log('ws-getDomById', domId); const domInfo = checkDomExit(domId); const width = domInfo.width; const height = domInfo.height; let x = domInfo.x; let y = domInfo.y; if (isIframe()) { console.log('dom in iframe'); if (top['$nav']) { // 通过navigator获取dom const iframe = top['$nav'].getIframeByPath(); if (iframe) { let iframeRect = iframe.getClientRects(); if (iframeRect && iframeRect[0]) { x += iframeRect[0].x; y += iframeRect[0].y; } throw new Error('can not find document in iframe by @psi/navigator'); } throw new Error('can not find document in iframe by @psi/navigator'); } else { // iframe嵌入,且没有@psi/navigator throw new Error('not support in iframe that without @psi/navigator'); } } return { width, height, x, y }; } var control = { /** * @description 提交浏览器信息 */ browserInfo() { const config = this.config; const { loginIp, userCode } = config; const { browser: { name, version, platform } } = config; this.postMessage('browserInfo', { loginIp, userCode, params: { browser: name, version, platform } }); }, /** * @description 浏览器切换显隐 */ webVisibilityChange() { const config = this.config; //const { loginIp, userCode } = config; const { appName, appId } = config; this.postMessage('webVisibilityChange', { appName, appId, params: { hidden: getDocument().hidden } }); }, /** * @description 受信任站点 */ trusteSite(http) { console.log('ws-trusteSite-http', http); const config = this.config; const { loginIp, userCode } = config; this.postMessage('trusteSite', { loginIp, userCode, params: { trusteSite: http } }); }, /** * @description 设置下载路径 * @params {String} path 下载路径地址 */ setDownloadPath(path) { const config = this.config; const { loginIp, userCode } = config; return this.postMessage('setDownloadPath', { loginIp, userCode, params: { downloadPath: path } }); }, /** * @description 下载视频 * @params {Array} downloads 下载录像参数 * { channelName: '11111', channelId: '1DSNHDHF654DS', beginTime: 1602559308127, endTime: 1602559308227, format: 1, sourceType: 1, streamType: 1 } * @params {Boolean} visible 是否显示下载窗口 */ downloadVideo(downloads, visible) { const config = this.config; const { loginIp, userCode } = config; return this.postMessage('downloadVideo', { loginIp, userCode, params: { array: downloads, visible: visible } }); }, /** * @description 创建控件 * * @param {Array} documents * { * array: [{ * ctrlCode: '11', * ctrlType: 'playerCtrl' * }] * } */ createCtrl(widgets) { console.log('ws-createCtrl', widgets); const _this = this; const config = this.config; // const { loginIp, userCode } = config; const { appName, appId } = config; let widgetParams = []; if (widgets.length === 0) { console.error('param widget must has a ctrlCode.'); return false; } widgets.forEach(item => { if (_this.ids.includes(item.ctrlCode)) { _this.destroyCtrl([item.ctrlCode]); } let widgetParam = {}; const { ctrlType, ctrlCode, ctrlProperty, visible, cutList, domId } = item; getDocument().getElementById(domId); // if(!domTarget) { // console.warn(`can not find dom by id ${domId}`); // // throw new Error(`can not find dom by id ${domId}`); // } let domInfo = getDomById(domId); let scrollInfo = getScrollInfo(); // 停止观测 // observer.disconnect(); widgetParam['ctrlType'] = ctrlType; widgetParam['visible'] = visible; widgetParam['ctrlCode'] = ctrlCode; widgetParam['ctrlProperty'] = ctrlProperty; //widgetParam['cutList'] = cutList; widgetParam['posX'] = domInfo.x; widgetParam['posY'] = domInfo.y; widgetParam['width'] = domInfo.width; widgetParam['height'] = domInfo.height; widgetParam['ratio'] = scrollInfo.ratio; widgetParam['scrollX'] = scrollInfo.scrollX; widgetParam['scrollY'] = scrollInfo.scrollY; widgetParam['scrollXH'] = scrollInfo.scrollXH; widgetParam['scrollYW'] = scrollInfo.scrollYW; // widgetParam['observer'] = observer; widgetParam['domId'] = domId; // widgetParam['domTarget'] = domTarget; widgetParams.push(widgetParam); _this.ctrls.push(widgetParam); _this.ids.push(ctrlCode); }); return this.postMessage('createCtrl', { // todo 回退uuidmap/ctrls处理 // loginIp, // userCode, appName, appId, params: { array: widgetParams } }); }, /** * @description 设置可见 * * @param {Array} ctrls * { * array: [{ * ctrlCode: "bf662065-3bda-4cb7-8fdd-b6e13997d84f" * visible: true * }] * } */ setCtrlVisible(ctrls) { const _this = this; const config = this.config; //const { loginIp, userCode } = config; const { appName, appId } = config; let ctrlParams = []; if (ctrls.length === 0) { return false; } ctrls.forEach(item => { const ctrlParam = {}; if (!_this.ids.includes(item.ctrlCode)) { return false; } const ctrl = _this.ctrls.find((ctrl) => { return ctrl.ctrlCode === item.ctrlCode; }); ctrl['visible'] = item.visible; ctrlParam['ctrlCode'] = item.ctrlCode; ctrlParam['visible'] = item.visible; ctrlParams.push(ctrlParam); }); return this.postMessage('setCtrlVisible', { appName, appId, params: { array: ctrlParams } }); }, /** * @description 设置控件属性--位置,剪裁 * * @param {Array} positions * { * array: [{ * id: 1, * posX: 100, * posY: 200 * }] * } */ setCtrlPos(positions) { const _this = this; const config = this.config; //const { loginIp, userCode } = config; const { appName, appId } = config; let widgetParams = []; if (positions.length === 0) { throw new Error('setCtrlPos must has a Id.'); } positions.forEach(item => { if (!_this.ids.includes(item.ctrlCode)) { throw new Error(`widget by id:${item.ctrlCode} has not been created.`); } const ctrl = _this.ctrls.find((ctrl) => { return ctrl.ctrlCode === item.ctrlCode; }); if (!ctrl) { throw new Error(`can not find ctrl by id:${item.ctrlCode}.`); } // 待设置属性列表 let propList = ['posX', 'posY', 'width', 'height', 'ratio', 'scrollX', 'scrollY', 'scrollXH', 'scrollYW', 'cutList']; // 设置控件属性 function setProp(ctrl, item, prop) { item.hasOwnProperty(prop) ? ctrl[prop] = item[prop] : ''; } propList.forEach(e => { setProp(ctrl, item, e); }); const widgetParam = ctrl; widgetParams.push(widgetParam); }); return this.postMessage('setCtrlPos', { appName, appId, params: { array: widgetParams } }); }, /** * @description 重新定位控件位置 * @params {Array} ['ctrlId1', 'ctrlId2'] */ reLocatedPosition(ctrlCode) { let _ctrlList = []; if (ctrlCode && ctrlCode.length > 0) { this.ctrls.forEach(e => { if (ctrlCode.includes(e.ctrlCode)) { _ctrlList.push(e); } }); } let _needLocationList = _ctrlList.length > 0 ? _ctrlList : this.ctrls; if (_needLocationList.length === 0) return false; let exitParams = _needLocationList.filter(e => { return (e.domId && checkDomExit(e.domId, false)); }); let params = exitParams.map(e => { let domInfo = getDomById(e.domId); let scrollInfo = getScrollInfo(); let ctrlCode = e.ctrlCode; let cutList = e.cutList; let posX = domInfo.x; let posY = domInfo.y; let width = domInfo.width; let height = domInfo.height; let ratio = scrollInfo.ratio; let scrollX = scrollInfo.scrollX; let scrollY = scrollInfo.scrollY; let scrollXH = scrollInfo.scrollXH; let scrollYW = scrollInfo.scrollYW; return { ctrlCode, cutList, posX, posY, width, height, ratio, scrollX, scrollY, scrollXH, scrollYW }; }); if (params.length) { return this.setCtrlPos(params); } else { return new Promise((resolve) => { resolve(true); }); } }, /** * @description 销毁控件 * * @param {Array} ids * { * array: ['1','2'] * } */ destroyCtrl(ids) { if (ids.length === 0) { return false; } const _this = this; const config = this.config; //const { loginIp, userCode } = config; const { appName, appId } = config; const _ids = [...ids]; // 删除缓存中的控件和ids const params = ids.map(item => { return { ctrlCode: item }; }); _ids.forEach(id => { // if (!_this.ids.includes(id)) { // throw new Error(`element by id:${id} has not been created.`); // } for (var i = 0; i < _this.ctrls.length; i++) { if (_this.ctrls[i].ctrlCode === id) { _this.ctrls.splice(i, 1); _this.ids.splice(i, 1); } } }); return this.postMessage('destroyCtrl', { appName, appId, params: { array: params } }); }, /** * @description 播放实时视频 * * @param {Object} * { * "ctrlCode":"ctrlCode",// 唯一标识符 * "channelIds": ["AcqRGNrqA1B15042F6AMEO"]// 播放的通道编码 * } */ openCtrlPreview(obj) { const config = this.config; const { loginIp, userCode } = config; if (!obj.ctrlCode || !this.ids.includes(obj.ctrlCode)) { throw new Error(`widget by id:${obj.ctrlCode} has not been created.`); } if (obj.channelIds.length === 0) { return false; } const arr = obj.channelIds.map((i) => { return { channelId: i }; }); return this.postMessage('openCtrlPreview', { loginIp, userCode, params: { array: [ { ctrlCode: obj.ctrlCode, array: arr } ] } }); }, /** * @description 播放录像 * * @param {Object} * [ * { * "ctrlCode":"code0", * "array": * [{ * "beginTime": "2019-02-21 00:00:00", * "channelId": "AcqRGNrqA1B15042F6AMEO", * "endTime": "2019-02-21 23:59:59" * }] * } * ] */ openCtrlRecord(arr) { const config = this.config; var obj = arr[0]; if (!obj.ctrlCode || !this.ids.includes(obj.ctrlCode)) { throw new Error(`widget by id:${obj.ctrlCode} has not been created.`); } const { loginIp, userCode } = config; return this.postMessage('openCtrlRecord', { loginIp, userCode, params: { array: arr } }); }, /** * @description 关闭单个控件所有视频 * * @param {Object} * { * "ctrlCode":["uuidcode"] //唯一标识符 * } */ closeCtrlVideo(arr) { const config = this.config; const { loginIp, userCode } = config; const arrParams = arr.map(item => { return { ctrlCode: item }; }); return this.postMessage('closeCtrlVideo', { loginIp, userCode, params: { array: arrParams } }); }, /** * @description 弹窗打开实时视频 * * @param {Array} arr * // 标准参数 ["channelId1", "channelId2" ] * // 兼容qt参数,传入对象{array: [{channelId: "channelId1"}, {channelId: "channelId2"}]} */ openVideo(arr) { const config = this.config; const { userCode, loginIp } = config; let params = {}; if (Array.isArray(arr)) { let _arr = arr.map(i => { return { channelId: i }; }); params = { array: _arr }; } else { // 兼容之前的代码,之前根据客户端协议传递,为未处理格式的对象 params = arr; } return this.postMessage('openVideo', { loginIp, userCode, params: params }); }, /** * @description 弹窗打开录像 * * @param {any} arr */ openRecord(arr) { const config = this.config; const { userCode, loginIp } = config; let params = {}; if (Array.isArray(arr)) { params = { array: arr }; } else { // 兼容之前的代码,之前根据客户端协议传递,为未处理格式的对象 params = arr; } return this.postMessage('openRecord', { loginIp, userCode, params: params }); }, /** * @description 打开混合弹窗 * @params {String} menuCode 菜单code * @params {Array} 根据输入参数展示对应按钮。0:以图搜图,1:上传工作台,2:上传视图作战 * @params {Array} array 客户端通道和播放时间 * [{ "channelId": "AcqRGNrqA1B15042F6AMEO", // 通道Id "beginTime": "2021-01-05 13:57:00", // 回放开始时间 "endTime": "2021-01-05 14:26:59" // 回放结束时间 }] */ openMixedModeDialog(menuCode, array, toolBarFucList = [0, 1, 2]) { const config = this.config; const { userCode, loginIp } = config; let params = { destinationCode: menuCode, toolBarFucList: toolBarFucList, array: array }; return this.postMessage('openMixedModeDialog', { loginIp, userCode, params: params }); }, /** * @description 图片增强 * * @param {any} url * @param {any} value * @param {number} [type=1] [[1, 去偏色], [2, 去雾], [3, 夜增强], [4, 降噪]] */ PictureEnhance(url, value, type = 1) { const config = this.config; const { userCode, loginIp } = config; const params = { loginIp, userCode, params: { array: [{ type: `${type}`, degree: `${value}`, url }] } }; return this.postMessage('PictureEnhance', params); } }; var transparent = { // 透传方法,参数不做任何处理 // transparent(method, params) { // const config = this.config; // //const { loginIp, userCode } = config; // const { appName, appId } = config; // return this.postMessage(method, { // // loginIp, // // userCode, // appName, // appId, // params: params // }); // }, // 透传方法,参数不做任何处理 transparent(method, params) { return this.postMessage(method, params); } }; // import basic from './basic'; var wsActions = { account, control, transparent // basic }; var defaultMessageEvents = { /** * @description 获取版本信息结果 */ getVersionResult(data) { this.getVersionEnd = true; this.currentDssVersion = data; if (this.onlineDssVersion !== '') { this.compareVersion(); } }, /** * @description 客户端截图,以图搜图 */ goToSearchPic(data) { console.log('ws-goToSearchPic', data); if (data && data.params && data.params.array && Array.isArray(data.params.array)) { let menuCode = data.params.destinationCode; let param = {}; param[menuCode] = data.params.array[0]; if (frames[`nav-frame-${menuCode}`]) { frames[`nav-frame-${menuCode}`].$nav.push({ code: menuCode, params: param }); } else { window && window['$nav'] && window['$nav'].push({ code: menuCode, params: param }); } } else { this.Vue.prototype.$Message.info('未查询到数据'); } }, /** * @description 登陆结果 */ loginState(data) { console.log("登录成功"); if (data) { // 登录成功 this.isLoginSuccess = data; // 登录结束 this.loginEnd = true; if (typeof this.callback.loginResult === 'function') { this.callback.loginResult.call(this, this.isLoginSuccess); } } else { // 登录失败 this.loginFailCount++; if (this.loginFailCount < this.reLoginCount + 1) { // 登录未到最大次数 this.loginClient(); } else { // 登录达到最大次数 // 登录结束 this.loginEnd = true; // 重置登录失败次数 this.loginFailCount = 0; this.isLoginSuccess = data; if (typeof this.callback.loginResult === 'function') { this.callback.loginResult.call(this, this.isLoginSuccess); } } } }, registerState(data) { console.log("注册成功"); if (data) { // 注册成功 this.isLoginSuccess = data; // 注册结束 this.loginEnd = true; if (typeof this.callback.registerResult === 'function') { this.callback.registerResult.call(this, this.isLoginSuccess); } } else { // 注册失败 this.loginFailCount++; if (this.loginFailCount < this.reLoginCount + 1) { // 注册未到最大次数 this.loginClient(); } else { // 注册达到最大次数 // 注册结束 this.loginEnd = true; // 重置注册失败次数 this.loginFailCount = 0; this.isLoginSuccess = data; if (typeof this.callback.registerResult === 'function') { this.callback.registerResult.call(this, this.isLoginSuccess); } } } }, /** * @description 创建控件结果 */ createCtrlResult(data) { // todo 修改ctrls 和 ids let _data = data; let failIds = []; _data.forEach(e => { if (e.result !== 0) { failIds.push(e.ctrlCode); } }); this.ids.forEach((e, i) => { if (failIds.indexOf(e) !== -1) { this.ids.splice(i, 1); this.ctrls.splice(i, 1); } }); }, /** * @description 销毁控件结果 */ destroyCtrlResult(data) { // 未发现这种情况,不好模拟,暂未调试 // todo 修改ctrls 和 ids console.log(data); } }; /** * @description 处理客户端返回数据的数据格式 * @author 178730 * @date 2021-04-27 */ var dealEventData = { registerState: registerState, loginState: loginState, getVersionResult: getVersionResult, // goToSearchPic, createCtrlResult: createCtrlResult }; function registerState(data) { return data.params.registerResult === 0; } function loginState(data) { return data.params.loginResult === 0; } function getVersionResult(data) { return data.params.version + ''; } // function goToSearchPic(data) { // return data; // } function createCtrlResult(data) { return data.params.array; } /*! ***************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. ***************************************************************************** */ /* global Reflect, Promise */ var extendStatics = function(d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; function __extends(d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); } function __values(o) { var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0; if (m) return m.call(o); return { next: function () { if (o && i >= o.length) o = void 0; return { value: o && o[i++], done: !o }; } }; } function __read(o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; } function __spread() { for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); return ar; } var Event = /** @class */ (function () { function Event(type, target) { this.target = target; this.type = type; } return Event; }()); var ErrorEvent = /** @class */ (function (_super) { __extends(ErrorEvent, _super); function ErrorEvent(error, target) { var _this = _super.call(this, 'error', target) || this; _this.message = error.message; _this.error = error; return _this; } return ErrorEvent; }(Event)); var CloseEvent = /** @class */ (function (_super) { __extends(CloseEvent, _super); function CloseEvent(code, reason, target) { if (code === void 0) { code = 1000; } if (reason === void 0) { reason = ''; } var _this = _super.call(this, 'close', target) || this; _this.wasClean = true; _this.code = code; _this.reason = reason; return _this; } return CloseEvent; }(Event)); /*! * Reconnecting WebSocket * by Pedro Ladaria * https://github.com/pladaria/reconnecting-websocket * License MIT */ var getGlobalWebSocket = function () { if (typeof WebSocket !== 'undefined') { // @ts-ignore return WebSocket; } }; /** * Returns true if given argument looks like a WebSocket class */ var isWebSocket = function (w) { return typeof w !== 'undefined' && !!w && w.CLOSING === 2; }; var DEFAULT = { maxReconnectionDelay: 10000, minReconnectionDelay: 1000 + Math.random() * 4000, minUptime: 5000, reconnectionDelayGrowFactor: 1.3, connectionTimeout: 4000, maxRetries: Infinity, maxEnqueuedMessages: Infinity, startClosed: false, debug: false, }; var ReconnectingWebSocket = /** @class */ (function () { function ReconnectingWebSocket(url, protocols, options) { var _this = this; if (options === void 0) { options = {}; } this._listeners = { error: [], message: [], open: [], close: [], }; this._retryCount = -1; this._shouldReconnect = true; this._connectLock = false; this._binaryType = 'blob'; this._closeCalled = false; this._messageQueue = []; /** * An event listener to be called when the WebSocket connection's readyState changes to CLOSED */ this.onclose = null; /** * An event listener to be called when an error occurs */ this.onerror = null; /** * An event listener to be called when a message is received from the server */ this.onmessage = null; /** * An event listener to be called when the WebSocket connection's readyState changes to OPEN; * this indicates that the connection is ready to send and receive data */ this.onopen = null; this._handleOpen = function (event) { _this._debug('open event'); var _a = _this._options.minUptime, minUptime = _a === void 0 ? DEFAULT.minUptime : _a; clearTimeout(_this._connectTimeout); _this._uptimeTimeout = setTimeout(function () { return _this._acceptOpen(); }, minUptime); _this._ws.binaryType = _this._binaryType; // send enqueued messages (messages sent before websocket open event) _this._messageQueue.forEach(function (message) { return _this._ws.send(message); }); _this._messageQueue = []; if (_this.onopen) { _this.onopen(event); } _this._listeners.open.forEach(function (listener) { return _this._callEventListener(event, listener); }); }; this._handleMessage = function (event) { _this._debug('message event'); if (_this.onmessage) { _this.onmessage(event); } _this._listeners.message.forEach(function (listener) { return _this._callEventListener(event, listener); }); }; this._handleError = function (event) { _this._debug('error event', event.message); _this._disconnect(undefined, event.message === 'TIMEOUT' ? 'timeout' : undefined); if (_this.onerror) { _this.onerror(event); } _this._debug('exec error listeners'); _this._listeners.error.forEach(function (listener) { return _this._callEventListener(event, listener); }); _this._connect(); }; this._handleClose = function (event) { _this._debug('close event'); _this._clearTimeouts(); if (_this._shouldReconnect) { _this._connect(); } if (_this.onclose) { _this.onclose(event); } _this._listeners.close.forEach(function (listener) { return _this._callEventListener(event, listener); }); }; this._url = url; this._protocols = protocols; this._options = options; if (this._options.startClosed) { this._shouldReconnect = false; } this._connect(); } Object.defineProperty(ReconnectingWebSocket, "CONNECTING", { get: function () { return 0; }, enumerable: true, configurable: true }); Object.defineProperty(ReconnectingWebSocket, "OPEN", { get: function () { return 1; }, enumerable: true, configurable: true }); Object.defineProperty(ReconnectingWebSocket, "CLOSING", { get: function () { return 2; }, enumerable: true, configurable: true }); Object.defineProperty(ReconnectingWebSocket, "CLOSED", { get: function () { return 3; }, enumerable: true, configurable: true }); Object.defineProperty(ReconnectingWebSocket.prototype, "CONNECTING", { get: function () { return ReconnectingWebSocket.CONNECTING; }, enumerable: true, configurable: true }); Object.defineProperty(ReconnectingWebSocket.prototype, "OPEN", { get: function () { return ReconnectingWebSocket.OPEN; }, enumerable: true, configurable: true }); Object.defineProperty(ReconnectingWebSocket.prototype, "CLOSING", { get: function () { return ReconnectingWebSocket.CLOSING; }, enumerable: true, configurable: true }); Object.defineProperty(ReconnectingWebSocket.prototype, "CLOSED", { get: function () { return ReconnectingWebSocket.CLOSED; }, enumerable: true, configurable: true }); Object.defineProperty(ReconnectingWebSocket.prototype, "binaryType", { get: function () { return this._ws ? this._ws.binaryType : this._binaryType; }, set: function (value) { this._binaryType = value; if (this._ws) { this._ws.binaryType = value; } }, enumerable: true, configurable: true }); Object.defineProperty(ReconnectingWebSocket.prototype, "retryCount", { /** * Returns the number or connection retries */ get: function () { return Math.max(this._retryCount, 0); }, enumerable: true, configurable: true }); Object.defineProperty(ReconnectingWebSocket.prototype, "bufferedAmount", { /** * The number of bytes of data that have been queued using calls to send() but not yet * transmitted to the network. This value resets to zero once all queued data has been sent. * This value does not reset to zero when the connection is closed; if you keep calling send(), * this will continue to climb. Read only */ get: function () { var bytes = this._messageQueue.reduce(function (acc, message) { if (typeof message === 'string') { acc += message.length; // not byte size } else if (message instanceof Blob) { acc += message.size; } else { acc += message.byteLength; } return acc; }, 0); return bytes + (this._ws ? this._ws.bufferedAmount : 0); }, enumerable: true, configurable: true }); Object.defineProperty(ReconnectingWebSocket.prototype, "extensions", { /** * The extensions selected by the server. This is currently only the empty string or a list of * extensions as negotiated by the connection */ get: function () { return this._ws ? this._ws.extensions : ''; }, enumerable: true, configurable: true }); Object.defineProperty(ReconnectingWebSocket.prototype, "protocol", { /** * A string indicating the name of the sub-protocol the server selected; * this will be one of the strings specified in the protocols parameter when creating the * WebSocket object */ get: function () { return this._ws ? this._ws.protocol : ''; }, enumerable: true, configurable: true }); Object.defineProperty(ReconnectingWebSocket.prototype, "readyState", { /** * The current state of the connection; this is one of the Ready state constants */ get: function () { if (this._ws) { return this._ws.readyState; } return this._options.startClosed ? ReconnectingWebSocket.CLOSED : ReconnectingWebSocket.CONNECTING; }, enumerable: true, configurable: true }); Object.defineProperty(ReconnectingWebSocket.prototype, "url", { /** * The URL as resolved by the constructor */ get: function () { return this._ws ? this._ws.url : ''; }, enumerable: true, configurable: true }); /** * Closes the WebSocket connection or connection attempt, if any. If the connection is already * CLOSED, this method does nothing */ ReconnectingWebSocket.prototype.close = function (code, reason) { if (code === void 0) { code = 1000; } this._closeCalled = true; this._shouldReconnect = false; this._clearTimeouts(); if (!this._ws) { this._debug('close enqueued: no ws instance'); return; } if (this._ws.readyState === this.CLOSED) { this._debug('close: already closed'); return; } this._ws.close(code, reason); }; /** * Closes the WebSocket connection or connection attempt and connects again. * Resets retry counter; */ ReconnectingWebSocket.prototype.reconnect = function (code, reason) { this._shouldReconnect = true; this._closeCalled = false; this._retryCount = -1; if (!this._ws || this._ws.readyState === this.CLOSED) { this._connect(); } else { this._disconnect(code, reason); this._connect(); } }; /** * Enqueue specified data to be transmitted to the server over the WebSocket connection */ ReconnectingWebSocket.prototype.send = function (data) { if (this._ws && this._ws.readyState === this.OPEN) { this._debug('send', data); this._ws.send(data); } else { var _a = this._options.maxEnqueuedMessages, maxEnqueuedMessages = _a === void 0 ? DEFAULT.maxEnqueuedMessages : _a; if (this._messageQueue.length < maxEnqueuedMessages) { this._debug('enqueue', data); this._messageQueue.push(data); } } }; /** * Register an event handler of a specific event type */ ReconnectingWebSocket.prototype.addEventListener = function (type, listener) { if (this._listeners[type]) { // @ts-ignore this._listeners[type].push(listener); } }; ReconnectingWebSocket.prototype.dispatchEvent = function (event) { var e_1, _a; var listeners = this._listeners[event.type]; if (listeners) { try { for (var listeners_1 = __values(listeners), listeners_1_1 = listeners_1.next(); !listeners_1_1.done; listeners_1_1 = listeners_1.next()) { var listener = listeners_1_1.value; this._callEventListener(event, listener); } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (listeners_1_1 && !listeners_1_1.done && (_a = listeners_1.return)) _a.call(listeners_1); } finally { if (e_1) throw e_1.error; } } } return true; }; /** * Removes an event listener */ ReconnectingWebSocket.prototype.removeEventListener = function (type, listener) { if (this._listeners[type]) { // @ts-ignore this._listeners[type] = this._listeners[type].filter(function (l) { return l !== listener; }); } }; ReconnectingWebSocket.prototype._debug = function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } if (this._options.debug) { // not using spread because compiled version uses Symbols // tslint:disable-next-line console.log.apply(console, __spread(['RWS>'], args)); } }; ReconnectingWebSocket.prototype._getNextDelay = function () { var _a = this._options, _b = _a.reconnectionDelayGrowFactor, reconnectionDelayGrowFactor = _b === void 0 ? DEFAULT.reconnectionDelayGrowFactor : _b, _c = _a.minReconnectionDelay, minReconnectionDelay = _c === void 0 ? DEFAULT.minReconnectionDelay : _c, _d = _a.maxReconnectionDelay, maxReconnectionDelay = _d === void 0 ? DEFAULT.maxReconnectionDelay : _d; var delay = 0; if (this._retryCount > 0) { delay = minReconnectionDelay * Math.pow(reconnectionDelayGrowFactor, this._retryCount - 1); if (delay > maxReconnectionDelay) { delay = maxReconnectionDelay; } } this._debug('next delay', delay); return delay; }; ReconnectingWebSocket.prototype._wait = function () { var _this = this; return new Promise(function (resolve) { setTimeout(resolve, _this._getNextDelay()); }); }; ReconnectingWebSocket.prototype._getNextUrl = function (urlProvider) { if (typeof urlProvider === 'string') { return Promise.resolve(urlProvider); } if (typeof urlProvider === 'function') { var url = urlProvider(); if (typeof url === 'string') { return Promise.resolve(url); } if (!!url.then) { return url; } } throw Error('Invalid URL'); }; ReconnectingWebSocket.prototype._connect = function () { var _this = this; if (this._connectLock || !this._shouldReconnect) { return; } this._connectLock = true; var _a = this._options, _b = _a.maxRetries, maxRetries = _b === void 0 ? DEFAULT.maxRetries : _b, _c = _a.connectionTimeout, connectionTimeout = _c === void 0 ? DEFAULT.connectionTimeout : _c, _d = _a.WebSocket, WebSocket = _d === void 0 ? getGlobalWebSocket() : _d; if (this._retryCount >= maxRetries) { this._debug('max retries reached', this._retryCount, '>=', maxRetries); return; } this._retryCount++; this._debug('connect', this._retryCount); this._removeListeners(); if (!isWebSocket(WebSocket)) { throw Error('No valid WebSocket class provided'); } this._wait() .then(function () { return _this._getNextUrl(_this._url); }) .then(function (url) { // close could be called before creating the ws if (_this._closeCalled) { return; } _this._debug('connect', { url: url, protocols: _this._protocols }); _this._ws = _this._protocols ? new WebSocket(url, _this._protocols) : new WebSocket(url); _this._ws.onerror = function (e) { window.postMessage({method: "connectResult", success: false}, "*") } _this._ws.binaryType = _this._binaryType; _this._connectLock = false; _this._addListeners(); _this._connectTimeout = setTimeout(function () { return _this._handleTimeout(); }, connectionTimeout); }); }; ReconnectingWebSocket.prototype._handleTimeout = function () { this._debug('timeout event'); this._handleError(new ErrorEvent(Error('TIMEOUT'), this)); }; ReconnectingWebSocket.prototype._disconnect = function (code, reason) { if (code === void 0) { code = 1000; } this._clearTimeouts(); if (!this._ws) { return; } this._removeListeners(); try { this._ws.close(code, reason); this._handleClose(new CloseEvent(code, reason, this)); } catch (error) { // ignore } }; ReconnectingWebSocket.prototype._acceptOpen = function () { this._debug('accept open'); this._retryCount = 0; }; ReconnectingWebSocket.prototype._callEventListener = function (event, listener) { if ('handleEvent' in listener) { // @ts-ignore listener.handleEvent(event); } else { // @ts-ignore listener(event); } }; ReconnectingWebSocket.prototype._removeListeners = function () { if (!this._ws) { return; } this._debug('removeListeners'); this._ws.removeEventListener('open', this._handleOpen); this._ws.removeEventListener('close', this._handleClose); this._ws.removeEventListener('message', this._handleMessage); // @ts-ignore this._ws.removeEventListener('error', this._handleError); }; ReconnectingWebSocket.prototype._addListeners = function () { if (!this._ws) { return; } this._debug('addListeners'); this._ws.addEventListener('open', this._handleOpen); this._ws.addEventListener('close', this._handleClose); this._ws.addEventListener('message', this._handleMessage); // @ts-ignore this._ws.addEventListener('error', this._handleError); }; ReconnectingWebSocket.prototype._clearTimeouts = function () { clearTimeout(this._connectTimeout); clearTimeout(this._uptimeTimeout); }; return ReconnectingWebSocket; }()); var reconnectingWebsocketCjs = ReconnectingWebSocket; var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; function unwrapExports (x) { return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; } function createCommonjsModule(fn, module) { return module = { exports: {} }, fn(module, module.exports), module.exports; } var es5 = createCommonjsModule(function (module, exports) { !function(e,t){module.exports=t();}(commonjsGlobal,(function(){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var i=t[n]={i:n,l:!1,exports:{}};return e[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n});},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0});},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)r.d(n,i,function(t){return e[t]}.bind(null,i));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=90)}({17:function(e,t,r){t.__esModule=!0,t.default=void 0;var n=r(18),i=function(){function e(){}return e.getFirstMatch=function(e,t){var r=t.match(e);return r&&r.length>0&&r[1]||""},e.getSecondMatch=function(e,t){var r=t.match(e);return r&&r.length>1&&r[2]||""},e.matchAndReturnConst=function(e,t,r){if(e.test(t))return r},e.getWindowsVersionName=function(e){switch(e){case"NT":return "NT";case"XP":return "XP";case"NT 5.0":return "2000";case"NT 5.1":return "XP";case"NT 5.2":return "2003";case"NT 6.0":return "Vista";case"NT 6.1":return "7";case"NT 6.2":return "8";case"NT 6.3":return "8.1";case"NT 10.0":return "10";default:return}},e.getMacOSVersionName=function(e){var t=e.split(".").splice(0,2).map((function(e){return parseInt(e,10)||0}));if(t.push(0),10===t[0])switch(t[1]){case 5:return "Leopard";case 6:return "Snow Leopard";case 7:return "Lion";case 8:return "Mountain Lion";case 9:return "Mavericks";case 10:return "Yosemite";case 11:return "El Capitan";case 12:return "Sierra";case 13:return "High Sierra";case 14:return "Mojave";case 15:return "Catalina";default:return}},e.getAndroidVersionName=function(e){var t=e.split(".").splice(0,2).map((function(e){return parseInt(e,10)||0}));if(t.push(0),!(1===t[0]&&t[1]<5))return 1===t[0]&&t[1]<6?"Cupcake":1===t[0]&&t[1]>=6?"Donut":2===t[0]&&t[1]<2?"Eclair":2===t[0]&&2===t[1]?"Froyo":2===t[0]&&t[1]>2?"Gingerbread":3===t[0]?"Honeycomb":4===t[0]&&t[1]<1?"Ice Cream Sandwich":4===t[0]&&t[1]<4?"Jelly Bean":4===t[0]&&t[1]>=4?"KitKat":5===t[0]?"Lollipop":6===t[0]?"Marshmallow":7===t[0]?"Nougat":8===t[0]?"Oreo":9===t[0]?"Pie":void 0},e.getVersionPrecision=function(e){return e.split(".").length},e.compareVersions=function(t,r,n){void 0===n&&(n=!1);var i=e.getVersionPrecision(t),s=e.getVersionPrecision(r),o=Math.max(i,s),a=0,u=e.map([t,r],(function(t){var r=o-e.getVersionPrecision(t),n=t+new Array(r+1).join(".0");return e.map(n.split("."),(function(e){return new Array(20-e.length).join("0")+e})).reverse()}));for(n&&(a=o-Math.min(i,s)),o-=1;o>=a;){if(u[0][o]>u[1][o])return 1;if(u[0][o]===u[1][o]){if(o===a)return 0;o-=1;}else if(u[0][o]1?i-1:0),o=1;o0){var o=Object.keys(r),u=a.default.find(o,(function(e){return t.isOS(e)}));if(u){var d=this.satisfies(r[u]);if(void 0!==d)return d}var c=a.default.find(o,(function(e){return t.isPlatform(e)}));if(c){var f=this.satisfies(r[c]);if(void 0!==f)return f}}if(s>0){var l=Object.keys(i),h=a.default.find(l,(function(e){return t.isBrowser(e,!0)}));if(void 0!==h)return this.compareVersion(i[h])}},t.isBrowser=function(e,t){void 0===t&&(t=!1);var r=this.getBrowserName().toLowerCase(),n=e.toLowerCase(),i=a.default.getBrowserTypeByAlias(n);return t&&i&&(n=i.toLowerCase()),n===r},t.compareVersion=function(e){var t=[0],r=e,n=!1,i=this.getBrowserVersion();if("string"==typeof i)return ">"===e[0]||"<"===e[0]?(r=e.substr(1),"="===e[1]?(n=!0,r=e.substr(2)):t=[],">"===e[0]?t.push(1):t.push(-1)):"="===e[0]?r=e.substr(1):"~"===e[0]&&(n=!0,r=e.substr(1)),t.indexOf(a.default.compareVersions(i,r,n))>-1},t.isOS=function(e){return this.getOSName(!0)===String(e).toLowerCase()},t.isPlatform=function(e){return this.getPlatformType(!0)===String(e).toLowerCase()},t.isEngine=function(e){return this.getEngineName(!0)===String(e).toLowerCase()},t.is=function(e){return this.isBrowser(e)||this.isOS(e)||this.isPlatform(e)},t.some=function(e){var t=this;return void 0===e&&(e=[]),e.some((function(e){return t.is(e)}))},e}();t.default=d,e.exports=t.default;},92:function(e,t,r){t.__esModule=!0,t.default=void 0;var n,i=(n=r(17))&&n.__esModule?n:{default:n};var s=/version\/(\d+(\.?_?\d+)+)/i,o=[{test:[/googlebot/i],describe:function(e){var t={name:"Googlebot"},r=i.default.getFirstMatch(/googlebot\/(\d+(\.\d+))/i,e)||i.default.getFirstMatch(s,e);return r&&(t.version=r),t}},{test:[/opera/i],describe:function(e){var t={name:"Opera"},r=i.default.getFirstMatch(s,e)||i.default.getFirstMatch(/(?:opera)[\s/](\d+(\.?_?\d+)+)/i,e);return r&&(t.version=r),t}},{test:[/opr\/|opios/i],describe:function(e){var t={name:"Opera"},r=i.default.getFirstMatch(/(?:opr|opios)[\s/](\S+)/i,e)||i.default.getFirstMatch(s,e);return r&&(t.version=r),t}},{test:[/SamsungBrowser/i],describe:function(e){var t={name:"Samsung Internet for Android"},r=i.default.getFirstMatch(s,e)||i.default.getFirstMatch(/(?:SamsungBrowser)[\s/](\d+(\.?_?\d+)+)/i,e);return r&&(t.version=r),t}},{test:[/Whale/i],describe:function(e){var t={name:"NAVER Whale Browser"},r=i.default.getFirstMatch(s,e)||i.default.getFirstMatch(/(?:whale)[\s/](\d+(?:\.\d+)+)/i,e);return r&&(t.version=r),t}},{test:[/MZBrowser/i],describe:function(e){var t={name:"MZ Browser"},r=i.default.getFirstMatch(/(?:MZBrowser)[\s/](\d+(?:\.\d+)+)/i,e)||i.default.getFirstMatch(s,e);return r&&(t.version=r),t}},{test:[/focus/i],describe:function(e){var t={name:"Focus"},r=i.default.getFirstMatch(/(?:focus)[\s/](\d+(?:\.\d+)+)/i,e)||i.default.getFirstMatch(s,e);return r&&(t.version=r),t}},{test:[/swing/i],describe:function(e){var t={name:"Swing"},r=i.default.getFirstMatch(/(?:swing)[\s/](\d+(?:\.\d+)+)/i,e)||i.default.getFirstMatch(s,e);return r&&(t.version=r),t}},{test:[/coast/i],describe:function(e){var t={name:"Opera Coast"},r=i.default.getFirstMatch(s,e)||i.default.getFirstMatch(/(?:coast)[\s/](\d+(\.?_?\d+)+)/i,e);return r&&(t.version=r),t}},{test:[/yabrowser/i],describe:function(e){var t={name:"Yandex Browser"},r=i.default.getFirstMatch(/(?:yabrowser)[\s/](\d+(\.?_?\d+)+)/i,e)||i.default.getFirstMatch(s,e);return r&&(t.version=r),t}},{test:[/ucbrowser/i],describe:function(e){var t={name:"UC Browser"},r=i.default.getFirstMatch(s,e)||i.default.getFirstMatch(/(?:ucbrowser)[\s/](\d+(\.?_?\d+)+)/i,e);return r&&(t.version=r),t}},{test:[/Maxthon|mxios/i],describe:function(e){var t={name:"Maxthon"},r=i.default.getFirstMatch(s,e)||i.default.getFirstMatch(/(?:Maxthon|mxios)[\s/](\d+(\.?_?\d+)+)/i,e);return r&&(t.version=r),t}},{test:[/epiphany/i],describe:function(e){var t={name:"Epiphany"},r=i.default.getFirstMatch(s,e)||i.default.getFirstMatch(/(?:epiphany)[\s/](\d+(\.?_?\d+)+)/i,e);return r&&(t.version=r),t}},{test:[/puffin/i],describe:function(e){var t={name:"Puffin"},r=i.default.getFirstMatch(s,e)||i.default.getFirstMatch(/(?:puffin)[\s/](\d+(\.?_?\d+)+)/i,e);return r&&(t.version=r),t}},{test:[/sleipnir/i],describe:function(e){var t={name:"Sleipnir"},r=i.default.getFirstMatch(s,e)||i.default.getFirstMatch(/(?:sleipnir)[\s/](\d+(\.?_?\d+)+)/i,e);return r&&(t.version=r),t}},{test:[/k-meleon/i],describe:function(e){var t={name:"K-Meleon"},r=i.default.getFirstMatch(s,e)||i.default.getFirstMatch(/(?:k-meleon)[\s/](\d+(\.?_?\d+)+)/i,e);return r&&(t.version=r),t}},{test:[/micromessenger/i],describe:function(e){var t={name:"WeChat"},r=i.default.getFirstMatch(/(?:micromessenger)[\s/](\d+(\.?_?\d+)+)/i,e)||i.default.getFirstMatch(s,e);return r&&(t.version=r),t}},{test:[/qqbrowser/i],describe:function(e){var t={name:/qqbrowserlite/i.test(e)?"QQ Browser Lite":"QQ Browser"},r=i.default.getFirstMatch(/(?:qqbrowserlite|qqbrowser)[/](\d+(\.?_?\d+)+)/i,e)||i.default.getFirstMatch(s,e);return r&&(t.version=r),t}},{test:[/msie|trident/i],describe:function(e){var t={name:"Internet Explorer"},r=i.default.getFirstMatch(/(?:msie |rv:)(\d+(\.?_?\d+)+)/i,e);return r&&(t.version=r),t}},{test:[/\sedg\//i],describe:function(e){var t={name:"Microsoft Edge"},r=i.default.getFirstMatch(/\sedg\/(\d+(\.?_?\d+)+)/i,e);return r&&(t.version=r),t}},{test:[/edg([ea]|ios)/i],describe:function(e){var t={name:"Microsoft Edge"},r=i.default.getSecondMatch(/edg([ea]|ios)\/(\d+(\.?_?\d+)+)/i,e);return r&&(t.version=r),t}},{test:[/vivaldi/i],describe:function(e){var t={name:"Vivaldi"},r=i.default.getFirstMatch(/vivaldi\/(\d+(\.?_?\d+)+)/i,e);return r&&(t.version=r),t}},{test:[/seamonkey/i],describe:function(e){var t={name:"SeaMonkey"},r=i.default.getFirstMatch(/seamonkey\/(\d+(\.?_?\d+)+)/i,e);return r&&(t.version=r),t}},{test:[/sailfish/i],describe:function(e){var t={name:"Sailfish"},r=i.default.getFirstMatch(/sailfish\s?browser\/(\d+(\.\d+)?)/i,e);return r&&(t.version=r),t}},{test:[/silk/i],describe:function(e){var t={name:"Amazon Silk"},r=i.default.getFirstMatch(/silk\/(\d+(\.?_?\d+)+)/i,e);return r&&(t.version=r),t}},{test:[/phantom/i],describe:function(e){var t={name:"PhantomJS"},r=i.default.getFirstMatch(/phantomjs\/(\d+(\.?_?\d+)+)/i,e);return r&&(t.version=r),t}},{test:[/slimerjs/i],describe:function(e){var t={name:"SlimerJS"},r=i.default.getFirstMatch(/slimerjs\/(\d+(\.?_?\d+)+)/i,e);return r&&(t.version=r),t}},{test:[/blackberry|\bbb\d+/i,/rim\stablet/i],describe:function(e){var t={name:"BlackBerry"},r=i.default.getFirstMatch(s,e)||i.default.getFirstMatch(/blackberry[\d]+\/(\d+(\.?_?\d+)+)/i,e);return r&&(t.version=r),t}},{test:[/(web|hpw)[o0]s/i],describe:function(e){var t={name:"WebOS Browser"},r=i.default.getFirstMatch(s,e)||i.default.getFirstMatch(/w(?:eb)?[o0]sbrowser\/(\d+(\.?_?\d+)+)/i,e);return r&&(t.version=r),t}},{test:[/bada/i],describe:function(e){var t={name:"Bada"},r=i.default.getFirstMatch(/dolfin\/(\d+(\.?_?\d+)+)/i,e);return r&&(t.version=r),t}},{test:[/tizen/i],describe:function(e){var t={name:"Tizen"},r=i.default.getFirstMatch(/(?:tizen\s?)?browser\/(\d+(\.?_?\d+)+)/i,e)||i.default.getFirstMatch(s,e);return r&&(t.version=r),t}},{test:[/qupzilla/i],describe:function(e){var t={name:"QupZilla"},r=i.default.getFirstMatch(/(?:qupzilla)[\s/](\d+(\.?_?\d+)+)/i,e)||i.default.getFirstMatch(s,e);return r&&(t.version=r),t}},{test:[/firefox|iceweasel|fxios/i],describe:function(e){var t={name:"Firefox"},r=i.default.getFirstMatch(/(?:firefox|iceweasel|fxios)[\s/](\d+(\.?_?\d+)+)/i,e);return r&&(t.version=r),t}},{test:[/electron/i],describe:function(e){var t={name:"Electron"},r=i.default.getFirstMatch(/(?:electron)\/(\d+(\.?_?\d+)+)/i,e);return r&&(t.version=r),t}},{test:[/chromium/i],describe:function(e){var t={name:"Chromium"},r=i.default.getFirstMatch(/(?:chromium)[\s/](\d+(\.?_?\d+)+)/i,e)||i.default.getFirstMatch(s,e);return r&&(t.version=r),t}},{test:[/chrome|crios|crmo/i],describe:function(e){var t={name:"Chrome"},r=i.default.getFirstMatch(/(?:chrome|crios|crmo)\/(\d+(\.?_?\d+)+)/i,e);return r&&(t.version=r),t}},{test:[/GSA/i],describe:function(e){var t={name:"Google Search"},r=i.default.getFirstMatch(/(?:GSA)\/(\d+(\.?_?\d+)+)/i,e);return r&&(t.version=r),t}},{test:function(e){var t=!e.test(/like android/i),r=e.test(/android/i);return t&&r},describe:function(e){var t={name:"Android Browser"},r=i.default.getFirstMatch(s,e);return r&&(t.version=r),t}},{test:[/playstation 4/i],describe:function(e){var t={name:"PlayStation 4"},r=i.default.getFirstMatch(s,e);return r&&(t.version=r),t}},{test:[/safari|applewebkit/i],describe:function(e){var t={name:"Safari"},r=i.default.getFirstMatch(s,e);return r&&(t.version=r),t}},{test:[/.*/i],describe:function(e){var t=-1!==e.search("\\(")?/^(.*)\/(.*)[ \t]\((.*)/:/^(.*)\/(.*) /;return {name:i.default.getFirstMatch(t,e),version:i.default.getSecondMatch(t,e)}}}];t.default=o,e.exports=t.default;},93:function(e,t,r){t.__esModule=!0,t.default=void 0;var n,i=(n=r(17))&&n.__esModule?n:{default:n},s=r(18);var o=[{test:[/Roku\/DVP/],describe:function(e){var t=i.default.getFirstMatch(/Roku\/DVP-(\d+\.\d+)/i,e);return {name:s.OS_MAP.Roku,version:t}}},{test:[/windows phone/i],describe:function(e){var t=i.default.getFirstMatch(/windows phone (?:os)?\s?(\d+(\.\d+)*)/i,e);return {name:s.OS_MAP.WindowsPhone,version:t}}},{test:[/windows /i],describe:function(e){var t=i.default.getFirstMatch(/Windows ((NT|XP)( \d\d?.\d)?)/i,e),r=i.default.getWindowsVersionName(t);return {name:s.OS_MAP.Windows,version:t,versionName:r}}},{test:[/Macintosh(.*?) FxiOS(.*?) Version\//],describe:function(e){var t=i.default.getSecondMatch(/(Version\/)(\d[\d.]+)/,e);return {name:s.OS_MAP.iOS,version:t}}},{test:[/macintosh/i],describe:function(e){var t=i.default.getFirstMatch(/mac os x (\d+(\.?_?\d+)+)/i,e).replace(/[_\s]/g,"."),r=i.default.getMacOSVersionName(t),n={name:s.OS_MAP.MacOS,version:t};return r&&(n.versionName=r),n}},{test:[/(ipod|iphone|ipad)/i],describe:function(e){var t=i.default.getFirstMatch(/os (\d+([_\s]\d+)*) like mac os x/i,e).replace(/[_\s]/g,".");return {name:s.OS_MAP.iOS,version:t}}},{test:function(e){var t=!e.test(/like android/i),r=e.test(/android/i);return t&&r},describe:function(e){var t=i.default.getFirstMatch(/android[\s/-](\d+(\.\d+)*)/i,e),r=i.default.getAndroidVersionName(t),n={name:s.OS_MAP.Android,version:t};return r&&(n.versionName=r),n}},{test:[/(web|hpw)[o0]s/i],describe:function(e){var t=i.default.getFirstMatch(/(?:web|hpw)[o0]s\/(\d+(\.\d+)*)/i,e),r={name:s.OS_MAP.WebOS};return t&&t.length&&(r.version=t),r}},{test:[/blackberry|\bbb\d+/i,/rim\stablet/i],describe:function(e){var t=i.default.getFirstMatch(/rim\stablet\sos\s(\d+(\.\d+)*)/i,e)||i.default.getFirstMatch(/blackberry\d+\/(\d+([_\s]\d+)*)/i,e)||i.default.getFirstMatch(/\bbb(\d+)/i,e);return {name:s.OS_MAP.BlackBerry,version:t}}},{test:[/bada/i],describe:function(e){var t=i.default.getFirstMatch(/bada\/(\d+(\.\d+)*)/i,e);return {name:s.OS_MAP.Bada,version:t}}},{test:[/tizen/i],describe:function(e){var t=i.default.getFirstMatch(/tizen[/\s](\d+(\.\d+)*)/i,e);return {name:s.OS_MAP.Tizen,version:t}}},{test:[/linux/i],describe:function(){return {name:s.OS_MAP.Linux}}},{test:[/CrOS/],describe:function(){return {name:s.OS_MAP.ChromeOS}}},{test:[/PlayStation 4/],describe:function(e){var t=i.default.getFirstMatch(/PlayStation 4[/\s](\d+(\.\d+)*)/i,e);return {name:s.OS_MAP.PlayStation4,version:t}}}];t.default=o,e.exports=t.default;},94:function(e,t,r){t.__esModule=!0,t.default=void 0;var n,i=(n=r(17))&&n.__esModule?n:{default:n},s=r(18);var o=[{test:[/googlebot/i],describe:function(){return {type:"bot",vendor:"Google"}}},{test:[/huawei/i],describe:function(e){var t=i.default.getFirstMatch(/(can-l01)/i,e)&&"Nova",r={type:s.PLATFORMS_MAP.mobile,vendor:"Huawei"};return t&&(r.model=t),r}},{test:[/nexus\s*(?:7|8|9|10).*/i],describe:function(){return {type:s.PLATFORMS_MAP.tablet,vendor:"Nexus"}}},{test:[/ipad/i],describe:function(){return {type:s.PLATFORMS_MAP.tablet,vendor:"Apple",model:"iPad"}}},{test:[/Macintosh(.*?) FxiOS(.*?) Version\//],describe:function(){return {type:s.PLATFORMS_MAP.tablet,vendor:"Apple",model:"iPad"}}},{test:[/kftt build/i],describe:function(){return {type:s.PLATFORMS_MAP.tablet,vendor:"Amazon",model:"Kindle Fire HD 7"}}},{test:[/silk/i],describe:function(){return {type:s.PLATFORMS_MAP.tablet,vendor:"Amazon"}}},{test:[/tablet(?! pc)/i],describe:function(){return {type:s.PLATFORMS_MAP.tablet}}},{test:function(e){var t=e.test(/ipod|iphone/i),r=e.test(/like (ipod|iphone)/i);return t&&!r},describe:function(e){var t=i.default.getFirstMatch(/(ipod|iphone)/i,e);return {type:s.PLATFORMS_MAP.mobile,vendor:"Apple",model:t}}},{test:[/nexus\s*[0-6].*/i,/galaxy nexus/i],describe:function(){return {type:s.PLATFORMS_MAP.mobile,vendor:"Nexus"}}},{test:[/[^-]mobi/i],describe:function(){return {type:s.PLATFORMS_MAP.mobile}}},{test:function(e){return "blackberry"===e.getBrowserName(!0)},describe:function(){return {type:s.PLATFORMS_MAP.mobile,vendor:"BlackBerry"}}},{test:function(e){return "bada"===e.getBrowserName(!0)},describe:function(){return {type:s.PLATFORMS_MAP.mobile}}},{test:function(e){return "windows phone"===e.getBrowserName()},describe:function(){return {type:s.PLATFORMS_MAP.mobile,vendor:"Microsoft"}}},{test:function(e){var t=Number(String(e.getOSVersion()).split(".")[0]);return "android"===e.getOSName(!0)&&t>=3},describe:function(){return {type:s.PLATFORMS_MAP.tablet}}},{test:function(e){return "android"===e.getOSName(!0)},describe:function(){return {type:s.PLATFORMS_MAP.mobile}}},{test:function(e){return "macos"===e.getOSName(!0)},describe:function(){return {type:s.PLATFORMS_MAP.desktop,vendor:"Apple"}}},{test:function(e){return "windows"===e.getOSName(!0)},describe:function(){return {type:s.PLATFORMS_MAP.desktop}}},{test:function(e){return "linux"===e.getOSName(!0)},describe:function(){return {type:s.PLATFORMS_MAP.desktop}}},{test:function(e){return "playstation 4"===e.getOSName(!0)},describe:function(){return {type:s.PLATFORMS_MAP.tv}}},{test:function(e){return "roku"===e.getOSName(!0)},describe:function(){return {type:s.PLATFORMS_MAP.tv}}}];t.default=o,e.exports=t.default;},95:function(e,t,r){t.__esModule=!0,t.default=void 0;var n,i=(n=r(17))&&n.__esModule?n:{default:n},s=r(18);var o=[{test:function(e){return "microsoft edge"===e.getBrowserName(!0)},describe:function(e){if(/\sedg\//i.test(e))return {name:s.ENGINE_MAP.Blink};var t=i.default.getFirstMatch(/edge\/(\d+(\.?_?\d+)+)/i,e);return {name:s.ENGINE_MAP.EdgeHTML,version:t}}},{test:[/trident/i],describe:function(e){var t={name:s.ENGINE_MAP.Trident},r=i.default.getFirstMatch(/trident\/(\d+(\.?_?\d+)+)/i,e);return r&&(t.version=r),t}},{test:function(e){return e.test(/presto/i)},describe:function(e){var t={name:s.ENGINE_MAP.Presto},r=i.default.getFirstMatch(/presto\/(\d+(\.?_?\d+)+)/i,e);return r&&(t.version=r),t}},{test:function(e){var t=e.test(/gecko/i),r=e.test(/like gecko/i);return t&&!r},describe:function(e){var t={name:s.ENGINE_MAP.Gecko},r=i.default.getFirstMatch(/gecko\/(\d+(\.?_?\d+)+)/i,e);return r&&(t.version=r),t}},{test:[/(apple)?webkit\/537\.36/i],describe:function(){return {name:s.ENGINE_MAP.Blink}}},{test:[/(apple)?webkit/i],describe:function(e){var t={name:s.ENGINE_MAP.WebKit},r=i.default.getFirstMatch(/webkit\/(\d+(\.?_?\d+)+)/i,e);return r&&(t.version=r),t}}];t.default=o,e.exports=t.default;}})})); }); var Bowser = unwrapExports(es5); es5.bowser; // 与客户端交互方法列表 const browser = Bowser.getParser(window.navigator.userAgent); class Ws { constructor({ url = 'ws://localhost', port = '1234', publicKey = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDbEpPpxpLJft4W9YZj8bRh2bYYZshBEsKOlxgyn11rlEyTasjBSZRV9aj33tvQ2T55izH0fWl+dL/dLZChawFrlGDcH8JuWge2xYMgII9mggcYa0UiQ7pLXJ9ivXZ/cOY3HzrRQdR7dGTSNn3Z0Ctbns6mLgvlA2r3qMNs/8wHBwIDAQAB', reConnectCount = 3, reLoginCount = 0, loginIp = location.hostname, appName = "", loginPort = location.port, userName = '', userPwd = '', token = '', callback = { connectResult: null, loginResult: null }, isKeepConnect = true, detectDssVersion = true, messageEvents = {} }) { // 是否连接客户端 this.isConnectSuccessQt = false; // 是否登录客户端 this.isLoginSuccess = false; // 外部注册客户端消息处理 this.messageEvents = {}; // 最大重连数 this.reConnectCount = 3; // 连接失败次数 this.connectFailCount = 0; // 连接完成标识 this.connectEnd = true; // 连接客户端开始时间 this.connectStartTime = 0; // 连接超时时间 this.connectTimeOut = 30 * 1000; // 登录完成标识 this.loginEnd = true; // 登录客户端开始时间 this.loginStartTime = 0; // 登录超时时间 this.loginTimeOut = 60 * 1000; // 最大重登数 this.reLoginCount = 0; // 连接失败次数 this.loginFailCount = 0; // 当前websocket登录配置 this.config = { browser: {} }; // 用户标识符 this.userCode = 0; //对应注册的唯一编码 this.appId = 0; // 是否检测客户端版本 this.detectDssVersion = true; // 当前客户端版本 this.currentDssVersion = ''; // 获取当前版本结束标志 //getVersionEnd: Boolean = true; // 获取版本开始时间 //getVersionStartTime: number = 0; // 获取版本超时时间 //getVersionTimeOut: number = 30 * 1000; // 线上客户端版本 this.onlineDssVersion = ''; // 线上客户顿版本获取地址后缀,32系统文件名添加32 this.onlineDssVersionAfterfix = '/data/VSL/DSSEnterpriseClient/LightWeightVersion.txt'; // 线上客户顿获取地址后缀,32系统文件名添加32 this.onlineDssAfterfix = '/data/VSL/DSSEnterpriseClient/DSS_LightWeight_Client.zip'; // 是否一直保持重新连接 this.isKeepConnect = true; // 创建的控件ID列表 this.ids = []; // 创建的控件列表 this.ctrls = []; // 心跳 this.heartBeatTimer = null; // 监听的添加式方法表 this.handlers = {}; this.url = url; this.port = port; this.userCode = new Date().valueOf(); this.appId = new Date().valueOf(); //对应注册的唯一编码,可以取一个随机字符串。 this.webSocket = null; this.reConnectCount = reConnectCount; this.reLoginCount = reLoginCount; this.publicKey = publicKey; this.loginIp = loginIp; this.appName = appName; //应用名称,相同的应用名称会共用一个客户端进程。 this.loginPort = loginPort; this.userName = userName; this.userPwd = userPwd; this.token = token; this.callback = callback; this.isKeepConnect = isKeepConnect; this.detectDssVersion = detectDssVersion; this.messageEvents = messageEvents || {}; this.connectFailCount = this.connectFailCount; // 基础操作所需功能或属性 this.ids = []; this.ctrls = []; // 是否连接客户端 this.isConnectSuccessQt = false; // 是否登陆客户端 this.isLoginSuccess = false; this.heartBeatTimer = null; // 用户注册监听事件表 this.handlers = {}; // 用户注册监听事件表 this.listerns = new Map(); // 获取与客户端交互方法列表 const defaultActions = []; Object.keys(wsActions).forEach(item => { if (hasKey(wsActions, item)) { defaultActions.push(wsActions[item]); } }); // 与客户端通讯功能注册 usePlugin(defaultActions); // 处理客户端消息 合并以内置方法为主,客户自定义事件与内置方法重复,则抛弃 this.messageEvents = Object.assign(this.messageEvents, defaultMessageEvents); Object.keys(this.messageEvents).forEach(item => { this.addEventListener(item, this.messageEvents[item].bind(this)); }); // 初始化配置参数 this.initConfig(); // 连接客户端 //this. connectSocket(); // 登录 // this.detectConnectQt().then((res: Boolean) => { // if(res) { // // 登陆客户端 // console.log(212); // this.loginClient(); // } // }); } /** * @description 获得实例对象 */ static getInstance(options) { if (!top['$ws']) { if (!this._instance) { this._instance = new Ws(options || {}); top['$ws'] = this._instance; } } else { this._instance = top['$ws']; // TODO 合并参数 // 合并messageEvents // if(options.messageEvents) { // Object.assign(this._instance.messageEvents, options.messageEvents); // 移除所有监听 // ------ // Object.keys(this._instance.messageEvents).forEach(item => { // this._instance.addEventListener(item, this._instance.messageEvents[item].bind(this._instance)); // }); // } } return this._instance; } /** * @description 用户注册监听事件,覆盖式监听 * @params {String} eventType 事件名称 * @params {any} callback 回调函数 */ on(eventType, callback) { this.listerns.set(eventType, callback); } /** * @description 用户取消监听事件,覆盖式监听 * @params {String} eventType 事件名称 */ off(eventType) { delete this.listerns[eventType]; } /** * @description 用户注册监听事件,添加式监听 * @params {String} eventType 事件名称 * @params {any} handler 回调函数 */ addEventListener(eventType, handler) { // 首先判断handlers内有没有type事件容器,没有则创建一个新数组容器 if (!(eventType in this.handlers)) { this.handlers[eventType] = []; } // 将事件存入 this.handlers[eventType].push(handler); } /** * @description 添加式监听,触发事件 * @params {String} eventType 事件名称 * @params {any} params 函数参数 */ dispatchEvent(eventType, ...params) { // 若没有注册该事件则抛出错误 if (!(eventType in this.handlers)) { return new Error('未注册该事件'); } // 便利触发 this.handlers[eventType].forEach(handler => { handler(...params); }); } /** * @description 用户取消监听事件 * @params {String} eventType 事件名称 */ removeEventListener(eventType, handler) { // 无效事件抛出 if (!(eventType in this.handlers)) { return new Error('无效事件'); } if (!handler) { // 直接移除事件 delete this.handlers[eventType]; } else { const idx = this.handlers[eventType].findIndex(ele => ele === handler); // 抛出异常事件 if (idx === -1) { return new Error('无该绑定事件'); } // 移除事件 this.handlers[eventType].splice(idx, 1); if (this.handlers[eventType].length === 0) { delete this.handlers[eventType]; } } } /** * @description 发送消息给客户端 * @params {String} method 事件名称 * @params {Object} data 传输消息的数据内容 */ postMessage(method, data) { console.log('sendMessageToClient', method, data); const { webSocket } = this; data.method = method; // 不需要判断登录和连接的方法过滤 //let filterList = ['register', 'unregister', 'browserInfo', 'getVersion', 'trusteSite']; let filterList = ['register', 'unregister', 'browserInfo', 'trusteSite']; if (filterList.includes(method)) { webSocket.send(JSON.stringify(data)); // if(method == 'unregister'){ // const { appName } = _this.config; // if('appName' in _this.config){ // _this.config[appName] = ''; // } // } return Promise.resolve(true); } return new Promise((resolve, reject) => { this.keeper().then(res => { if (res) { // if(method == "register"){ // _this.loginEnd = true; // } webSocket.send(JSON.stringify(data)); resolve(true); } else { reject(false); } }).catch(e => { console.error('ws-error in keeper'); }); }); } /* * 初始化配置 */ initConfig() { // token登陆的username通过token截取 if (this.token && this.token.split('_')[0]) { this.userName = this.token.split('_')[0]; } this.config = { userName: this.userName, userCode: this.userCode, appId: this.appId, loginPort: this.loginPort, loginIp: this.loginIp, userPwd: this.userPwd, token: this.token, appName: this.appName, port: this.port }; // 浏览器信息 const browserInfo = { name: '', version: '', platform: '' }; browserInfo.name = browser.getBrowserName().toLowerCase(); browserInfo.version = browser.getBrowser().version.toLowerCase(); browserInfo.platform = browser._ua.indexOf('Win64') >= 0 || browser._ua.indexOf('Wow64') >= 0 ? 'win64' : 'win32'; this.config['browser'] = browserInfo; } /** * @description 连接客户端 */ connectSocket(config) { this.connectFailCount = 0; this.connectEnd = false; this.connectStartTime = Date.now(); let { port } = config; let url = this.url + ":" + port; // 连接客户端 this.webSocket = new reconnectingWebsocketCjs(url, '', { maxRetries: this.reConnectCount }); // 取消订阅的事件 this.removeEvents(); // 订阅事件 this.addEvents(); return this.detectConnectQt(); } /** * @description 获取线上和线下客户端版本 */ // getDSSVersion() { // this.getOnlineDssVersion(); // this.getLocalDssVersion(); // } /** * @description 获取线上客户端版本 */ // getOnlineDssVersion() { // // 待解决跨域问题 // let _this = this; // let platform = this.config['browser'].platform; // let versionUrl = this.onlineDssVersionAfterfix; // if(platform === 'win32') { // versionUrl = versionUrl.replace('.txt', '32.txt'); // } // var request = new XMLHttpRequest(); // request.open("get", versionUrl);/*设置请求方法与路径*/ // request.send(null);/*不发送数据到服务器*/ // request.onload = function () {/*XHR对象获取到返回信息后执行*/ // if (request.status == 200) {/*返回状态为200,即为数据获取成功*/ // _this.onlineDssVersion = request.response.replace('ClientVersion = ', '') // if(_this.currentDssVersion !== '') { // _this.compareVersion(); // } // } // } // } /** * @description 检测连接客户端状态 */ detectConnectQt() { let _this = this; return new Promise((resolve, reject) => { if (!_this.connectEnd) { // 连接中 // let now = Date.now(); // if((now - _this.connectStartTime) > _this.connectTimeOut) { // console.log(`ws-this.connectEndTime-${now}`); // reject('connect timeout'); // } let _interval = setInterval(() => { if (_this.connectEnd) { clearInterval(_interval); resolve(_this.isConnectSuccessQt); } }, 50); } else { resolve(_this.isConnectSuccessQt); } }); } /** * @description 检测登录客户端状态 */ detectLoginClient() { let _this = this; return new Promise((resolve, reject) => { console.log(this.loginEnd, "this.loginEnd"); if (!this.loginEnd) { // 登录中 let _interval = setInterval(() => { if (_this.loginEnd) { clearInterval(_interval); resolve(_this.isLoginSuccess); } }, 50); } else { resolve(_this.isLoginSuccess); } }); } /** * @description 连接状态守护 */ keepConnect() { return new Promise((resolve, reject) => { // 监测连接状态 this.detectConnectQt().then((connectStatus) => { // 连接正常 if (connectStatus) { resolve(true); } else { // 连接状态失效,重新连接 // this. connectSocket({}).then((ReconnectStatus: Boolean) => { // // 重连成功 // if(ReconnectStatus) { // resolve(true); // } else { // console.log(`ws-in-keepConnect-reConnect-fail`); // reject(false); // } // }) this.Vue.prototype.$Message.info("请先连接客户端"); } }); }); } /** * @description 连接和登录状态守护 */ keeper() { return new Promise((resolve, reject) => { // 监测连接状态 this.detectConnectQt().then((connectStatus) => { // 连接正常 if (connectStatus) { this.detectLoginClient().then((loginStatus) => { // 登录正常 if (loginStatus) { resolve(true); } else { // 登录异常 // 登录 console.log(507); this.loginClient(); // 登录后的状态监测 this.detectLoginClient().then((reLoginStatus) => { if (reLoginStatus) { resolve(true); } else { console.log(`ws-in-keeper-reLogin-fail`); reject(false); } }); } }); } else { // 连接状态失效,重新连接 // this. connectSocket({}).then((ReconnectStatus: Boolean) => { // // 连接成功 // if(ReconnectStatus) { // // 登录 // console.log(`ws-in-keeper-reConnect-reLogin`); // console.log(528); // this.loginClient() // // 登录状态监测 // this.detectLoginClient().then((loginStatus: Boolean) => { // if(loginStatus) { // resolve(true); // } else { // console.log(`ws-in-keeper-reLogin-fail`); // reject(false); // } // }) // } else { // console.log(`ws-in-keeper-reConnect-fail`); // reject(false); // } // }) this.Vue.prototype.$Message.info("请先连接客户端"); } }); }); } /** * @description 获取当前客户端版本 */ // getLocalDssVersion() { // let _this = this; // this.getVersion(); // console.log(`ws-getLocalDssVersion-getVersionEnd-${this.getVersionEnd}`) // return new Promise((resolve, reject) => { // if(!this.getVersionEnd) { // 连接中或者获取中 // // let now = Date.now(); // // if((now - _this.getVersionStartTime) > _this.getVersionTimeOut) { // // console.log(`ws-this.getVersionEndTime-${now}`); // // reject('get version timeout'); // // } // let _interval = setInterval(() => { // if(_this.getVersionEnd) { // clearInterval(_interval); // resolve(_this.currentDssVersion); // } // }, 50) // } else { // resolve(_this.currentDssVersion); // } // }) // } /** * @description 比较客户端版本 */ compareVersion() { if (this.currentDssVersion && this.onlineDssVersion && Number(this.onlineDssVersion) > Number(this.currentDssVersion)) { this.dispatchEvent('updateDss'); // this.Vue && this.Vue.prototype.$Modal.confirm({ // title: '客户端更新', // content: '系统检测到新客户端版本,请更新后使用?', // onOk: () => { // this.downloadClient(); // }, // onCancel: () => { // this.detectDssVersion = false; // } // }); } } /** * @description 下载客户端 */ downloadClient() { var agent = navigator.userAgent.toLowerCase(); let type = '64'; if (agent.indexOf("win32") >= 0 || agent.indexOf("wow32") >= 0) { type = '32'; } else if (agent.indexOf("win64") >= 0 || agent.indexOf("wow64") >= 0) { type = '64'; } let downUrl = location.origin + '/data/VSL/DSSEnterpriseClient/DSS_LightWeight_Client'; type === '32' ? downUrl = downUrl + '32.zip' : downUrl = downUrl + '.zip'; window.open(downUrl); } /** * @description 登录客户端 * @params {Object} config 登录相关配置 */ register(config) { console.log('ws-login-start'); this.loginFailCount = 0; // 如果登陆时用户名变更,更新userCode let { userName, token } = config; // token登陆的username通过token截取 if (token && token.split('_')[0]) { userName = token.split('_')[0]; } if (this.config['userName'] && (userName !== this.config['userName'])) { this.userCode = new Date().valueOf(); this.appId = new Date().valueOf(); } this.userName = userName; this.initConfig(); Object.assign(this.config, config); this.detectConnectQt().then((res) => { if (res) { // 若已登录,先注销 console.log('ws-login-start-this.isLoginSuccess', this.isLoginSuccess); // if (this.isLoginSuccess) { // this.unregister(); // } // 登陆客户端 console.log(637); this.loginClient(); // 获取线上客户端版本 //this.detectDssVersion && this.getDSSVersion(); } else { // 未连接客户端 // this. connectSocket({}).then((res1: Boolean) => { // if(res1) { // // 登陆客户端 // console.log(646); // this.loginClient(); // // 获取线上客户端版本 // this.detectDssVersion && this.getDSSVersion(); // } else { // throw new Error('连接客户端失败'); // } // }) this.Vue.prototype.$Message.info("请先连接客户端"); } }); } /** * @description 登出客户端 */ unregister() { // 退出客户端 this.logoutClient(); // this.detectLoginClient().then(res => { // res && this.logoutClient(); // }) this.ids = []; this.ctrls = []; this.isLoginSuccess = false; if (typeof this.callback.loginResult === 'function') { this.callback.loginResult.call(this, this.isLoginSuccess); } } /** * @description 添加websocket/window监听事件 */ addEvents() { const webSocket = this.webSocket; webSocket.addEventListener('open', this.onOpen.bind(this)); webSocket.addEventListener('message', this.onMessage.bind(this)); webSocket.addEventListener('error', this.onError.bind(this)); window.addEventListener('resize', this.reLocatedPosition.bind(this)); window.addEventListener('scroll', this.reLocatedPosition.bind(this)); window.addEventListener('visibilitychange', this.webVisibilityChange.bind(this)); window.addEventListener('onunload', this.closeBrowser.bind(this)); } /** * @description 移除websocket/window监听事件 */ removeEvents() { const webSocket = this.webSocket; webSocket.removeEventListener('open', this.onOpen); webSocket.removeEventListener('message', this.onMessage); webSocket.removeEventListener('error', this.onError); window.removeEventListener('resize', this.reLocatedPosition); window.removeEventListener('scroll', this.reLocatedPosition); window.removeEventListener('visibilitychange', this.webVisibilityChange); window.removeEventListener('onunload', this.closeBrowser); } /** * @description 连接客户端成功事件 */ onOpen() { console.log('ws-onOpen'); // chrome浏览器版本大于80,需要添加信任站点,加载http/https跨站点资源 // if(this.config['browser'].name === 'chrome' && this.config['browser'].version && Number(this.config['browser'].version.split('.')[0]) >= 80) { // this.trusteSite(location.hostname); // } this.isConnectSuccessQt = true; this.dispatchEvent('connectStateChange', true); this.connectEnd = true; if (typeof this.callback.connectResult === 'function') { this.callback.connectResult.call(this, this.isConnectSuccessQt); } // 获取客户端版本 //this.getVersionEnd = false; //this.getDSSVersion(); } /** * @description 接收客户端消息 * @params {Object} event 接收客户端的消息数据 */ onMessage(event) { try { const data = JSON.parse(event.data); const { method } = data; console.log('receiveMessageFromClient', method, event); const callback = this.listerns.get(method); // 数据格式处理 let dealDataRes = dealEventData[method] ? dealEventData[method](data) : data; this.dispatchEvent(method, dealDataRes); // if (method === 'registerState') { // callback; // } // else { // callback && callback(data); // } // if (method === 'loginState') { // console.log(this.isLoginSuccess, "this.isLoginSuccess"); // callback; // } // else { // callback && callback(data); // } callback && callback(data); } catch (e) { // 客户端协议中含有返回的不是Json数据 console.log('ws-error-客户端返回的消息不是Json数据', e); } } /** * @description 客户端发生错误事件 */ onError() { this.ctrls = []; this.ids = []; this.isConnectSuccessQt = false; // clearTimeout(this.heartbeatTimer); this.connectFailCount++; this.dispatchEvent('connectStateChange', false); if (this.connectFailCount === this.reConnectCount + 1) { this.connectEnd = true; this.isKeepConnect && this.keepConnect(); if (typeof this.callback.connectResult === 'function') { this.callback.connectResult.call(this, this.isConnectSuccessQt); } } } /** * @description 判断是否成功连接客户端 */ isOpen() { if (!this.webSocket) return false; return this.webSocket.readyState === 1; } /** * @description 心跳事件 */ // _heartbeat() { // this.heartbeat(); // clearTimeout(this.heartbeatTimer); // this.heartbeatTimer = setTimeout(() => { // this._heartbeat(); // }, 10000); // } /** * @description 关闭浏览器事件 */ closeBrowser() { this.unregister(); // 延迟100ms登出,关闭所有控件 var timestamp = new Date().getTime(); while ((new Date().getTime() - timestamp) < 100) { } } } // 唯一实例 Ws._instance = null; /** * @description 判断对象是否含有某属性 * @params {Object} obj 对象 * @params {String} key 属性key */ function hasKey(obj, key) { return key in obj; } /** * @description 与客户端通讯功能注册 * @params {Array} actions 功能列表 */ function usePlugin(actions) { actions.forEach((plugin) => { Object.getOwnPropertyNames(plugin).forEach(prop => { Ws.prototype[prop] = plugin[prop]; }); }); } return Ws; }))); //# sourceMappingURL=DHWs.js.map