Merge branch 'hotfix/21.56.9' into master
[gitter.git] / server / api / v1 / eyeballs.js
blobd3b4bf7314ee94dce8a1e8684f0afe5891ceffca
1 'use strict';
3 var env = require('gitter-web-env');
4 var logger = env.logger;
5 var stats = env.stats;
7 var presenceService = require('gitter-web-presence');
8 var bayeux = require('../../web/bayeux');
10 module.exports = function(req, res, next) {
11 var socketId = req.body.socketId;
12 var on = parseInt(req.body.on, 10);
14 bayeux.clientExists(socketId, function(exists) {
15 if (!exists) {
16 stats.eventHF('eyeballs.failed');
17 stats.eventHF('eyeballs.failed.invalid.socket');
19 logger.warn('eyeball: socket ' + socketId + ' does not exist. ');
20 return res.sendStatus(400);
23 presenceService.clientEyeballSignal(req.user.id, socketId, on, function(err) {
24 if (err) {
25 stats.eventHF('eyeballs.failed');
27 if (err.invalidSocketId) {
28 stats.eventHF('eyeballs.failed.invalid.presence');
30 logger.warn(
31 'eyeball: socket ' +
32 socketId +
33 ' exists in the faye engine, but not in the presence service.'
35 bayeux.destroyClient(socketId);
37 return res.sendStatus(400);
40 return next(err);
43 res.format({
44 text: function() {
45 res.send('OK');
47 json: function() {
48 res.send({ success: true });
50 html: function() {
51 res.send('OK');
53 });
54 });
55 });