|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
/* jshint esversion: 6 */
|
|
|
|
|
|
|
|
|
|
const sockjs = require('sockjs');
|
|
|
|
|
const co = require('co');
|
|
|
|
|
var config;
|
|
|
|
|
try {
|
|
|
|
|
config = require('./config');
|
|
|
|
|
} catch (e) {
|
|
|
|
@ -9,10 +10,10 @@ try {
|
|
|
|
|
}
|
|
|
|
|
var origin = config.httpUnsafeOrigin || 'http://localhost:3000/';
|
|
|
|
|
|
|
|
|
|
exports.install = function(server, callbackFunction) {
|
|
|
|
|
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');
|
|
|
|
|
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);
|
|
|
|
@ -43,16 +44,12 @@ function getBaseUrlByConnection(conn) {
|
|
|
|
|
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 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) {
|
|
|
|
|
if (null === conn) {
|
|
|
|
|
console.log("null == conn");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
@ -63,18 +60,22 @@ sockjs_echo.on('connection', function(conn) {
|
|
|
|
|
console.log("ooserver setting handlers");
|
|
|
|
|
conn.on('data', function(message) {
|
|
|
|
|
console.log("In data");
|
|
|
|
|
return co(function* () {
|
|
|
|
|
var data;
|
|
|
|
|
try {
|
|
|
|
|
console.log("Received: " + message);
|
|
|
|
|
var data = JSON.parse(message);
|
|
|
|
|
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"
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
@ -82,18 +83,16 @@ sockjs_echo.on('connection', function(conn) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.log("error receiving response: docId = %s type = %s\r\n%s", docId, (data && data.type) ? data.type : 'null', e.stack);
|
|
|
|
|
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() {
|
|
|
|
|
return co(function* () {
|
|
|
|
|
console.log("On close");
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
console.log("ooserver sending welcome message");
|
|
|
|
|
sendData(conn, {
|
|
|
|
|
type: 'license',
|
|
|
|
|