koajs / koa.io Goto Github PK
View Code? Open in Web Editor NEW[MAINTAINERS WANTED] Realtime web framework combine koa and socket.io.
[MAINTAINERS WANTED] Realtime web framework combine koa and socket.io.
Here is my code.
const koa = require('koa.io')
const app = koa()
// if I use the original 'koa', it's ok
// const app = require('koa')()
const Router = require('koa-router')
const router = new Router()
router.get('/test', function * () {
console.log(this.query); // output {}
console.log(this.request.query); // output {}
})
app.use(router.routes())
Thanks.
This should be easy, but when calling app.listen
app.createServer
(an io can only be attached to one server), it would be nice if the returned server was also available (later on) as app.server
(app.io
already is). It would also be nice (as a convenience), to have app.address
be an alias for server.address
Todo list:
app.listen
app.createServer
sets app.server
app.listen
app.createServer
sets 'app.address`Could you please check on the demo dependencies
1st koa-generic-session
npm ERR! Windows_NT 6.1.7601
npm ERR! argv "D:\SW\iojs\node.exe" "D:\SW\iojs\node_modules\npm\bin\npm-cli.js" "i"
npm ERR! node v2.0.0
npm ERR! npm v2.9.0
npm ERR! code ETARGET
npm ERR! notarget No compatible version found: koa-generic-session@'>=3.0.0 <4.0.0'
npm ERR! notarget Valid install targets:
npm ERR! notarget ["1.0.0","1.1.0","1.1.2","1.1.3","1.2.0","1.2.1","1.2.2","1.2.3","1.3.0","1.4.0","
1.5.0","1.6.0","1.7.0","1.8.0"]
npm ERR! notarget
npm ERR! notarget This is most likely not a problem with npm itself.
npm ERR! notarget In most cases you or one of your dependencies are requesting
npm ERR! notarget a package version that doesn't exist.
npm ERR! notarget
npm ERR! notarget It was specified as a dependency of 'socket.io-chat'
npm ERR! notarget
npm ERR! Please include the following file with any support request:
npm ERR! D:\Users\SlobodanB\ws\koa.io\example\chat\npm-debug.log
When I changed it to 1.8.0
D:\Users\SlobodanB\ws\koa.io\example\chat\node_modules\koa.io\node_modules\socket.io\node_modules\so
cket.io-client\node_modules\engine.io-client\node_modules\ws>if not defined npm_config_node_gyp (nod
e "D:\SW\iojs\node_modules\npm\bin\node-gyp-bin....\node_modules\node-gyp\bin\node-gyp.js" rebuil
d ) else (rebuild)
npm ERR! Windows_NT 6.1.7601
npm ERR! argv "D:\SW\iojs\node.exe" "D:\SW\iojs\node_modules\npm\bin\npm-cli.js" "i"
npm ERR! node v2.0.0
npm ERR! npm v2.9.0
npm ERR! file C:\Users\slobodanb\AppData\Roaming\npm-cache\debug\2.2.0\package\package.json
npm ERR! code EJSONPARSE
npm ERR! Failed to parse json
npm ERR! Unexpected token '\u0000' at 1:1
npm ERR!
npm ERR! ^
npm ERR! File: C:\Users\slobodanb\AppData\Roaming\npm-cache\debug\2.2.0\package\package.json
npm ERR! Failed to parse package.json data.
npm ERR! package.json must be actual JSON, not just JavaScript.
npm ERR!
npm ERR! This is not a bug in npm.
npm ERR! Tell the package author to fix their package.json file. JSON.parse
npm ERR! Please include the following file with any support request:
npm ERR! D:\Users\SlobodanB\ws\koa.io\example\chat\npm-debug.log
It look like only HTTP is supported no HTTPS server or am I from another planet?
Edit: BTW Like what you have here!
Hello Everybody,
I'm happy to announce that I'm working towards the next release of Koa.io. Since this is the first thing I've maintained that has a community built around it, I'd like to get you guys' feedback for this release. This release is also a big step towards 1.0.
Goals for this release:
server
when calling app.listen
. Having access to the address directly would be nice too. (#33)If anyone else has something that they'd like to add to this list, I'm open to suggestions. However, other than things on this list, I'm putting a feature-freeze on 0.1.0
(forgive my poor english.)
I know how to route io.
ex: app.io.route(path, gen);
I want to make a routing like this:
app.io.use(function* (next) {
// connection
yield* mwNext(next);
// disconnection
});
and mwNext yield following 'beforeRouteGen' -> 'next' -> 'afterRouteGen'.
anyone know how to do that?
Hello Koa-Team :-)
I like your Idea of creating a new and better reboot of Express.
But I am a little bit confused about the dependency about Express 3.4.8 in the chat example ;-)
You mean "koa": ">= 0.0.3" maybe ?
Router.prototype.middleware = function () {
var self = this;
var gen = compose(this.fns);
return function* router(next) {
debug('in router middleware');
if (!self.fns.length) {
debug('router not exist');
return yield* next;
}
var context = this;
var socket = this.socket;
// replace socket.onevent to start the router
socket._onevent = socket.onevent;
socket.onevent = function (packet) {
var args = packet.data || [];
if (!args.length) {
debug('event args not exist');
return socket._onevent(packet);
}
// <------ inserted
if (null != packet.id) {
debug('attaching ack callback to event');
args.push(this.ack(packet.id));
}
// <------- end
context.event = args[0];
context.data = args.slice(1);
co.wrap(gen).call(context, function (err) {
if (err) console.error(err.stack);
//TODO: error
socket._onevent(packet);
});
};
yield* next;
};
};
it seems koa.io was updated 2 years ago, will it be updated recently to fix some repo with new versions?
I don't see in the example how 'add user' is invoked? I was expecting a line of code to state: this.broadcast.emit('add user'...
I just noticed koa.io today, pretty slick!
I think I will do a screencast on this soon.
I was looking for a way to do a callback in response to an event.
With normal socket.io it would be done like below 'cb'
socket.on('someEvent', function (data, cb) {
// do something with data...
cb(null, 'client done processing data...');
});
I looked through the code and it doesn't seem to be possible, unless I'm missing something.
It would be pretty cool to be able to do something like
app.io.route('someEvent', function *(next, data){
// do something with data...
this.body = 'client done processing data...';
});
and have the message 'client done processing data...' get sent back as the callback to the clientside emitter.
Your thoughts?
Thanks!
When the client hits an endpoint, trying to do something like so
var router = require('koa-router')();
router.get('/test', function *(next) {
//this.brodcast?
this.body = dostuff();
})
Is this possible? Want to send messages to clients when endpoints are hit.
Its hard to catch issues if the socket routes not throwing errors, one way to handle it, its to put a try catch in each route, but I find it quite annoying to put it every time when in development.
Hi :-)
I am unsure about to ask the right one, so I do it here.
I try to port reveal.js from Express to Koa and was successful doing this in general. The only problem is, the render engine ejs what doesn't notice things needed for doing the expected scale of 1.0
Because both Koa-Wrappers (co-ejs and koa-ejs) do this wrong, I also think it is possible the problem is in an other level of the application.
reveal.js is using headjs - I could exclude the problem causes from there by removing it.
Also using iojs or nodejs doesn't make things different.
Using browser debug console it seams like the scale=0.2 though there is
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
Also the relative position and width/left -50% .. isn't right. It seams the screen is used as larger then the browser window.
var koa = require('koa.io');
var path = require('path');
var fs = require('fs');
var staticCache = require('koa-static-cache');
var app = koa();
var route = require('koa-route');
var port = process.env.PORT || 8000;
var render = require('koa-ejs');
render(app, {
root: path.join(__dirname, 'presentations'),
layout: 'layout',
viewExt: 'ejs',
cache: false,
debug: true,
});
app.use(staticCache(path.join(__dirname, 'public')));
function *pptone(next) {
yield this.render('pptone', {title:'PPT Test'});
yield next;
};
app.use(route.get('/pptone', pptone));
app.listen(port, function(){
console.log('Server listenign at port %d', port);
});
// ... further the socket server follows ...
Hope for any help and ideas - maybe someone has seen this before in different kind. :-)
(forgive my english)
npm version 0.0.3:
/lib/application.js
line 83 forEach callback has no argument.
github version
/lib/application.js
line 75 same forEach callback problem.
I edit to this, worked.
namespace.forEach(function eachNamespaceUseMiddleware(ns) {
self.io.of(ns).use(session);
});
I haven't looked into this package too much as of yet, but because the koa-generic-session version in the example project is broken, it compelled me to go look into where it was used. And after looking it up in the application.js file, I still don't understand why it's even needed (the unfinished comment doesn't help either), so any insight would be appreciated, as I didn't find any references in the other files as well.
I'll probably answer this next question myself, after I start going over the library a bit more in-depth, but is there any way/plans for 'koa.io' and 'koa' to be decoupled and do something similar to the 'koa-router', extending the koa app object when passed in?
It was last updated in May, so I thought I'd ask.
If it's not, would you be interested in having someone take it over?
It will be cool to support multiple middlewares on the same route just like koa-router
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.