flarestart / egg-websocket-plugin Goto Github PK
View Code? Open in Web Editor NEWA standard WebSocket plugin for egg.js
License: MIT License
A standard WebSocket plugin for egg.js
License: MIT License
eeg官方的socket.io不能用原生来直接链接,正想自己搞就发现了这个,谢谢作者的分享
正式环境下没办法连接websocket啊.
// app/router.js
app.ws.route('/ws', wsBuild, controller.law.xxx)
// app/controller/law.js
async xxx() {
const { ctx, app } = this;
if (!ctx.websocket) {
throw new Error('this function can only be use in websocket router');
}
console.log('client connected');
ctx.websocket
.on('message', (msg) => {
console.log('receive', msg);
})
.on('close', (code, reason) => {
console.log('websocket closed', code, reason);
});
}
// app/middleware/wsBuild.js
'use strict';
module.exports = () => {
return async function wsBuild(ctx, next) {
console.log('xxxx')
await next();
};
};
PS: config.default.js未做任何配置
"egg": "^2.15.1",
"egg-websocket-plugin": "^1.0.1",
是不是没有办法去主动的踢掉当前已经存在连接的客户
您好,我一直使用你这个插件,但eggs升级,安装的时候出现错误,请问可以解决吗?:
While resolving: [email protected]
Found: [email protected]
node_modules/egg
egg@"^3" from the root project
Could not resolve dependency:
peer egg@"^2.26.0" from [email protected]
node_modules/egg-websocket-plugin
egg-websocket-plugin@"*" from the root project
Fix the upstream dependency conflict, or retry
this command with --force or --legacy-peer-deps
to accept an incorrect (and potentially broken) dependency resolution.
作者您好,现在,我一直使用您这个插件,方法也写差不多了,上次我给你反馈安装出现错误后,你对插件进行了升级。但是,我并没有忙于升级,而是用你未升级的版本测试一下,能不能用,经过我的测试,发现是可以用的,我也写了很多方法,socket连接,接收消息,都是没有问题的,
但是,今天,我需要安装一个二维码的库,我安装的时候出现错误提示,提示不能安装,但我看到反馈的错误信息,竟然是和你的这个插件有关,反馈如下:
`npm install qr-image
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/egg
npm ERR! peer egg@"^3.12.0" from [email protected]
npm ERR! node_modules/egg-mock
npm ERR! peerOptional egg-mock@">=5.8.3" from [email protected]
npm ERR! node_modules/egg-bin
npm ERR! dev egg-bin@"^5" from the root project
npm ERR! dev egg-mock@"^5" from the root project
npm ERR! egg@"^3" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer egg@"^2.26.0" from [email protected]
npm ERR! node_modules/egg-websocket-plugin
npm ERR! egg-websocket-plugin@"^1.0.1" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: [email protected]
npm ERR! node_modules/egg
npm ERR! peer egg@"^2.26.0" from [email protected]
npm ERR! node_modules/egg-websocket-plugin
npm ERR! egg-websocket-plugin@"^1.0.1" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR!
npm ERR! For a full report see:
npm ERR! C:\Users\Administrator\AppData\Local\npm-cache_logs\2023-05-08T02_55_59_318Z-eresolve-report.txt
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Administrator\AppData\Local\npm-cache_logs\2023-05-08T02_55_59_318Z-debug-0.log`
我想再重新安装一下你更新后的插件,也是类似的提示,安装不上,是不是需要把你的老版本卸载后再进行安装?如果那样的话,会不会影响到我已经写好的控制器方法?所以想先向您咨询一下后再下手
`H:\NodeJSProjects\仿微信\egg-wechat> npm i egg-websocket-plugin --save
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/egg
npm ERR! egg@"^3" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer egg@"^2.26.0" from [email protected]
npm ERR! node_modules/egg-websocket-plugin
npm ERR! egg-websocket-plugin@"^1.0.1" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR!
npm ERR! For a full report see:
npm ERR! C:\Users\Administrator\AppData\Local\npm-cache_logs\2023-05-08T05_13_10_073Z-eresolve-report.txt
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Administrator\AppData\Local\npm-cache_logs\2023-05-08T05_13_10_073Z-debug-0.log
PS H:\NodeJSProjects\仿微信\egg-wechat> npm i egg-websocket-plugin
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/egg
npm ERR! egg@"^3" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer egg@"^2.26.0" from [email protected]
npm ERR! node_modules/egg-websocket-plugin
npm ERR! egg-websocket-plugin@"^1.0.1" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR!
npm ERR! For a full report see:
npm ERR! C:\Users\Administrator\AppData\Local\npm-cache_logs\2023-05-08T05_14_47_724Z-eresolve-report.txt
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Administrator\AppData\Local\npm-cache_logs\2023-05-08T05_14_47_724Z-debug-0.log`
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.