Merge branch 'echidna' into serviceworker

pull/1/head
yflory 7 years ago
commit 14db9fad8e

@ -16,13 +16,14 @@ define([
Messaging, Constants, Feedback, LocalStore, /*AStore, */Channel, Messaging, Constants, Feedback, LocalStore, /*AStore, */Channel,
AppConfig, Nthen) { AppConfig, Nthen) {
/* This file exposes functionality which is specific to Cryptpad, but not to /* This file exposes functionality which is specific to Cryptpad, but not to
any particular pad type. This includes functions for committing metadata any particular pad type. This includes functions for committing metadata
about pads to your local storage for future use and improved usability. about pads to your local storage for future use and improved usability.
Additionally, there is some basic functionality for import/export. Additionally, there is some basic functionality for import/export.
*/ */
var urlArgs = Util.find(Config, ['requireConf', 'urlArgs']) || '';
var postMessage = function (/*cmd, data, cb*/) { var postMessage = function (/*cmd, data, cb*/) {
/*setTimeout(function () { /*setTimeout(function () {
AStore.query(cmd, data, cb); AStore.query(cmd, data, cb);
@ -768,7 +769,7 @@ define([
var postMsg, worker; var postMsg, worker;
Nthen(function (waitFor2) { Nthen(function (waitFor2) {
if (SharedWorker) { if (SharedWorker) {
worker = new SharedWorker('/common/outer/sharedworker.js'); worker = new SharedWorker('/common/outer/sharedworker.js' + urlArgs);
console.log(worker); console.log(worker);
worker.port.onmessage = function (ev) { worker.port.onmessage = function (ev) {
if (ev.data === "SW_READY") { if (ev.data === "SW_READY") {
@ -788,7 +789,7 @@ define([
if (worker) { return void worker.postMessage(data); } 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) { .then(function(reg) {
// Add handler for receiving messages from the service worker // Add handler for receiving messages from the service worker
navigator.serviceWorker.addEventListener('message', function (ev) { navigator.serviceWorker.addEventListener('message', function (ev) {
@ -828,7 +829,7 @@ define([
/**/console.log('Registration failed with ' + error); /**/console.log('Registration failed with ' + error);
}); });
} else if (Worker) { } else if (Worker) {
worker = new Worker('/common/outer/webworker.js'); worker = new Worker('/common/outer/webworker.js' + urlArgs);
worker.onmessage = function (ev) { worker.onmessage = function (ev) {
msgEv.fire(ev); msgEv.fire(ev);
}; };

@ -1,37 +1,24 @@
/* jshint ignore:start */ /* jshint ignore:start */
importScripts('/bower_components/requirejs/require.js'); 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; window = self;
localStorage = { localStorage = {
setItem: function (k, v) { localStorage[k] = v; }, setItem: function (k, v) { localStorage[k] = v; },
getItem: function (k) { return localStorage[k]; } getItem: function (k) { return localStorage[k]; }
}; };
require([ require([
'/common/requireconfig.js'
], function (RequireConfig) {
require.config(RequireConfig());
require([
'/common/common-util.js', '/common/common-util.js',
'/common/outer/worker-channel.js', '/common/outer/worker-channel.js',
'/common/outer/store-rpc.js' '/common/outer/store-rpc.js'
], function (Util, Channel, Rpc) { ], function (Util, Channel, Rpc) {
var msgEv = Util.mkEvent(); var msgEv = Util.mkEvent();
Channel.create(msgEv, postMessage, function (chan) { Channel.create(msgEv, postMessage, function (chan) {
console.log('ww ready');
var clientId = '1'; var clientId = '1';
Object.keys(Rpc.queries).forEach(function (q) { Object.keys(Rpc.queries).forEach(function (q) {
if (q === 'CONNECT') { return; } if (q === 'CONNECT') { return; }
@ -48,7 +35,6 @@ require([
}); });
}); });
chan.on('CONNECT', function (cfg, cb) { chan.on('CONNECT', function (cfg, cb) {
console.log('onConnect');
// load Store here, with cfg, and pass a "query" (chan.query) // load Store here, with cfg, and pass a "query" (chan.query)
// cId is a clientId used in ServiceWorker or SharedWorker // cId is a clientId used in ServiceWorker or SharedWorker
cfg.query = function (cId, cmd, data, cb) { cfg.query = function (cId, cmd, data, cb) {
@ -67,7 +53,6 @@ require([
}); });
}; };
Rpc.queries['CONNECT'](clientId, cfg, function (data) { Rpc.queries['CONNECT'](clientId, cfg, function (data) {
console.log(data);
if (data && data.state === "ALREADY_INIT") { if (data && data.state === "ALREADY_INIT") {
return void cb(data); return void cb(data);
} }
@ -109,4 +94,5 @@ require([
onmessage = function (e) { onmessage = function (e) {
msgEv.fire(e); msgEv.fire(e);
}; };
});
}); });

@ -1,3 +1,4 @@
/* jshint ignore:start */
var id; var id;
//= Math.floor(Math.random()*100000); //= Math.floor(Math.random()*100000);

@ -1 +0,0 @@
worker/
Loading…
Cancel
Save