Skip to content

Instantly share code, notes, and snippets.

@DamonOehlman
Created October 4, 2011 06:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DamonOehlman/1261033 to your computer and use it in GitHub Desktop.
Save DamonOehlman/1261033 to your computer and use it in GitHub Desktop.
Bridging eve -> socket.io -> eve
var socket = io.connect(server),
reSock = /^sock\:.*$/i;
socket.on('connect', function() {
eve.on('*', function() {
// get the last argument
var lastArg = arguments.length ? arguments[arguments.length - 1] : null;
// if the last arg is a socket connection, then don't send it to the serve
// because we got it from the server...
if ((! lastArg) || (! reSock.test(lastArg))) {
socket.emit.apply(socket, ['event', eve.nt()].concat(Array.prototype.slice.call(arguments, 0)));
} // if
});
socket.on('event', function(evtName) {
eve.apply(eve, [evtName, DECKEM].concat(Array.prototype.slice.call(arguments, 1)));
});
});
io.sockets.on('connection', function(socket) {
socket.on('event', function() {
var emitArgs = ['event'].concat(Array.prototype.slice.call(arguments, 0)).concat('sock:' + socket.id);
// send the event to other connected listeners
// and add the client id to the end of the list so it can be distinguished on the client
socket.broadcast.emit.apply(socket, emitArgs);
});
});
@DamonOehlman
Copy link
Author

Code has been ripped from two projects I'm working on:

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