@@ -763,6 +763,10 @@ class SocketClient {
763
763
this . socket . on ( 'refresh' , this . refreshEventHandler . bind ( this ) )
764
764
// received user status
765
765
this . socket . on ( 'user status' , this . userStatusEventHandler . bind ( this ) )
766
+
767
+ // when a new client disconnect
768
+ this . socket . on ( 'disconnect' , this . disconnectEventHandler . bind ( this ) )
769
+
766
770
}
767
771
768
772
refreshEventHandler ( ) {
@@ -781,6 +785,12 @@ class SocketClient {
781
785
}
782
786
exports . emitUserStatus ( this . socket )
783
787
}
788
+
789
+ disconnectEventHandler ( ) {
790
+ if ( isDuplicatedInSocketQueue ( disconnectSocketQueue , this . socket ) ) return
791
+ disconnectSocketQueue . push ( this . socket )
792
+ exports . disconnect ( this . socket )
793
+ }
784
794
}
785
795
786
796
function connection ( socket ) {
@@ -983,13 +993,6 @@ function connection (socket) {
983
993
}
984
994
socket . broadcast . to ( noteId ) . emit ( 'cursor blur' , out )
985
995
} )
986
-
987
- // when a new client disconnect
988
- socket . on ( 'disconnect' , function ( ) {
989
- if ( isDuplicatedInSocketQueue ( socket , disconnectSocketQueue ) ) return
990
- disconnectSocketQueue . push ( socket )
991
- disconnect ( socket )
992
- } )
993
996
}
994
997
995
998
exports = module . exports = realtime
@@ -1003,5 +1006,7 @@ exports.updateUserData = updateUserData
1003
1006
exports . startConnection = startConnection
1004
1007
exports . emitRefresh = emitRefresh
1005
1008
exports . emitUserStatus = emitUserStatus
1009
+ exports . disconnect = disconnect
1006
1010
exports . notes = notes
1007
1011
exports . users = users
1012
+ exports . disconnectSocketQueue = disconnectSocketQueue
0 commit comments