websocket

https://www.jianshu.com/p/3b5fbc1abc9d
mounted() {
this.initWebSocket();
this.timer = setInterval(() => {
this.websocketsend(88888);
},1500)
},
beforeRouteLeave(to,from,next) {
this.websock.close();
clearInterval(this.timer);
next();
}
//初始化weosocket
initWebSocket(){
//ws地址
// const wsuri = process.env.WS_API + “/websocket/threadsocket”;
let mymessage = encodeURIComponent(this.AppParams.session+this.AppParams.hotel_id);
let basePath = httpTool.httpUrlEnv();
this.HOTELBASHPATH(basePath);
let wsuri = ‘’;
let payws = ‘’;
if(sessionStorage.getItem(‘windowUrl’) == ‘i/master’||sessionStorage.getItem(‘windowUrl’)’/q/master/’) {
wsuri = “wss://qa.fortrun.cn/todolistws?wsCode=” + mymessage; // qa
payws = “wss://qa.fortrun.cn/payws/”;
}else {
// wsuri = “ws://118.25.187.159:8131/todolistws?wsCode=” + mymessage;
wsuri = “wss://wqt.fortrun.cn”+sessionStorage.getItem(‘windowUrl’)+“todolistws?wsCode=” + mymessage;
payws = “wss://wqt.fortrun.cn”+sessionStorage.getItem(‘windowUrl’)+“payws/”;
}
this.TODOLISTWS(wsuri);
this.PAYWS(payws);
// const wsuri = “ws://qa.fortrun.cn:8131/todolistws?wsCode=” + mymessage; // qa
// const wsuri = “ws://118.25.187.159:8131/todolistws?wsCode=” + mymessage;
this.websock = new WebSocket(wsuri);
this.websock.onopen = this.websocketonopen;
this.websock.onmessage = this.websocketonmessage;
this.websock.onclose = this.websocketclose;
},
websocketonopen(e){ //建立通道
// let redata = e;
console.log('websocket建立链接
’)
},
websocketonmessage(e){ //数据接收
console.log(‘websocket数据接收成功==’);
console.log(e);
let date = e.data;
if (date == ‘“refresh”’) {
this.getTodoLists();
this.getSockerE();
}
},
websocketsend(agentData){//数据发送
console.log(‘websocket数据发送成功==’)
console.log(agentData);
this.websock.send(agentData);
},
websocketclose(e){ //关闭通道
console.log(“关闭通道connection closed (” + e.code + “)”);
},

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值