Remove Crypto from the modules loaded with RequireJS in realtime-input
It now has to be passed in the config in the main JS file
This commit is contained in:
parent
8ac69ca262
commit
d3203d1c2a
@ -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,14 +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 allMessages = [];
|
|
||||||
var initializing = true;
|
var initializing = true;
|
||||||
var recoverableErrorCount = 0; // unused
|
var recoverableErrorCount = 0; // unused
|
||||||
var toReturn = {};
|
var toReturn = {};
|
||||||
@ -99,6 +98,11 @@ 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);
|
||||||
|
|
||||||
@ -127,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
|
||||||
@ -205,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();
|
||||||
|
|
||||||
@ -249,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) {
|
||||||
|
|||||||
@ -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,12 +248,29 @@ define([
|
|||||||
// our encryption key
|
// our encryption key
|
||||||
cryptKey: key,
|
cryptKey: key,
|
||||||
|
|
||||||
|
// method which allows us to get the id of the user
|
||||||
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
|
||||||
};
|
};
|
||||||
|
|
||||||
|
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; }
|
||||||
|
|
||||||
@ -265,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);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user