Skip to content
Snippets Groups Projects
Commit 27f2c3e2 authored by Atanamo's avatar Atanamo
Browse files

Delay client disconnects to avoid notifies on reconnect

parent ae892c0d
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -76,7 +76,7 @@ class Channel
_registerListeners: (clientSocket) ->
# Store callback for channel-specific disconnect on socket
clientSocket[@listenerNameDisconnect] = disconnectCallback = =>
@_handleClientLeave(clientSocket, true, true)
@_handleClientDisconnect(clientSocket)
 
# Register channel-specific client events
clientSocket.on @eventNameMsg, (messageText) => @_handleClientMessage(clientSocket, messageText)
Loading
Loading
@@ -313,12 +313,21 @@ class Channel
log.debug "Client requests chat history for '#{@name}'"
@_sendHistoryToSocket(clientSocket)
 
_handleClientLeave: (clientSocket, isClose=false, isDisconnect=false) ->
_handleClientLeave: (clientSocket, isClose=false) ->
if not isClose and clientSocket.identity.getUserID() is @creatorID
# Disallow permanent leaving on channels created by the client
@_sendToSocket(clientSocket, 'leave_fail', 'Cannot leave own channels')
else
@removeClient(clientSocket, isClose, isDisconnect)
@removeClient(clientSocket, isClose)
_handleClientDisconnect: (clientSocket) ->
# Immediately unregister listeners
@_unregisterListeners(clientSocket)
# Delay disconnect for configured time - This will allow to rejoin before disconnect is executed
delay_promise = Q.delay(Config.CLIENTS_DISCONNECT_DELAY)
delay_promise = delay_promise.then =>
@removeClient(clientSocket, true, true)
delay_promise.done()
 
_handleClientDeleteRequest: (clientSocket) ->
if clientSocket.identity.getUserID() isnt @creatorID
Loading
Loading
Loading
Loading
@@ -34,7 +34,8 @@ module.exports =
 
CLIENT_AUTH_SECRET: 'SECRET_2' # A secret string to be used as part of the security token (The token needs to be sent from a client on login)
 
GAMES_LOOKUP_INTERVAL: 20 # Interval time in seconds, for looking up the games list in database and create/destroy appropriate bots accordingly
GAMES_LOOKUP_INTERVAL: 60 # Interval time in seconds, for looking up the games list in database and create/destroy appropriate bots accordingly
CLIENTS_DISCONNECT_DELAY: 2000 # Timeout in milliseconds, for waiting for reconnect of a client before broadcasting its disconnection (If it reconnects before timeout, nothing is broadcasted)
MAX_CHANNEL_LOGS: 100 # Maximum number of logs per channel in database - This controls the max size of the chat logs table
MAX_CHANNEL_LOGS_TO_CLIENT: 50 # Maximum number of channel logs for a client - This controls the max length of a channel's chat history a client can request
MAX_CHANNELS_PER_CLIENT: 3 # Maximum number of channels a client/user is allowed to create
Loading
Loading
Loading
Loading
@@ -13,6 +13,9 @@ Database = require './database'
SocketHandler = require './sockethandler'
BotManager = require './botmanager'
 
## Configure global libraries
Q.longStackSupport = Config.DEBUG_ENABLED # On debug mode, enable better stack trace support for promises (Performance overhead)
## Create library API objects
app = express()
server = http.createServer(app) # Create HTTP server instance
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment