mirror of
https://github.com/ONLYOFFICE/server.git
synced 2026-02-10 18:05:07 +08:00
[socket.io] Move from sockjs built-in properties to socketio
This commit is contained in:
committed by
Sergey Konovalov
parent
09fe41af75
commit
2f124fe07f
@ -270,7 +270,7 @@
|
||||
},
|
||||
"socketio": {
|
||||
"connection": {
|
||||
"path": "/doc/socket.io/",
|
||||
"path": "/doc/",
|
||||
"serveClient": false,
|
||||
"pingTimeout": 20000,
|
||||
"pingInterval": 25000,
|
||||
|
||||
@ -295,7 +295,7 @@ exports.RESTORE = 'no cache';
|
||||
exports.CONTENT_DISPOSITION_INLINE = 'inline';
|
||||
exports.CONTENT_DISPOSITION_ATTACHMENT = 'attachment';
|
||||
|
||||
exports.CONN_CLOSED = 3;
|
||||
exports.CONN_CLOSED = "closed";
|
||||
|
||||
exports.FILE_STATUS_OK = 'ok';
|
||||
exports.FILE_STATUS_UPDATE_VERSION = 'updateversion';
|
||||
|
||||
@ -53,7 +53,8 @@ Context.prototype.initFromConnection = function(conn) {
|
||||
let tenant = tenantManager.getTenantByConnection(this, conn);
|
||||
let docId = conn.docid;
|
||||
if (!docId) {
|
||||
const docIdParsed = constants.DOC_ID_SOCKET_PATTERN.exec(conn.url);
|
||||
let handshake = conn.handshake;
|
||||
const docIdParsed = constants.DOC_ID_SOCKET_PATTERN.exec(handshake.url);
|
||||
if (docIdParsed && 1 < docIdParsed.length) {
|
||||
docId = docIdParsed[1];
|
||||
}
|
||||
|
||||
@ -77,7 +77,7 @@ function getTenant(ctx, domain) {
|
||||
return tenant;
|
||||
}
|
||||
function getTenantByConnection(ctx, conn) {
|
||||
return isMultitenantMode() ? getTenant(ctx, utils.getDomainByConnection(ctx, conn.request)) : getDefautTenant();
|
||||
return isMultitenantMode() ? getTenant(ctx, utils.getDomainByConnection(ctx, conn)) : getDefautTenant();
|
||||
}
|
||||
function getTenantByRequest(ctx, req) {
|
||||
return isMultitenantMode() ? getTenant(ctx, utils.getDomainByRequest(ctx, req)) : getDefautTenant();
|
||||
|
||||
@ -693,8 +693,9 @@ function getBaseUrlByRequest(req) {
|
||||
exports.getBaseUrlByConnection = getBaseUrlByConnection;
|
||||
exports.getBaseUrlByRequest = getBaseUrlByRequest;
|
||||
function getDomainByConnection(ctx, conn) {
|
||||
let host = conn.headers['host'];
|
||||
let forwardedHost = conn.headers['x-forwarded-host'];
|
||||
let incomingMessage = conn.request;
|
||||
let host = incomingMessage.headers['host'];
|
||||
let forwardedHost = incomingMessage.headers['x-forwarded-host'];
|
||||
ctx.logger.debug("getDomainByConnection headers['host']=%s headers['x-forwarded-host']=%s", host, forwardedHost);
|
||||
return getDomain(host, forwardedHost);
|
||||
}
|
||||
|
||||
@ -508,7 +508,7 @@ function fillJwtByConnection(ctx, conn) {
|
||||
}
|
||||
|
||||
function sendData(ctx, conn, data) {
|
||||
conn.write(JSON.stringify(data));
|
||||
conn.emit('message', JSON.stringify(data));
|
||||
const type = data ? data.type : null;
|
||||
ctx.logger.debug('sendData: type = %s', type);
|
||||
}
|
||||
@ -1031,12 +1031,13 @@ function* publishCloseUsersConnection(ctx, docId, users, isOriginalId, code, des
|
||||
}
|
||||
}
|
||||
function closeUsersConnection(docId, usersMap, isOriginalId, code, description) {
|
||||
let elConnection;
|
||||
//close
|
||||
let conn;
|
||||
for (let i = connections.length - 1; i >= 0; --i) {
|
||||
elConnection = connections[i];
|
||||
if (elConnection.docId === docId) {
|
||||
if (isOriginalId ? usersMap[elConnection.user.idOriginal] : usersMap[elConnection.user.id]) {
|
||||
elConnection.close(code, description);
|
||||
conn = connections[i];
|
||||
if (conn.docId === docId) {
|
||||
if (isOriginalId ? usersMap[conn.user.idOriginal] : usersMap[conn.user.id]) {
|
||||
conn.close(code, description);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1329,8 +1330,6 @@ exports.install = function(server, callbackFunction) {
|
||||
ctx.logger.info('io.use end');
|
||||
next(checkJwtRes.decoded ? undefined : new Error("not authorized"));
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
@ -1456,7 +1455,7 @@ exports.install = function(server, callbackFunction) {
|
||||
delete conn.authChangesAck;
|
||||
break;
|
||||
default:
|
||||
ctx.logger.debug("unknown command %d", data);
|
||||
ctx.logger.debug("unknown command %j", data);
|
||||
break;
|
||||
}
|
||||
if(clientStatsD) {
|
||||
@ -1789,7 +1788,7 @@ exports.install = function(server, callbackFunction) {
|
||||
return el.sessionId === sessionId;//Delete this connection
|
||||
});
|
||||
//closing could happen during async action
|
||||
if (constants.CONN_CLOSED !== conn.readyState) {
|
||||
if (constants.CONN_CLOSED !== conn.conn.readyState) {
|
||||
// Кладем в массив, т.к. нам нужно отправлять данные для открытия/сохранения документа
|
||||
connections.push(conn);
|
||||
yield addPresence(ctx, conn, true);
|
||||
@ -2261,7 +2260,7 @@ exports.install = function(server, callbackFunction) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (constants.CONN_CLOSED === conn.readyState) {
|
||||
if (constants.CONN_CLOSED === conn.conn.readyState) {
|
||||
//closing could happen during async action
|
||||
return;
|
||||
}
|
||||
@ -2323,7 +2322,7 @@ exports.install = function(server, callbackFunction) {
|
||||
return el.sessionId === data.sessionId;//Delete this connection
|
||||
});
|
||||
//closing could happen during async action
|
||||
if (constants.CONN_CLOSED !== conn.readyState) {
|
||||
if (constants.CONN_CLOSED !== conn.conn.readyState) {
|
||||
// Кладем в массив, т.к. нам нужно отправлять данные для открытия/сохранения документа
|
||||
connections.push(conn);
|
||||
yield addPresence(ctx, conn, true);
|
||||
@ -2454,7 +2453,7 @@ exports.install = function(server, callbackFunction) {
|
||||
const docId = conn.docId;
|
||||
const tmpUser = conn.user;
|
||||
let hasForgotten;
|
||||
if (constants.CONN_CLOSED === conn.readyState) {
|
||||
if (constants.CONN_CLOSED === conn.conn.readyState) {
|
||||
//closing could happen during async action
|
||||
return false;
|
||||
}
|
||||
@ -2472,7 +2471,7 @@ exports.install = function(server, callbackFunction) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (constants.CONN_CLOSED === conn.readyState) {
|
||||
if (constants.CONN_CLOSED === conn.conn.readyState) {
|
||||
//closing could happen during async action
|
||||
return false;
|
||||
}
|
||||
@ -2489,7 +2488,7 @@ exports.install = function(server, callbackFunction) {
|
||||
}
|
||||
}
|
||||
|
||||
if (constants.CONN_CLOSED === conn.readyState) {
|
||||
if (constants.CONN_CLOSED === conn.conn.readyState) {
|
||||
//closing could happen during async action
|
||||
return false;
|
||||
}
|
||||
@ -2498,7 +2497,7 @@ exports.install = function(server, callbackFunction) {
|
||||
if (!bIsRestore && 2 === countNoView && !tmpUser.view) {
|
||||
// Ставим lock на документ
|
||||
const lockRes = yield editorData.lockAuth(ctx, docId, firstParticipantNoView.id, 2 * cfgExpLockDoc);
|
||||
if (constants.CONN_CLOSED === conn.readyState) {
|
||||
if (constants.CONN_CLOSED === conn.conn.readyState) {
|
||||
//closing could happen during async action
|
||||
return false;
|
||||
}
|
||||
@ -2512,7 +2511,7 @@ exports.install = function(server, callbackFunction) {
|
||||
yield* setLockDocumentTimer(ctx, docId, lockDocument.id);
|
||||
}
|
||||
}
|
||||
if (constants.CONN_CLOSED === conn.readyState) {
|
||||
if (constants.CONN_CLOSED === conn.conn.readyState) {
|
||||
//closing could happen during async action
|
||||
return false;
|
||||
}
|
||||
@ -2527,13 +2526,13 @@ exports.install = function(server, callbackFunction) {
|
||||
if (!bIsRestore && needSendChanges(conn)) {
|
||||
yield* sendAuthChanges(ctx, conn.docId, [conn]);
|
||||
}
|
||||
if (constants.CONN_CLOSED === conn.readyState) {
|
||||
if (constants.CONN_CLOSED === conn.conn.readyState) {
|
||||
//closing could happen during async action
|
||||
return false;
|
||||
}
|
||||
yield* sendAuthInfo(ctx, conn, bIsRestore, participantsMap, hasForgotten, opt_openedAt);
|
||||
}
|
||||
if (constants.CONN_CLOSED === conn.readyState) {
|
||||
if (constants.CONN_CLOSED === conn.conn.readyState) {
|
||||
//closing could happen during async action
|
||||
return false;
|
||||
}
|
||||
@ -3055,7 +3054,8 @@ exports.install = function(server, callbackFunction) {
|
||||
let rights = constants.RIGHTS.Edit;
|
||||
if (config.get('server.edit_singleton')) {
|
||||
// ToDo docId from url ?
|
||||
const docIdParsed = constants.DOC_ID_SOCKET_PATTERN.exec(conn.url);
|
||||
let handshake = conn.handshake;
|
||||
const docIdParsed = constants.DOC_ID_SOCKET_PATTERN.exec(handshake.url);
|
||||
if (docIdParsed && 1 < docIdParsed.length) {
|
||||
const participantsMap = yield getParticipantMap(ctx, docIdParsed[1]);
|
||||
for (let i = 0; i < participantsMap.length; ++i) {
|
||||
@ -3437,7 +3437,7 @@ exports.install = function(server, callbackFunction) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (constants.CONN_CLOSED === conn.readyState) {
|
||||
if (constants.CONN_CLOSED === conn.conn.readyState) {
|
||||
ctx.logger.error('expireDoc connection closed');
|
||||
}
|
||||
yield addPresence(ctx, conn, false);
|
||||
|
||||
Reference in New Issue
Block a user