Commit 1e0ce030 authored by wuhao's avatar wuhao 🎯

asd

parent 856759c8
/* eslint-disable eqeqeq */
/* eslint-disable array-callback-return */
'use strict'; 'use strict';
const { Controller } = require('egg'); const { Controller } = require('egg');
...@@ -12,8 +14,8 @@ class HomeController extends Controller { ...@@ -12,8 +14,8 @@ class HomeController extends Controller {
const { ctx, app } = this; const { ctx, app } = this;
console.log(ctx.request.body, '111111'); console.log(ctx.request.body, '111111');
const { id, msg } = ctx.request.body; const { id, msg, mutiplemsg } = ctx.request.body;
if (!id) { if (!id && !mutiplemsg) {
ctx.body = { ctx.body = {
code: 0, code: 0,
success: true, success: true,
...@@ -25,13 +27,25 @@ class HomeController extends Controller { ...@@ -25,13 +27,25 @@ class HomeController extends Controller {
const clients = app.io.sockets.sockets; const clients = app.io.sockets.sockets;
// query中的id为 用户id io可以直接emit // query中的id为 用户id io可以直接emit
Object.values(clients)?.map(io => { Object.values(clients)?.map(io => {
const index = id.indexOf(io?.handshake?.query?.id); const key = io?.handshake?.query?.id;
if (Array.isArray(id) && index !== -1) { if (mutiplemsg) {
io.emit('message', msg); mutiplemsg?.map(it => {
} else if (io?.handshake?.query?.id === id) { console.log('====================================');
io.emit('message', msg); 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 = { 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