I am trying to develop a plugin for DokuWiki that will enable real-time collaborative editing of wiki pages. I am using Node.js and ShareJS to do so, but I am having some trouble since it's the first time I am using them...
What I got so far is based on this and this pages.
ShareJS Server - http://localhost:3000
var express = require('express');
var app = express();
app.use(function(req, res, next) {
res.header('Access-Control-Allow-Origin', 'http://localhost:3000');
res.header('Access-Control-Allow-Methods', 'GET, OPTIONS');
res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization');
res.header('Access-Control-Allow-Credentials', true);
return next();
});
// public folder to store assets
app.use(express.static(__dirname + '/public'));
// get sharejs dependencies
var sharejs = require('share');
require('redis');
// options for sharejs
var options = {
db: {type: 'redis'},
browserChannel: { cors: "http://localhost/dokuwiki/" },
};
// attach the express server to sharejs
sharejs.server.attach(app, options);
// listen on port 3000 (for localhost) or the port defined for heroku
var port = process.env.PORT || 3000;
app.listen(port);
Which by the way outputs this warning when I run it:
DokuWiki
When editing a wiki page, say http://localhost/dokuwiki/doku.php?id=start&do=edit
, the plugin includes these scripts:
- http://localhost:3000/channel/bcsocket.js
- http://localhost:3000/share/share.js
- http://localhost:3000/share/textarea.js
And then executes this:
window.onload = function() {
// get dokuwiki editor textarea element
var pad = document.getElementById('wiki__text');
if (pad) { // if a wiki page is being edited
// Server options
var options = {
origin: "http://localhost:3000/channel"
};
// Connect to the server
var connection = sharejs.open('test', 'text', options, function(error, doc) {
doc.attach_textarea(pad);
});
}
};
Which lead to the following errors on the DokuWiki page editor:
What am I missing? Thanks in advance!
Managed to solve it! :) The DeprecationWarning is still there and I don't know why, but it's working now.
All it took was editing the ShareJS Server code:
Removed the
browserChannel: { cors: "http://localhost/dokuwiki/" },
line from the ShareJS optionsTweaked with the Access-Control-Allow-Origin middleware
Here's the "final" ShareJS Server code:
And that's it! Now I just need to edit this code a bit more to make different wiki pages have different ShareJS textareas.