Commit 12125bbc authored by Adrien Dorsaz's avatar Adrien Dorsaz

sendMessage now send JSON Object to give informations about who is the sender...

sendMessage now send JSON Object to give informations about who is the sender and what is the subject.

Maybe later we'll add a target 'to' and we'll make XMPP inception :D
parent d926eab0
......@@ -13,7 +13,7 @@ function saveOptions(e) {
// Save new password if required
let passwordInput = document.querySelector("#password");
if (passwordInput) {
if (passwordInput && passwordInput.value !== '') {
// TODO Currently, we only implement PLAIN authentication, so we need PLAIN password
//let bufferPassword = new TextEncoder("utf-8").encode(passwordInput.value);
//crypto.subtle.digest('SHA-512', bufferPassword)
......@@ -30,7 +30,7 @@ function saveOptions(e) {
});
// Try to connect
chrome.runtime.sendMessage('connect');
browser.runtime.sendMessage({'from': 'options', 'subject': 'connect'});
}
function restoreOptions() {
......
......@@ -13,7 +13,7 @@ for (let pane in panel) {
function displayFirstRun(response) {
if (response.configured == true) {
panel['firstrun'].style.display = 'none';
chrome.runtime.sendMessage('isConnected', displayConnect);
chrome.runtime.sendMessage({'from': 'panel', 'subject': 'isConnected'}, displayConnect);
}
else {
panel['firstrun'].style.display = 'block';
......@@ -40,10 +40,9 @@ function clientConnected(response) {
if (response.step == 'initialized') {
panel['info'].style.display = 'block';
panel['info'].innerHTML = 'Client initiated connection with server. Waiting for authentication…'
window.setTimeout(checkConnection, 100);
checkConnection();
}
if (response.connected == true) {
else if (response.connected == true) {
panel['error'].style.display = 'none';
panel['info'].style.display = 'none';
panel['pubsub'].style.display = 'block';
......@@ -55,11 +54,11 @@ function clientConnected(response) {
}
function sendConnect(ev) {
chrome.runtime.sendMessage('connect', clientConnected);
browser.runtime.sendMessage({'from': 'panel', 'subject': 'connect'}, clientConnected);
}
function checkConnection() {
chrome.runtime.sendMessage('isConnected', clientConnected);
browser.runtime.sendMessage({'from': 'panel', 'subject': 'isConnected'}, clientConnected);
}
connectButtons = document.getElementsByClassName('connectClient');
......@@ -71,13 +70,20 @@ for (let key = 0; key < connectButtons.length; key++) {
let panelListener = function (message, sender, sendRepsone) {
let asynchroneResponse = false;
if (message == "refreshNetwork") {
// TODO: Update network panel if it's the current one
switch (message.subject) {
case "clientInitialized":
if (message.from === 'xmpp-pane') {
checkConnection();
}
break;
case "refreshNetwork":
// TODO: Update network panel if it's the current one
break;
}
return asynchroneResponse;
}
chrome.runtime.onMessage.addListener(panelListener)
browser.runtime.onMessage.addListener(panelListener)
chrome.runtime.sendMessage('isConfigured', displayFirstRun);
browser.runtime.sendMessage({'from': 'panel', 'subject': 'isConfigured'}, displayFirstRun);
......@@ -51,12 +51,12 @@ retrieveConfig = function () {
});
};
var xmppPaneClient = null;
let xmppPaneClient = null;
xmppClientListener = function (message, sender, sendResponse) {
let asynchroneResponse = false;
switch (message) {
switch (message.subject) {
case 'isConfigured':
asynchroneResponse = true;
retrieveConfig()
......@@ -114,6 +114,10 @@ xmppClientListener = function (message, sender, sendResponse) {
xmppPaneClient.connect()
.then(
function (initialized) {
if (message.from !== 'panel') {
browser.runtime.sendMessage({'from': 'xmpp-pane', 'subject': 'clientInitialized'})
}
sendResponse({
step: 'initialized'
});
......@@ -140,4 +144,4 @@ xmppClientListener = function (message, sender, sendResponse) {
}
}
chrome.runtime.onMessage.addListener(xmppClientListener)
browser.runtime.onMessage.addListener(xmppClientListener)
......@@ -69,7 +69,7 @@ class Network {
break;
}
chrome.runtime.sendMessage("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