Remove sockjs dependency and ooserver code

pull/1/head
yflory 6 years ago
parent a66d8c1384
commit 29f8cfbfe0

@ -1,120 +0,0 @@
/* jshint esversion: 6 */
const sockjs = require('sockjs');
var config;
try {
config = require('./config');
} catch (e) {
console.log("You can customize the configuration by copying config.example.js to config.js");
config = require('./config.example');
}
var origin = config.httpUnsafeOrigin || 'http://localhost:3000/';
module.exports.install = function(server, port, callbackFunction) {
console.log();
var sockjs_opts = {sockjs_url: ""},
sockjs_echo = sockjs.createServer(sockjs_opts);
//urlParse = new RegExp("^/common/onlyoffice/doc/([0-9-.a-zA-Z_=]*)/c.+", 'i');
console.log("Start ooserver");
console.log("Port " + port);
function getBaseUrl(protocol, hostHeader, forwardedProtoHeader, forwardedHostHeader) {
var url = '';
if (forwardedProtoHeader) {
url += forwardedProtoHeader;
} else if (protocol) {
url += protocol;
} else {
url += 'http';
}
url += '://';
if (forwardedHostHeader) {
url += forwardedHostHeader;
} else if (hostHeader) {
url += hostHeader;
} else {
url += origin.slice(0, -1);
}
return url;
}
function getBaseUrlByConnection(conn) {
return getBaseUrl('', conn.headers['host'], conn.headers['x-forwarded-proto'], conn.headers['x-forwarded-host']);
}
function sendData(conn, data) {
conn.write(JSON.stringify(data));
}
//function sendDataWarning(conn, msg) { sendData(conn, {type: "warning", message: msg}); }
//function sendDataMessage(conn, msg) { sendData(conn, {type: "message", messages: msg}); }
sockjs_echo.on('connection', function(conn) {
console.log("ooserver in connection");
if (null === conn) {
console.log("null == conn");
return;
}
conn.baseUrl = getBaseUrlByConnection(conn);
console.log("BaseUrl: " + conn.baseUrl);
conn.sessionIsSendWarning = false;
conn.sessionTimeConnect = conn.sessionTimeLastAction = new Date().getTime();
console.log("ooserver setting handlers");
conn.on('data', function(message) {
console.log("In data");
var data;
try {
console.log("Received: " + message);
data = JSON.parse(message);
if (data.type === "isSaveLock") {
//return void sendData(conn, {type: "saveLock", saveLock: false});
}
if (data.type === "saveChanges") {
//return void sendData(conn, {type: 'savePartChanges', changesIndex: 0});
}
if (data.type !== 'auth') { return; }
console.log("Response auth");
var fileUrl = data.openCmd.url;//origin + "oodoc/test.bin";
/*if (data.openCmd) {
if (data.openCmd.format === "xlsx") {
fileUrl = origin + "oocell/test.bin";
} else if (data.openCmd.format === "pptx") {
fileUrl = origin + "ooslide/test.bin";
}
}*/
sendData(conn, {"type":"auth","result":1,"sessionId":"08e77705-dc5c-477d-b73a-b1a7cbca1e9b","sessionTimeConnect":1494226099270,"participants":[]});
sendData(conn, {"type":"documentOpen","data":{"type":"open","status":"ok","data":{"Editor.bin":fileUrl}}});
} catch (e) {
console.error(e);
//console.log("error receiving response: docId = %s type = %s\r\n%s", docId, (data && data.type) ? data.type : 'null', e.stack);
}
});
conn.on('error', function() {
console.log("On error");
});
conn.on('close', function() {
console.log("On close");
});
console.log("ooserver sending welcome message");
sendData(conn, {
type: 'license',
license: {
type: 3,
light: false,
trial: false,
rights: 1,
buildVersion: "4.3.3",
buildNumber: 4,
branding: false
}
});
});
sockjs_echo.installHandlers(server, {prefix: '/common/onlyoffice/doc/[0-9-.a-zA-Z_=]*/c', log: function(severity, message) {
console.log(message);
}});
callbackFunction();
};

@ -18,8 +18,7 @@
"sortify": "^1.0.4", "sortify": "^1.0.4",
"stream-to-pull-stream": "^1.7.2", "stream-to-pull-stream": "^1.7.2",
"tweetnacl": "~0.12.2", "tweetnacl": "~0.12.2",
"ws": "^1.0.1", "ws": "^1.0.1"
"sockjs": "^0.3.18"
}, },
"devDependencies": { "devDependencies": {
"flow-bin": "^0.59.0", "flow-bin": "^0.59.0",

@ -9,7 +9,6 @@ var WebSocketServer = require('ws').Server;
var NetfluxSrv = require('./node_modules/chainpad-server/NetfluxWebsocketSrv'); var NetfluxSrv = require('./node_modules/chainpad-server/NetfluxWebsocketSrv');
var Package = require('./package.json'); var Package = require('./package.json');
var Path = require("path"); var Path = require("path");
var OOServer = require('./ooserver.js');
var nThen = require("nthen"); var nThen = require("nthen");
var config; var config;
@ -257,9 +256,7 @@ app.use(function (req, res, next) {
var httpServer = httpsOpts ? Https.createServer(httpsOpts, app) : Http.createServer(app); var httpServer = httpsOpts ? Https.createServer(httpsOpts, app) : Http.createServer(app);
/* Install sockjs websocket server */ httpServer.listen(config.httpPort,config.httpAddress,function(){
//OOServer.install(httpServer, config.httpPort, () => {
httpServer.listen(config.httpPort,config.httpAddress,function(){
var host = config.httpAddress; var host = config.httpAddress;
var hostName = !host.indexOf(':') ? '[' + host + ']' : host; var hostName = !host.indexOf(':') ? '[' + host + ']' : host;
@ -267,12 +264,9 @@ var httpServer = httpsOpts ? Https.createServer(httpsOpts, app) : Http.createSer
var ps = port === 80? '': ':' + port; var ps = port === 80? '': ':' + port;
console.log('\n[%s] server available http://%s%s', new Date().toISOString(), hostName, ps); console.log('\n[%s] server available http://%s%s', new Date().toISOString(), hostName, ps);
}); });
//});
if (config.httpSafePort) { if (config.httpSafePort) {
var safeHttpServer = Http.createServer(app).listen(config.httpSafePort, config.httpAddress); Http.createServer(app).listen(config.httpSafePort, config.httpAddress);
//OOServer.install(safeHttpServer, config.httpSafePort, () => {
//});
} }
var wsConfig = { server: httpServer }; var wsConfig = { server: httpServer };

Loading…
Cancel
Save