Files
ClassContent/项目合集/聊天室/app版本/代码/fontend/socket/socket.js
2024-09-27 02:06:13 +08:00

34 lines
612 B
JavaScript

import io from '@hyoga/uni-socket.io';
class socket {
constructor() {
this.socket = null;
this.init();
}
init () {
this.socket = io('http://192.168.31.101:3000', {
query: {},
transports: [ 'websocket', 'polling' ],
timeout: 5000,
});
this.onEvent();
}
onEvent() {
this.socket.on("connect", () => {
console.log("链接建立成功...")
uni.showToast({
icon: "none",
title: "debug 成功链接服务器...",
duration: 1000,
});
});
this.socket.on("error", (msg) => {
console.log('链接错误:', msg);
})
}
}
export default new socket();