fix: Retry to join chat room till server starts
This commit is contained in:
parent
e26064436b
commit
5c8effe7a1
1 changed files with 19 additions and 14 deletions
33
socketio.js
33
socketio.js
|
|
@ -72,22 +72,27 @@ io.on('connection', function (socket) {
|
|||
});
|
||||
// end frappe.chat
|
||||
|
||||
request.get(get_url(socket, '/api/method/frappe.realtime.get_user_info'))
|
||||
.type('form')
|
||||
.query({
|
||||
sid: sid
|
||||
})
|
||||
.end(function (err, res) {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return;
|
||||
}
|
||||
if (res.status == 200) {
|
||||
var room = get_user_room(socket, res.body.message.user);
|
||||
let join_chat_room = () => {
|
||||
request.get(get_url(socket, '/api/method/frappe.realtime.get_user_info'))
|
||||
.type('form')
|
||||
.query({
|
||||
sid: sid
|
||||
})
|
||||
.then(res => {
|
||||
const room = get_user_room(socket, res.body.message.user);
|
||||
socket.join(room);
|
||||
socket.join(get_site_room(socket));
|
||||
}
|
||||
});
|
||||
})
|
||||
.catch(e => {
|
||||
if (e.code === 'ECONNREFUSED') {
|
||||
// retry after 1s
|
||||
return setTimeout(join_chat_room, 1000);
|
||||
}
|
||||
log(e.code);
|
||||
});
|
||||
};
|
||||
|
||||
join_chat_room();
|
||||
|
||||
socket.on('disconnect', function () {
|
||||
delete socket.files;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue