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
|
|
@ -0,0 +1,125 @@
|
|||
/* global bridge */
|
||||
|
||||
(function(exports) {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Name of the service that is responsible for messaging functionality.
|
||||
* @type {string}
|
||||
*/
|
||||
const SERVICE_NAME = 'messaging-service';
|
||||
/**
|
||||
* Disable default client timeout from bridge by setting the timeout to false.
|
||||
* @type {number|boolean}
|
||||
*/
|
||||
const TIMEOUT = false;
|
||||
|
||||
/**
|
||||
* Reference to active bridge client instance.
|
||||
* @type {Client}
|
||||
*/
|
||||
var client;
|
||||
|
||||
/**
|
||||
* Unique identifier of app instance where client resides in.
|
||||
* @type {string}
|
||||
*/
|
||||
var appInstanceId;
|
||||
|
||||
var MessagingClient = {
|
||||
/**
|
||||
* Initializes connection to MessagingService hosted in a SharedWorker.
|
||||
* @param {string} applicationInstanceId Unique identifier of app instance
|
||||
* where client resides in.
|
||||
*/
|
||||
init(applicationInstanceId) {
|
||||
if (!applicationInstanceId) {
|
||||
throw new Error('AppInstanceId is required!');
|
||||
}
|
||||
|
||||
var serviceEndpoint = new SharedWorker(
|
||||
'/services/js/messaging/messaging_service.js'
|
||||
);
|
||||
|
||||
appInstanceId = applicationInstanceId;
|
||||
|
||||
client = bridge.client({
|
||||
service: SERVICE_NAME,
|
||||
endpoint: serviceEndpoint,
|
||||
timeout: TIMEOUT
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Sends an SMS based on the specified parameter object.
|
||||
* @param {Object} options Options object that contains :-
|
||||
* - recipients (string or array of string): contains the list of
|
||||
* recipients for this message
|
||||
* - content (string): the message's body
|
||||
* - serviceId (optional long or string): the SIM serviceId we use to send
|
||||
* the message
|
||||
* - onsuccess (optional function): will be called when one SMS has been
|
||||
* sent successfully, with the request's result as argument. Can be called
|
||||
* several times.
|
||||
* - onerror (optional function): will be called when one SMS transmission
|
||||
* failed, with the error object as argument. Can be called several times.
|
||||
* - oncomplete (optional function): will be called when all messages have
|
||||
* been sent. Its argument will have the following properties:
|
||||
* + hasError (boolean): whether we had at least one error
|
||||
* + return (array): each item is an object with the following properties:
|
||||
* . success (boolean): whether this is a success or an error
|
||||
* . result (request's result): the request's result object
|
||||
* . recipient (string): the recipient used for this transmission.
|
||||
* @return {Promise}
|
||||
*/
|
||||
sendSMS(options) {
|
||||
return client.method('sendSMS', options, appInstanceId);
|
||||
},
|
||||
|
||||
/**
|
||||
* Sends an MMS based on the specified parameter object.
|
||||
* @param {Object} options Options object is the options field with the
|
||||
* following properties:
|
||||
* - recipients (string or array of string): recipients for this message.
|
||||
* - subject (optional string): subject for this message.
|
||||
* - content (array of SMIL slides): this is the content for the message
|
||||
* (see ConversationView for more information).
|
||||
* - serviceId (optional long or string): the SIM that should be used for
|
||||
* sending this message. If this is not the current default configuration
|
||||
* for sending MMS, then we'll first switch the configuration to this
|
||||
* serviceId, and only then send the message. That means that the
|
||||
* "sending" event will come quite late in this case.
|
||||
* - onsuccess (optional func): called only once, even for several
|
||||
* recipients, when the message is successfully sent.
|
||||
* - onerror (optional func): called only once if there is an error.
|
||||
* @return {Promise}
|
||||
*/
|
||||
sendMMS(options) {
|
||||
return client.method('sendMMS', options, appInstanceId);
|
||||
},
|
||||
|
||||
/**
|
||||
* Resends message with the given opts.
|
||||
* Takes a formatted message in case you happen to have one.
|
||||
* @param {Object} message The message object containing all the information
|
||||
* depending on the type of the message which can be 'sms' or 'mms'.
|
||||
* @return {Promise}
|
||||
*/
|
||||
resendMessage(message) {
|
||||
return client.method('resendMessage', message, appInstanceId);
|
||||
},
|
||||
|
||||
/**
|
||||
* Gets the MMS object having a given id.
|
||||
* @param {number} id The id of the MMS we wish to get.
|
||||
* @return {Promise<MmsMessage>} A Promise object that handles the success
|
||||
* or error of the operation.
|
||||
*/
|
||||
retrieveMMS(id) {
|
||||
return client.method('retrieveMMS', id, appInstanceId);
|
||||
}
|
||||
};
|
||||
|
||||
exports.MessagingClient = Object.freeze(MessagingClient);
|
||||
|
||||
})(window);
|
||||
|
|
@ -0,0 +1,197 @@
|
|||
/* global bridge,
|
||||
BridgeServiceMixin,
|
||||
MozMobileMessageClient,
|
||||
Settings,
|
||||
SMIL
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
if (!('BridgeServiceMixin' in self)) {
|
||||
importScripts('/services/js/bridge_service_mixin.js');
|
||||
}
|
||||
|
||||
if (!('MozMobileMessageClient' in self)) {
|
||||
importScripts('/services/js/moz_mobile_message/moz_mobile_message_client.js');
|
||||
}
|
||||
|
||||
(function(exports) {
|
||||
|
||||
const SERVICE_NAME = 'messaging-service';
|
||||
|
||||
const METHODS = Object.freeze([
|
||||
'sendSMS', 'sendMMS', 'resendMessage', 'retrieveMMS'
|
||||
]);
|
||||
|
||||
function ensureBridge() {
|
||||
if (!('bridge' in self) || !('service' in bridge)) {
|
||||
importScripts('/lib/bridge/service.js');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 0 is a valid value so we need to take care to not consider it as a falsy
|
||||
* value. We want to return null for anything that's not a number or a
|
||||
* string containing a number.
|
||||
*/
|
||||
function sanitizeServiceId(serviceId) {
|
||||
if (serviceId == null || // null or undefined
|
||||
isNaN(+serviceId)) {
|
||||
serviceId = null;
|
||||
} else {
|
||||
serviceId = +serviceId;
|
||||
}
|
||||
|
||||
return serviceId;
|
||||
}
|
||||
|
||||
function getSendOptionsFromServiceId(serviceId) {
|
||||
var sendOpts;
|
||||
|
||||
if (serviceId != null && // not null, not undefined
|
||||
Settings.hasSeveralSim()) {
|
||||
sendOpts = { serviceId: serviceId };
|
||||
}
|
||||
|
||||
return sendOpts;
|
||||
}
|
||||
|
||||
var MessagingService = {
|
||||
/**
|
||||
* Initializes our service using the Service mixin's initService and
|
||||
* requests mozMobileMessage shim as client.
|
||||
*/
|
||||
init() {
|
||||
ensureBridge();
|
||||
|
||||
this.initService();
|
||||
},
|
||||
|
||||
/**
|
||||
* Send sms by using send API shim.
|
||||
* @param {String|String[]} recipients Contains the list of recipients for
|
||||
* this message.
|
||||
* @param {String} content The message's body.
|
||||
* @param {Number|String} serviceId The SIM serviceId we use to send the
|
||||
* message.
|
||||
* @param {appInstanceId} appInstanceId Unique id of the app instance
|
||||
* requesting service.
|
||||
* @returns {Promise} Promise with array of the request result.
|
||||
*/
|
||||
sendSMS({ recipients, content, serviceId }, appInstanceId) {
|
||||
recipients = recipients || [];
|
||||
serviceId = sanitizeServiceId(serviceId);
|
||||
|
||||
if (!Array.isArray(recipients)) {
|
||||
recipients = [recipients];
|
||||
}
|
||||
|
||||
var sendOpts = getSendOptionsFromServiceId(serviceId);
|
||||
var mobileMessageClient = MozMobileMessageClient.forApp(appInstanceId);
|
||||
|
||||
var results = recipients.map((recipient) => {
|
||||
return mobileMessageClient.send(recipient, content, sendOpts).then(
|
||||
(message) => ({ message: message }), (error) => ({ error: error })
|
||||
);
|
||||
});
|
||||
|
||||
return Promise.all(results).then((values) =>
|
||||
values.map((result, idx) => ({
|
||||
success: !result.error,
|
||||
result: result.message,
|
||||
code: result.error,
|
||||
recipient: recipients[idx]
|
||||
}))
|
||||
);
|
||||
},
|
||||
|
||||
/**
|
||||
* Send mms by using sendMMS API shim.
|
||||
* @param {String|String[]} recipients Recipients for this message.
|
||||
* @param {String} subject Subject for this message.
|
||||
* @param {Object[]} content This is the content for the message (
|
||||
* see ConversationView for more information).
|
||||
* @param {Number|String} serviceId The SIM that should be used for
|
||||
* sending this message. If this is not the current default configuration
|
||||
* for sending MMS, then we'll first switch the configuration to this
|
||||
* serviceId, and only then send the message. That means that the
|
||||
* "sending" event will come quite late in this case.
|
||||
* @param {appInstanceId} appInstanceId Unique id of the app instance
|
||||
* requesting service.
|
||||
* @returns {Promise} DOMRequest promise with success result or error.
|
||||
*/
|
||||
sendMMS({ recipients, content, subject, serviceId }, appInstanceId) {
|
||||
serviceId = sanitizeServiceId(serviceId);
|
||||
|
||||
if (!Array.isArray(recipients)) {
|
||||
recipients = [recipients];
|
||||
}
|
||||
|
||||
var message = SMIL.generate(content);
|
||||
|
||||
var sendOpts = getSendOptionsFromServiceId(serviceId);
|
||||
|
||||
return MozMobileMessageClient.forApp(appInstanceId).sendMMS({
|
||||
receivers: recipients,
|
||||
subject: subject,
|
||||
smil: message.smil,
|
||||
attachments: message.attachments
|
||||
}, sendOpts);
|
||||
},
|
||||
|
||||
/**
|
||||
* Resend a message by send API shim with existing message information.
|
||||
* @param {Message} message Target message that need to be resent.
|
||||
* @param {appInstanceId} appInstanceId Unique id of the app instance
|
||||
* requesting service.
|
||||
* @returns {Promise} DOMRequest promise with success result or error.
|
||||
*/
|
||||
resendMessage(message, appInstanceId) {
|
||||
if (!message) {
|
||||
throw new Error('Message to resend is not defined.');
|
||||
}
|
||||
|
||||
var serviceId = Settings.getServiceIdByIccId(message.iccId);
|
||||
var sendOpts = getSendOptionsFromServiceId(serviceId);
|
||||
var request;
|
||||
|
||||
var mobileMessageClient = MozMobileMessageClient.forApp(appInstanceId);
|
||||
|
||||
if (message.type === 'sms') {
|
||||
request = mobileMessageClient.send(
|
||||
message.receiver, message.body, sendOpts
|
||||
);
|
||||
} else if (message.type === 'mms') {
|
||||
request = mobileMessageClient.sendMMS({
|
||||
receivers: message.receivers,
|
||||
subject: message.subject,
|
||||
smil: message.smil,
|
||||
attachments: message.attachments
|
||||
}, sendOpts);
|
||||
}
|
||||
|
||||
return mobileMessageClient.delete(message.id).then(() => request);
|
||||
},
|
||||
|
||||
/**
|
||||
* Retrieve a MMS by retrieveMMS API shim by message ID.
|
||||
* @param {Number} id mms message id for retrieval.
|
||||
* @param {appInstanceId} appInstanceId Unique id of the app instance
|
||||
* requesting service.
|
||||
* @returns {Promise} DOMRequest promise with success result or error.
|
||||
*/
|
||||
retrieveMMS(id, appInstanceId) {
|
||||
return MozMobileMessageClient.forApp(appInstanceId).retrieveMMS(id);
|
||||
}
|
||||
};
|
||||
|
||||
exports.MessagingService = BridgeServiceMixin.mixin(
|
||||
MessagingService,
|
||||
SERVICE_NAME,
|
||||
{ methods: METHODS }
|
||||
);
|
||||
|
||||
if (!self.document) {
|
||||
MessagingService.init();
|
||||
}
|
||||
|
||||
})(self);
|
||||
Loading…
Reference in a new issue