Thanks in no small measure to Maxim, I have a local server running and today, I have a working prototype.
However, when I try to install the same plugin on our server, it does not show up. Can't figure out why.
My plugin's source is:
Code: Select all
(function (window, undefined) {
window.Asc.plugin.init = function () {
function script () {
try {
console.log(`adding Tag "${window.Asc.addTag}"`);
var oTagDocument = Api.GetDocument();
oTagDocument.CreateNewHistoryPoint();
oParagraph = Api.CreateParagraph();
oParagraph.AddText(window.Asc.addTag);
oTagDocument.InsertContent([oParagraph]);
} catch (e) {
console.error(e)
}
}
const sScript = script.toString()
.replace(/^\s*function\s+script\s*\(\)\s*\{\s+/m, '')
.replace(/\s*\}\s*$/m,'')
console.log(sScript)
window.Asc.plugin.info.recalculate = true;
this.executeCommand("close", sScript);
};
window.Asc.plugin.button = function (id) {
};
})(window, undefined);
Code: Select all
window.addEventListener("message", receiveMessage, {captive: true, passive: true})
function receiveMessage (event) {
console.log(window.Asc, event)
let o
try {
o = JSON.parse(event.data)
} catch (e) {
console.warn(e)
o = {}
}
o.raw = event.data
if(o.type !== 'addTag')
return
o.tag? window.Asc.addTag = o.tag: triggerAddTag()
}
function triggerAddTag () { // assumes only 1 plugin is installed
$('.item-plugins').click()
}
Code: Select all
document.querySelector('iframe').contentWindow.postMessage(JSON.stringify({type: 'addTag', tag: 'hi mom!'}), '*')
document.querySelector('iframe').contentWindow.postMessage(JSON.stringify({type: 'addTag'}), '*')
We realize that we will have to publish the code changes snce we are changing app.js .. but we're just fine with that.
However, on the server, documentServer is not running via docker, it is a direct installation (with /var/www/onlyoffice being the install path).
Under /var/www/onlyoffice/documentserver there was no `sdkjs-plugins` directory for some reason, so I created it. I put my plugin and the pluginsbase file in there:
Code: Select all
ubuntu@wbf:~$ ls -la /var/www/onlyoffice/documentserver/sdkjs-plugins/
total 40
drwxr-xr-x 3 onlyoffice onlyoffice 4096 Oct 4 17:15 .
drwxr-xr-x 6 onlyoffice onlyoffice 4096 Sep 7 00:21 ..
drwxr-xr-x 2 onlyoffice onlyoffice 4096 Oct 4 17:07 addTag
-rw-r--r-- 1 onlyoffice onlyoffice 27532 Oct 4 17:07 pluginBase.js
ubuntu@wbf:~$ ls -la /var/www/onlyoffice/documentserver/sdkjs-plugins/addTag/
total 56
drwxr-xr-x 2 onlyoffice onlyoffice 4096 Oct 4 17:07 .
drwxr-xr-x 3 onlyoffice onlyoffice 4096 Oct 4 17:15 ..
-rw-r--r-- 1 onlyoffice onlyoffice 785 Oct 4 17:07 code.js
-rw-r--r-- 1 onlyoffice onlyoffice 714 Oct 4 17:07 config.json
-rw-r--r-- 1 onlyoffice onlyoffice 2754 Oct 4 17:07 icon@2x.png
-rw-r--r-- 1 onlyoffice onlyoffice 2754 Oct 4 17:07 icon.png
-rw-r--r-- 1 onlyoffice onlyoffice 246 Oct 4 17:07 index.html
Code: Select all
ubuntu@wbf:~$ find /var/www/onlyoffice -name app.js -ls
//...
872242 1436 -rw-r--r-- 1 onlyoffice onlyoffice 1468815 Oct 4 17:09 /var/www/onlyoffice/documentserver/web-apps/apps/documenteditor/main/app.js
//...
So, looking at the configurations:
Code: Select all
ubuntu@wbf:~$ ls -la /etc/onlyoffice/documentserver
total 36
drwxr-xr-x 3 root root 4096 Oct 4 17:22 .
drwxr-xr-x 3 root root 4096 Aug 7 13:19 ..
-rw-r--r-- 1 root root 4288 Aug 26 20:10 default.json
-rw-r--r-- 1 root root 1121 Aug 7 13:19 development-mac.json
-rw-r--r-- 1 root root 1143 Aug 7 13:19 development-windows.json
drwxr-xr-x 2 root root 4096 Aug 7 13:19 log4js
-rw-r--r-- 1 root root 1501 Aug 7 13:19 production-linux.json
-rw-r--r-- 1 root root 1167 Aug 7 13:19 production-windows.json
Code: Select all
"services": {
"CoAuthoring": {
"server": {
"sockjsUrl": "/web-apps/vendor/sockjs/sockjs.min.js",
"static_content": {
"/sdkjs": {
"path": "/var/www/onlyoffice/documentserver/sdkjs",
"options": {"maxAge": "7d"}
},
"/web-apps": {
"path": "/var/www/onlyoffice/documentserver/web-apps",
"options": {"maxAge": "7d"}
},
"/welcome": {
"path": "/var/www/onlyoffice/documentserver/server/welcome",
"options": {"maxAge": "7d"}
},
"/sdkjs-plugins": {
Code: Select all
"services": {
"CoAuthoring": {
"server": {
"port": 8000,
"workerpercpu": 1,
//...going on
},
"token": {
"enable": {
"browser": false,
"request": {
"inbox": false,
"outbox": false
}
},
"inbox": {
"header": "Authorization",
"prefix": "Bearer "
},
"outbox": {
"header": "Authorization",
//... encryption configuration removed for this post
},
"session": {
//...
}
},
"plugins": {
"uri": "/sdkjs-plugins"
}