Add support for login & logout while keeping the same shared worker

pull/1/head
yflory 7 years ago
parent 02b282a1a5
commit 47dee664da

@ -932,9 +932,12 @@ define([
document.location.reload(); document.location.reload();
} else if (o && !n) { } else if (o && !n) {
LocalStore.logout(); LocalStore.logout();
postMessage("DISCONNECT");
} }
}); });
LocalStore.onLogout(function () {
console.log('onLogout: disconnect');
postMessage("DISCONNECT");
});
if (PINNING_ENABLED && LocalStore.isLoggedIn()) { if (PINNING_ENABLED && LocalStore.isLoggedIn()) {
console.log("logged in. pads will be pinned"); console.log("logged in. pads will be pinned");

@ -23,6 +23,7 @@ define([
Crypto, ChainPad, Listmap, nThen, Saferphore) { Crypto, ChainPad, Listmap, nThen, Saferphore) {
var Store = {}; var Store = {};
var create = function () {
var postMessage = function () {}; var postMessage = function () {};
var broadcast = function () {}; var broadcast = function () {};
var sendDriveEvent = function () {}; var sendDriveEvent = function () {};
@ -1454,4 +1455,9 @@ define([
store.network.disconnect(); store.network.disconnect();
}; };
return Store; return Store;
};
return {
create: create
};
}); });

@ -27,10 +27,15 @@ var init = function (client, cb) {
'/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, SRpc) {
debug('SW Required ressources loaded'); debug('SW Required ressources loaded');
var msgEv = Util.mkEvent(); var msgEv = Util.mkEvent();
if (!self.Rpc) {
self.Rpc = SRpc();
}
var Rpc = self.Rpc;
var postToClient = function (data) { var postToClient = function (data) {
postMsg(client, data); postMsg(client, data);
}; };
@ -51,11 +56,17 @@ var init = function (client, cb) {
console.error(e); console.error(e);
console.log(data); console.log(data);
} }
if (q === "DISCONNECT") {
console.log('Deleting existing store!');
delete self.Rpc;
delete self.store;
}
}); });
}); });
chan.on('CONNECT', function (cfg, cb) { chan.on('CONNECT', function (cfg, cb) {
debug('SW Connect callback'); debug('SW Connect callback');
if (self.store) { if (self.store) {
debug('Store already exists!');
if (cfg.driveEvents) { if (cfg.driveEvents) {
Rpc._subscribeToDrive(clientId); Rpc._subscribeToDrive(clientId);
} }

@ -27,10 +27,15 @@ var init = function (client, cb) {
'/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, SRpc) {
debug('SharedW Required ressources loaded'); debug('SharedW Required ressources loaded');
var msgEv = Util.mkEvent(); var msgEv = Util.mkEvent();
if (!self.Rpc) {
self.Rpc = SRpc();
}
var Rpc = self.Rpc;
var postToClient = function (data) { var postToClient = function (data) {
postMsg(client, data); postMsg(client, data);
}; };
@ -51,6 +56,11 @@ var init = function (client, cb) {
console.error(e); console.error(e);
console.log(data); console.log(data);
} }
if (q === "DISCONNECT") {
console.log('Deleting existing store!');
delete self.Rpc;
delete self.store;
}
}); });
}); });
chan.on('CONNECT', function (cfg, cb) { chan.on('CONNECT', function (cfg, cb) {

@ -1,6 +1,10 @@
define([ define([
'/common/outer/async-store.js' '/common/outer/async-store.js'
], function (Store) { ], function (AStore) {
var create = function () {
var Store = AStore.create();
var Rpc = {}; var Rpc = {};
var queries = Rpc.queries = { var queries = Rpc.queries = {
@ -85,5 +89,8 @@ define([
Rpc._subscribeToMessenger = Store._subscribeToMessenger; Rpc._subscribeToMessenger = Store._subscribeToMessenger;
return Rpc; return Rpc;
};
return create;
}); });

@ -15,9 +15,11 @@ 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, SRpc) {
var msgEv = Util.mkEvent(); var msgEv = Util.mkEvent();
var Rpc = SRpc();
Channel.create(msgEv, postMessage, function (chan) { Channel.create(msgEv, postMessage, function (chan) {
var clientId = '1'; var clientId = '1';
Object.keys(Rpc.queries).forEach(function (q) { Object.keys(Rpc.queries).forEach(function (q) {

Loading…
Cancel
Save