Added basic jsdoc for the messages.js file

This commit is contained in:
Paulin Jorys 2017-07-19 18:08:43 +02:00
parent 079126360d
commit bdfc115a0a

View File

@ -1,6 +1,13 @@
var callbacks = {}
var callbacks_ids = 1;
/**
* var sendMessage - Sends a message with arguments to the NaCl module
*
* @param {String} method A named method
* @param {(String|Array)} params An array of options or a signle string
* @return {void} The NaCl module calls back trought the handleMessage method
*/
var sendMessage = function(method, params) {
return new Promise(function(resolve, reject) {
var id = callbacks_ids++;
@ -14,6 +21,12 @@ var sendMessage = function(method, params) {
});
}
/**
* handleMessage - Handles messages from the NaCl module
*
* @param {Object} msg An object given by the NaCl module
* @return {void}
*/
function handleMessage(msg) {
if (msg.data.callbackId && callbacks[msg.data.callbackId]) { // if it's a callback, treat it as such
callbacks[msg.data.callbackId][msg.data.type](msg.data.ret);