You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
940 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import useUserInfo from "~/composables/useUserInfo";
export default function useSocket(){
return new Promise(()=>{
const user = useUserInfo()
// 连接服务端
const socket = io('http://research.mcnetmart.com:2120');//这里请填写你的域名外网端口为socket端口
socket.on('connect', function () {
this.emit('login', user.$state.info.id);
});
// 后端推送来消息时
socket.on('translateDoc', async function (msg) {//这里的new_msg请一定要注意官方文档都写的是content但是后端发送的自定义是new_msg后端定义成new_msg前端却接受content的字段。所以是接受不了的
console.log("收到消息:" + msg);
// 调接口
resolve()
// await fetch('http://research.mcnetmart.com/api/translate/getUserTranslateDocInfo?id='+msg,{headers:{token: 'cd91b1e5-0ba0-4c47-ad17-48d6dfa63224'}})
});
})
}