Skip to content

Instantly share code, notes, and snippets.

@keithmgould
Created May 20, 2012 15:11
Show Gist options
  • Save keithmgould/2758466 to your computer and use it in GitHub Desktop.
Save keithmgould/2758466 to your computer and use it in GitHub Desktop.
require.JS module for socket.IO
define(["constants"], function (constants) {
var socket = io.connect(constants.socketURL),
sendables = ["new-message"];
return {
listen : function (callback) {
socket.on("new-message", function (msg) {
callback({ type : "receive-message", data : msg});
});
},
emit : function (msg) {
var sendable,
i = 0;
for( ; sendable = sendables[i++] ; ){
if (sendable === msg.type){
socket.emit(msg.type, msg.data );
}
}
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment