Add support for login & logout while keeping the same shared worker
This commit is contained in:
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");
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@ -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,89 +1,96 @@
|
|||||||
define([
|
define([
|
||||||
'/common/outer/async-store.js'
|
'/common/outer/async-store.js'
|
||||||
], function (Store) {
|
], function (AStore) {
|
||||||
var Rpc = {};
|
|
||||||
|
|
||||||
var queries = Rpc.queries = {
|
var create = function () {
|
||||||
// Ready
|
var Store = AStore.create();
|
||||||
CONNECT: Store.init,
|
|
||||||
DISCONNECT: Store.disconnect,
|
var Rpc = {};
|
||||||
CREATE_README: Store.createReadme,
|
|
||||||
MIGRATE_ANON_DRIVE: Store.migrateAnonDrive,
|
var queries = Rpc.queries = {
|
||||||
// RPC
|
// Ready
|
||||||
INIT_RPC: Store.initRpc,
|
CONNECT: Store.init,
|
||||||
UPDATE_PIN_LIMIT: Store.updatePinLimit,
|
DISCONNECT: Store.disconnect,
|
||||||
GET_PIN_LIMIT: Store.getPinLimit,
|
CREATE_README: Store.createReadme,
|
||||||
CLEAR_OWNED_CHANNEL: Store.clearOwnedChannel,
|
MIGRATE_ANON_DRIVE: Store.migrateAnonDrive,
|
||||||
REMOVE_OWNED_CHANNEL: Store.removeOwnedChannel,
|
// RPC
|
||||||
UPLOAD_CHUNK: Store.uploadChunk,
|
INIT_RPC: Store.initRpc,
|
||||||
UPLOAD_COMPLETE: Store.uploadComplete,
|
UPDATE_PIN_LIMIT: Store.updatePinLimit,
|
||||||
UPLOAD_STATUS: Store.uploadStatus,
|
GET_PIN_LIMIT: Store.getPinLimit,
|
||||||
UPLOAD_CANCEL: Store.uploadCancel,
|
CLEAR_OWNED_CHANNEL: Store.clearOwnedChannel,
|
||||||
PIN_PADS: Store.pinPads,
|
REMOVE_OWNED_CHANNEL: Store.removeOwnedChannel,
|
||||||
UNPIN_PADS: Store.unpinPads,
|
UPLOAD_CHUNK: Store.uploadChunk,
|
||||||
GET_DELETED_PADS: Store.getDeletedPads,
|
UPLOAD_COMPLETE: Store.uploadComplete,
|
||||||
GET_PINNED_USAGE: Store.getPinnedUsage,
|
UPLOAD_STATUS: Store.uploadStatus,
|
||||||
// ANON RPC
|
UPLOAD_CANCEL: Store.uploadCancel,
|
||||||
INIT_ANON_RPC: Store.initAnonRpc,
|
PIN_PADS: Store.pinPads,
|
||||||
ANON_RPC_MESSAGE: Store.anonRpcMsg,
|
UNPIN_PADS: Store.unpinPads,
|
||||||
GET_FILE_SIZE: Store.getFileSize,
|
GET_DELETED_PADS: Store.getDeletedPads,
|
||||||
GET_MULTIPLE_FILE_SIZE: Store.getMultipleFileSize,
|
GET_PINNED_USAGE: Store.getPinnedUsage,
|
||||||
// Store
|
// ANON RPC
|
||||||
GET: Store.get,
|
INIT_ANON_RPC: Store.initAnonRpc,
|
||||||
SET: Store.set,
|
ANON_RPC_MESSAGE: Store.anonRpcMsg,
|
||||||
ADD_PAD: Store.addPad,
|
GET_FILE_SIZE: Store.getFileSize,
|
||||||
SET_PAD_TITLE: Store.setPadTitle,
|
GET_MULTIPLE_FILE_SIZE: Store.getMultipleFileSize,
|
||||||
MOVE_TO_TRASH: Store.moveToTrash,
|
// Store
|
||||||
RESET_DRIVE: Store.resetDrive,
|
GET: Store.get,
|
||||||
GET_METADATA: Store.getMetadata,
|
SET: Store.set,
|
||||||
SET_DISPLAY_NAME: Store.setDisplayName,
|
ADD_PAD: Store.addPad,
|
||||||
SET_PAD_ATTRIBUTE: Store.setPadAttribute,
|
SET_PAD_TITLE: Store.setPadTitle,
|
||||||
GET_PAD_ATTRIBUTE: Store.getPadAttribute,
|
MOVE_TO_TRASH: Store.moveToTrash,
|
||||||
SET_ATTRIBUTE: Store.setAttribute,
|
RESET_DRIVE: Store.resetDrive,
|
||||||
GET_ATTRIBUTE: Store.getAttribute,
|
GET_METADATA: Store.getMetadata,
|
||||||
LIST_ALL_TAGS: Store.listAllTags,
|
SET_DISPLAY_NAME: Store.setDisplayName,
|
||||||
GET_TEMPLATES: Store.getTemplates,
|
SET_PAD_ATTRIBUTE: Store.setPadAttribute,
|
||||||
GET_SECURE_FILES_LIST: Store.getSecureFilesList,
|
GET_PAD_ATTRIBUTE: Store.getPadAttribute,
|
||||||
GET_PAD_DATA: Store.getPadData,
|
SET_ATTRIBUTE: Store.setAttribute,
|
||||||
GET_STRONGER_HASH: Store.getStrongerHash,
|
GET_ATTRIBUTE: Store.getAttribute,
|
||||||
INCREMENT_TEMPLATE_USE: Store.incrementTemplateUse,
|
LIST_ALL_TAGS: Store.listAllTags,
|
||||||
// Messaging
|
GET_TEMPLATES: Store.getTemplates,
|
||||||
INVITE_FROM_USERLIST: Store.inviteFromUserlist,
|
GET_SECURE_FILES_LIST: Store.getSecureFilesList,
|
||||||
ADD_DIRECT_MESSAGE_HANDLERS: Store.addDirectMessageHandlers,
|
GET_PAD_DATA: Store.getPadData,
|
||||||
// Messenger
|
GET_STRONGER_HASH: Store.getStrongerHash,
|
||||||
CONTACTS_GET_FRIEND_LIST: Store.messenger.getFriendList,
|
INCREMENT_TEMPLATE_USE: Store.incrementTemplateUse,
|
||||||
CONTACTS_GET_MY_INFO: Store.messenger.getMyInfo,
|
// Messaging
|
||||||
CONTACTS_GET_FRIEND_INFO: Store.messenger.getFriendInfo,
|
INVITE_FROM_USERLIST: Store.inviteFromUserlist,
|
||||||
CONTACTS_REMOVE_FRIEND: Store.messenger.removeFriend,
|
ADD_DIRECT_MESSAGE_HANDLERS: Store.addDirectMessageHandlers,
|
||||||
CONTACTS_OPEN_FRIEND_CHANNEL: Store.messenger.openFriendChannel,
|
// Messenger
|
||||||
CONTACTS_GET_FRIEND_STATUS: Store.messenger.getFriendStatus,
|
CONTACTS_GET_FRIEND_LIST: Store.messenger.getFriendList,
|
||||||
CONTACTS_GET_MORE_HISTORY: Store.messenger.getMoreHistory,
|
CONTACTS_GET_MY_INFO: Store.messenger.getMyInfo,
|
||||||
CONTACTS_SEND_MESSAGE: Store.messenger.sendMessage,
|
CONTACTS_GET_FRIEND_INFO: Store.messenger.getFriendInfo,
|
||||||
CONTACTS_SET_CHANNEL_HEAD: Store.messenger.setChannelHead,
|
CONTACTS_REMOVE_FRIEND: Store.messenger.removeFriend,
|
||||||
// Pad
|
CONTACTS_OPEN_FRIEND_CHANNEL: Store.messenger.openFriendChannel,
|
||||||
SEND_PAD_MSG: Store.sendPadMsg,
|
CONTACTS_GET_FRIEND_STATUS: Store.messenger.getFriendStatus,
|
||||||
JOIN_PAD: Store.joinPad,
|
CONTACTS_GET_MORE_HISTORY: Store.messenger.getMoreHistory,
|
||||||
GET_FULL_HISTORY: Store.getFullHistory,
|
CONTACTS_SEND_MESSAGE: Store.messenger.sendMessage,
|
||||||
IS_NEW_CHANNEL: Store.isNewChannel,
|
CONTACTS_SET_CHANNEL_HEAD: Store.messenger.setChannelHead,
|
||||||
// Drive
|
// Pad
|
||||||
DRIVE_USEROBJECT: Store.userObjectCommand,
|
SEND_PAD_MSG: Store.sendPadMsg,
|
||||||
// Settings,
|
JOIN_PAD: Store.joinPad,
|
||||||
DELETE_ACCOUNT: Store.deleteAccount,
|
GET_FULL_HISTORY: Store.getFullHistory,
|
||||||
|
IS_NEW_CHANNEL: Store.isNewChannel,
|
||||||
|
// Drive
|
||||||
|
DRIVE_USEROBJECT: Store.userObjectCommand,
|
||||||
|
// Settings,
|
||||||
|
DELETE_ACCOUNT: Store.deleteAccount,
|
||||||
|
};
|
||||||
|
|
||||||
|
Rpc.query = function (cmd, data, cb) {
|
||||||
|
if (queries[cmd]) {
|
||||||
|
queries[cmd]('0', data, cb);
|
||||||
|
} else {
|
||||||
|
console.error('UNHANDLED_STORE_RPC');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Internal calls
|
||||||
|
Rpc._removeClient = Store._removeClient;
|
||||||
|
Rpc._subscribeToDrive = Store._subscribeToDrive;
|
||||||
|
Rpc._subscribeToMessenger = Store._subscribeToMessenger;
|
||||||
|
|
||||||
|
return Rpc;
|
||||||
};
|
};
|
||||||
|
|
||||||
Rpc.query = function (cmd, data, cb) {
|
return create;
|
||||||
if (queries[cmd]) {
|
|
||||||
queries[cmd]('0', data, cb);
|
|
||||||
} else {
|
|
||||||
console.error('UNHANDLED_STORE_RPC');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Internal calls
|
|
||||||
Rpc._removeClient = Store._removeClient;
|
|
||||||
Rpc._subscribeToDrive = Store._subscribeToDrive;
|
|
||||||
Rpc._subscribeToMessenger = Store._subscribeToMessenger;
|
|
||||||
|
|
||||||
return Rpc;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -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…
x
Reference in New Issue
Block a user