问题
I have included YDN DB file (ydn-db-isw-core-crypt-qry-dev.js) to encrypt Index DB in angular app.It's added in index.html body section after socket.io-1.4.5.js,a loader spinner.head section includes plivo.min.js library-
<script type="text/javascript" src="./assets/ydnCoreCryptQryDev.js"></script>
Earlier i was using plain IndexDB and things were going well.But the collection details were visible in developer tools.
Now after including YDN DB,It just keeps loading homepage after setting user credentials in window session storage and finished Db initialising.
The DB initialization code is -
function open() {
var deferred = $q.defer();
var options = {
Encryption: {
encryptKey: false, // optional encrypt primary key
secrets: [{
name: 'dddd',
key: 'xxxxxxxxxx'
}]
}
};
var schema = {
stores:[{
name:'profile',
encrypted: true
},{
name:'contacts',
encrypted: true
},{
name:'archive',
encrypted: true
},{
name:'avatars',
encrypted: true
},{
name:'groups',
encrypted: true
},{
name:'notifications',
encrypted: true
}]
};
var db = new ydn.db.Storage('nowconferdb', schema, options);
db.onReady(function() {
console.log('DB is initialized');
avatarstorage.setDB(db);
contactstorage.setDB(db);
profilestorage.setDB(db);
groupstorage.setDB(db);
archivestorage.setDB(db);
notificationstorage.setDB(db);
deferred.resolve(true);
});
db.addEventListener('fail', function (event) {
var err = event.getError();
if (err.name == 'versionchange') {
console.log('The application is updated, please refresh to upgrade.');
avatarstorage.setup(db);
contactstorage.setup(db);
profilestorage.setup(db);
groupstorage.setup(db);
archivestorage.setup(db);
notificationstorage.setup(db);
} else {
console.log('connection failed with ' + err.name + ' by ' + err.message);
db = null; // no operation can be placed to the database instance
}
deferred.reject(false);
});
return deferred.promise;
}
After this following should execute which is not executing also I am passing the DB to multiple services for Use. -
storageservice.open().then(function() {
console.log('post initializing storageservice'); // <<<<
if (me.getAuth()) {
console.log('user is authenticated'); // <<<<
me.loadMe(sessionUser._id).then(function(profile) {
me.setMe(angular.extend(profile, sessionUser)).then(function() {
console.log('setting user');
deferred.resolve();
},
function() {
deferred.reject(1);
});
}, function() {
me.setMe(sessionUser).then(function() {
console.log('setting user info');
deferred.resolve();
}, function() {
deferred.reject(1);
});
});
}
else {
console.log('user is not authenticated');
me.loadMe(sessionUser._id).then(function(profile) {
console.log('loaded profile:'+JSON.stringify(profile));
deferred.resolve(profile);
}, function() {
me.setMe(sessionUser).then(function() {
console.log('setting user details');
deferred.resolve();
}, function() {
console.log('failed to set user');
deferred.reject(1);
});
});
}
});
Can somebody help.
Thanks a lot.
Update -
Used callback approach in place of deferred.promise and code started executing to next block (getting console of "post initializing storageservice","user is authenticated").
Everything looks fine with deferred.promise, Little awkward !!
来源:https://stackoverflow.com/questions/39168002/ydn-db-include-issue