Skip to content
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

Adds a next branch that makes koa-websocket work with koa-router 7.x #18

Merged
merged 5 commits into from
Oct 1, 2016

Conversation

cymen
Copy link
Contributor

@cymen cymen commented Oct 1, 2016

This PR resolves issue #14. The root cause of the incompatibility appears to be koa-router 7.x using a newer version of koa-compose that doesn't function the same. I upgraded koa-compose and changed how the result of the composition was called -- it looks like explicit context passing instead of binding the context is the newer approach?

Because I couldn't seem to maintain koa 1.x compatibility, I guessed this should be a next kind of thing for koa-websocket.

@cymen cymen closed this Oct 1, 2016
@cymen cymen reopened this Oct 1, 2016
@cymen
Copy link
Contributor Author

cymen commented Oct 1, 2016

Hrm... I couldn't figure out how to open this PR to next on your repo. Maybe the branch has to exist? If so and you want this PR as next, can you branch off your master and push it up as next and I can change the target of this PR to it?

@kudos
Copy link
Owner

kudos commented Oct 1, 2016

Thanks! I'll push a pre-release 3.0.0 bump to npm for this shortly.

@cymen
Copy link
Contributor Author

cymen commented Oct 1, 2016

@kudos Thanks!

@ralyodio
Copy link

ralyodio commented Oct 2, 2016

awesome! been waiting for this for a couple of months.

@ralyodio
Copy link

I still only see 2.1.1 on npm. Did you ever push this pre-release to npm?

@kudos
Copy link
Owner

kudos commented Dec 24, 2016

@chovy it's tagged next not latest on NPM. If you npm install koa-websocket@next you'll get 3.0.1 instead. When Koa moves 2.0 from next to latest I'll move koa-websocket too.

@ralyodio
Copy link

ralyodio commented Dec 27, 2016

Gotcha. Thanks. I figured npm page would have shown an @next if it were available somewhere.

I think koa is waiting for async/await to not need a flag before it becomes stable. Probably April from what I hear.

@AaronHarris
Copy link

As of Node 7.6, a flag is not needed for async/await, and Koa now ships v2 as the @latest when installing.

@jiacai2050
Copy link

  "dependencies": {
    "koa": "^2.2.0",
    "koa-ejs": "^4.0.0",
    "koa-router": "^7.2.0",
    "koa-static": "^3.0.0",
    "koa-websocket": "^4.0.0"
  }

With above dependencies, websocket router is still not working.

router.get('/ws', async (ctx) => {
  console.log(ctx)
  ctx.websocket.send('Hello World');
  ctx.websocket.on('message', function (message) {
    // do something with the message from client
    console.log(message);
    ctx.websocket.send(message);
  });
});

@lennerd
Copy link

lennerd commented Jun 20, 2017

Same for me.

@jiacai2050
Copy link

const ws = require('koa-router')();
const websockify = require('koa-websocket');
const Koa = require('koa');

let app = new Koa()
let sock = websockify(app);

ws.get('/ping', async (ctx) => {
    ctx.websocket.on('message', (message) => {
        console.log(message);
        ctx.websocket.send(message);
    });
});
app.ws.use(ws.routes()).use(ws.allowedMethods());
app.listen(3000);

@lennerd Above snippets work for me.

@lennerd
Copy link

lennerd commented Jun 20, 2017

Yes, I was able to get it working, too. Had problems with koa-session, but this is solved now. Thanks for the snippet!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants