-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RFC] egg-socket.io #269
Comments
基于 |
嗯, websocket / socket.io 算是比较重要的一个 showcase 的插件. |
主要是集群的不好做 |
得 |
依赖 socket.io ,基于标准的 redis 来做 cluster server。跟 cluster-client 没有半毛关系的。 |
@fengmk2 现在的 cluster 逻辑会导致 websocket 握手失败 |
没明白为啥要用 cluster-client 实现? |
当我没说 cluster-client ~ 反正就是需要一个完善的 websocket 插件~ |
@denghongcai 所以要基于 redis 来维持 websocket 的 session,走 socket.io 标准的模式。 |
目前最快的是 https://github.com/uWebSockets/uWebSockets 但是最通用和最易用的是 socket.io https://www.npmjs.com/package/socket.io |
https://www.npmjs.com/package/socket.io-redis
|
@fengmk2 socket.io可以直接使用uWebsockets |
websocket和socket.io都是非常重要的一个模块,使用的人太多了,所以egg得在这个上面封装一套支持集群模式的方案。 |
@atian25 会有 socket.io 吗? |
@arden 这个库有可能内部实现用 socket.io 吧, 看具体写的时候. @gxcsoccer @ngot 你们谁上? |
我来搞 |
@ngot 👍 ,可以在正文 issue 写一下方案 |
@fengmk2 @ngot @atian25 另外据说socket.io 2.0默认用uWebsockets做为ws引擎。 |
我觉得如果基于socket.io做的话,就叫 egg-socket.io 吧,egg-websocket 要做的话,就只对uWebSockets封装 |
要不要把某领域的解决方案放这里 #287 |
@ngot 改名了 |
npm 也占个 0.0.1吧
发自我的 iPhone
… 在 2017年2月10日,19:29,Hengfei Zhuang ***@***.***> 写道:
https://github.com/eggjs/egg-socket.io 先占坑
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
先不用考虑这么多,实践中摸索吧,egg-socketio 也只是我们提供的一个插件和一个扩展的解决方案,先不侵入到 egg 的核心中。 |
@ngot |
@arden 上面说了,如果混部,那根本不需要考虑 egg 集成的事情了。 |
Directory Structure
router.jsmodule.exports = app => {
app.get('/', 'home'); // http router
app.io.on('connection', socket => {
socket.on('chat', app.io.controller.chat);
});
}; config.jsexports.io = {
cmiddleware: [ 'auth' ], // connection middleware
pmiddleware: [ 'filter' ], // packet middleware
}; app/io/middleware/auth.jsmodule.exports = app => {
return (socket, next) => {
console.log('auth middleware!');
next();
};
}; app/io/middleware/filter.jsmodule.exports = app => {
return (packet, next) => {
console.log('filter middleware!');
next();
};
}; app/io/controller/chat.jsmodule.exports = app => {
return msg => {
console.log('chat :', msg + process.pid);
setTimeout(function () {
socket.emit('res', 'Hello World !');
}, 500);
}
}; 最终就这样吧 |
|
@atian25 fixed |
exports.io = {
middleware: {
connection: [ 'auth' ], // connection middleware
packet: [ 'filter' ], // packet middleware
}
}; 这样怎么样? 另外, 这里会不会存在数组配置合并的问题? |
这个只有应用会配,问题不大的 |
|
|
@ngot 把两者方案选型的考虑, 以及最终方案, 更新到顶楼吧. |
嗯。我还在继续看,上下文,session那块,等完整了,更新到正文。 |
@ngot 先更新一版吧,需要补全的地方,注明下。 等会我要发 egg-feed 了 |
我觉得可以参考下sailsjs。那上面的websocket,我看着炒鸡爽 |
@luicfer 提炼下写下提案? |
我还在国外考驾照…下周发个版 |
@ngot 提案也更新到顶楼吧 |
@atian25 done |
发了 + [email protected] 了。求试用建议@_@ |
有没有写 |
已经发布 1.0.0 |
Directory Structure
Configuration
Middleware
middleware are functions which every connection or packet will be processed by.
Connection Middleware
app/io/middleware/auth.js
config/config.default.js
pay attention to the namespace, the config will only work for a specific namespace.
Packet Middleware
app/io/middleware/filter.js
config/config.default.js
pay attention to the namespace, the config will only work for a specific namespace.
Controller
controller is designed to handle the
emit
event from the client.example:
app/io/controller/chat.js
next, config the router at
app/router.js
The text was updated successfully, but these errors were encountered: