2014-11-07 12:38:12 -05:00
|
|
|
Metrics = require "metrics-sharelatex"
|
|
|
|
logger = require "logger-sharelatex"
|
2014-11-10 06:27:08 -05:00
|
|
|
WebsocketController = require "./WebsocketController"
|
2014-11-07 12:38:12 -05:00
|
|
|
|
|
|
|
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?
|
2014-11-07 12:38:12 -05:00
|
|
|
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
|
|
|
|