From 5b84bc1a255ab28b8fbdebc619d80badabf80935 Mon Sep 17 00:00:00 2001 From: ansuz Date: Wed, 28 Feb 2018 18:15:01 +0100 Subject: [PATCH] simplify server --- ooserver.js | 34 ++++++++++++++++------------------ server.js | 4 ++-- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/ooserver.js b/ooserver.js index f72cbeb2b..9745321ac 100644 --- a/ooserver.js +++ b/ooserver.js @@ -10,13 +10,14 @@ try { } var origin = config.httpUnsafeOrigin || 'http://localhost:3000/'; -module.exports.install = function(server, callbackFunction) { +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 " + sockjs_echo.port); + console.log("Port " + port); function getBaseUrl(protocol, hostHeader, forwardedProtoHeader, forwardedHostHeader) { var url = ''; @@ -64,24 +65,21 @@ module.exports.install = function(server, callbackFunction) { try { console.log("Received: " + message); data = JSON.parse(message); - switch (data.type) { - case 'auth': - console.log("Response auth"); - var fileUrl = 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}}}); - break; - default: - break; + if (data.type !== 'auth') { return; } + console.log("Response auth"); + + var fileUrl = 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); diff --git a/server.js b/server.js index c28e05fbd..157482368 100644 --- a/server.js +++ b/server.js @@ -251,7 +251,7 @@ app.use(function (req, res, next) { var httpServer = httpsOpts ? Https.createServer(httpsOpts, app) : Http.createServer(app); /* Install sockjs websocket server */ -OOServer.install(httpServer, () => { +OOServer.install(httpServer, config.httpPort, () => { httpServer.listen(config.httpPort,config.httpAddress,function(){ var host = config.httpAddress; var hostName = !host.indexOf(':') ? '[' + host + ']' : host; @@ -264,7 +264,7 @@ OOServer.install(httpServer, () => { }); if (config.httpSafePort) { var safeHttpServer = Http.createServer(app).listen(config.httpSafePort, config.httpAddress); - OOServer.install(safeHttpServer, () => { + OOServer.install(safeHttpServer, config.httpSafePort, () => { }); }