我对JavaScript和Socket.io还是很陌生,我正在尝试为管理员和普通用户创建一个空间。
唯一要抓住的是我希望普通用户聊天输出到管理员聊天。
我该如何做这样的事情?我已经阅读了入门部分,但仍然有点迷茫。
答案 0 :(得分:0)
我将解释用户流,这可能有助于解决您的问题。
Uncaught Error: ENOENT, renderer/specs/swagger-1.13.json.gz not found in <<path>>/node_modules/electron/dist/Electron.app/Contents/Resources/electron.asar
at createError (electron/js2c/asar.js:126)
at Object.fs.readFileSync (electron/js2c/asar.js:603)
at new Client (swagger-client.js?6d40:214)
at eval (AppData.vue?749b:20)
at Module../node_modules/vuetify-loader/lib/loader.js!./node_modules/cache-loader/dist/cjs.js?!./node_modules/vue-loader/lib/index.js?!./src/components/AppData.vue?vue&type=script&lang=js& (app.js:7924)
at __webpack_require__ (app.js:727)
at fn (app.js:101)
at eval (AppData.vue?a6b9:1)
at Module../src/components/AppData.vue?vue&type=script&lang=js& (app.js:12875)
at __webpack_require__ (app.js:727)
用户登录时,您想通过相同的(管理员)握手将套接字连接到服务器
let adminSockets = []; // Here I'm considering multiple admin
let userSocketMap = {};
当用户彼此发送消息时(用户1向用户2发送消息)
io.of('/').on('connect', socket => {
let { isAdmin, userId } = socket.handshake.headers
if(isAdmin) {
adminSockets.push(socket)
} else {
userSocketMap[userId] = socket;
}
});