Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
//This method is supposed to tell the sockets server
//to post an refresh event with data to a selected client id
export function* postRefreshEvent(clientId, data) {
var connection = require('socket.io-emitter')({ host: '127.0.0.1', port: 8081 });
connection.emit('refresh', clientId, data);
return {statusCode: OK}
}
// Websockets
export function setup(server) {
server.connection({
port: 8081,
labels: ['history']
})
var io = require('socket.io')(server.select('history').listener)
var users = [];
io.on('connection', function (socket) {
var addedUser = false;
socket.on('add user', function (userId, room) {
console.log("Add user", userId)
socket.userId = userId;
socket.room = "UserHistory";
socket.join(room)
users[userId] = userId;
addedUser = true;
console.log("Added", users)
});
socket.on('refresh', function (clientId, data) {
console.log('Refresh', clientId)
console.log('Refresh', data)
})
socket.on('disconnect', function () {
// remove the username from global usernames list
if (addedUser) {
delete users[socket.userId];
}
console.log("Removed", users)
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.