Merge branch 'beta' of github.com:xwiki-labs/cryptpad into beta
This commit is contained in:
commit
22cf18f78c
@ -10,7 +10,7 @@ module.exports = {
|
|||||||
// the port on which your httpd will listen
|
// the port on which your httpd will listen
|
||||||
httpPort: 3000,
|
httpPort: 3000,
|
||||||
// the port used for websockets
|
// the port used for websockets
|
||||||
websocketPort: 3001,
|
websocketPort: 3000,
|
||||||
|
|
||||||
// You now have a choice of storage engines
|
// You now have a choice of storage engines
|
||||||
|
|
||||||
@ -19,7 +19,7 @@ module.exports = {
|
|||||||
* it will not scale well if your server stays alive for a long time.
|
* it will not scale well if your server stays alive for a long time.
|
||||||
* but it is completely dependency free
|
* but it is completely dependency free
|
||||||
*/
|
*/
|
||||||
storage: './storage/amnesia',
|
//storage: './storage/amnesia',
|
||||||
|
|
||||||
/* the 'lvl' storage module uses leveldb
|
/* the 'lvl' storage module uses leveldb
|
||||||
* it persists, and will perform better than amnesiadb
|
* it persists, and will perform better than amnesiadb
|
||||||
@ -31,8 +31,8 @@ module.exports = {
|
|||||||
*
|
*
|
||||||
* to delete all pads, run `rm -rf $YOUR_DB`
|
* to delete all pads, run `rm -rf $YOUR_DB`
|
||||||
*/
|
*/
|
||||||
// storage: './storage/lvl',
|
storage: './storage/lvl',
|
||||||
// levelPath: './test.level.db'
|
levelPath: './test.level.db'
|
||||||
|
|
||||||
/* mongo is the original storage engine for cryptpad
|
/* mongo is the original storage engine for cryptpad
|
||||||
* it has been more thoroughly tested, but requires a little more setup
|
* it has been more thoroughly tested, but requires a little more setup
|
||||||
|
|||||||
@ -18,6 +18,7 @@ module.exports.create = function(conf, cb){
|
|||||||
|
|
||||||
var db=[],
|
var db=[],
|
||||||
index=0;
|
index=0;
|
||||||
|
|
||||||
cb({
|
cb({
|
||||||
message: function(channelName, content, cb){
|
message: function(channelName, content, cb){
|
||||||
var val = {
|
var val = {
|
||||||
@ -27,17 +28,18 @@ module.exports.create = function(conf, cb){
|
|||||||
time: new Date().getTime(),
|
time: new Date().getTime(),
|
||||||
};
|
};
|
||||||
db.push(val);
|
db.push(val);
|
||||||
cb();
|
if (cb) { cb(); }
|
||||||
},
|
},
|
||||||
getMessages: function(channelName, cb){
|
getMessages: function(channelName, handler, cb){
|
||||||
db.sort(function(a,b){
|
db.sort(function(a,b){
|
||||||
return a.id - b.id;
|
return a.id - b.id;
|
||||||
});
|
});
|
||||||
db.filter(function(val){
|
db.filter(function(val){
|
||||||
return val.chan === channelName;
|
return val.chan === channelName;
|
||||||
}).forEach(function(doc){
|
}).forEach(function(doc){
|
||||||
cb(doc.msg);
|
handler(doc.msg);
|
||||||
});
|
});
|
||||||
|
if (cb) { cb(); }
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@ -4,7 +4,7 @@ require.config({ paths: {
|
|||||||
|
|
||||||
define([
|
define([
|
||||||
'/api/config?cb=' + Math.random().toString(16).substring(2),
|
'/api/config?cb=' + Math.random().toString(16).substring(2),
|
||||||
'/common/RealtimeTextarea.js',
|
'/common/realtime-input.js',
|
||||||
'/common/messages.js',
|
'/common/messages.js',
|
||||||
'/common/crypto.js',
|
'/common/crypto.js',
|
||||||
'/common/TextPatcher.js',
|
'/common/TextPatcher.js',
|
||||||
@ -17,12 +17,15 @@ define([
|
|||||||
var $ = module.$ = window.jQuery;
|
var $ = module.$ = window.jQuery;
|
||||||
var Fabric = module.Fabric = window.fabric;
|
var Fabric = module.Fabric = window.fabric;
|
||||||
|
|
||||||
$(window).on('hashchange', function() {
|
|
||||||
window.location.reload();
|
var key;
|
||||||
});
|
var channel = '';
|
||||||
if (window.location.href.indexOf('#') === -1) {
|
if (!/#/.test(window.location.href)) {
|
||||||
window.location.href = window.location.href + '#' + Crypto.genKey();
|
key = Crypto.genKey();
|
||||||
return;
|
} else {
|
||||||
|
var hash = window.location.hash.slice(1);
|
||||||
|
channel = hash.slice(0, 32);
|
||||||
|
key = hash.slice(32);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialize Fabric */
|
/* Initialize Fabric */
|
||||||
@ -56,17 +59,23 @@ define([
|
|||||||
$canvas.css('border-color', bool? 'black': 'red');
|
$canvas.css('border-color', bool? 'black': 'red');
|
||||||
};
|
};
|
||||||
|
|
||||||
var key = Crypto.parseKey(window.location.hash.substring(1));
|
|
||||||
var initializing = true;
|
var initializing = true;
|
||||||
|
|
||||||
var config = module.config = {
|
var config = module.config = {
|
||||||
websocketURL: Config.websocketURL + '_old',
|
// TODO initialState ?
|
||||||
|
websocketURL: Config.websocketURL,
|
||||||
userName: Crypto.rand64(8),
|
userName: Crypto.rand64(8),
|
||||||
channel: key.channel,
|
channel: channel,
|
||||||
cryptKey: key.cryptKey
|
cryptKey: key,
|
||||||
|
crypto: Crypto,
|
||||||
};
|
};
|
||||||
|
|
||||||
var onInit = config.onInit = function (info) { };
|
var onInit = config.onInit = function (info) {
|
||||||
|
window.location.hash = info.channel + key;
|
||||||
|
$(window).on('hashchange', function() {
|
||||||
|
window.location.reload();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
var onRemote = config.onRemote = function () {
|
var onRemote = config.onRemote = function () {
|
||||||
if (initializing) { return; }
|
if (initializing) { return; }
|
||||||
|
|||||||
@ -1,207 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2014 XWiki SAS
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
define([
|
|
||||||
'/common/messages.js',
|
|
||||||
'/bower_components/reconnectingWebsocket/reconnecting-websocket.js',
|
|
||||||
'/common/crypto.js',
|
|
||||||
'/common/chainpad.js',
|
|
||||||
'/bower_components/jquery/dist/jquery.min.js',
|
|
||||||
], function (Messages, ReconnectingWebSocket, Crypto) {
|
|
||||||
var $ = window.jQuery;
|
|
||||||
var ChainPad = window.ChainPad;
|
|
||||||
var PARANOIA = true;
|
|
||||||
var module = { exports: {} };
|
|
||||||
|
|
||||||
/**
|
|
||||||
* If an error is encountered but it is recoverable, do not immediately fail
|
|
||||||
* but if it keeps firing errors over and over, do fail.
|
|
||||||
*/
|
|
||||||
var MAX_RECOVERABLE_ERRORS = 15;
|
|
||||||
|
|
||||||
/** Maximum number of milliseconds of lag before we fail the connection. */
|
|
||||||
var MAX_LAG_BEFORE_DISCONNECT = 20000;
|
|
||||||
|
|
||||||
var warn = function (x) { console.error(x); };
|
|
||||||
|
|
||||||
/* websocket stuff */
|
|
||||||
var isSocketDisconnected = function (socket, realtime) {
|
|
||||||
var sock = socket._socket;
|
|
||||||
return sock.readyState === sock.CLOSING
|
|
||||||
|| sock.readyState === sock.CLOSED
|
|
||||||
|| (realtime.getLag().waiting && realtime.getLag().lag > MAX_LAG_BEFORE_DISCONNECT);
|
|
||||||
};
|
|
||||||
|
|
||||||
// this differs from other functions with similar names in that
|
|
||||||
// you are expected to pass a socket into it.
|
|
||||||
var checkSocket = function (socket) {
|
|
||||||
if (isSocketDisconnected(socket, socket.realtime) &&
|
|
||||||
!socket.intentionallyClosing) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// TODO before removing websocket implementation
|
|
||||||
// bind abort to onLeaving
|
|
||||||
var abort = function (socket, realtime) {
|
|
||||||
realtime.abort();
|
|
||||||
try { socket._socket.close(); } catch (e) { warn(e); }
|
|
||||||
};
|
|
||||||
|
|
||||||
var makeWebsocket = function (url) {
|
|
||||||
var socket = new ReconnectingWebSocket(url);
|
|
||||||
var out = {
|
|
||||||
onOpen: [],
|
|
||||||
onClose: [],
|
|
||||||
onError: [],
|
|
||||||
onMessage: [],
|
|
||||||
send: function (msg) { socket.send(msg); },
|
|
||||||
close: function () { socket.close(); },
|
|
||||||
_socket: socket
|
|
||||||
};
|
|
||||||
var mkHandler = function (name) {
|
|
||||||
return function (evt) {
|
|
||||||
for (var i = 0; i < out[name].length; i++) {
|
|
||||||
if (out[name][i](evt) === false) {
|
|
||||||
console.log(name +"Handler");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
};
|
|
||||||
socket.onopen = mkHandler('onOpen');
|
|
||||||
socket.onclose = mkHandler('onClose');
|
|
||||||
socket.onerror = mkHandler('onError');
|
|
||||||
socket.onmessage = mkHandler('onMessage');
|
|
||||||
return out;
|
|
||||||
};
|
|
||||||
/* end websocket stuff */
|
|
||||||
|
|
||||||
var start = module.exports.start = function (config) {
|
|
||||||
|
|
||||||
var websocketUrl = config.websocketURL;
|
|
||||||
var userName = config.userName;
|
|
||||||
var channel = config.channel;
|
|
||||||
var cryptKey = config.cryptKey;
|
|
||||||
var passwd = 'y';
|
|
||||||
|
|
||||||
var toReturn = {};
|
|
||||||
|
|
||||||
var socket = makeWebsocket(websocketUrl);
|
|
||||||
|
|
||||||
var allMessages = [];
|
|
||||||
var isErrorState = false;
|
|
||||||
var initializing = true;
|
|
||||||
var recoverableErrorCount = 0;
|
|
||||||
|
|
||||||
socket.onOpen.push(function (evt) {
|
|
||||||
var realtime = socket.realtime = ChainPad.create(userName,
|
|
||||||
passwd,
|
|
||||||
channel,
|
|
||||||
config.initialState || '',
|
|
||||||
{
|
|
||||||
transformFunction: config.transformFunction
|
|
||||||
});
|
|
||||||
|
|
||||||
if (config.onInit) {
|
|
||||||
// extend as you wish
|
|
||||||
config.onInit({
|
|
||||||
realtime: realtime
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
realtime.onUserListChange(function (userList) {
|
|
||||||
if (!initializing || userList.indexOf(userName) === -1) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// if we spot ourselves being added to the document, we'll switch
|
|
||||||
// 'initializing' off because it means we're fully synced.
|
|
||||||
initializing = false;
|
|
||||||
|
|
||||||
// execute an onReady callback if one was supplied
|
|
||||||
// pass an object so we can extend this later
|
|
||||||
if (config.onReady) {
|
|
||||||
// extend as you wish
|
|
||||||
config.onReady({
|
|
||||||
userList: userList,
|
|
||||||
realtime: realtime
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// when you receive a message...
|
|
||||||
socket.onMessage.push(function (evt) {
|
|
||||||
if (isErrorState) { return; }
|
|
||||||
|
|
||||||
var message = Crypto.decrypt(evt.data, cryptKey);
|
|
||||||
allMessages.push(message);
|
|
||||||
|
|
||||||
// super important step that avoids us having
|
|
||||||
// the 'backspace bug'
|
|
||||||
if (config.onLocal) {
|
|
||||||
config.onLocal();
|
|
||||||
}
|
|
||||||
|
|
||||||
realtime.message(message);
|
|
||||||
});
|
|
||||||
|
|
||||||
// when you receive a patch
|
|
||||||
realtime.onPatch(function () {
|
|
||||||
if (config.onRemote) {
|
|
||||||
config.onRemote({
|
|
||||||
realtime: realtime
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// when a message is ready to send
|
|
||||||
realtime.onMessage(function (message) {
|
|
||||||
if (isErrorState) { return; }
|
|
||||||
message = Crypto.encrypt(message, cryptKey);
|
|
||||||
try {
|
|
||||||
socket.send(message);
|
|
||||||
} catch (e) {
|
|
||||||
warn(e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
var socketChecker = setInterval(function () {
|
|
||||||
if (checkSocket(socket)) {
|
|
||||||
warn("Socket disconnected!");
|
|
||||||
|
|
||||||
recoverableErrorCount += 1;
|
|
||||||
|
|
||||||
if (recoverableErrorCount >= MAX_RECOVERABLE_ERRORS) {
|
|
||||||
warn("Giving up!");
|
|
||||||
abort(socket, realtime);
|
|
||||||
if (config.onAbort) {
|
|
||||||
config.onAbort({
|
|
||||||
realtime: realtime
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (socketChecker) { clearInterval(socketChecker); }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},200);
|
|
||||||
|
|
||||||
realtime.start();
|
|
||||||
});
|
|
||||||
return toReturn;
|
|
||||||
};
|
|
||||||
return module.exports;
|
|
||||||
});
|
|
||||||
@ -4,10 +4,9 @@ define([
|
|||||||
var ChainPad = window.ChainPad;
|
var ChainPad = window.ChainPad;
|
||||||
var JsonOT = {};
|
var JsonOT = {};
|
||||||
|
|
||||||
/* FIXME
|
|
||||||
resultOp after transform0() might be null, in which case you should return null
|
|
||||||
because it is simply a transformation which yields a "do nothing" operation */
|
|
||||||
var validate = JsonOT.validate = function (text, toTransform, transformBy) {
|
var validate = JsonOT.validate = function (text, toTransform, transformBy) {
|
||||||
|
var DEBUG = window.REALTIME_DEBUG = window.REALTIME_DEBUG || {};
|
||||||
|
|
||||||
var resultOp, text2, text3;
|
var resultOp, text2, text3;
|
||||||
try {
|
try {
|
||||||
// text = O (mutual common ancestor)
|
// text = O (mutual common ancestor)
|
||||||
@ -28,7 +27,7 @@ define([
|
|||||||
return resultOp;
|
return resultOp;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
var info = window.REALTIME_MODULE.ot_parseError = {
|
var info = DEBUG.ot_parseError = {
|
||||||
type: 'resultParseError',
|
type: 'resultParseError',
|
||||||
resultOp: resultOp,
|
resultOp: resultOp,
|
||||||
|
|
||||||
@ -40,11 +39,11 @@ define([
|
|||||||
text3: text3,
|
text3: text3,
|
||||||
error: e
|
error: e
|
||||||
};
|
};
|
||||||
console.log('Debugging info available at `window.REALTIME_MODULE.ot_parseError`');
|
console.log('Debugging info available at `window.REALTIME_DEBUG.ot_parseError`');
|
||||||
}
|
}
|
||||||
} catch (x) {
|
} catch (x) {
|
||||||
console.error(x);
|
console.error(x);
|
||||||
window.REALTIME_MODULE.ot_applyError = {
|
window.DEBUG.ot_applyError = {
|
||||||
type: 'resultParseError',
|
type: 'resultParseError',
|
||||||
resultOp: resultOp,
|
resultOp: resultOp,
|
||||||
|
|
||||||
@ -56,7 +55,7 @@ define([
|
|||||||
text3: text3,
|
text3: text3,
|
||||||
error: x
|
error: x
|
||||||
};
|
};
|
||||||
console.log('Debugging info available at `window.REALTIME_MODULE.ot_applyError`');
|
console.log('Debugging info available at `window.REALTIME_DEBUG.ot_applyError`');
|
||||||
}
|
}
|
||||||
|
|
||||||
// returning **null** breaks out of the loop
|
// returning **null** breaks out of the loop
|
||||||
|
|||||||
@ -51,6 +51,7 @@ const mkChannel = (ctx, id) => {
|
|||||||
};
|
};
|
||||||
const chan = {
|
const chan = {
|
||||||
_: internal,
|
_: internal,
|
||||||
|
time: now(),
|
||||||
id: id,
|
id: id,
|
||||||
members: internal.members,
|
members: internal.members,
|
||||||
bcast: (msg) => channelBcast(ctx, chan.id, msg),
|
bcast: (msg) => channelBcast(ctx, chan.id, msg),
|
||||||
|
|||||||
@ -15,16 +15,15 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
define([
|
define([
|
||||||
'/common/messages.js',
|
|
||||||
'/common/netflux-client.js',
|
'/common/netflux-client.js',
|
||||||
'/common/crypto.js',
|
|
||||||
'/common/es6-promise.min.js',
|
'/common/es6-promise.min.js',
|
||||||
'/common/chainpad.js',
|
'/common/chainpad.js',
|
||||||
'/bower_components/jquery/dist/jquery.min.js',
|
'/bower_components/jquery/dist/jquery.min.js',
|
||||||
], function (Messages, Netflux, Crypto) {
|
], function (Netflux) {
|
||||||
var $ = window.jQuery;
|
var $ = window.jQuery;
|
||||||
var ChainPad = window.ChainPad;
|
var ChainPad = window.ChainPad;
|
||||||
var PARANOIA = true;
|
var PARANOIA = true;
|
||||||
|
var USE_HISTORY = true;
|
||||||
var module = { exports: {} };
|
var module = { exports: {} };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -44,16 +43,14 @@ define([
|
|||||||
var websocketUrl = config.websocketURL;
|
var websocketUrl = config.websocketURL;
|
||||||
var userName = config.userName;
|
var userName = config.userName;
|
||||||
var channel = config.channel;
|
var channel = config.channel;
|
||||||
var chanKey = config.cryptKey;
|
var chanKey = config.cryptKey || '';
|
||||||
|
var Crypto = config.crypto;
|
||||||
var cryptKey = Crypto.parseKey(chanKey).cryptKey;
|
var cryptKey = Crypto.parseKey(chanKey).cryptKey;
|
||||||
var passwd = 'y';
|
var passwd = 'y';
|
||||||
|
|
||||||
// make sure configuration is defined
|
// make sure configuration is defined
|
||||||
config = config || {};
|
config = config || {};
|
||||||
|
|
||||||
var doc = config.doc || null;
|
|
||||||
|
|
||||||
var allMessages = [];
|
|
||||||
var initializing = true;
|
var initializing = true;
|
||||||
var recoverableErrorCount = 0; // unused
|
var recoverableErrorCount = 0; // unused
|
||||||
var toReturn = {};
|
var toReturn = {};
|
||||||
@ -101,14 +98,17 @@ define([
|
|||||||
};
|
};
|
||||||
|
|
||||||
var onReady = function(wc, network) {
|
var onReady = function(wc, network) {
|
||||||
|
if(config.setMyID) {
|
||||||
|
config.setMyID({
|
||||||
|
myID: wc.myID
|
||||||
|
});
|
||||||
|
}
|
||||||
// Trigger onJoining with our own Cryptpad username to tell the toolbar that we are synced
|
// Trigger onJoining with our own Cryptpad username to tell the toolbar that we are synced
|
||||||
onJoining(wc.myID);
|
onJoining(wc.myID);
|
||||||
|
|
||||||
// we're fully synced
|
// we're fully synced
|
||||||
initializing = false;
|
initializing = false;
|
||||||
|
|
||||||
// execute an onReady callback if one was supplied
|
|
||||||
// FIXME this should be once the chain has synced
|
|
||||||
if (config.onReady) {
|
if (config.onReady) {
|
||||||
config.onReady({
|
config.onReady({
|
||||||
realtime: realtime
|
realtime: realtime
|
||||||
@ -131,11 +131,10 @@ define([
|
|||||||
var message = chainpadAdapter.msgIn(peer, msg);
|
var message = chainpadAdapter.msgIn(peer, msg);
|
||||||
|
|
||||||
verbose(message);
|
verbose(message);
|
||||||
allMessages.push(message);
|
|
||||||
|
|
||||||
if (!initializing) {
|
if (!initializing) {
|
||||||
if (toReturn.onLocal) {
|
if (config.onLocal) {
|
||||||
toReturn.onLocal();
|
config.onLocal();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// pass the message into Chainpad
|
// pass the message into Chainpad
|
||||||
@ -209,11 +208,6 @@ define([
|
|||||||
wc.on('join', onJoining);
|
wc.on('join', onJoining);
|
||||||
wc.on('leave', onLeaving);
|
wc.on('leave', onLeaving);
|
||||||
|
|
||||||
if(config.setMyID) {
|
|
||||||
config.setMyID({
|
|
||||||
myID: wc.myID
|
|
||||||
});
|
|
||||||
}
|
|
||||||
// Open a Chainpad session
|
// Open a Chainpad session
|
||||||
realtime = createRealtime();
|
realtime = createRealtime();
|
||||||
|
|
||||||
@ -253,14 +247,22 @@ define([
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Get the channel history
|
// Get the channel history
|
||||||
var hc;
|
if(USE_HISTORY) {
|
||||||
wc.members.forEach(function (p) {
|
var hc;
|
||||||
if (p.length === 16) { hc = p; }
|
|
||||||
});
|
wc.members.forEach(function (p) {
|
||||||
wc.history_keeper = hc;
|
if (p.length === 16) { hc = p; }
|
||||||
if (hc) { network.sendto(hc, JSON.stringify(['GET_HISTORY', wc.id])); }
|
});
|
||||||
|
wc.history_keeper = hc;
|
||||||
|
|
||||||
|
if (hc) { network.sendto(hc, JSON.stringify(['GET_HISTORY', wc.id])); }
|
||||||
|
}
|
||||||
|
|
||||||
realtime.start();
|
realtime.start();
|
||||||
|
|
||||||
|
if(!USE_HISTORY) {
|
||||||
|
onReady(wc, network);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var findChannelById = function(webChannels, channelId) {
|
var findChannelById = function(webChannels, channelId) {
|
||||||
|
|||||||
@ -1,20 +1,23 @@
|
|||||||
define([
|
define([
|
||||||
'/api/config?cb=' + Math.random().toString(16).substring(2),
|
'/api/config?cb=' + Math.random().toString(16).substring(2),
|
||||||
'/common/RealtimeTextarea.js',
|
'/common/realtime-input.js',
|
||||||
'/common/crypto.js',
|
'/common/crypto.js',
|
||||||
'/common/TextPatcher.js',
|
'/common/TextPatcher.js',
|
||||||
'/bower_components/jquery/dist/jquery.min.js'
|
'/bower_components/jquery/dist/jquery.min.js'
|
||||||
], function (Config, Realtime, Crypto, TextPatcher) {
|
], function (Config, Realtime, Crypto, TextPatcher) {
|
||||||
var $ = window.jQuery;
|
var $ = window.jQuery;
|
||||||
$(window).on('hashchange', function() {
|
|
||||||
window.location.reload();
|
|
||||||
});
|
|
||||||
if (window.location.href.indexOf('#') === -1) {
|
|
||||||
window.location.href = window.location.href + '#' + Crypto.genKey();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var key = Crypto.parseKey(window.location.hash.substring(1));
|
var key;
|
||||||
|
var channel = '';
|
||||||
|
if (window.location.href.indexOf('#') === -1) {
|
||||||
|
key = Crypto.genKey();
|
||||||
|
//window.location.href = window.location.href + '#' + Crypto.genKey();
|
||||||
|
//return;
|
||||||
|
} else {
|
||||||
|
var hash = window.location.hash.substr(1);
|
||||||
|
channel = hash.substr(0,32);
|
||||||
|
key = hash.substr(32);
|
||||||
|
}
|
||||||
|
|
||||||
var $textarea = $('textarea'),
|
var $textarea = $('textarea'),
|
||||||
$run = $('#run');
|
$run = $('#run');
|
||||||
@ -29,13 +32,15 @@ define([
|
|||||||
transformFunction
|
transformFunction
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
var userName = Crypto.rand64(8);
|
||||||
|
|
||||||
var config = {
|
var config = {
|
||||||
textarea: $textarea[0],
|
initialState: '',
|
||||||
websocketURL: Config.websocketURL + '_old',
|
websocketURL: Config.websocketURL,
|
||||||
webrtcURL: Config.webrtcURL,
|
userName: userName,
|
||||||
userName: Crypto.rand64(8),
|
channel: channel,
|
||||||
channel: key.channel,
|
cryptKey: key,
|
||||||
cryptKey: key.cryptKey,
|
crypto: Crypto,
|
||||||
};
|
};
|
||||||
var initializing = true;
|
var initializing = true;
|
||||||
|
|
||||||
@ -44,7 +49,10 @@ define([
|
|||||||
|
|
||||||
setEditable(false);
|
setEditable(false);
|
||||||
|
|
||||||
var onInit = config.onInit = function (info) { };
|
var onInit = config.onInit = function (info) {
|
||||||
|
window.location.hash = info.channel + key;
|
||||||
|
$(window).on('hashchange', function() { window.location.reload(); });
|
||||||
|
};
|
||||||
|
|
||||||
var onRemote = config.onRemote = function (info) {
|
var onRemote = config.onRemote = function (info) {
|
||||||
if (initializing) { return; }
|
if (initializing) { return; }
|
||||||
|
|||||||
@ -194,9 +194,6 @@ define([
|
|||||||
var now = function () { return new Date().getTime(); };
|
var now = function () { return new Date().getTime(); };
|
||||||
|
|
||||||
var realtimeOptions = {
|
var realtimeOptions = {
|
||||||
// configuration :D
|
|
||||||
doc: inner,
|
|
||||||
|
|
||||||
// provide initialstate...
|
// provide initialstate...
|
||||||
initialState: stringifyDOM(inner) || '{}',
|
initialState: stringifyDOM(inner) || '{}',
|
||||||
|
|
||||||
@ -213,7 +210,9 @@ define([
|
|||||||
channel: key.channel,
|
channel: key.channel,
|
||||||
|
|
||||||
// encryption key
|
// encryption key
|
||||||
cryptKey: key.cryptKey
|
cryptKey: key.cryptKey,
|
||||||
|
|
||||||
|
crypto: Crypto,
|
||||||
};
|
};
|
||||||
|
|
||||||
var DD = new DiffDom(diffOptions);
|
var DD = new DiffDom(diffOptions);
|
||||||
|
|||||||
@ -87,7 +87,6 @@ define([
|
|||||||
}
|
}
|
||||||
|
|
||||||
var fixThings = false;
|
var fixThings = false;
|
||||||
// var key = Crypto.parseKey(window.location.hash.substring(1));
|
|
||||||
var editor = window.editor = Ckeditor.replace('editor1', {
|
var editor = window.editor = Ckeditor.replace('editor1', {
|
||||||
// https://dev.ckeditor.com/ticket/10907
|
// https://dev.ckeditor.com/ticket/10907
|
||||||
needsBrFiller: fixThings,
|
needsBrFiller: fixThings,
|
||||||
@ -184,7 +183,6 @@ define([
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var now = function () { return new Date().getTime(); };
|
|
||||||
|
|
||||||
var initializing = true;
|
var initializing = true;
|
||||||
var userList = {}; // List of pretty name of all users (mapped with their server ID)
|
var userList = {}; // List of pretty name of all users (mapped with their server ID)
|
||||||
@ -250,16 +248,29 @@ define([
|
|||||||
// our encryption key
|
// our encryption key
|
||||||
cryptKey: key,
|
cryptKey: key,
|
||||||
|
|
||||||
// configuration :D
|
// method which allows us to get the id of the user
|
||||||
doc: inner,
|
|
||||||
|
|
||||||
setMyID: setMyID,
|
setMyID: setMyID,
|
||||||
|
|
||||||
|
// Crypto object to avoid loading it twice in Cryptpad
|
||||||
|
crypto: Crypto,
|
||||||
|
|
||||||
// really basic operational transform
|
// really basic operational transform
|
||||||
transformFunction : JsonOT.validate
|
transformFunction : JsonOT.validate
|
||||||
// pass in websocket/netflux object TODO
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var updateUserList = function(shjson) {
|
||||||
|
// Extract the user list (metadata) from the hyperjson
|
||||||
|
var hjson = JSON.parse(shjson);
|
||||||
|
var peerUserList = hjson[hjson.length-1];
|
||||||
|
if(peerUserList.metadata) {
|
||||||
|
var userData = peerUserList.metadata;
|
||||||
|
// Update the local user data
|
||||||
|
addToUserList(userData);
|
||||||
|
hjson.pop();
|
||||||
|
}
|
||||||
|
return hjson;
|
||||||
|
}
|
||||||
|
|
||||||
var onRemote = realtimeOptions.onRemote = function (info) {
|
var onRemote = realtimeOptions.onRemote = function (info) {
|
||||||
if (initializing) { return; }
|
if (initializing) { return; }
|
||||||
|
|
||||||
@ -269,18 +280,7 @@ define([
|
|||||||
cursor.update();
|
cursor.update();
|
||||||
|
|
||||||
// Extract the user list (metadata) from the hyperjson
|
// Extract the user list (metadata) from the hyperjson
|
||||||
var hjson = JSON.parse(shjson);
|
var hjson = updateUserList(shjson);
|
||||||
var peerUserList = hjson[hjson.length-1];
|
|
||||||
if(peerUserList.metadata) {
|
|
||||||
var userData = peerUserList.metadata;
|
|
||||||
// Update the local user data
|
|
||||||
userList = userData;
|
|
||||||
// Send the new data to the toolbar
|
|
||||||
if(toolbarList && typeof toolbarList.onChange === "function") {
|
|
||||||
toolbarList.onChange(userList);
|
|
||||||
}
|
|
||||||
hjson.pop();
|
|
||||||
}
|
|
||||||
|
|
||||||
// build a dom from HJSON, diff, and patch the editor
|
// build a dom from HJSON, diff, and patch the editor
|
||||||
applyHjson(shjson);
|
applyHjson(shjson);
|
||||||
|
|||||||
@ -206,14 +206,12 @@ define([
|
|||||||
// our encryption key
|
// our encryption key
|
||||||
cryptKey: key,
|
cryptKey: key,
|
||||||
|
|
||||||
// configuration :D
|
|
||||||
doc: inner,
|
|
||||||
|
|
||||||
setMyID: setMyID,
|
setMyID: setMyID,
|
||||||
|
|
||||||
// really basic operational transform
|
// really basic operational transform
|
||||||
transformFunction : JsonOT.validate
|
transformFunction : JsonOT.validate,
|
||||||
// pass in websocket/netflux object TODO
|
|
||||||
|
crypto: Crypto,
|
||||||
};
|
};
|
||||||
|
|
||||||
var onRemote = realtimeOptions.onRemote = function (info) {
|
var onRemote = realtimeOptions.onRemote = function (info) {
|
||||||
|
|||||||
@ -8,7 +8,6 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<a id="edit" href="#" target="_blank">Edit this document's style</a>
|
<a id="edit" href="#" target="_blank">Edit this document's style</a>
|
||||||
<textarea id="css" style="display:none !important;"></textarea>
|
|
||||||
|
|
||||||
<h1>HTML Ipsum Presents</h1>
|
<h1>HTML Ipsum Presents</h1>
|
||||||
|
|
||||||
|
|||||||
@ -1,31 +1,34 @@
|
|||||||
define([
|
define([
|
||||||
'/api/config?cb=' + Math.random().toString(16).substring(2),
|
'/api/config?cb=' + Math.random().toString(16).substring(2),
|
||||||
'/common/realtime-input.js',
|
'/common/realtime-input.js',
|
||||||
'/common/messages.js',
|
|
||||||
'/common/crypto.js',
|
'/common/crypto.js',
|
||||||
|
'/common/TextPatcher.js',
|
||||||
'/bower_components/jquery/dist/jquery.min.js',
|
'/bower_components/jquery/dist/jquery.min.js',
|
||||||
'/customize/pad.js'
|
'/customize/pad.js'
|
||||||
], function (Config, Realtime, Messages, Crypto) {
|
], function (Config, Realtime, Crypto, TextPatcher) {
|
||||||
// TODO consider adding support for less.js
|
// TODO consider adding support for less.js
|
||||||
var $ = window.jQuery;
|
var $ = window.jQuery;
|
||||||
$(window).on('hashchange', function() {
|
|
||||||
window.location.reload();
|
|
||||||
});
|
|
||||||
|
|
||||||
var userName = Crypto.rand64(8);
|
var module = window.APP = {};
|
||||||
|
|
||||||
if (window.location.href.indexOf('#') === -1) {
|
var key;
|
||||||
window.location.href = window.location.href + '#' + Crypto.genKey();
|
var channel = '';
|
||||||
return;
|
if (!/#/.test(window.location.href)) {
|
||||||
|
key = Crypto.genKey();
|
||||||
|
} else {
|
||||||
|
var hash = window.location.hash.slice(1);
|
||||||
|
channel = hash.slice(0, 32);
|
||||||
|
key = hash.slice(32);
|
||||||
}
|
}
|
||||||
|
|
||||||
var key = Crypto.parseKey(window.location.hash.slice(1));
|
var config = {
|
||||||
|
websocketURL: Config.websocketURL,
|
||||||
|
channel: channel,
|
||||||
|
cryptKey: key,
|
||||||
|
crypto: Crypto,
|
||||||
|
};
|
||||||
|
|
||||||
var $style = $('style').first(),
|
var userName = module.userName = config.userName = Crypto.rand64(8);
|
||||||
$css = $('#css'),
|
|
||||||
$edit = $('#edit');
|
|
||||||
|
|
||||||
$edit.attr('href', '/text/'+ window.location.hash);
|
|
||||||
|
|
||||||
var lazyDraw = (function () {
|
var lazyDraw = (function () {
|
||||||
var to,
|
var to,
|
||||||
@ -38,29 +41,47 @@ define([
|
|||||||
};
|
};
|
||||||
}());
|
}());
|
||||||
|
|
||||||
var draw = function () {
|
var draw = function (content) { lazyDraw(content); };
|
||||||
lazyDraw($css.val());
|
|
||||||
|
var initializing = true;
|
||||||
|
|
||||||
|
var onInit = config.onInit = function (info) {
|
||||||
|
window.location.hash = info.channel + key;
|
||||||
|
var realtime = module.realtime = info.realtime;
|
||||||
|
module.patchText = TextPatcher.create({
|
||||||
|
realtime: realtime,
|
||||||
|
logging: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
$(window).on('hashchange', function() {
|
||||||
|
window.location.reload();
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
$css // set the initial value
|
var onReady = config.onReady = function (info) {
|
||||||
.val($style.text())
|
var userDoc = module.realtime.getUserDoc();
|
||||||
.on('change', draw);
|
draw(userDoc);
|
||||||
|
console.log("Ready");
|
||||||
|
initializing = false;
|
||||||
|
};
|
||||||
|
|
||||||
var rts = $('textarea').toArray().map(function (e, i) {
|
var onRemote = config.onRemote = function () {
|
||||||
|
draw(module.realtime.getUserDoc());
|
||||||
|
};
|
||||||
|
|
||||||
var config = {
|
var onAbort = config.onAbort = function (info) {
|
||||||
onRemote: draw,
|
// notify the user of the abort
|
||||||
onInit: draw,
|
window.alert("Network Connection Lost");
|
||||||
onReady: draw,
|
};
|
||||||
|
|
||||||
textarea: e,
|
var onLocal = config.onLocal = function () {
|
||||||
websocketURL: Config.websocketURL,
|
// nope
|
||||||
userName: userName,
|
};
|
||||||
channel: key.channel,
|
|
||||||
cryptKey: key.cryptKey
|
|
||||||
};
|
|
||||||
|
|
||||||
var rt = Realtime.start(config);
|
var $style = $('style').first(),
|
||||||
return rt;
|
$edit = $('#edit');
|
||||||
});
|
|
||||||
|
$edit.attr('href', '/text/'+ window.location.hash);
|
||||||
|
|
||||||
|
var rt = Realtime.start(config);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,32 +1,38 @@
|
|||||||
define([
|
define([
|
||||||
'/api/config?cb=' + Math.random().toString(16).substring(2),
|
'/api/config?cb=' + Math.random().toString(16).substring(2),
|
||||||
'/common/RealtimeTextarea.js',
|
'/common/realtime-input.js',
|
||||||
'/common/messages.js',
|
|
||||||
'/common/crypto.js',
|
'/common/crypto.js',
|
||||||
'/common/TextPatcher.js',
|
'/common/TextPatcher.js',
|
||||||
'/bower_components/jquery/dist/jquery.min.js',
|
'/bower_components/jquery/dist/jquery.min.js',
|
||||||
'/customize/pad.js'
|
'/customize/pad.js'
|
||||||
], function (Config, Realtime, Messages, Crypto, TextPatcher) {
|
], function (Config, Realtime, Crypto, TextPatcher) {
|
||||||
var $ = window.jQuery;
|
var $ = window.jQuery;
|
||||||
$(window).on('hashchange', function() {
|
|
||||||
window.location.reload();
|
var key;
|
||||||
});
|
var channel = '';
|
||||||
if (window.location.href.indexOf('#') === -1) {
|
if (window.location.href.indexOf('#') === -1) {
|
||||||
window.location.href = window.location.href + '#' + Crypto.genKey();
|
key = Crypto.genKey();
|
||||||
return;
|
} else {
|
||||||
|
var hash = window.location.hash.substr(1);
|
||||||
|
channel = hash.substr(0, 32);
|
||||||
|
key = hash.substr(32);
|
||||||
}
|
}
|
||||||
|
|
||||||
var module = window.APP = {};
|
var module = window.APP = {};
|
||||||
var key = Crypto.parseKey(window.location.hash.substring(1));
|
|
||||||
|
var userName = module.userName = Crypto.rand64(8);
|
||||||
|
|
||||||
var initializing = true;
|
var initializing = true;
|
||||||
var $textarea = $('textarea');
|
var $textarea = $('textarea');
|
||||||
|
|
||||||
var config = module.config = {
|
var config = module.config = {
|
||||||
|
initialState: '',
|
||||||
textarea: $textarea[0],
|
textarea: $textarea[0],
|
||||||
websocketURL: Config.websocketURL + '_old',
|
websocketURL: Config.websocketURL,
|
||||||
userName: Crypto.rand64(8),
|
userName: userName,
|
||||||
channel: key.channel,
|
channel: channel,
|
||||||
cryptKey: key.cryptKey
|
cryptKey: key,
|
||||||
|
crypto: Crypto,
|
||||||
};
|
};
|
||||||
|
|
||||||
var setEditable = function (bool) { $textarea.attr('disabled', !bool); };
|
var setEditable = function (bool) { $textarea.attr('disabled', !bool); };
|
||||||
@ -34,7 +40,12 @@ define([
|
|||||||
|
|
||||||
setEditable(false);
|
setEditable(false);
|
||||||
|
|
||||||
var onInit = config.onInit = function (info) { };
|
var onInit = config.onInit = function (info) {
|
||||||
|
window.location.hash = info.channel + key;
|
||||||
|
$(window).on('hashchange', function() {
|
||||||
|
window.location.reload();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
var onRemote = config.onRemote = function (info) {
|
var onRemote = config.onRemote = function (info) {
|
||||||
if (initializing) { return; }
|
if (initializing) { return; }
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user