Commit db10fe49 authored by Adrien Dorsaz's avatar Adrien Dorsaz

entity - network - client wip

parent 12125bbc
......@@ -48,6 +48,10 @@ class Client {
this.lastContractId = 0;
}
get network() {
return this.xmppNet;
}
// Promising a contract
promise(_message, _nodeName) {
return new Promise((resolve, reject) => {
......@@ -439,6 +443,8 @@ class Client {
}
console.log('client: discoPubsubService: succeed: ' + entity);
this.xmppNet.registerService(entity);
},
(bindError) => {
console.log('client: discoPubsubService: unknown error: ' + bindError.error);
......
......@@ -15,13 +15,20 @@ class Entity {
// value: identity name
this.identities = new Map();
// Features and protocols supported by the entity
this.features = [];
this.features = new Set();
this.protocols = new Map();
}
get identityMap() {
return this.identities;
}
get featureSet() {
return this.features;
}
/*
* _identity is a <identity> XML Node
* _xmllang is the client preerend language
*/
addIdentity(_identity) {
let type = _identity.getAttribute('type');
......@@ -48,6 +55,6 @@ class Entity {
* _feature is a <feature> XML Node
*/
addFeature(_feature) {
this.features.push(_feature.getAttribute('var'));
this.features.add(_feature.getAttribute('var'));
}
}
......@@ -17,6 +17,7 @@ class Network {
// key: serviceid (jid?)
// object: array(metaData, nodeMap, collectionMap, leafMap)
// metaData: name (string), features (set)
this.pubsub = new Map();
// key: serviceid
......@@ -28,18 +29,19 @@ class Network {
switch (typeof (_netElement)) {
case 'Entity':
for (let [idKey, idValue] of _netElement.identities) {
for (let [idKey, idValue] of _netElement.identityMap) {
if (idKey.xmllang == 'en'
|| idKey.xmllang == this.xmllang) {
// If pubsub service is discoverd save it on the pubsub/services path
if (idKey.type == "pubsub"
&& idKey.category == "service") {
let service = [];
service["metaData"] = [];
service["metaData"]["name"] = idValue;
service["collections"] = new Map();
service["leaves"] = new Map();
let service = new Map();
service.set("metaData", new Map());
service.get("metaData").set("name", idValue);
service.get("metaData").set("features", new Set());
service.set("collections", new Map());
service.set("leaves", new Map());
this.pubsub.set(_netElement.jid, service);
}
}
......@@ -50,26 +52,26 @@ class Network {
for (let [idKey, idValue] of _netElement.identities) {
if (idKey.type == "pubsub"
&& idKey.category == "collection") {
service["collections"].set(idKey.node, []);
service.get("collections").set(idKey.node, new Map());
}
if (idKey.type == "pubsub"
&& idKey.category == "leaf") {
service["leaves"].set(idKey.node, []);
service.get("leaves").set(idKey.node, new Map());
}
}
}
for (let feature of _netElement.features) {
let featureNode = entityNode.createElement("feature");
featureNode.addAttribute("type", feature)
for (let feature of _netElement.featureSet) {
// TODO: decide which features to track and how to use them
service.get("metaData").get("features").add(feature);
}
break;
}
browser.runtime.sendMessage({'subject': 'refreshNetwork'});
browser.runtime.sendMessage({
'subject': 'refreshNetwork'
});
}
/*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment