Add web worker support. Load the whole library in a web worker

and make the high-level API accessible from an asynchronous proxy.
Entropy is seeded to worker on each generateKeyPair() call.
Allow serialization of packets and custom types for messaging API.
This commit is contained in:
Thomas Oberndörfer
2014-01-13 13:56:06 +01:00
parent 4f2100fa40
commit 3612fc12dc
25 changed files with 499 additions and 20 deletions

View File

@@ -46,6 +46,25 @@ module.exports = {
*/
newPacketFromTag: function (tag) {
return new this[packetClassFromTagName(tag)]();
},
/**
* Allocate a new packet from structured packet clone
* See {@link http://www.w3.org/html/wg/drafts/html/master/infrastructure.html#safe-passing-of-structured-data}
* @param {Object} packetClone packet clone
* @returns {Object} new packet object with data from packet clone
*/
fromStructuredClone: function(packetClone) {
var tagName = enums.read(enums.packet, packetClone.tag)
var packet = this.newPacketFromTag(tagName);
for (var attr in packetClone) {
if (packetClone.hasOwnProperty(attr)) {
packet[attr] = packetClone[attr];
}
}
if (packet.postCloneTypeFix) {
packet.postCloneTypeFix();
}
return packet;
}
};
@@ -57,10 +76,3 @@ module.exports = {
function packetClassFromTagName(tag) {
return tag.substr(0, 1).toUpperCase() + tag.substr(1);
}
for (var i in enums.packet) {
var packetClass = module.exports[packetClassFromTagName(i)];
if (packetClass !== undefined)
packetClass.prototype.tag = enums.packet[i];
}