Last active
December 14, 2015 10:39
-
-
Save danfinlay/5073527 to your computer and use it in GitHub Desktop.
A question regarding 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
//I need to be handling an occasional data influx whether or not a client is connected, | |
//but if one is connected, I'd like them to be notified of it. | |
//The problem is I don't know how to do that with socket.io | |
//A simple example of how I wish I could write it would be: | |
// | |
occasionallyGetData(function(dataGot){ | |
socket.emit('newData', dataGot) | |
regularlyHandle(dataGot) | |
}) | |
io.sockets.on('connection', function (socket) { | |
}); | |
//Could I assign the socket to a global object? I suspect that would only support one connection: | |
var globalSocket | |
occasionallyGetData(function(dataGot){ | |
if(globalSocket) | |
globalSocket('newData', dataGot) | |
regularlyHandle(dataGot) | |
}) | |
io.sockets.on('connection', function (socket) { | |
globalSocket = socket | |
}); | |
//What's a way? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I updated the example to clarify my situation.