Reputation: 27
I have made a chat app using socket.io and node.
Issue- But problem is that if I am emiting some event from inside of "disconnect" handler back to client and there on client side inside handler for this event localStorage.setItem('msgText', msg)
. Its not saving to local storage.(As on disconnect event client has already been disconnected)
Used node-localstorage
module to set data in local storage of browser, while painting view when user logs-in , but its not saving data to localStorage of browser
const LocalStorage = require('node-localstorage').LocalStorage
let localStorage = new LocalStorage('./scratch')
localStorage.setItem('name_test', 'tom')
console.log(localStorage.getItem('name_test'))
Any suggestion , as how to tackle the scenario / issue is most appreciated on this ?
Upvotes: 1
Views: 3949
Reputation: 644
When you fire the disconnect
event, you could set your local storage just before. If I am understanding correctly I believe the below example should work for you
function disconnectUserFromChat() {
return new Promise(function(resolve, reject) {
try {
localStorage.setItem('key', 'Value')
resolve()
} catch(error) {
reject(error)
}
})
})
disconnectUserFromChat()
.then(function() {
socket.on('disconnect', function() {
console.log('Disconnected')
})
})
Upvotes: 1