cryptpad/www/common/sframe-common.js

39 lines
1.2 KiB
JavaScript
Raw Normal View History

2017-08-17 22:28:54 +08:00
define([
2017-08-17 22:56:18 +08:00
'/bower_components/nthen/index.js',
2017-08-17 22:28:54 +08:00
'/common/sframe-chainpad-netflux-inner.js',
2017-08-17 22:56:18 +08:00
'/common/sframe-channel.js'
], function (nThen, CpNfInner, SFrameChannel) {
2017-08-17 22:28:54 +08:00
// Chainpad Netflux Inner
2017-08-17 22:56:18 +08:00
var funcs = {};
var ctx = {};
funcs.startRealtime = function (options) {
if (ctx.cpNfInner) { return ctx.cpNfInner; }
options.sframeChan = ctx.sframeChan;
ctx.cpNfInner = CpNfInner.start(options);
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 22:28:54 +08:00
};
2017-08-17 23:34:08 +08:00
funcs.setPadTitleInDrive = function (title, cb) {
ctx.sframeChan.query('Q_SET_PAD_TITLE_IN_DRIVE', title, function (err) {
if (cb) { cb(err); }
});
2017-08-17 22:28:54 +08:00
};
2017-08-17 22:56:18 +08: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 23:34:08 +08:00
}).nThen(function () {
2017-08-17 22:56:18 +08:00
cb(funcs);
});
} };
2017-08-17 22:28:54 +08:00
});