Created
May 20, 2012 15:11
-
-
Save keithmgould/2758466 to your computer and use it in GitHub Desktop.
require.JS module for socket.IO
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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