Created
May 25, 2016 04:59
-
-
Save blackavec/d43fde7c4a63b93e9fe797acef0e835d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var socketsRepo = require(your db handler repository class)(); | |
base.io.on('connection', function (socket) { | |
var region = socket.handshake.query.region || null; | |
// the codes when connection just connected | |
socketsRepo.insertSocket(socket.session.user._id, socket.id, region).then(function () { | |
socket.on('disconnect', function () { | |
socketsRepo.deleteSocket(socket.id).then(function () { | |
// your code after it deleted the socket | |
}, function (err) { | |
console.error(err); | |
}); | |
}); | |
}, function (err) { | |
console.error(err); | |
socket.disconnect(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how do I get
socketsRepo
?