Skip to content
This repository has been archived by the owner on Apr 30, 2019. It is now read-only.

Proper way to use socket.io with aero? #82

Closed
johnpittman opened this issue Mar 21, 2016 · 4 comments
Closed

Proper way to use socket.io with aero? #82

johnpittman opened this issue Mar 21, 2016 · 4 comments
Labels

Comments

@johnpittman
Copy link

How do I get the instance of the http server to init socket.io?
I guessed this:

const server = app.run();

const io = require('socket.io')(server);

io.on('connection', (socket) => {
console.log('a user connected');

socket.on('disconnect', () => {
console.log('user disconnected');
});
});

@johnpittman johnpittman changed the title How to use socket.io with aero? Proper way to use socket.io with aero? Mar 21, 2016
@akyoto
Copy link
Collaborator

akyoto commented Mar 22, 2016

I don't know socket.io but this is how you can access it: app.server.http

app.server gives you the Aero Server instance and app.server.http gives you the http or node-spdy server object.

app.run() returns app.ready which is a promise that gets fulfilled when the server loaded all pages and started the server.

So I recommend doing it like this:

app.run().then(() => {
    console.log(app.server.http)
})

@akyoto
Copy link
Collaborator

akyoto commented Mar 22, 2016

Oh, I just realized that I didn't upload these changes yet.
The currently released module (1.4.1) requires app.server.httpServer, not app.server.http.
Sorry for the misleading information.

@akyoto
Copy link
Collaborator

akyoto commented Mar 23, 2016

As of 1.4.2 which was released today the correct way to access the server object is app.server.http and has also been included in the documentation now.

@johnpittman
Copy link
Author

You are awesome. Thanks!

@akyoto akyoto closed this as completed Mar 23, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants