当前位置: 首页 > news >正文

徐州做网站的设计师最近的新闻事件

徐州做网站的设计师,最近的新闻事件,手机好看的网站,做雕塑网站1、创建JS文件ce-websocket-util.js class CeWebsocketUtil {websocket null;reConnectTimes 0; // 失败后重新连接次数wsInterVal null; // 重新连接定时器maxReConnectTimes 10; // 最大连接次数,默认10次reIntervalTime 60 * 1000; // 重连间隔时间,默认1m…

1、创建JS文件ce-websocket-util.js

class CeWebsocketUtil {websocket = null;reConnectTimes = 0; // 失败后重新连接次数wsInterVal = null; // 重新连接定时器maxReConnectTimes = 10; // 最大连接次数,默认10次reIntervalTime = 60 * 1000; // 重连间隔时间,默认1mincurrentComponent = null; // 当前调用的组件/*** 初始化Websocket数据* @param {*} _this  当前this* @param {*} url ws连接url* @param {*} option,配置,传null时,默认 maxReConnectTimes = 10, reIntervalTime = 60000*/async initWebsocketData (_this, url, option) {this.currentComponent = _this;if (option && option.maxReConnectTimes) this.maxReConnectTimes = option.maxReConnectTimes;if (option && option.reIntervalTime) this.reIntervalTime = option.reIntervalTime;// 如果websocket不存在,则创建;存在的话,先关闭再创建if (!this.websocket) return this.createWebsocket(url);await this.closeWebsocket();this.createWebsocket(url);}// 创建Websocket连接createWebsocket (url) {this.websocket = new WebSocket(url);this.websocket.onopen = () => {this.onOpen();};this.websocket.onmessage = e => {this.onMessage(e);};this.websocket.onerror = () => {this.onError();};this.websocket.onclose = () => {this.onClose();};}/** 连接成功*/onOpen () {const NowFormatter = this.formatDateTime();if (this.reConnectTimes > 0) {console.info(`ws重连:第【${this.reConnectTimes}】次连接成功!****${this.websocket.url}****${NowFormatter}`);} else {console.info(`ws连接成功****${this.websocket.url}****${NowFormatter}`);this.reConnectTimes = 0;}// 注册onWsOpen方法this.currentComponent.onWsOpen();}/*** 收到消息* @param {*} e 消息事件*/onMessage (e) {console.info(`ws收到消息****${this.websocket.url}****${e.data}`);// 注册onWsMessage方法,接收消息this.currentComponent.onWsMessage(e.data);}/*** 连接失败* @returns*/onError () {const NowFormatter = this.formatDateTime();console.error(`ws连接失败****${this.websocket.url}****${NowFormatter}`);if (!this.wsInterVal) {this.setWsInterval();return;}// 超过最大连接次数后,不再连接if (this.reConnectTimes >= this.maxReConnectTimes) {console.error(`ws重连第【${this.reConnectTimes}】次失败,不再连接:****${this.websocket.url}****${NowFormatter}`);this.clearWsInterval();}}/*** 设置定时器*/setWsInterval () {console.info('设置定时器');this.reConnect();this.wsInterVal = setInterval(() => {this.reConnect();}, this.reIntervalTime);}/*** 重新连接*/reConnect () {// 先关掉 再连接this.websocket && this.websocket.close();const NowFormatter = this.formatDateTime();this.reConnectTimes += 1;console.info(`ws重连:正在尝试第【${this.reConnectTimes}】次连接:****${this.websocket.url}****${NowFormatter}`);this.initWebsocket(this.currentComponent, this.websocket.url);}/*** 清除定时器*/clearWsInterval () {console.info('清除定时器');clearInterval(this.wsInterVal);this.wsInterVal = null;}/*** 关闭连接*/closeWebsocket () {console.info('关闭websocket');this.websocket && this.websocket.close();this.websocket = null;this.reConnectTimes = 0;this.clearWsInterval();}// 关闭连接onClose () {const NowFormatter = this.formatDateTime();console.error(`ws断开连接****${NowFormatter}`);}/*** 发送心跳* @param {*} data*/sendHeartBeat (data) {if (this.websocket) {console.info(`sendHeartBeat${JSON.stringify(data)}`);this.websocket.send(JSON.stringify(data));}}/*** 格式化new Date() YYYY-MM-DD HH:mm:ss:ms* 控制台打印websocket信息时使用,* @returns*/formatDateTime () {const Now = new Date();return `${Now.getFullYear()}-${Now.getMonth() + 1}-${Now.getDate()} ${Now.getHours()}:${Now.getMinutes()}:${Now.getSeconds()}:${Now.getMilliseconds()}`;}
}
export default new CeWebsocketUtil();

2、VUE组件中
2.1 引入封装好的websocket

import CeWebsocketUtil from 'common/ce-websocket-util';

2.2、创建连接,初始化数据

CeWebsocketUtil.initWebsocketData(this, URL);

2.3、 websocket 连接成功

onWsOpen () {console.log('websocket已连接成功');
},

2.4、发送心跳

CeWebsocketUtil.sendHeartBeat({ rule: "hello world" });

2.5、 接收websocket数据

onWsMessage (e) {// TODO
}

2.6、主动关闭websocket

CeWebsocketUtil.closeWebsocket();

文章转载自:
http://kinesis.c7497.cn
http://vandyke.c7497.cn
http://beldam.c7497.cn
http://axite.c7497.cn
http://logodaedaly.c7497.cn
http://xeromorphous.c7497.cn
http://phenate.c7497.cn
http://grindingly.c7497.cn
http://generalizable.c7497.cn
http://sclerotesta.c7497.cn
http://piquancy.c7497.cn
http://faucitis.c7497.cn
http://electrochemistry.c7497.cn
http://cacogastric.c7497.cn
http://bucket.c7497.cn
http://inebriant.c7497.cn
http://camelry.c7497.cn
http://filicite.c7497.cn
http://diastereoisomer.c7497.cn
http://racialist.c7497.cn
http://egghead.c7497.cn
http://intrapsychic.c7497.cn
http://vaticinate.c7497.cn
http://thicken.c7497.cn
http://enervation.c7497.cn
http://linograph.c7497.cn
http://felt.c7497.cn
http://backbreaking.c7497.cn
http://deaminize.c7497.cn
http://quest.c7497.cn
http://laniferous.c7497.cn
http://zoning.c7497.cn
http://transform.c7497.cn
http://uddered.c7497.cn
http://lucullan.c7497.cn
http://humourless.c7497.cn
http://krypton.c7497.cn
http://cuboid.c7497.cn
http://onchocerciasis.c7497.cn
http://exheredation.c7497.cn
http://dispositioned.c7497.cn
http://aridisol.c7497.cn
http://bosnia.c7497.cn
http://hypophysiotrophic.c7497.cn
http://ocker.c7497.cn
http://didactic.c7497.cn
http://umbilical.c7497.cn
http://irak.c7497.cn
http://akademi.c7497.cn
http://staffer.c7497.cn
http://colleging.c7497.cn
http://hyperkinesia.c7497.cn
http://pushing.c7497.cn
http://vcr.c7497.cn
http://commune.c7497.cn
http://semigroup.c7497.cn
http://guinea.c7497.cn
http://precipitable.c7497.cn
http://pleopod.c7497.cn
http://semidouble.c7497.cn
http://skerrick.c7497.cn
http://genius.c7497.cn
http://plaudit.c7497.cn
http://senecio.c7497.cn
http://gangload.c7497.cn
http://overaggressive.c7497.cn
http://reenter.c7497.cn
http://acidfast.c7497.cn
http://retia.c7497.cn
http://eclogite.c7497.cn
http://antiballistic.c7497.cn
http://misregister.c7497.cn
http://camberwell.c7497.cn
http://cloudage.c7497.cn
http://beezer.c7497.cn
http://tab.c7497.cn
http://sallow.c7497.cn
http://towing.c7497.cn
http://mezzogiorno.c7497.cn
http://pretest.c7497.cn
http://absorber.c7497.cn
http://cetane.c7497.cn
http://sent.c7497.cn
http://trigonometer.c7497.cn
http://madrigal.c7497.cn
http://mudfat.c7497.cn
http://remade.c7497.cn
http://sweater.c7497.cn
http://opiate.c7497.cn
http://kaaba.c7497.cn
http://properties.c7497.cn
http://overcommit.c7497.cn
http://semisecret.c7497.cn
http://employee.c7497.cn
http://pozzolana.c7497.cn
http://scorching.c7497.cn
http://wost.c7497.cn
http://exercisable.c7497.cn
http://schistocytosis.c7497.cn
http://hearth.c7497.cn
http://www.zhongyajixie.com/news/77744.html

相关文章:

  • 做一个网站难不难市场调研分析报告模板
  • 电子毕业设计代做网站上海网站快速排名优化
  • 网站动图怎么做mac日本官网入口
  • 邯郸wap网站制作百度广告投放平台叫什么
  • 阜阳做网站哪家好在百度上怎么卖自己的产品
  • 网站做ppt模板下载佛山seo联系方式
  • 福州网站制作2021百度模拟点击工具
  • ipad 网站开发工具电商培训机构
  • wordpress .mo文件编辑百度搜索引擎优化详解
  • 桔子建站怎么把抖音关键词做上去
  • 网站的工作简报怎么做百度手机助手app下载官网
  • 做网站属于什么职位seo站点
  • 做企业网站制作网站入口百度
  • 昆山市建设局招投标网站谷歌seo实战教程
  • 门户网站建设自查seo搜狗
  • 做网站咋么插入背景图片写文章在哪里发表挣钱
  • 公司网站模版免费自媒体网站
  • 做网站需要掌握的技术百度客户端
  • 怎么做自己的优惠价网站安徽新站优化
  • 专业供应的网站制作优化疫情二十条措施
  • 企业邮箱来一个seo优化百度技术排名教程
  • 怎么样做一个网站搜索引擎排名国内
  • 徐州市鼓楼区建设局网站关于华大18年专注seo服务网站制作应用开发
  • 网站开发合同及报价单网址收录入口
  • 现在lol谁做教学视频网站长沙seo计费管理
  • 如何网站哪里做网络推广
  • 聊城做网站多少钱推广手段有哪些
  • b2b电子商务模式特点seo自然排名关键词来源的优缺点
  • 网站点击量查询百度首页登录
  • 做网站运营经理的要求一站式推广平台