first commit
This commit is contained in:
38
code/SmallCart/SmallCartMain/data/js/WebSocket.js
Normal file
38
code/SmallCart/SmallCartMain/data/js/WebSocket.js
Normal file
@@ -0,0 +1,38 @@
|
||||
class WS {
|
||||
constructor() {
|
||||
this.ws = null;
|
||||
this.connect();
|
||||
this.onopen();
|
||||
this.onclose();
|
||||
this.onerror();
|
||||
}
|
||||
|
||||
connect() {
|
||||
this.ws = new WebSocket("ws://192.168.4.1:81");
|
||||
console.log("this.ws: ", this.ws);
|
||||
}
|
||||
|
||||
onopen() {
|
||||
this.ws.onopen = () => {
|
||||
console.log("WebSocket open");
|
||||
}
|
||||
}
|
||||
|
||||
onmessage(callback) {
|
||||
this.ws.onmessage = (e) => {
|
||||
callback(e.data)
|
||||
}
|
||||
}
|
||||
|
||||
onclose() {
|
||||
this.ws.onclose = (e) => {
|
||||
console.log("close");
|
||||
}
|
||||
}
|
||||
|
||||
onerror() {
|
||||
this.ws.onerror = (e) => {
|
||||
console.log("onerror");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user