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

egg-socket.io无法handle route #1789

Closed
microud opened this Issue Dec 6, 2017 · 4 comments

Comments

Projects
None yet
4 participants
@microud

microud commented Dec 6, 2017

  • Node Version: 8.7.0
  • Egg Version: 2.0.0
  • Plugin Name: egg-socket.io
  • Plugin Version:
  • Platform: macOS
  • Mini Showcase Repository:

使用egg-socket.io之后,middleware都可以正常工作,发送对应的消息,但是 app/io/router.js 中的“路由”并没有通过指定的controller进行处理。

调试了一下插件中的 io.js 发现:

if (nsp[RouterConfigSymbol]) {
        for (const [ event, handler ] of nsp[RouterConfigSymbol].entries()) {
          socket.on(event, (...args) => {
            const ctx = args.splice(-1)[0];
            ctx.args = ctx.req.args = args;
            handler.call(ctx)
              .then(() => ctx[CtxEventSymbol].emit('finshed'))
              .catch(e => {
                if (e instanceof Error) {
                  e.message = '[egg-socket.io] controller execute error: ' + e.message;
                } else /* istanbul ignore next */{
                  debug(e);
                }
                ctx[CtxEventSymbol].emit('finshed', e);
              });
          });
        }
      }

该段代码中的 nsp[RouterConfigSymbol] 一直为undefined,打印nsp得到

controller: { chat: [Object], test: [Object] },
controllers: [Getter],

测了一天多,傻了都。求帮忙,先谢过了。

@ngot

This comment has been minimized.

Show comment
Hide comment
@ngot

ngot Dec 7, 2017

Member

并没有这个文件(app/io/router.js)的约定只有 app/router.js

看文档:https://github.com/eggjs/egg-socket.io#directory-structure

Member

ngot commented Dec 7, 2017

并没有这个文件(app/io/router.js)的约定只有 app/router.js

看文档:https://github.com/eggjs/egg-socket.io#directory-structure

@zengwe

This comment has been minimized.

Show comment
Hide comment
@zengwe

zengwe Feb 25, 2018

我发现我的也写在里面结果还是不能执行对应的controller,controller: { chat: [Object], test: [Object] },这个打印结果也相同

zengwe commented Feb 25, 2018

我发现我的也写在里面结果还是不能执行对应的controller,controller: { chat: [Object], test: [Object] },这个打印结果也相同

@NiBoTe

This comment has been minimized.

Show comment
Hide comment
@NiBoTe

NiBoTe May 19, 2018

请问问题是怎么解决的呢?

NiBoTe commented May 19, 2018

请问问题是怎么解决的呢?

@microud

This comment has been minimized.

Show comment
Hide comment
@microud

microud May 25, 2018

@zengwe @NiBoTe 解决的方法就是上面ngot讲的——仔细看文档,这个issue关闭的原因也是没有跟着文档来。socket.io的路由是跟web路由写在一起的。有具体问题联系主页的邮箱吧。

microud commented May 25, 2018

@zengwe @NiBoTe 解决的方法就是上面ngot讲的——仔细看文档,这个issue关闭的原因也是没有跟着文档来。socket.io的路由是跟web路由写在一起的。有具体问题联系主页的邮箱吧。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment