Commit 8d8edf8a authored by Adrien Dorsaz's avatar Adrien Dorsaz

wip: adding network scheme (not finished, only the main idea)

parent 7ddfb31d
......@@ -29,6 +29,7 @@
"src/xmpp/core/iq.js",
"src/xmpp/discover/entity.js",
"src/xmpp/server.js",
"src/xmpp/network.js",
"src/xmpp/client.js",
"src/xmpp-pane-main.js"
]
......
......@@ -40,6 +40,9 @@ class Client {
this.bindError = null;
this.tls = false;
// XMPP Network discovered
this.xmppNet = new Network(this.config.xmllang);
// Contracts
this.contracts = {};
this.lastContractId = 0;
......@@ -395,11 +398,16 @@ class Client {
* Discover an Entity
*
* Node attribute is optional
* This is WIP and will be replaced by "discoverPubSubService"
* the idea will be to:
* * disco#info on service name
* * disco#items on first level of service
* * disco#info on each of discovered node of first level service
*/
discover(_entity, _node = null) {
console.log('client: discover: starting');
discoPubsubService (_entity, _node = null) {
console.log('client: discoPubsubService: starting');
let iq = new IQ({
let iqinfo = new IQ({
from: this.config.jid,
to: _entity,
id: this.lastContractId++,
......@@ -407,18 +415,18 @@ class Client {
});
if (_node) {
iq.addExtendedAttribute('node', _node);
iqInfo.addExtendedAttribute('node', _node);
}
let query = this.dom.createElementNS(Constants.NS_DISCO_INFO, 'query');
iq.build(query)
.then((iqElement) => {
iqInfo.build(query)
.then((iqInfoService) => {
// TODO: Add expected namespace as Constants.NS_DISCO_INFO
this.promise(iqElement, 'iq')
this.promise(iqInfoService, 'iq')
.then(
(iqResponse) => {
let entity = new Entity();
let entity = new Entity(iqResponse.getElementsByTagName('iq')[0].getAttribute('from'));
let identities = iqResponse.getElementsByTagName('identity');
let features = iqResponse.getElementsByTagName('feature');
......@@ -430,10 +438,10 @@ class Client {
entity.addFeature(features[i]);
}
console.log('client: discover: succeed: ' + entity);
console.log('client: discoPubsubService: succeed: ' + entity);
},
(bindError) => {
console.log('client: discover: unknown error: ' + bindError.error);
console.log('client: discoPubsubService: unknown error: ' + bindError.error);
});
});
}
......
......@@ -46,4 +46,7 @@ class Constants {
static get NS_DISCO_INFO() {
return "http://jabber.org/protocol/disco#info";
}
static get NS_DISCO_ITEMS() {
return "http://jabber.org/protocol/disco#items";
}
}
......@@ -27,8 +27,9 @@ class Entity {
let type = _identity.getAttribute('type');
let category = _identity.getAttribute('category');
let name = _identity.getAttribute('name');
let node = _identity.getAttribute('node');
let idKey = ['type': type, 'category': category];
let idKey = ['type': type, 'category': category, 'node': node];
let identity = this.identities.get(idKey)
if (identity) {
......
/*
* Network is a representation of the discovered XMPP network
*
* It receives result from discovery and return adapted HTML code
* to visualize the network.
*/
class Network {
constructor(_xmllang) {
// Prefered language to use if possible
this.xmllang = _xmllang;
// Map model
this.discover = new Map();
// key: jid
this.entities = new Map();
// key: serviceid (jid?)
// object: array(metaData, nodeMap, collectionMap, leafMap)
this.pubsub = new Map();
// key: serviceid
// object: nodeid
this.pubsubSubscriptions = new Map();
}
registerService(_netElement) {
switch(typeof(_netElement)) {
case 'Entity':
for (let [idKey, idValue] of _netElement.identities) {
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();
this.pubsub.set(_netElement.jid, service);
}
}
if (this.pubsub.has(_netElement.jid)){
let service = this.pubsub.get(_netElement.jid);
for (let [idKey, idValue] of _netElement.identities) {
if (idKey.type == "pubsub"
&& idKey.category == "collection") {
service["collections"].set(idKey.node, []);
}
if (idKey.type == "pubsub"
&& idKey.category == "leaf") {
service["leaves"].set(idKey.node, []);
}
}
}
for (let feature of _netElement.features) {
let featureNode = entityNode.createElement("feature");
featureNode.addAttribute("type", feature)
// TODO: decide which features to track and how to use them
}
break;
}
chrome.runtime.sendMessage("refreshNetwork");
}
/*
* Create a JSON representation of the network
* This representation is only used to save the network to local storage
*/
stringify() {
let jsonNet;
return jsonNet;
}
/*
* Read the network from a JSON object
* This will be used to restore network from local storage
*/
parse(_jsonNet) {
return ;
}
}
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