feat: 重构signalr,在线人数允许不用登录
This commit is contained in:
22
Yi.Bbs.Vue3/src/hubs/mainHub.js
Normal file
22
Yi.Bbs.Vue3/src/hubs/mainHub.js
Normal file
@@ -0,0 +1,22 @@
|
||||
import signalR from "@/utils/signalR";
|
||||
import useSocketStore from "@/stores/socket.js";
|
||||
const receiveMsg=(connection)=> {
|
||||
connection.on("onlineNum", (data) => {
|
||||
const socketStore = useSocketStore();
|
||||
socketStore.setOnlineNum(data);
|
||||
});
|
||||
connection.on("forceOut", (msg) => {
|
||||
useUserStore()
|
||||
.logOut()
|
||||
.then(() => {
|
||||
alert(msg);
|
||||
location.href = "/index";
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export default ()=>{
|
||||
signalR.start(`main`,receiveMsg);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user