Publish Vulpes Preview 15 sources for desktop, Android and Tundra
Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
This commit is contained in:
parent
93e3a48004
commit
b38dea0597
25901 changed files with 9982925 additions and 369 deletions
90
assets/webapps/costcontrol.gaiamobile.org/js/iac_manager.js
Normal file
90
assets/webapps/costcontrol.gaiamobile.org/js/iac_manager.js
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
/* global debug, Promise */
|
||||
/* exported IACManager */
|
||||
'use strict';
|
||||
|
||||
var IACManager = (function() {
|
||||
var TIMEOUT = 60 * 1000; // 1 minute
|
||||
var configuration;
|
||||
|
||||
function init(cfg) {
|
||||
configuration = cfg;
|
||||
}
|
||||
|
||||
function broadcastStartOfSMSQuery(type) {
|
||||
return IACManager._sendBroadcastMessage(_generateMsg(type, 'enable'));
|
||||
}
|
||||
|
||||
function broadcastEndOfSMSQuery(type) {
|
||||
return IACManager._sendBroadcastMessage(_generateMsg(type, 'disable'));
|
||||
}
|
||||
|
||||
function _sendBroadcastMessage(msg) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
navigator.mozApps.getSelf().onsuccess = function(evt) {
|
||||
var app = evt.target.result;
|
||||
app.connect('costcontrolSmsQuery').then(function onConnAccepted(ports) {
|
||||
debug('Connection with sms app established...');
|
||||
ports.forEach(function(port) {
|
||||
var waitingForAnswerTimeout;
|
||||
|
||||
port.onmessage = function() {
|
||||
clearTimeout(waitingForAnswerTimeout);
|
||||
resolve();
|
||||
};
|
||||
// if no one has replied the message in one minute, the proposal
|
||||
// will be rejected
|
||||
waitingForAnswerTimeout = window.setTimeout(function() {
|
||||
var errorMsg = 'Rejection by Timeout. No received answer to ' +
|
||||
msg.action + ' ' + msg.type + ' request.';
|
||||
reject(errorMsg);
|
||||
}, TIMEOUT);
|
||||
|
||||
port.postMessage(msg);
|
||||
});
|
||||
}, function onConnRejected(reason) {
|
||||
console.log('Rejected connection attempt due to', reason);
|
||||
reject(reason);
|
||||
});
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
function _getSmsNumberList(service) {
|
||||
var silentSmsList = [];
|
||||
if (configuration && configuration[service]) {
|
||||
silentSmsList = configuration[service].senders;
|
||||
if (silentSmsList.indexOf(configuration[service].destination) === -1) {
|
||||
silentSmsList.push(configuration[service].destination);
|
||||
}
|
||||
}
|
||||
return silentSmsList;
|
||||
}
|
||||
|
||||
function _reset() {
|
||||
configuration = null;
|
||||
}
|
||||
|
||||
function _generateMsg(service, action) {
|
||||
var outgoingNumber = configuration[service] &&
|
||||
configuration[service].destination;
|
||||
var incomingNumbers = configuration[service] &&
|
||||
configuration[service].senders;
|
||||
return {
|
||||
action: action,
|
||||
type: service,
|
||||
smsNumbers: _getSmsNumberList(service),
|
||||
outgoingNumber: outgoingNumber,
|
||||
incomingNumbers: incomingNumbers
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
init: init,
|
||||
broadcastStartOfSMSQuery: broadcastStartOfSMSQuery,
|
||||
broadcastEndOfSMSQuery: broadcastEndOfSMSQuery,
|
||||
_getSmsNumberList: _getSmsNumberList,
|
||||
_generateMsg: _generateMsg,
|
||||
_sendBroadcastMessage: _sendBroadcastMessage,
|
||||
_reset: _reset
|
||||
};
|
||||
}());
|
||||
Loading…
Reference in a new issue