2020-06-23 17:29:38 +00:00
|
|
|
/* eslint-disable
|
|
|
|
camelcase,
|
|
|
|
*/
|
2014-11-13 11:48:49 +00:00
|
|
|
|
2020-07-07 10:06:02 +00:00
|
|
|
let HttpController
|
2020-06-23 17:29:44 +00:00
|
|
|
module.exports = HttpController = {
|
|
|
|
// The code in this controller is hard to unit test because of a lot of
|
|
|
|
// dependencies on internal socket.io methods. It is not critical to the running
|
|
|
|
// of ShareLaTeX, and is only used for getting stats about connected clients,
|
|
|
|
// and for checking internal state in acceptance tests. The acceptances tests
|
|
|
|
// should provide appropriate coverage.
|
2020-07-07 10:06:02 +00:00
|
|
|
_getConnectedClientView(ioClient) {
|
2020-06-23 17:29:44 +00:00
|
|
|
const client_id = ioClient.id
|
|
|
|
const {
|
|
|
|
project_id,
|
|
|
|
user_id,
|
|
|
|
first_name,
|
|
|
|
last_name,
|
|
|
|
email,
|
2021-07-13 11:04:45 +00:00
|
|
|
connected_time,
|
2020-06-23 17:29:44 +00:00
|
|
|
} = ioClient.ol_context
|
|
|
|
const client = {
|
|
|
|
client_id,
|
|
|
|
project_id,
|
|
|
|
user_id,
|
|
|
|
first_name,
|
|
|
|
last_name,
|
|
|
|
email,
|
2021-07-13 11:04:45 +00:00
|
|
|
connected_time,
|
2020-06-23 17:29:44 +00:00
|
|
|
}
|
2020-07-07 10:06:02 +00:00
|
|
|
client.rooms = Object.keys(ioClient.manager.roomClients[client_id] || {})
|
|
|
|
// drop the namespace
|
2021-07-13 11:04:45 +00:00
|
|
|
.filter(room => room !== '')
|
2020-07-07 10:06:02 +00:00
|
|
|
// room names are composed as '<NAMESPACE>/<ROOM>' and the default
|
|
|
|
// namespace is empty (see comments in RoomManager), just drop the '/'
|
2021-07-13 11:04:45 +00:00
|
|
|
.map(fullRoomPath => fullRoomPath.slice(1))
|
2020-07-07 10:06:02 +00:00
|
|
|
return client
|
2020-06-23 17:29:44 +00:00
|
|
|
},
|
2014-11-13 11:48:49 +00:00
|
|
|
|
2020-07-07 10:06:02 +00:00
|
|
|
getConnectedClients(req, res) {
|
2020-06-23 17:29:44 +00:00
|
|
|
const io = req.app.get('io')
|
|
|
|
const ioClients = io.sockets.clients()
|
2020-07-07 10:06:02 +00:00
|
|
|
|
|
|
|
res.json(ioClients.map(HttpController._getConnectedClientView))
|
2020-06-23 17:29:44 +00:00
|
|
|
},
|
|
|
|
|
2020-07-07 10:06:02 +00:00
|
|
|
getConnectedClient(req, res) {
|
2020-06-23 17:29:44 +00:00
|
|
|
const { client_id } = req.params
|
|
|
|
const io = req.app.get('io')
|
|
|
|
const ioClient = io.sockets.sockets[client_id]
|
|
|
|
if (!ioClient) {
|
|
|
|
res.sendStatus(404)
|
|
|
|
return
|
|
|
|
}
|
2020-07-07 10:06:02 +00:00
|
|
|
res.json(HttpController._getConnectedClientView(ioClient))
|
2021-07-13 11:04:45 +00:00
|
|
|
},
|
2020-06-23 17:29:44 +00:00
|
|
|
}
|