Commit 1e0ce030 authored by wuhao's avatar wuhao 🎯

asd

parent 856759c8
/* eslint-disable eqeqeq */
/* eslint-disable array-callback-return */
'use strict';
const { Controller } = require('egg');
......@@ -12,8 +14,8 @@ class HomeController extends Controller {
const { ctx, app } = this;
console.log(ctx.request.body, '111111');
const { id, msg } = ctx.request.body;
if (!id) {
const { id, msg, mutiplemsg } = ctx.request.body;
if (!id && !mutiplemsg) {
ctx.body = {
code: 0,
success: true,
......@@ -25,13 +27,25 @@ class HomeController extends Controller {
const clients = app.io.sockets.sockets;
// query中的id为 用户id io可以直接emit
Object.values(clients)?.map(io => {
const index = id.indexOf(io?.handshake?.query?.id);
if (Array.isArray(id) && index !== -1) {
io.emit('message', msg);
} else if (io?.handshake?.query?.id === id) {
io.emit('message', msg);
const key = io?.handshake?.query?.id;
if (mutiplemsg) {
mutiplemsg?.map(it => {
console.log('====================================');
console.log(it);
console.log('====================================');
if (it?.id == key) {
io.emit('message', it?.msg);
}
});
} else {
const index = id.indexOf(key);
if (Array.isArray(id) && index !== -1) {
io.emit('message', msg);
} else if (key === id) {
io.emit('message', msg);
}
return io;
}
return io;
});
ctx.body = {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment