I have:-
I'm currently working with a flask chatting web app. Where i've used flask_socketio for making active connection and sending data between server and clients.
1.On the server side
I made two socket events connect and disconnect this way :-
@socketio.on('connect')
def join_user():
name = session['name']
uid = session['uid']
print(f"\nConnected:\nName: {name}\nUid: {uid}\n")
join_room(uid)
send(f"{name} joined the room")
@socketio.on("disconnect")
def lost_con():
name = session['name']
uid = session['uid']
print(f"\nDisconnected:\nName: {name}\nUid: {uid}\n")
leave_room(uid)
send(f"{name} left the room")
@socketio.on("notify")
def notification(msg):
print(msg)
Where:- name is the name of user and uid is the name for chatting room.
2.On the client side :-
<script src="https://cdn.socket.io/4.4.1/socket.io.min.js" integrity="sha384-fKnu0iswBIqkjxrhQCTZ7qlLHOFEgNkRmK2vaO/LbTZSXdJfAu6ewRBdwHPhBo/H" crossorigin="anonymous"></script>
<script>
var socket = io.connect('/');
socket.on('connect', function() {
socket.emit("notify", "New user connected");
});
socket.on('disconnect', function() {
socket.emit("notify", " A user disconnected ");
});
</script>
I want:-
When ever a user get disconnected no matter whatever the reason is, it got kicked from the chatting room. Though it's working fine when I creatd a room from one tab and then join the same room with another tab, and then pressing back from the second tab(joined the room).
My problem:-
But while testing on android. On the Chrome browser, when i do the same and then instead of pressing back button and getting disconnected, I go to the opened tabs section and delete the opened tab with which i was joined the room I'm not getting any event invoked. I know deleting a opened tab doesn't provide the proper time on client side to invoke the socket.on(" disconnect"); function. But i should receive a disconnected request on the server side socketio.on("disconnected") but nothing happening on the server side too. That's preventing me to go further on that web app. How to got it working like I want something triggered on the server side on closing the tab directly. : (