diff --git a/ooserver.js b/ooserver.js deleted file mode 100644 index 78bb5a031..000000000 --- a/ooserver.js +++ /dev/null @@ -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(); -}; diff --git a/package.json b/package.json index 0292c2254..b6456cf4c 100644 --- a/package.json +++ b/package.json @@ -18,8 +18,7 @@ "sortify": "^1.0.4", "stream-to-pull-stream": "^1.7.2", "tweetnacl": "~0.12.2", - "ws": "^1.0.1", - "sockjs": "^0.3.18" + "ws": "^1.0.1" }, "devDependencies": { "flow-bin": "^0.59.0", diff --git a/server.js b/server.js index e1d70e1db..f36b17677 100644 --- a/server.js +++ b/server.js @@ -9,7 +9,6 @@ var WebSocketServer = require('ws').Server; var NetfluxSrv = require('./node_modules/chainpad-server/NetfluxWebsocketSrv'); var Package = require('./package.json'); var Path = require("path"); -var OOServer = require('./ooserver.js'); var nThen = require("nthen"); var config; @@ -201,8 +200,8 @@ var send404 = function (res, path) { }); }; -/* SPECIAL CODE FOR ONLYOFFICE -/* Font support as onlyoffice requires fonts transformed to js */ +/* SPECIAL CODE FOR ONLYOFFICE +/* Font support as onlyoffice requires fonts transformed to js */ var FONT_OBFUSCATION_MAGIC = new Buffer([ 0xA0, 0x66, 0xD6, 0x20, 0x14, 0x96, 0x47, 0xfa, 0x95, 0x69, 0xB8, 0x50, 0xB0, 0x41, 0x49, 0x48 ]); @@ -218,7 +217,7 @@ var FONT_NAME_MAP = {}; }); }); -/* Code to automatically transform font to js */ +/* Code to automatically transform font to js */ /* Currently not active, but might be necessary */ app.use("/common/onlyoffice/fonts/odttf/:name", function (req, res) { var name = req.params.name.replace(/\.js$/, '').toLowerCase(); @@ -257,22 +256,17 @@ app.use(function (req, res, next) { var httpServer = httpsOpts ? Https.createServer(httpsOpts, app) : Http.createServer(app); -/* Install sockjs websocket server */ -//OOServer.install(httpServer, config.httpPort, () => { - httpServer.listen(config.httpPort,config.httpAddress,function(){ - var host = config.httpAddress; - var hostName = !host.indexOf(':') ? '[' + host + ']' : host; +httpServer.listen(config.httpPort,config.httpAddress,function(){ + var host = config.httpAddress; + var hostName = !host.indexOf(':') ? '[' + host + ']' : host; - var port = config.httpPort; - var ps = port === 80? '': ':' + port; + var port = config.httpPort; + 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) { - var safeHttpServer = Http.createServer(app).listen(config.httpSafePort, config.httpAddress); - //OOServer.install(safeHttpServer, config.httpSafePort, () => { - //}); + Http.createServer(app).listen(config.httpSafePort, config.httpAddress); } var wsConfig = { server: httpServer };