|
|
@ -1,6 +1,7 @@
|
|
|
|
|
|
|
|
/* jshint esversion: 6 */
|
|
|
|
|
|
|
|
|
|
|
|
const sockjs = require('sockjs');
|
|
|
|
const sockjs = require('sockjs');
|
|
|
|
const co = require('co');
|
|
|
|
var config;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
config = require('./config');
|
|
|
|
config = require('./config');
|
|
|
|
} catch (e) {
|
|
|
|
} catch (e) {
|
|
|
@ -9,109 +10,107 @@ try {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var origin = config.httpUnsafeOrigin || 'http://localhost:3000/';
|
|
|
|
var origin = config.httpUnsafeOrigin || 'http://localhost:3000/';
|
|
|
|
|
|
|
|
|
|
|
|
exports.install = function(server, callbackFunction) {
|
|
|
|
module.exports.install = function(server, callbackFunction) {
|
|
|
|
var sockjs_opts = {sockjs_url: ""},
|
|
|
|
var sockjs_opts = {sockjs_url: ""},
|
|
|
|
sockjs_echo = sockjs.createServer(sockjs_opts),
|
|
|
|
sockjs_echo = sockjs.createServer(sockjs_opts);
|
|
|
|
urlParse = new RegExp("^/common/onlyoffice/doc/([0-9-.a-zA-Z_=]*)/c.+", 'i');
|
|
|
|
//urlParse = new RegExp("^/common/onlyoffice/doc/([0-9-.a-zA-Z_=]*)/c.+", 'i');
|
|
|
|
|
|
|
|
|
|
|
|
console.log("Start ooserver");
|
|
|
|
console.log("Start ooserver");
|
|
|
|
console.log("Port " + sockjs_echo.port);
|
|
|
|
console.log("Port " + sockjs_echo.port);
|
|
|
|
|
|
|
|
|
|
|
|
function getBaseUrl(protocol, hostHeader, forwardedProtoHeader, forwardedHostHeader) {
|
|
|
|
function getBaseUrl(protocol, hostHeader, forwardedProtoHeader, forwardedHostHeader) {
|
|
|
|
var url = '';
|
|
|
|
var url = '';
|
|
|
|
if (forwardedProtoHeader) {
|
|
|
|
if (forwardedProtoHeader) {
|
|
|
|
url += forwardedProtoHeader;
|
|
|
|
url += forwardedProtoHeader;
|
|
|
|
} else if (protocol) {
|
|
|
|
} else if (protocol) {
|
|
|
|
url += protocol;
|
|
|
|
url += protocol;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
url += 'http';
|
|
|
|
url += 'http';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
url += '://';
|
|
|
|
url += '://';
|
|
|
|
if (forwardedHostHeader) {
|
|
|
|
if (forwardedHostHeader) {
|
|
|
|
url += forwardedHostHeader;
|
|
|
|
url += forwardedHostHeader;
|
|
|
|
} else if (hostHeader) {
|
|
|
|
} else if (hostHeader) {
|
|
|
|
url += hostHeader;
|
|
|
|
url += hostHeader;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
url += origin.slice(0, -1);
|
|
|
|
url += origin.slice(0, -1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return url;
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function getBaseUrlByConnection(conn) {
|
|
|
|
function getBaseUrlByConnection(conn) {
|
|
|
|
return getBaseUrl('', conn.headers['host'], conn.headers['x-forwarded-proto'], conn.headers['x-forwarded-host']);
|
|
|
|
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) {
|
|
|
|
function sendData(conn, data) {
|
|
|
|
console.log("ooserver in connection");
|
|
|
|
conn.write(JSON.stringify(data));
|
|
|
|
if (null == conn) {
|
|
|
|
|
|
|
|
console.log("null == conn");
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
conn.baseUrl = getBaseUrlByConnection(conn);
|
|
|
|
//function sendDataWarning(conn, msg) { sendData(conn, {type: "warning", message: msg}); }
|
|
|
|
console.log("BaseUrl: " + conn.baseUrl);
|
|
|
|
//function sendDataMessage(conn, msg) { sendData(conn, {type: "message", messages: msg}); }
|
|
|
|
conn.sessionIsSendWarning = false;
|
|
|
|
|
|
|
|
conn.sessionTimeConnect = conn.sessionTimeLastAction = new Date().getTime();
|
|
|
|
sockjs_echo.on('connection', function(conn) {
|
|
|
|
console.log("ooserver setting handlers");
|
|
|
|
console.log("ooserver in connection");
|
|
|
|
conn.on('data', function(message) {
|
|
|
|
if (null === conn) {
|
|
|
|
console.log("In data");
|
|
|
|
console.log("null == conn");
|
|
|
|
return co(function* () {
|
|
|
|
return;
|
|
|
|
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);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
conn.baseUrl = getBaseUrlByConnection(conn);
|
|
|
|
});
|
|
|
|
console.log("BaseUrl: " + conn.baseUrl);
|
|
|
|
conn.on('error', function() {
|
|
|
|
conn.sessionIsSendWarning = false;
|
|
|
|
console.log("On error");
|
|
|
|
conn.sessionTimeConnect = conn.sessionTimeLastAction = new Date().getTime();
|
|
|
|
});
|
|
|
|
console.log("ooserver setting handlers");
|
|
|
|
conn.on('close', function() {
|
|
|
|
conn.on('data', function(message) {
|
|
|
|
return co(function* () {
|
|
|
|
console.log("In data");
|
|
|
|
console.log("On close");
|
|
|
|
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) {
|
|
|
|
sockjs_echo.installHandlers(server, {prefix: '/common/onlyoffice/doc/[0-9-.a-zA-Z_=]*/c', log: function(severity, message) {
|
|
|
|
console.log(message);
|
|
|
|
console.log(message);
|
|
|
|
}});
|
|
|
|
}});
|
|
|
|
|
|
|
|
|
|
|
|
callbackFunction();
|
|
|
|
callbackFunction();
|
|
|
|
};
|
|
|
|
};
|
|
|
|