2015-03-03 12:15:19 -05:00
|
|
|
WebsocketLoadBalancer = require "./WebsocketLoadBalancer"
|
2016-10-24 11:36:09 -04:00
|
|
|
DrainManager = require "./DrainManager"
|
2015-03-03 12:15:19 -05:00
|
|
|
logger = require "logger-sharelatex"
|
|
|
|
|
|
|
|
module.exports = HttpApiController =
|
|
|
|
sendMessage: (req, res, next) ->
|
|
|
|
logger.log {message: req.params.message}, "sending message"
|
2015-03-12 10:32:35 -04:00
|
|
|
if Array.isArray(req.body)
|
|
|
|
for payload in req.body
|
|
|
|
WebsocketLoadBalancer.emitToRoom req.params.project_id, req.params.message, payload
|
|
|
|
else
|
|
|
|
WebsocketLoadBalancer.emitToRoom req.params.project_id, req.params.message, req.body
|
2016-10-24 11:36:09 -04:00
|
|
|
res.send 204 # No content
|
|
|
|
|
|
|
|
startDrain: (req, res, next) ->
|
|
|
|
io = req.app.get("io")
|
|
|
|
rate = req.query.rate or "4"
|
2019-05-24 10:23:01 -04:00
|
|
|
rate = parseFloat(rate) || 0
|
2016-10-24 11:36:09 -04:00
|
|
|
logger.log {rate}, "setting client drain rate"
|
|
|
|
DrainManager.startDrain io, rate
|
2020-02-24 07:28:22 -05:00
|
|
|
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()
|