aboutsummaryrefslogtreecommitdiffstats
path: root/lang/js
diff options
context:
space:
mode:
Diffstat (limited to 'lang/js')
-rw-r--r--lang/js/src/Connection.js20
-rw-r--r--lang/js/src/Errors.js4
-rw-r--r--lang/js/src/permittedOperations.js3
-rw-r--r--lang/js/testapplication.js4
4 files changed, 19 insertions, 12 deletions
diff --git a/lang/js/src/Connection.js b/lang/js/src/Connection.js
index 8bc3d42a..4270be58 100644
--- a/lang/js/src/Connection.js
+++ b/lang/js/src/Connection.js
@@ -118,14 +118,18 @@ export class Connection{
};
me._connection.onMessage.addListener(listener);
- me._connection.postMessage(message.message);
-
- //TBD: needs to be aware if there is a pinentry pending
- // setTimeout(
- // function(){
- // me.disconnect();
- // reject(GPGMEJS_Error('CONN_TIMEOUT'));
- // }, timeout);
+ let timeout = new Promise(function(resolve, reject){
+ setTimeout(function(){
+ reject(GPGMEJS_Error('CONN_TIMEOUT'));
+ }, 5000);
+ });
+ if (permittedOperations[message.operation].pinentry){
+ return me._connection.postMessage(message.message);
+ } else {
+ return Promise.race([timeout,
+ me._connection.postMessage(message.message)
+ ]);
+ }
});
}
};
diff --git a/lang/js/src/Errors.js b/lang/js/src/Errors.js
index c49bfe21..04b13e10 100644
--- a/lang/js/src/Errors.js
+++ b/lang/js/src/Errors.js
@@ -104,12 +104,12 @@ export function GPGMEJS_Error(code = 'GENERIC_ERROR'){
if (errors.hasOwnProperty(code)){
code = 'GENERIC_ERROR';
}
- if (error.type === 'error'){
+ if (errors.type === 'error'){
return {code: 'code',
msg: errors[code].msg
};
}
- if (error.type === 'warning'){
+ if (errors.type === 'warning'){
console.log(code + ': ' + error[code].msg);
}
return undefined;
diff --git a/lang/js/src/permittedOperations.js b/lang/js/src/permittedOperations.js
index 3c11b8e0..892f4f2e 100644
--- a/lang/js/src/permittedOperations.js
+++ b/lang/js/src/permittedOperations.js
@@ -23,6 +23,8 @@
* operation: <Object>
required: Array<String>
optional: Array<String>
+ pinentry: Boolean If a pinentry dialog is expected, and a timeout of
+ 5000 ms would be too short
answer: <Object>
type: <String< The content type of answer expected
data: Array<String> The payload property of the answer. May be
@@ -59,6 +61,7 @@ export const permittedOperations = {
},
decrypt: {
+ pinentry: true,
required: ['data'],
optional: [
'protocol',
diff --git a/lang/js/testapplication.js b/lang/js/testapplication.js
index f47299e8..b2cb4c23 100644
--- a/lang/js/testapplication.js
+++ b/lang/js/testapplication.js
@@ -33,7 +33,7 @@ document.addEventListener('DOMContentLoaded', function() {
document.getElementById('answer').value = answer.data;
}
}, function(errormsg){
- alert('Error: '+ errormsg);
+ alert( errormsg.code + ' ' + errormsg.msg);
});
});
@@ -47,7 +47,7 @@ document.addEventListener('DOMContentLoaded', function() {
document.getElementById('answer').value = answer.data;
}
}, function(errormsg){
- alert('Error: '+ errormsg);
+ alert( errormsg.code + ' ' + errormsg.msg);
});
});
},