cryptpad/www/common/sframe-common.js

37 lines
1.0 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 22:56:18 +08:00
funcs.setTitle = function (title /*:string*/, cb) {
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....
}).nThen(function (waitFor) {
cb(funcs);
});
} };
2017-08-17 22:28:54 +08:00
});