Last active
September 12, 2019 14:08
-
-
Save kavinduchamiran/269589f49befce16b9ac34de622660b5 to your computer and use it in GitHub Desktop.
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
const server = http.createServer(app); | |
const io = socketIO(server, { | |
path: '/socket/' | |
}); | |
let sockets = {}; | |
let python_socket; | |
io.on('connection', socket => { | |
console.log('New client connected!'); | |
if(socket.handshake.headers.name === 'python'){ | |
python_socket = socket; | |
} | |
socket.on('userId', user => { | |
sockets[user.userId] = socket; | |
}) | |
if (python_socket) { | |
socket.on('newJob', job => { | |
let {id, link} = job; | |
python_socket.emit('new_job', {id, link}) | |
}); | |
python_socket.on('job_add_success', {userId} => { | |
let userSocket = sockets[userId]; | |
userSocket.emit('job_add_success'); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment