Skip to content

Commit

Permalink
[socket.io] Move from sockjs built-in properties to socketio
Browse files Browse the repository at this point in the history
  • Loading branch information
konovalovsergey committed Oct 27, 2022
1 parent 09fe41a commit 2f124fe
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Common/config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@
},
"socketio": {
"connection": {
"path": "/doc/socket.io/",
"path": "/doc/",
"serveClient": false,
"pingTimeout": 20000,
"pingInterval": 25000,
Expand Down
2 changes: 1 addition & 1 deletion Common/sources/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
3 changes: 2 additions & 1 deletion Common/sources/operationContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down
2 changes: 1 addition & 1 deletion Common/sources/tenantManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
5 changes: 3 additions & 2 deletions Common/sources/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
42 changes: 21 additions & 21 deletions DocService/sources/DocsCoServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -1329,8 +1330,6 @@ exports.install = function(server, callbackFunction) {
ctx.logger.info('io.use end');
next(checkJwtRes.decoded ? undefined : new Error("not authorized"));
}


});
});

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 2f124fe

Please sign in to comment.