2020-11-25 06:57:22 -05:00
|
|
|
const metrics = require('@overleaf/metrics')
|
2021-12-14 08:00:35 -05:00
|
|
|
const logger = require('@overleaf/logger')
|
2021-07-12 12:47:18 -04:00
|
|
|
const settings = require('@overleaf/settings')
|
2020-06-23 13:29:44 -04:00
|
|
|
const WebsocketController = require('./WebsocketController')
|
|
|
|
const HttpController = require('./HttpController')
|
|
|
|
const HttpApiController = require('./HttpApiController')
|
2021-09-14 04:36:24 -04:00
|
|
|
const WebsocketAddressManager = require('./WebsocketAddressManager')
|
2020-06-23 13:29:44 -04:00
|
|
|
const bodyParser = require('body-parser')
|
|
|
|
const base64id = require('base64id')
|
2020-08-20 08:12:56 -04:00
|
|
|
const { UnexpectedArgumentsError } = require('./Errors')
|
2024-02-02 06:49:05 -05:00
|
|
|
const Joi = require('joi')
|
2020-06-23 13:29:34 -04:00
|
|
|
|
2024-11-08 05:21:56 -05:00
|
|
|
const HOSTNAME = require('node:os').hostname()
|
2020-07-06 09:27:46 -04:00
|
|
|
|
2021-09-01 05:10:10 -04:00
|
|
|
const JOI_OBJECT_ID = Joi.string()
|
|
|
|
.required()
|
|
|
|
.regex(/^[0-9a-f]{24}$/)
|
|
|
|
.message('invalid id')
|
|
|
|
|
2020-07-07 06:06:02 -04:00
|
|
|
let Router
|
2020-06-23 13:29:44 -04:00
|
|
|
module.exports = Router = {
|
|
|
|
_handleError(callback, error, client, method, attrs) {
|
2020-07-07 06:06:02 -04:00
|
|
|
attrs = attrs || {}
|
2020-08-20 09:03:03 -04:00
|
|
|
for (const key of ['project_id', 'user_id']) {
|
2020-08-20 11:23:57 -04:00
|
|
|
attrs[key] = attrs[key] || client.ol_context[key]
|
2020-06-23 13:29:44 -04:00
|
|
|
}
|
|
|
|
attrs.client_id = client.id
|
|
|
|
attrs.err = error
|
2020-08-27 05:28:44 -04:00
|
|
|
attrs.method = method
|
2021-09-01 05:10:10 -04:00
|
|
|
if (Joi.isError(error)) {
|
2021-09-14 04:36:24 -04:00
|
|
|
logger.info(attrs, 'validation error')
|
2021-10-26 04:08:56 -04:00
|
|
|
let message = 'invalid'
|
2021-09-01 05:10:10 -04:00
|
|
|
try {
|
|
|
|
message = error.details[0].message
|
|
|
|
} catch (e) {
|
|
|
|
// ignore unexpected errors
|
|
|
|
logger.warn({ error, e }, 'unexpected validation error')
|
|
|
|
}
|
|
|
|
const serializedError = { message }
|
|
|
|
metrics.inc('validation-error', 1, {
|
|
|
|
status: method,
|
|
|
|
})
|
|
|
|
callback(serializedError)
|
|
|
|
} else if (error.name === 'CodedError') {
|
2020-08-20 05:41:16 -04:00
|
|
|
logger.warn(attrs, error.message)
|
|
|
|
const serializedError = { message: error.message, code: error.info.code }
|
2020-07-07 06:06:02 -04:00
|
|
|
callback(serializedError)
|
|
|
|
} else if (error.message === 'unexpected arguments') {
|
2021-09-14 04:36:24 -04:00
|
|
|
// the payload might be very large; put it on level debug
|
|
|
|
logger.debug(attrs, 'unexpected arguments')
|
2020-06-23 13:29:44 -04:00
|
|
|
metrics.inc('unexpected-arguments', 1, { status: method })
|
2020-07-07 06:06:02 -04:00
|
|
|
const serializedError = { message: error.message }
|
|
|
|
callback(serializedError)
|
2021-03-30 06:34:25 -04:00
|
|
|
} else if (error.message === 'no project_id found on client') {
|
|
|
|
logger.debug(attrs, error.message)
|
|
|
|
const serializedError = { message: error.message }
|
|
|
|
callback(serializedError)
|
2020-07-07 06:06:02 -04:00
|
|
|
} else if (
|
2020-06-23 13:29:44 -04:00
|
|
|
[
|
|
|
|
'not authorized',
|
2020-07-13 05:42:50 -04:00
|
|
|
'joinLeaveEpoch mismatch',
|
2021-07-13 07:04:45 -04:00
|
|
|
'doc updater could not load requested ops',
|
2021-09-01 05:10:10 -04:00
|
|
|
'no project_id found on client',
|
|
|
|
'cannot join multiple projects',
|
2020-06-23 13:29:44 -04:00
|
|
|
].includes(error.message)
|
|
|
|
) {
|
|
|
|
logger.warn(attrs, error.message)
|
2020-07-07 06:06:02 -04:00
|
|
|
const serializedError = { message: error.message }
|
|
|
|
callback(serializedError)
|
2020-06-23 13:29:44 -04:00
|
|
|
} else {
|
|
|
|
logger.error(attrs, `server side error in ${method}`)
|
|
|
|
// Don't return raw error to prevent leaking server side info
|
2020-07-07 06:06:02 -04:00
|
|
|
const serializedError = {
|
2021-07-13 07:04:45 -04:00
|
|
|
message: 'Something went wrong in real-time service',
|
2020-07-07 06:06:02 -04:00
|
|
|
}
|
|
|
|
callback(serializedError)
|
2020-06-23 13:29:44 -04:00
|
|
|
}
|
2021-09-01 05:10:10 -04:00
|
|
|
if (attrs.disconnect) {
|
|
|
|
setTimeout(function () {
|
|
|
|
client.disconnect()
|
|
|
|
}, 100)
|
|
|
|
}
|
2020-06-23 13:29:44 -04:00
|
|
|
},
|
2020-06-23 13:29:34 -04:00
|
|
|
|
2020-06-23 13:29:44 -04:00
|
|
|
_handleInvalidArguments(client, method, args) {
|
2020-08-20 08:12:56 -04:00
|
|
|
const error = new UnexpectedArgumentsError()
|
2020-06-23 13:29:44 -04:00
|
|
|
let callback = args[args.length - 1]
|
|
|
|
if (typeof callback !== 'function') {
|
|
|
|
callback = function () {}
|
|
|
|
}
|
|
|
|
const attrs = { arguments: args }
|
2020-07-07 06:06:02 -04:00
|
|
|
Router._handleError(callback, error, client, method, attrs)
|
2020-06-23 13:29:44 -04:00
|
|
|
},
|
2020-06-23 13:29:34 -04:00
|
|
|
|
2020-06-23 13:29:44 -04:00
|
|
|
configure(app, io, session) {
|
|
|
|
app.set('io', io)
|
2021-09-14 04:36:24 -04:00
|
|
|
|
|
|
|
if (settings.behindProxy) {
|
|
|
|
app.set('trust proxy', settings.trustedProxyIps)
|
|
|
|
}
|
|
|
|
const websocketAddressManager = new WebsocketAddressManager(
|
|
|
|
settings.behindProxy,
|
|
|
|
settings.trustedProxyIps
|
|
|
|
)
|
|
|
|
|
2020-06-23 13:29:44 -04:00
|
|
|
app.get('/clients', HttpController.getConnectedClients)
|
|
|
|
app.get('/clients/:client_id', HttpController.getConnectedClient)
|
2020-06-23 13:29:34 -04:00
|
|
|
|
2020-06-23 13:29:44 -04:00
|
|
|
app.post(
|
|
|
|
'/project/:project_id/message/:message',
|
|
|
|
bodyParser.json({ limit: '5mb' }),
|
|
|
|
HttpApiController.sendMessage
|
|
|
|
)
|
2020-06-23 13:29:34 -04:00
|
|
|
|
2022-01-06 04:25:45 -05:00
|
|
|
app.post('/drain', HttpApiController.startDrain)
|
2020-06-23 13:29:44 -04:00
|
|
|
app.post(
|
|
|
|
'/client/:client_id/disconnect',
|
|
|
|
HttpApiController.disconnectClient
|
|
|
|
)
|
2020-06-23 13:29:34 -04:00
|
|
|
|
2020-07-07 06:06:02 -04:00
|
|
|
session.on('connection', function (error, client, session) {
|
2020-06-23 13:29:44 -04:00
|
|
|
// init client context, we may access it in Router._handleError before
|
|
|
|
// setting any values
|
|
|
|
client.ol_context = {}
|
2020-07-13 05:42:50 -04:00
|
|
|
// bail out from joinDoc when a parallel joinDoc or leaveDoc is running
|
|
|
|
client.joinLeaveEpoch = 0
|
2020-06-23 13:29:34 -04:00
|
|
|
|
2020-07-07 06:06:02 -04:00
|
|
|
if (client) {
|
2020-06-23 13:29:44 -04:00
|
|
|
client.on('error', function (err) {
|
|
|
|
logger.err({ clientErr: err }, 'socket.io client error')
|
|
|
|
if (client.connected) {
|
|
|
|
client.emit('reconnectGracefully')
|
2020-07-07 06:06:02 -04:00
|
|
|
client.disconnect()
|
2020-06-23 13:29:44 -04:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2020-06-23 13:29:34 -04:00
|
|
|
|
2020-06-23 13:29:44 -04:00
|
|
|
if (settings.shutDownInProgress) {
|
|
|
|
client.emit('connectionRejected', { message: 'retry' })
|
|
|
|
client.disconnect()
|
|
|
|
return
|
|
|
|
}
|
2020-06-23 13:29:34 -04:00
|
|
|
|
2020-06-23 13:29:44 -04:00
|
|
|
if (
|
2020-07-07 06:06:02 -04:00
|
|
|
client &&
|
|
|
|
error &&
|
|
|
|
error.message.match(/could not look up session by key/)
|
2020-06-23 13:29:44 -04:00
|
|
|
) {
|
|
|
|
logger.warn(
|
2020-07-07 06:06:02 -04:00
|
|
|
{ err: error, client: !!client, session: !!session },
|
2020-06-23 13:29:44 -04:00
|
|
|
'invalid session'
|
|
|
|
)
|
|
|
|
// tell the client to reauthenticate if it has an invalid session key
|
|
|
|
client.emit('connectionRejected', { message: 'invalid session' })
|
|
|
|
client.disconnect()
|
|
|
|
return
|
|
|
|
}
|
2020-06-23 13:29:34 -04:00
|
|
|
|
2020-07-07 06:06:02 -04:00
|
|
|
if (error) {
|
2020-06-23 13:29:44 -04:00
|
|
|
logger.err(
|
2020-07-07 06:06:02 -04:00
|
|
|
{ err: error, client: !!client, session: !!session },
|
2020-06-23 13:29:44 -04:00
|
|
|
'error when client connected'
|
|
|
|
)
|
2020-07-07 06:06:02 -04:00
|
|
|
if (client) {
|
2020-06-23 13:29:44 -04:00
|
|
|
client.emit('connectionRejected', { message: 'error' })
|
|
|
|
}
|
2020-07-07 06:06:02 -04:00
|
|
|
if (client) {
|
2020-06-23 13:29:44 -04:00
|
|
|
client.disconnect()
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
2020-06-23 13:29:34 -04:00
|
|
|
|
2023-11-29 09:50:42 -05:00
|
|
|
const projectId = client.handshake?.query?.projectId
|
|
|
|
try {
|
|
|
|
Joi.assert(projectId, JOI_OBJECT_ID)
|
|
|
|
} catch (error) {
|
|
|
|
metrics.inc('socket-io.connection', 1, {
|
|
|
|
status: client.transport,
|
|
|
|
method: projectId ? 'bad-project-id' : 'missing-project-id',
|
|
|
|
})
|
|
|
|
client.emit('connectionRejected', {
|
|
|
|
message: 'missing/bad ?projectId=... query flag on handshake',
|
|
|
|
})
|
|
|
|
client.disconnect()
|
|
|
|
return
|
2023-06-14 05:16:27 -04:00
|
|
|
}
|
2020-06-23 13:29:34 -04:00
|
|
|
|
2023-11-29 09:50:42 -05:00
|
|
|
// The client.id is security sensitive. Generate a publicId for sending to other clients.
|
|
|
|
client.publicId = 'P.' + base64id.generateId()
|
|
|
|
|
2021-09-14 04:36:24 -04:00
|
|
|
client.remoteIp = websocketAddressManager.getRemoteIp(client.handshake)
|
|
|
|
const headers = client.handshake && client.handshake.headers
|
|
|
|
client.userAgent = headers && headers['user-agent']
|
|
|
|
|
2023-06-14 05:16:27 -04:00
|
|
|
metrics.inc('socket-io.connection', 1, {
|
|
|
|
status: client.transport,
|
2023-11-29 09:50:42 -05:00
|
|
|
method: 'auto-join-project',
|
2023-06-14 05:16:27 -04:00
|
|
|
})
|
2020-07-07 06:06:02 -04:00
|
|
|
metrics.gauge('socket-io.clients', io.sockets.clients().length)
|
2020-06-23 13:29:34 -04:00
|
|
|
|
2023-03-20 10:10:40 -04:00
|
|
|
logger.debug({ session, clientId: client.id }, 'client connected')
|
2020-06-23 13:29:34 -04:00
|
|
|
|
2020-07-07 06:06:02 -04:00
|
|
|
let user
|
|
|
|
if (session && session.passport && session.passport.user) {
|
2020-06-23 13:29:44 -04:00
|
|
|
;({ user } = session.passport)
|
2020-07-07 06:06:02 -04:00
|
|
|
} else if (session && session.user) {
|
2020-06-23 13:29:44 -04:00
|
|
|
;({ user } = session)
|
|
|
|
} else {
|
2023-11-29 09:50:42 -05:00
|
|
|
const anonymousAccessToken = session?.anonTokenAccess?.[projectId]
|
|
|
|
user = { _id: 'anonymous-user', anonymousAccessToken }
|
2020-06-23 13:29:44 -04:00
|
|
|
}
|
2020-06-23 13:29:34 -04:00
|
|
|
|
2020-07-06 09:27:46 -04:00
|
|
|
if (settings.exposeHostname) {
|
|
|
|
client.on('debug.getHostname', function (callback) {
|
|
|
|
if (typeof callback !== 'function') {
|
|
|
|
return Router._handleInvalidArguments(
|
|
|
|
client,
|
|
|
|
'debug.getHostname',
|
|
|
|
arguments
|
|
|
|
)
|
|
|
|
}
|
|
|
|
callback(HOSTNAME)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-11-29 09:50:42 -05:00
|
|
|
const joinProject = function (callback) {
|
2020-07-07 06:06:02 -04:00
|
|
|
WebsocketController.joinProject(
|
2020-06-23 13:29:44 -04:00
|
|
|
client,
|
|
|
|
user,
|
2023-03-20 10:10:40 -04:00
|
|
|
projectId,
|
2020-06-23 13:29:44 -04:00
|
|
|
function (err, ...args) {
|
2020-07-07 06:06:02 -04:00
|
|
|
if (err) {
|
|
|
|
Router._handleError(callback, err, client, 'joinProject', {
|
2023-03-20 10:10:40 -04:00
|
|
|
project_id: projectId,
|
2021-07-13 07:04:45 -04:00
|
|
|
user_id: user._id,
|
2020-06-23 13:29:44 -04:00
|
|
|
})
|
|
|
|
} else {
|
2020-07-07 06:06:02 -04:00
|
|
|
callback(null, ...args)
|
2020-06-23 13:29:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
2023-06-14 05:16:27 -04:00
|
|
|
}
|
2020-06-23 13:29:34 -04:00
|
|
|
|
2020-06-23 13:29:44 -04:00
|
|
|
client.on('disconnect', function () {
|
2021-05-10 05:16:50 -04:00
|
|
|
metrics.inc('socket-io.disconnect', 1, { status: client.transport })
|
2020-07-07 06:06:02 -04:00
|
|
|
metrics.gauge('socket-io.clients', io.sockets.clients().length)
|
2020-06-23 13:29:34 -04:00
|
|
|
|
2020-07-07 06:06:02 -04:00
|
|
|
WebsocketController.leaveProject(io, client, function (err) {
|
|
|
|
if (err) {
|
|
|
|
Router._handleError(function () {}, err, client, 'leaveProject')
|
2020-06-23 13:29:44 -04:00
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
2020-06-23 13:29:34 -04:00
|
|
|
|
2020-06-23 13:29:44 -04:00
|
|
|
// Variadic. The possible arguments:
|
|
|
|
// doc_id, callback
|
|
|
|
// doc_id, fromVersion, callback
|
|
|
|
// doc_id, options, callback
|
|
|
|
// doc_id, fromVersion, options, callback
|
2023-03-20 10:10:40 -04:00
|
|
|
client.on('joinDoc', function (docId, fromVersion, options, callback) {
|
2020-06-23 13:29:44 -04:00
|
|
|
if (typeof fromVersion === 'function' && !options) {
|
|
|
|
callback = fromVersion
|
|
|
|
fromVersion = -1
|
|
|
|
options = {}
|
|
|
|
} else if (
|
|
|
|
typeof fromVersion === 'number' &&
|
|
|
|
typeof options === 'function'
|
|
|
|
) {
|
|
|
|
callback = options
|
|
|
|
options = {}
|
|
|
|
} else if (
|
|
|
|
typeof fromVersion === 'object' &&
|
|
|
|
typeof options === 'function'
|
|
|
|
) {
|
|
|
|
callback = options
|
|
|
|
options = fromVersion
|
|
|
|
fromVersion = -1
|
|
|
|
} else if (
|
|
|
|
typeof fromVersion === 'number' &&
|
|
|
|
typeof options === 'object' &&
|
|
|
|
typeof callback === 'function'
|
|
|
|
) {
|
|
|
|
// Called with 4 args, things are as expected
|
|
|
|
} else {
|
|
|
|
return Router._handleInvalidArguments(client, 'joinDoc', arguments)
|
|
|
|
}
|
2021-09-01 05:10:10 -04:00
|
|
|
try {
|
|
|
|
Joi.assert(
|
2023-03-20 10:10:40 -04:00
|
|
|
{ doc_id: docId, fromVersion, options },
|
2021-09-01 05:10:10 -04:00
|
|
|
Joi.object({
|
|
|
|
doc_id: JOI_OBJECT_ID,
|
|
|
|
fromVersion: Joi.number().integer(),
|
|
|
|
options: Joi.object().required(),
|
|
|
|
})
|
|
|
|
)
|
|
|
|
} catch (error) {
|
|
|
|
return Router._handleError(callback, error, client, 'joinDoc', {
|
|
|
|
disconnect: 1,
|
|
|
|
})
|
|
|
|
}
|
2020-07-07 06:06:02 -04:00
|
|
|
WebsocketController.joinDoc(
|
2020-06-23 13:29:44 -04:00
|
|
|
client,
|
2023-03-20 10:10:40 -04:00
|
|
|
docId,
|
2020-06-23 13:29:44 -04:00
|
|
|
fromVersion,
|
|
|
|
options,
|
|
|
|
function (err, ...args) {
|
2020-07-07 06:06:02 -04:00
|
|
|
if (err) {
|
|
|
|
Router._handleError(callback, err, client, 'joinDoc', {
|
2023-03-20 10:10:40 -04:00
|
|
|
doc_id: docId,
|
2021-07-13 07:04:45 -04:00
|
|
|
fromVersion,
|
2020-06-23 13:29:44 -04:00
|
|
|
})
|
|
|
|
} else {
|
2020-07-07 06:06:02 -04:00
|
|
|
callback(null, ...args)
|
2020-06-23 13:29:44 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
2020-06-23 13:29:34 -04:00
|
|
|
|
2023-03-20 10:10:40 -04:00
|
|
|
client.on('leaveDoc', function (docId, callback) {
|
2020-06-23 13:29:44 -04:00
|
|
|
if (typeof callback !== 'function') {
|
|
|
|
return Router._handleInvalidArguments(client, 'leaveDoc', arguments)
|
|
|
|
}
|
2021-09-01 05:10:10 -04:00
|
|
|
try {
|
2023-03-20 10:10:40 -04:00
|
|
|
Joi.assert(docId, JOI_OBJECT_ID)
|
2021-09-01 05:10:10 -04:00
|
|
|
} catch (error) {
|
|
|
|
return Router._handleError(callback, error, client, 'joinDoc', {
|
|
|
|
disconnect: 1,
|
|
|
|
})
|
|
|
|
}
|
2023-03-20 10:10:40 -04:00
|
|
|
WebsocketController.leaveDoc(client, docId, function (err, ...args) {
|
2020-07-07 06:06:02 -04:00
|
|
|
if (err) {
|
2020-08-20 09:05:12 -04:00
|
|
|
Router._handleError(callback, err, client, 'leaveDoc', {
|
2023-03-20 10:10:40 -04:00
|
|
|
doc_id: docId,
|
2020-08-20 09:05:12 -04:00
|
|
|
})
|
2020-06-23 13:29:44 -04:00
|
|
|
} else {
|
2020-07-07 06:06:02 -04:00
|
|
|
callback(null, ...args)
|
2020-06-23 13:29:44 -04:00
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
2020-06-23 13:29:34 -04:00
|
|
|
|
2020-06-23 13:29:44 -04:00
|
|
|
client.on('clientTracking.getConnectedUsers', function (callback) {
|
|
|
|
if (typeof callback !== 'function') {
|
|
|
|
return Router._handleInvalidArguments(
|
|
|
|
client,
|
|
|
|
'clientTracking.getConnectedUsers',
|
|
|
|
arguments
|
|
|
|
)
|
|
|
|
}
|
2020-06-23 13:29:34 -04:00
|
|
|
|
2020-07-07 06:06:02 -04:00
|
|
|
WebsocketController.getConnectedUsers(client, function (err, users) {
|
|
|
|
if (err) {
|
|
|
|
Router._handleError(
|
2020-06-23 13:29:44 -04:00
|
|
|
callback,
|
|
|
|
err,
|
|
|
|
client,
|
|
|
|
'clientTracking.getConnectedUsers'
|
|
|
|
)
|
|
|
|
} else {
|
2020-07-07 06:06:02 -04:00
|
|
|
callback(null, users)
|
2020-06-23 13:29:44 -04:00
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
2020-06-23 13:29:34 -04:00
|
|
|
|
2021-07-13 07:04:45 -04:00
|
|
|
client.on(
|
|
|
|
'clientTracking.updatePosition',
|
|
|
|
function (cursorData, callback) {
|
|
|
|
if (!callback) {
|
2021-10-27 05:49:18 -04:00
|
|
|
callback = function () {
|
|
|
|
// NOTE: The frontend does not pass any callback to socket.io.
|
|
|
|
// Any error is already logged via Router._handleError.
|
|
|
|
}
|
2021-07-13 07:04:45 -04:00
|
|
|
}
|
|
|
|
if (typeof callback !== 'function') {
|
|
|
|
return Router._handleInvalidArguments(
|
2020-07-07 06:06:02 -04:00
|
|
|
client,
|
2021-07-13 07:04:45 -04:00
|
|
|
'clientTracking.updatePosition',
|
|
|
|
arguments
|
2020-07-07 06:06:02 -04:00
|
|
|
)
|
2020-06-23 13:29:44 -04:00
|
|
|
}
|
2021-07-13 07:04:45 -04:00
|
|
|
|
|
|
|
WebsocketController.updateClientPosition(
|
|
|
|
client,
|
|
|
|
cursorData,
|
|
|
|
function (err) {
|
|
|
|
if (err) {
|
|
|
|
Router._handleError(
|
|
|
|
callback,
|
|
|
|
err,
|
|
|
|
client,
|
|
|
|
'clientTracking.updatePosition'
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
callback()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
2020-06-23 13:29:34 -04:00
|
|
|
|
2023-03-20 10:10:40 -04:00
|
|
|
client.on('applyOtUpdate', function (docId, update, callback) {
|
2020-06-23 13:29:44 -04:00
|
|
|
if (typeof callback !== 'function') {
|
|
|
|
return Router._handleInvalidArguments(
|
|
|
|
client,
|
|
|
|
'applyOtUpdate',
|
|
|
|
arguments
|
|
|
|
)
|
|
|
|
}
|
2021-09-01 05:10:10 -04:00
|
|
|
try {
|
|
|
|
Joi.assert(
|
2023-03-20 10:10:40 -04:00
|
|
|
{ doc_id: docId, update },
|
2021-09-01 05:10:10 -04:00
|
|
|
Joi.object({
|
|
|
|
doc_id: JOI_OBJECT_ID,
|
|
|
|
update: Joi.object().required(),
|
|
|
|
})
|
|
|
|
)
|
|
|
|
} catch (error) {
|
|
|
|
return Router._handleError(callback, error, client, 'applyOtUpdate', {
|
|
|
|
disconnect: 1,
|
|
|
|
})
|
|
|
|
}
|
2021-07-13 07:04:45 -04:00
|
|
|
WebsocketController.applyOtUpdate(
|
|
|
|
client,
|
2023-03-20 10:10:40 -04:00
|
|
|
docId,
|
2021-07-13 07:04:45 -04:00
|
|
|
update,
|
|
|
|
function (err) {
|
|
|
|
if (err) {
|
|
|
|
Router._handleError(callback, err, client, 'applyOtUpdate', {
|
2023-03-20 10:10:40 -04:00
|
|
|
doc_id: docId,
|
2021-07-13 07:04:45 -04:00
|
|
|
update,
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
callback()
|
|
|
|
}
|
2020-06-23 13:29:44 -04:00
|
|
|
}
|
2021-07-13 07:04:45 -04:00
|
|
|
)
|
2020-06-23 13:29:44 -04:00
|
|
|
})
|
2023-06-14 05:16:27 -04:00
|
|
|
|
2023-11-29 09:50:42 -05:00
|
|
|
joinProject((err, project, permissionsLevel, protocolVersion) => {
|
|
|
|
if (err) {
|
|
|
|
client.emit('connectionRejected', err)
|
|
|
|
client.disconnect()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
client.emit('joinProjectResponse', {
|
|
|
|
publicId: client.publicId,
|
|
|
|
project,
|
|
|
|
permissionsLevel,
|
|
|
|
protocolVersion,
|
|
|
|
})
|
|
|
|
})
|
2020-06-23 13:29:44 -04:00
|
|
|
})
|
2021-07-13 07:04:45 -04:00
|
|
|
},
|
2020-06-23 13:29:44 -04:00
|
|
|
}
|