This commit is contained in:
X1627315083
2024-08-13 09:36:13 +08:00
parent 1f5ddc604a
commit a0c3b06b80
23 changed files with 23125 additions and 22325 deletions

46
src/tool/webSocket.js Normal file
View File

@@ -0,0 +1,46 @@
class MyWs {
constructor() {
this.ws = null;
// this.ws = new WebSocket();
}
linkWs(url) {
if (this.ws && this.ws.readyState == 1) return
this.ws = new WebSocket(url)
}
sendMessage(data) {
console.log(this);
if (this.ws && this.ws.readyState == 1) {
let obj = {
cmd: 1,
data: {
name: '123',
}
}
this.send(obj)
obj = {
cmd: 4,
data: {
msg: data,
}
}
this.send(obj)
// obj = {
// cmd: 6,
// data: {
// msg: data,
// }
// }
// this.send(obj,this.ws)
}
}
send(obj) {
console.log(2323);
this.ws.send(JSON.stringify(obj))
}
close(){
if (this.ws && this.ws.readyState == 1) {
this.ws.close()
}
}
}
export default new MyWs();