diff --git a/.jshintignore b/.jshintignore index c9c5d3eb8..9d6d3c2fb 100644 --- a/.jshintignore +++ b/.jshintignore @@ -9,6 +9,7 @@ www/scratch www/common/toolbar.js www/common/hyperscript.js www/common/tippy.min.js +www/common/onlyoffice/* www/pad/wysiwygarea-plugin.js www/pad/mediatag-plugin.js @@ -17,3 +18,4 @@ www/pad/mediatag-plugin-dialog.js www/common/media-tag-nacl.min.js customize/ + diff --git a/ooserver.js b/ooserver.js index 7d1c1b3ef..f72cbeb2b 100644 --- a/ooserver.js +++ b/ooserver.js @@ -1,6 +1,7 @@ +/* jshint esversion: 6 */ const sockjs = require('sockjs'); -const co = require('co'); +var config; try { config = require('./config'); } catch (e) { @@ -9,109 +10,107 @@ try { } var origin = config.httpUnsafeOrigin || 'http://localhost:3000/'; -exports.install = function(server, callbackFunction) { -var sockjs_opts = {sockjs_url: ""}, -sockjs_echo = sockjs.createServer(sockjs_opts), -urlParse = new RegExp("^/common/onlyoffice/doc/([0-9-.a-zA-Z_=]*)/c.+", 'i'); +module.exports.install = function(server, callbackFunction) { + 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("Start ooserver"); + console.log("Port " + sockjs_echo.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}); -} + 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']); + } -sockjs_echo.on('connection', function(conn) { - console.log("ooserver in connection"); - if (null == conn) { - console.log("null == conn"); - return; + function sendData(conn, data) { + conn.write(JSON.stringify(data)); } - 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"); - return co(function* () { - try { - console.log("Received: " + message); - var data = JSON.parse(message); - switch (data.type) { - case 'auth': - console.log("Response auth"); - var fileUrl = origin + "oodoc/test.bin"; - 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; - } - } catch (e) { - console.log("error receiving response: docId = %s type = %s\r\n%s", docId, (data && data.type) ? data.type : 'null', e.stack); + //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.on('error', function() { - console.log("On error"); - }); - conn.on('close', function() { - return co(function* () { - console.log("On close"); - }); + 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); + 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; + } + } 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 + } + }); }); - 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); - }}); + sockjs_echo.installHandlers(server, {prefix: '/common/onlyoffice/doc/[0-9-.a-zA-Z_=]*/c', log: function(severity, message) { + console.log(message); + }}); - callbackFunction(); + callbackFunction(); }; diff --git a/package.json b/package.json index 369540a65..48b5b0c4d 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,6 @@ "stream-to-pull-stream": "^1.7.2", "tweetnacl": "~0.12.2", "ws": "^1.0.1", - "co": "^4.6.0", "sockjs": "^0.3.18" }, "devDependencies": { diff --git a/www/oocell/doc.js b/www/oocell/doc.js index fd9dca9ea..eb148a347 100644 --- a/www/oocell/doc.js +++ b/www/oocell/doc.js @@ -1,4 +1,5 @@ -config = { +/* globals DocsAPI */ +window.config = { "document": { "fileType": "xlsx", "key": "Khirz6zTPdfd7", @@ -26,8 +27,8 @@ config = { } console.log("in change (remote)"); }, - "onReady": function(evt) { console.log("in onReady"); }, - "onAppReady": function(evt) { console.log("in onAppReady"); }, + "onReady": function(/*evt*/) { console.log("in onReady"); }, + "onAppReady": function(/*evt*/) { console.log("in onAppReady"); }, } }; window.onbeforeunload = function () { @@ -35,6 +36,5 @@ window.onbeforeunload = function () { if (ifr) { ifr.remove(); } }; - -var docEditor = new DocsAPI.DocEditor("placeholder", config); +window.docEditor = new DocsAPI.DocEditor("placeholder", window.config); diff --git a/www/oodoc/doc.js b/www/oodoc/doc.js index d872c8ebe..316b80ba5 100644 --- a/www/oodoc/doc.js +++ b/www/oodoc/doc.js @@ -1,4 +1,5 @@ -config = { +/* globals DocsAPI */ +window.config = { "document": { "fileType": "docx", "key": "Khirz6zTPdfd7", @@ -13,12 +14,11 @@ config = { } }, "events": { - "onDocumentStateChange": function(evt) { console.log("in change"); }, - "onReady": function(evt) { console.log("in onReady"); } + "onDocumentStateChange": function (/* evt */) { console.log("in change"); }, + "onReady": function (/* evt */) { console.log("in onReady"); } } }; window.onbeforeunload = null; - -var docEditor = new DocsAPI.DocEditor("placeholder", config); +window.docEditor = new DocsAPI.DocEditor("placeholder", window.config); diff --git a/www/ooslide/doc.js b/www/ooslide/doc.js index 31cfad8e8..9bae6b275 100644 --- a/www/ooslide/doc.js +++ b/www/ooslide/doc.js @@ -1,4 +1,5 @@ -config = { +/* globals DocsAPI */ +window.config = { "document": { "fileType": "pptx", "key": "Khirz6zTPdfd7", @@ -13,12 +14,12 @@ config = { } }, "events": { - "onDocumentStateChange": function(evt) { console.log("in change"); }, - "onReady": function(evt) { console.log("in onReady"); } + "onDocumentStateChange": function (/* evt */) { console.log("in change"); }, + "onReady": function (/* evt */) { console.log("in onReady"); } } }; window.onbeforeunload = null; -var docEditor = new DocsAPI.DocEditor("placeholder", config); +window.docEditor = new DocsAPI.DocEditor("placeholder", window.config);