Commit f6daed85 authored by Adrien Dorsaz's avatar Adrien Dorsaz

panel, client, network: wip explore server

parent 1a21cce1
......@@ -24,12 +24,13 @@
<div id="pubsubpanel" class="panel">
<h1>Communities</h1>
<a href="subscribe">Subscribe to new Community</a>
<h2>Example.org</h2>
<ul>
<li>Foo Example</li>
<li>Bar Example</li>
</ul>
<form id='explore'>
<label for="exploreServer">Server:</label><input id="exploreServer" type="text"></input>
<button type="send">explore</button>
</form>
<div id="xmppNet"></div>
</div>
<script src="panel.js"></script>
......
......@@ -70,12 +70,38 @@ function checkConnection() {
}, clientConnected);
}
function refreshNetwork(network) {
if (network) {
let xmppNet = document.getElementById('xmppNet');
xmppNet.innerHTML = network.toString();
}
else {
panel['error'].style.display = 'block';
panel['error'].innerHTML = 'No response received !';
}
}
function exploreServer(ev) {
browser.runtime.sendMessage({
'from': 'panel',
'subject': 'exploreServer',
'payload': document.getElementById('exploreServer').value
}, refreshNetwork);
}
connectButtons = document.getElementsByClassName('connectClient');
for (let key = 0; key < connectButtons.length; key++) {
connectButtons[key].onclick = sendConnect;
}
exploreForm = document.getElementById('explore');
exploreForm.addEventListener('submit', (event) => {
exploreServer(event);
event.preventDefault();
}, false);
let panelListener = function (message, sender, sendRepsone) {
let asynchroneResponse = false;
......
......@@ -61,12 +61,12 @@ xmppClientListener = function (message, sender, sendResponse) {
asynchroneResponse = true;
retrieveConfig()
.then(
function (config) {
(config) => {
sendResponse({
configured: true
});
},
function (error) {
(error) => {
sendResponse({
configured: false
});
......@@ -107,13 +107,13 @@ xmppClientListener = function (message, sender, sendResponse) {
asynchroneResponse = true;
retrieveConfig()
.then(
function (_config) {
(_config) => {
xmppPaneClient = new Client(_config);
_config = null;
xmppPaneClient.connect()
.then(
function (initialized) {
(initialized) => {
if (message.from !== 'panel') {
browser.runtime.sendMessage({
'from': 'xmpp-pane',
......@@ -125,14 +125,14 @@ xmppClientListener = function (message, sender, sendResponse) {
step: 'initialized'
});
},
function (error) {
(error) => {
sendResponse({
connected: false,
error: error
});
});
},
function (error) {
(error) => {
sendResponse({
connected: false,
error: error
......@@ -140,6 +140,24 @@ xmppClientListener = function (message, sender, sendResponse) {
}
);
break;
case 'exploreServer':
asynchroneResponse = true;
xmppPaneClient.discoPubsubService(message.payload)
.then(
(network) => {
sendResponse({
'step': 'discovered',
'network': xmppPaneClient.network
});
},
(error) => {
sendResponse({
'step': 'discovered',
'error': error
});
});
break;
}
if (asynchroneResponse) {
......
......@@ -411,46 +411,55 @@ class Client {
* * disco#info on each of discovered node of first level service
*/
discoPubsubService(_entity, _node = null) {
console.log('client: discoPubsubService: starting');
let iqInfo = new IQ({
from: this.config.jid,
to: _entity,
id: this.lastContractId++,
type: 'get'
});
if (_node) {
iqInfo.addExtendedAttribute('node', _node);
}
let query = this.dom.createElementNS(Constants.NS_DISCO_INFO, 'query');
iqInfo.build(query)
.then((iqInfoService) => {
// TODO: Add expected namespace as Constants.NS_DISCO_INFO
this.promise(iqInfoService, 'iq')
.then(
(iqResponse) => {
let entity = new Entity(iqResponse.getAttribute('from'));
let identities = iqResponse.getElementsByTagName('identity');
let features = iqResponse.getElementsByTagName('feature');
for (let i = 0; i < identities.length; i++) {
entity.addFeature(identities[i]);
}
return new Promise((resolve, reject) => {
console.log('client: discoPubsubService: starting');
for (let i = 0; i < features.length; i++) {
entity.addFeature(features[i]);
}
let iqInfo = new IQ({
from: this.config.jid,
to: _entity,
id: this.lastContractId++,
type: 'get'
});
console.log('client: discoPubsubService: succeed: ' + entity);
if (_node) {
iqInfo.addExtendedAttribute('node', _node);
}
this.xmppNet.registerService(entity);
},
(bindError) => {
console.log('client: discoPubsubService: unknown error: ' + bindError.error);
});
});
let query = this.dom.createElementNS(Constants.NS_DISCO_INFO, 'query');
iqInfo.build(query)
.then((iqInfoService) => {
// TODO: Add expected namespace as Constants.NS_DISCO_INFO
this.promise(iqInfoService, 'iq')
.then(
(iqResponse) => {
let entity = new Entity(iqResponse.getAttribute('from'));
let identities = iqResponse.getElementsByTagName('identity');
let features = iqResponse.getElementsByTagName('feature');
for (let i = 0; i < identities.length; i++) {
entity.addFeature(identities[i]);
}
for (let i = 0; i < features.length; i++) {
entity.addFeature(features[i]);
}
console.log('client: discoPubsubService: succeed: ' + entity);
this.xmppNet.registerService(entity);
},
(error) => {
reject('client: discoPubsubService: unknown error: ' + error);
})
.then(
(result) => {
resolve(this.xmppNet)
},
(error) => {
reject('client was not able to discover pubsub service: ' + _entity);
});
})
});
}
}
......@@ -26,9 +26,8 @@ class Network {
}
registerService(_netElement) {
switch (typeof (_netElement)) {
case 'Entity':
if (_netElement instanceof Entity) {
// Look for identities
for (let [idKey, idValue] of _netElement.identityMap) {
if (idKey.xmllang == 'en'
|| idKey.xmllang == this.xmllang) {
......@@ -47,8 +46,11 @@ class Network {
}
}
// Fill the pubusb service
if (this.pubsub.has(_netElement.jid)) {
let service = this.pubsub.get(_netElement.jid);
// Look for collections and leaves
for (let [idKey, idValue] of _netElement.identities) {
if (idKey.type == "pubsub"
&& idKey.category == "collection") {
......@@ -62,11 +64,18 @@ class Network {
}
}
for (let feature of _netElement.featureSet) {
// TODO: decide which features to track and how to use them
service.get("metaData").get("features").add(feature);
// Look for features
let service = null;
if (this.pubsub.has(_netElement.jid)) {
let service = this.pubsub.get(_netElement.jid);
}
if (service){
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({
......
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