overleaf/services/real-time/app/coffee/Router.coffee

25 lines
738 B
CoffeeScript
Raw Normal View History

Metrics = require "metrics-sharelatex"
logger = require "logger-sharelatex"
2014-11-10 06:27:08 -05:00
WebsocketController = require "./WebsocketController"
module.exports = Router =
configure: (app, io, session) ->
session.on 'connection', (error, client, session) ->
if error?
logger.err err: error, "error when client connected"
client?.disconnect()
return
Metrics.inc('socket-io.connection')
logger.log session: session, "got session"
user = session.user
2014-11-10 06:27:08 -05:00
if !user? or !user._id?
logger.log "terminating session without authenticated user"
client.disconnect()
2014-11-10 06:27:08 -05:00
return
client.on "joinProject", (data = {}, callback) ->
2014-11-10 06:40:19 -05:00
WebsocketController.joinProject(client, user, data?.project_id, callback)
2014-11-10 06:27:08 -05:00