cryptpad/www/common/sframe-common.js

56 lines
1.7 KiB
JavaScript
Raw Normal View History

2017-08-17 14:28:54 +00:00
define([
2017-08-17 14:56:18 +00:00
'/bower_components/nthen/index.js',
2017-08-17 14:28:54 +00:00
'/common/sframe-chainpad-netflux-inner.js',
2017-08-17 16:28:05 +00:00
'/common/sframe-channel.js',
'/common/sframe-common-title.js'
], function (nThen, CpNfInner, SFrameChannel, Title) {
2017-08-17 14:28:54 +00:00
// Chainpad Netflux Inner
2017-08-17 14:56:18 +00:00
var funcs = {};
var ctx = {};
funcs.startRealtime = function (options) {
if (ctx.cpNfInner) { return ctx.cpNfInner; }
options.sframeChan = ctx.sframeChan;
ctx.cpNfInner = CpNfInner.start(options);
ctx.cpNfInner.metadataMgr.onChangeLazy(options.onLocal);
2017-08-17 14:56:18 +00:00
return ctx.cpNfInner;
};
funcs.isLoggedIn = function () {
if (!ctx.cpNfInner) { throw new Error("cpNfInner is not ready!"); }
return ctx.cpNfInner.metadataMgr.getPrivateData().accountName;
2017-08-17 14:28:54 +00:00
};
2017-08-17 15:34:08 +00:00
funcs.setPadTitleInDrive = function (title, cb) {
ctx.sframeChan.query('Q_SET_PAD_TITLE_IN_DRIVE', title, function (err) {
2017-08-17 16:28:05 +00:00
if (cb) { cb(err, title); }
2017-08-17 15:34:08 +00:00
});
2017-08-17 14:28:54 +00:00
};
2017-08-17 16:28:05 +00:00
// Title module
funcs.createTitle = Title.create;
funcs.getDefaultTitle = function () {
if (!ctx.cpNfInner) { throw new Error("cpNfInner is not ready!"); }
return ctx.cpNfInner.metadataMgr.getMetadata().defaultTitle;
};
2017-08-17 16:09:17 +00:00
funcs.setDisplayName = function (name, cb) {
ctx.sframeChan.query('Q_SETTINGS_SET_DISPLAY_NAME', name, function (err) {
if (cb) { cb(err); }
});
};
2017-08-17 16:28:05 +00:00
2017-08-17 14:56:18 +00:00
Object.freeze(funcs);
return { create: function (cb) {
nThen(function (waitFor) {
SFrameChannel.create(window.top, waitFor(function (sfc) { ctx.sframeChan = sfc; }));
// CpNfInner.start() should be here....
2017-08-17 15:34:08 +00:00
}).nThen(function () {
2017-08-17 14:56:18 +00:00
cb(funcs);
});
} };
2017-08-17 14:28:54 +00:00
});