From de35fc5ecf6e91b8e0e39a0e3e3020428def4718 Mon Sep 17 00:00:00 2001 From: Jakob Ackermann Date: Mon, 24 Feb 2020 13:28:22 +0100 Subject: [PATCH] [HttpApiController] implement the disconnection of a single client The http route returns as soon as the client has fully disconnected. --- .../app/coffee/HttpApiController.coffee | 16 +++++++++++++++- services/real-time/app/coffee/Router.coffee | 1 + 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/services/real-time/app/coffee/HttpApiController.coffee b/services/real-time/app/coffee/HttpApiController.coffee index f99bef6dd6..299d198f57 100644 --- a/services/real-time/app/coffee/HttpApiController.coffee +++ b/services/real-time/app/coffee/HttpApiController.coffee @@ -18,4 +18,18 @@ module.exports = HttpApiController = rate = parseFloat(rate) || 0 logger.log {rate}, "setting client drain rate" DrainManager.startDrain io, rate - res.send 204 \ No newline at end of file + res.send 204 + + disconnectClient: (req, res, next) -> + io = req.app.get("io") + client_id = req.params.client_id + client = io.sockets.sockets[client_id] + + if !client + logger.info({client_id}, "api: client already disconnected") + res.sendStatus(404) + return + logger.warn({client_id}, "api: requesting client disconnect") + client.on "disconnect", () -> + res.sendStatus(204) + client.disconnect() diff --git a/services/real-time/app/coffee/Router.coffee b/services/real-time/app/coffee/Router.coffee index 276c64e2dd..99aacce3bc 100644 --- a/services/real-time/app/coffee/Router.coffee +++ b/services/real-time/app/coffee/Router.coffee @@ -53,6 +53,7 @@ module.exports = Router = app.post "/project/:project_id/message/:message", httpAuth, bodyParser.json(limit: "5mb"), HttpApiController.sendMessage app.post "/drain", httpAuth, HttpApiController.startDrain + app.post "/client/:client_id/disconnect", httpAuth, HttpApiController.disconnectClient session.on 'connection', (error, client, session) -> client?.on "error", (err) ->