sframe common changes

This commit is contained in:
Caleb James DeLisle
2017-08-17 16:56:18 +02:00
parent d1157c4d72
commit 3b5af3ea74
2 changed files with 34 additions and 22 deletions

View File

@@ -1,23 +1,36 @@
define([
'jquery',
'/bower_components/nthen/index.js',
'/common/sframe-chainpad-netflux-inner.js',
], function ($, CpNfInner) {
var common = {};
var cpNfInner;
'/common/sframe-channel.js'
], function (nThen, CpNfInner, SFrameChannel) {
// Chainpad Netflux Inner
common.startRealtime = function (options) {
if (cpNfInner) { return cpNfInner; }
cpNfInner = CpNfInner.start(options);
return cpNfInner;
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;
};
common.isLoggedIn = function () {
if (!cpNfInner) { throw new Error("cpNfInner is not ready!"); }
return cpNfInner.metadataMgr.getPrivateData().accountName;
funcs.isLoggedIn = function () {
if (!ctx.cpNfInner) { throw new Error("cpNfInner is not ready!"); }
return ctx.cpNfInner.metadataMgr.getPrivateData().accountName;
};
return common;
funcs.setTitle = function (title /*:string*/, cb) {
};
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);
});
} };
});