Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
SocketIo_Middleware
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wuhao
SocketIo_Middleware
Commits
1e0ce030
Commit
1e0ce030
authored
May 26, 2023
by
wuhao
🎯
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
asd
parent
856759c8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
8 deletions
+22
-8
home.js
app/controller/home.js
+22
-8
No files found.
app/controller/home.js
View file @
1e0ce030
/* 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
=
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment