mirror of https://github.com/xwiki-labs/cryptpad
Merge branch 'echidna' into serviceworker
This commit is contained in:
commit
14db9fad8e
|
@ -16,13 +16,14 @@ define([
|
|||
Messaging, Constants, Feedback, LocalStore, /*AStore, */Channel,
|
||||
AppConfig, Nthen) {
|
||||
|
||||
|
||||
/* This file exposes functionality which is specific to Cryptpad, but not to
|
||||
any particular pad type. This includes functions for committing metadata
|
||||
about pads to your local storage for future use and improved usability.
|
||||
|
||||
Additionally, there is some basic functionality for import/export.
|
||||
*/
|
||||
var urlArgs = Util.find(Config, ['requireConf', 'urlArgs']) || '';
|
||||
|
||||
var postMessage = function (/*cmd, data, cb*/) {
|
||||
/*setTimeout(function () {
|
||||
AStore.query(cmd, data, cb);
|
||||
|
@ -768,7 +769,7 @@ define([
|
|||
var postMsg, worker;
|
||||
Nthen(function (waitFor2) {
|
||||
if (SharedWorker) {
|
||||
worker = new SharedWorker('/common/outer/sharedworker.js');
|
||||
worker = new SharedWorker('/common/outer/sharedworker.js' + urlArgs);
|
||||
console.log(worker);
|
||||
worker.port.onmessage = function (ev) {
|
||||
if (ev.data === "SW_READY") {
|
||||
|
@ -788,7 +789,7 @@ define([
|
|||
if (worker) { return void worker.postMessage(data); }
|
||||
};
|
||||
|
||||
navigator.serviceWorker.register('/common/outer/serviceworker.js', {scope: '/'})
|
||||
navigator.serviceWorker.register('/common/outer/serviceworker.js' + urlArgs, {scope: '/'})
|
||||
.then(function(reg) {
|
||||
// Add handler for receiving messages from the service worker
|
||||
navigator.serviceWorker.addEventListener('message', function (ev) {
|
||||
|
@ -828,7 +829,7 @@ define([
|
|||
/**/console.log('Registration failed with ' + error);
|
||||
});
|
||||
} else if (Worker) {
|
||||
worker = new Worker('/common/outer/webworker.js');
|
||||
worker = new Worker('/common/outer/webworker.js' + urlArgs);
|
||||
worker.onmessage = function (ev) {
|
||||
msgEv.fire(ev);
|
||||
};
|
||||
|
|
|
@ -1,112 +1,98 @@
|
|||
/* jshint ignore:start */
|
||||
importScripts('/bower_components/requirejs/require.js');
|
||||
require.config({
|
||||
// fix up locations so that relative urls work.
|
||||
baseUrl: '/',
|
||||
paths: {
|
||||
// jquery declares itself as literally "jquery" so it cannot be pulled by path :(
|
||||
"jquery": "/bower_components/jquery/dist/jquery.min",
|
||||
// json.sortify same
|
||||
"json.sortify": "/bower_components/json.sortify/dist/JSON.sortify",
|
||||
cm: '/bower_components/codemirror'
|
||||
},
|
||||
map: {
|
||||
'*': {
|
||||
'css': '/bower_components/require-css/css.js',
|
||||
'less': '/common/RequireLess.js',
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
window = self;
|
||||
localStorage = {
|
||||
setItem: function (k, v) { localStorage[k] = v; },
|
||||
getItem: function (k) { return localStorage[k]; }
|
||||
};
|
||||
require([
|
||||
'/common/common-util.js',
|
||||
'/common/outer/worker-channel.js',
|
||||
'/common/outer/store-rpc.js'
|
||||
], function (Util, Channel, Rpc) {
|
||||
var msgEv = Util.mkEvent();
|
||||
|
||||
Channel.create(msgEv, postMessage, function (chan) {
|
||||
console.log('ww ready');
|
||||
var clientId = '1';
|
||||
Object.keys(Rpc.queries).forEach(function (q) {
|
||||
if (q === 'CONNECT') { return; }
|
||||
if (q === 'JOIN_PAD') { return; }
|
||||
if (q === 'SEND_PAD_MSG') { return; }
|
||||
chan.on(q, function (data, cb) {
|
||||
require([
|
||||
'/common/requireconfig.js'
|
||||
], function (RequireConfig) {
|
||||
require.config(RequireConfig());
|
||||
require([
|
||||
'/common/common-util.js',
|
||||
'/common/outer/worker-channel.js',
|
||||
'/common/outer/store-rpc.js'
|
||||
], function (Util, Channel, Rpc) {
|
||||
var msgEv = Util.mkEvent();
|
||||
|
||||
Channel.create(msgEv, postMessage, function (chan) {
|
||||
var clientId = '1';
|
||||
Object.keys(Rpc.queries).forEach(function (q) {
|
||||
if (q === 'CONNECT') { return; }
|
||||
if (q === 'JOIN_PAD') { return; }
|
||||
if (q === 'SEND_PAD_MSG') { return; }
|
||||
chan.on(q, function (data, cb) {
|
||||
try {
|
||||
Rpc.queries[q](clientId, data, cb);
|
||||
} catch (e) {
|
||||
console.error('Error in webworker when executing query ' + q);
|
||||
console.error(e);
|
||||
console.log(data);
|
||||
}
|
||||
});
|
||||
});
|
||||
chan.on('CONNECT', function (cfg, cb) {
|
||||
// load Store here, with cfg, and pass a "query" (chan.query)
|
||||
// cId is a clientId used in ServiceWorker or SharedWorker
|
||||
cfg.query = function (cId, cmd, data, cb) {
|
||||
cb = cb || function () {};
|
||||
chan.query(cmd, data, function (err, data2) {
|
||||
if (err) { return void cb({error: err}); }
|
||||
cb(data2);
|
||||
});
|
||||
};
|
||||
cfg.broadcast = function (excludes, cmd, data, cb) {
|
||||
cb = cb || function () {};
|
||||
if (excludes.indexOf(clientId) !== -1) { return; }
|
||||
chan.query(cmd, data, function (err, data2) {
|
||||
if (err) { return void cb({error: err}); }
|
||||
cb(data2);
|
||||
});
|
||||
};
|
||||
Rpc.queries['CONNECT'](clientId, cfg, function (data) {
|
||||
if (data && data.state === "ALREADY_INIT") {
|
||||
return void cb(data);
|
||||
}
|
||||
if (cfg.driveEvents) {
|
||||
Rpc._subscribeToDrive(clientId);
|
||||
}
|
||||
if (cfg.messenger) {
|
||||
Rpc._subscribeToMessenger(clientId);
|
||||
}
|
||||
cb(data);
|
||||
});
|
||||
});
|
||||
var chanId;
|
||||
chan.on('JOIN_PAD', function (data, cb) {
|
||||
chanId = data.channel;
|
||||
try {
|
||||
Rpc.queries[q](clientId, data, cb);
|
||||
Rpc.queries['JOIN_PAD'](clientId, data, cb);
|
||||
} catch (e) {
|
||||
console.error('Error in webworker when executing query ' + q);
|
||||
console.error('Error in webworker when executing query JOIN_PAD');
|
||||
console.error(e);
|
||||
console.log(data);
|
||||
}
|
||||
});
|
||||
});
|
||||
chan.on('CONNECT', function (cfg, cb) {
|
||||
console.log('onConnect');
|
||||
// load Store here, with cfg, and pass a "query" (chan.query)
|
||||
// cId is a clientId used in ServiceWorker or SharedWorker
|
||||
cfg.query = function (cId, cmd, data, cb) {
|
||||
cb = cb || function () {};
|
||||
chan.query(cmd, data, function (err, data2) {
|
||||
if (err) { return void cb({error: err}); }
|
||||
cb(data2);
|
||||
});
|
||||
};
|
||||
cfg.broadcast = function (excludes, cmd, data, cb) {
|
||||
cb = cb || function () {};
|
||||
if (excludes.indexOf(clientId) !== -1) { return; }
|
||||
chan.query(cmd, data, function (err, data2) {
|
||||
if (err) { return void cb({error: err}); }
|
||||
cb(data2);
|
||||
});
|
||||
};
|
||||
Rpc.queries['CONNECT'](clientId, cfg, function (data) {
|
||||
console.log(data);
|
||||
if (data && data.state === "ALREADY_INIT") {
|
||||
return void cb(data);
|
||||
chan.on('SEND_PAD_MSG', function (msg, cb) {
|
||||
var data = {
|
||||
msg: msg,
|
||||
channel: chanId
|
||||
};
|
||||
try {
|
||||
Rpc.queries['SEND_PAD_MSG'](clientId, data, cb);
|
||||
} catch (e) {
|
||||
console.error('Error in webworker when executing query SEND_PAD_MSG');
|
||||
console.error(e);
|
||||
console.log(data);
|
||||
}
|
||||
if (cfg.driveEvents) {
|
||||
Rpc._subscribeToDrive(clientId);
|
||||
}
|
||||
if (cfg.messenger) {
|
||||
Rpc._subscribeToMessenger(clientId);
|
||||
}
|
||||
cb(data);
|
||||
});
|
||||
});
|
||||
var chanId;
|
||||
chan.on('JOIN_PAD', function (data, cb) {
|
||||
chanId = data.channel;
|
||||
try {
|
||||
Rpc.queries['JOIN_PAD'](clientId, data, cb);
|
||||
} catch (e) {
|
||||
console.error('Error in webworker when executing query JOIN_PAD');
|
||||
console.error(e);
|
||||
console.log(data);
|
||||
}
|
||||
});
|
||||
chan.on('SEND_PAD_MSG', function (msg, cb) {
|
||||
var data = {
|
||||
msg: msg,
|
||||
channel: chanId
|
||||
};
|
||||
try {
|
||||
Rpc.queries['SEND_PAD_MSG'](clientId, data, cb);
|
||||
} catch (e) {
|
||||
console.error('Error in webworker when executing query SEND_PAD_MSG');
|
||||
console.error(e);
|
||||
console.log(data);
|
||||
}
|
||||
});
|
||||
}, true);
|
||||
}, true);
|
||||
|
||||
onmessage = function (e) {
|
||||
msgEv.fire(e);
|
||||
};
|
||||
onmessage = function (e) {
|
||||
msgEv.fire(e);
|
||||
};
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
/* jshint ignore:start */
|
||||
var id;
|
||||
//= Math.floor(Math.random()*100000);
|
||||
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
worker/
|
Loading…
Reference in New Issue