Skip to content

Instantly share code, notes, and snippets.

@gerzhan
Forked from pauldenotter/plugin.js
Created August 14, 2016 04:08
Show Gist options
  • Save gerzhan/13c01e5cc3bca4acfda6a78b35773382 to your computer and use it in GitHub Desktop.
Save gerzhan/13c01e5cc3bca4acfda6a78b35773382 to your computer and use it in GitHub Desktop.
Binding socket.io to a hapi.js plugin in node.js
var socketIO = require('socket.io'),
io;
// hapi plugin registration
exports.register = function(plugin, options, next) {
// this is the hapi specific binding
io = socketIO.listen(plugin.servers[0].listener);
io.sockets.on('connection', function(socket) {
socket.emit({msg: 'welcome'});
});
next();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment