合并代码
This commit is contained in:
@@ -1,11 +1,27 @@
|
||||
import MyEvent from "@/tool/myEvents";
|
||||
class MyWs {
|
||||
constructor() {
|
||||
this.ws = null;
|
||||
// this.ws = new WebSocket();
|
||||
let http = process.env.VUE_APP_BASE_URL.replace(/^https?:\/\//, '')
|
||||
this.messageUrl = http+'/notification'
|
||||
}
|
||||
linkWs(url) {
|
||||
console.log(this.ws && this.ws.readyState == 1);
|
||||
if (this.ws && this.ws.readyState == 1) return
|
||||
this.ws = new WebSocket(url)
|
||||
this.ws.onmessage = (e)=>{
|
||||
try {
|
||||
MyWs.receiveText(JSON.parse(e.data))
|
||||
} catch (error) {
|
||||
console.error('websocket',error)
|
||||
}
|
||||
}
|
||||
console.log(this.ws);
|
||||
}
|
||||
static receiveText(data,call){
|
||||
console.log('receive',data);
|
||||
MyEvent.emit('getMessage',data)
|
||||
}
|
||||
sendMessage(data) {
|
||||
console.log(this);
|
||||
@@ -43,4 +59,5 @@ class MyWs {
|
||||
}
|
||||
}
|
||||
}
|
||||
export default new MyWs();
|
||||
|
||||
export default new MyWs()
|
||||
Reference in New Issue
Block a user