diff --git a/services/real-time/app/coffee/Router.coffee b/services/real-time/app/coffee/Router.coffee index f89e1d9eaf..3d891f1476 100644 --- a/services/real-time/app/coffee/Router.coffee +++ b/services/real-time/app/coffee/Router.coffee @@ -55,6 +55,8 @@ module.exports = Router = app.post "/client/:client_id/disconnect", httpAuth, HttpApiController.disconnectClient session.on 'connection', (error, client, session) -> + # init client context, we may access it in Router._handleError before + # setting any values client.ol_context = {} client?.on "error", (err) -> @@ -113,13 +115,9 @@ module.exports = Router = metrics.inc('socket-io.disconnect') metrics.gauge('socket-io.clients', io.sockets.clients()?.length - 1) - cleanup = () -> - delete client.ol_context WebsocketController.leaveProject io, client, (err) -> if err? - Router._handleError cleanup, err, client, "leaveProject" - else - cleanup() + Router._handleError (() ->), err, client, "leaveProject" # Variadic. The possible arguments: # doc_id, callback diff --git a/services/real-time/app/coffee/WebsocketController.coffee b/services/real-time/app/coffee/WebsocketController.coffee index 3ca030ca0c..f93e67f2a2 100644 --- a/services/real-time/app/coffee/WebsocketController.coffee +++ b/services/real-time/app/coffee/WebsocketController.coffee @@ -33,6 +33,7 @@ module.exports = WebsocketController = logger.warn {err, project_id, user_id, client_id: client.id}, "user is not authorized to join project" return callback(err) + client.ol_context = {} client.ol_context["privilege_level"] = privilegeLevel client.ol_context["user_id"] = user_id client.ol_context["project_id"] = project_id