Skip to content

Instantly share code, notes, and snippets.

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('')({ host: '', port: 8081 });
connection.emit('refresh', clientId, data);
return {statusCode: OK}
// Websockets
export function setup(server) {
port: 8081,
labels: ['history']
var io = require('')('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; = "UserHistory";
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.