pass in Crypto to realtime-input
This commit is contained in:
@@ -67,6 +67,7 @@ define([
|
|||||||
userName: Crypto.rand64(8),
|
userName: Crypto.rand64(8),
|
||||||
channel: channel,
|
channel: channel,
|
||||||
cryptKey: key,
|
cryptKey: key,
|
||||||
|
crypto: Crypto,
|
||||||
};
|
};
|
||||||
|
|
||||||
var onInit = config.onInit = function (info) {
|
var onInit = config.onInit = function (info) {
|
||||||
|
|||||||
@@ -6,10 +6,6 @@ define([
|
|||||||
'/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();
|
|
||||||
});*/
|
|
||||||
|
|
||||||
var key;
|
var key;
|
||||||
var channel = '';
|
var channel = '';
|
||||||
@@ -44,6 +40,7 @@ define([
|
|||||||
userName: userName,
|
userName: userName,
|
||||||
channel: channel,
|
channel: channel,
|
||||||
cryptKey: key,
|
cryptKey: key,
|
||||||
|
crypto: Crypto,
|
||||||
};
|
};
|
||||||
var initializing = true;
|
var initializing = true;
|
||||||
|
|
||||||
@@ -54,6 +51,7 @@ define([
|
|||||||
|
|
||||||
var onInit = config.onInit = function (info) {
|
var onInit = config.onInit = function (info) {
|
||||||
window.location.hash = info.channel + key;
|
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) {
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
@@ -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,22 +1,12 @@
|
|||||||
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',
|
'/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();
|
|
||||||
});
|
|
||||||
/*
|
|
||||||
if (window.location.href.indexOf('#') === -1) {
|
|
||||||
window.location.href = window.location.href + '#' + Crypto.genKey();
|
|
||||||
return;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
|
|
||||||
var key;
|
var key;
|
||||||
var channel = '';
|
var channel = '';
|
||||||
@@ -42,6 +32,7 @@ define([
|
|||||||
userName: userName,
|
userName: userName,
|
||||||
channel: channel,
|
channel: channel,
|
||||||
cryptKey: key,
|
cryptKey: key,
|
||||||
|
crypto: Crypto,
|
||||||
};
|
};
|
||||||
|
|
||||||
var setEditable = function (bool) { $textarea.attr('disabled', !bool); };
|
var setEditable = function (bool) { $textarea.attr('disabled', !bool); };
|
||||||
@@ -51,6 +42,9 @@ define([
|
|||||||
|
|
||||||
var onInit = config.onInit = function (info) {
|
var onInit = config.onInit = function (info) {
|
||||||
window.location.hash = info.channel + key;
|
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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user