WebAPI/WebMMS: Difference between revisions

From MozillaWiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 5: Line 5:
= API =
= API =


   // TODO should we merge with this with SmsManager?
   /**
  * TODO should we merge with this with SmsManager? There are good reasons for and against it.
  * Pro: One API to rule them all, less API clutter, easier to write integrated SMS/MMS app
  *      (which is what everybody wants anyway)
  * Con: MMS is vastly more complex than SMS, both in terms of API as in terms of implementation
  *      and storing; implementations need to be acutely aware of MMS and how to deal with them.
  */
   interface MmsManager
   interface MmsManager
   {
   {
  DOMRequest       send(MmsMessage message);
    DOMRequest   send(MmsMessage message);
  DOMRequest[]     send(MmsMessage message[]);
    DOMRequest[] send(MmsMessage message[]);
  DOMRequest       delete(in long id);
    DOMRequest   delete(long id);
  DOMRequest       delete(in MmsMessage message);
    DOMRequest   delete(MmsMessage message);
  DOMRequest       getMessage(in long id);
    DOMRequest   getMessage(long id);
  DOMRequest       getMessages(in SMSFilter filter, bool reverse);
    DOMRequest   getMessages(SMSFilter filter, bool reverse);
 
    /**
    * Fetch a message's data. Only applicable if message.delivery == "unfetched"
    */
    DOMRequest  fetchMessage(MmsMessage message);
 
    /**
    * Forward a message to a different number.
    */
    DOMRequest  forwardMessage(MmsMessage message, recipient);
 
    /**
    * Cancel a message's delivery with the MMSC.
    */
    DOMRequest  cancelMessage(MmsMessage message);
   }
   }
    
    
Line 19: Line 40:
   interface MmsMessage
   interface MmsMessage
   {
   {
    /**
    * Cf. SmsMessage
    */
     readonly attribute long                id;
     readonly attribute long                id;
    /**
    * Like SmsMessage::delivery, but with an additional possible value: "unfetched"
    */
     readonly attribute DOMString            delivery;
     readonly attribute DOMString            delivery;
    /**
    * Cf. SmsMessage
    */
     readonly attribute DOMString            sender;
     readonly attribute DOMString            sender;
     readonly attribute DOMString            receiver; //TODO should this be plural?
 
    /**
    * TODO Should this be plural? (AFAIK MMS supports group messaging.)
    */
     readonly attribute DOMString            receiver;
 
    /**
    * Cf. SmsMessage
    */
     readonly attribute Date                timestamp;
     readonly attribute Date                timestamp;
    /**
    * DOM document object representing the SMIL document.
    */
     readonly attribute Document            contentDocument;
     readonly attribute Document            contentDocument;
    readonly attribute MmsAttachmentStorage attachments;
 
   
     /**
     /**
     * "unfetched"
     * Object containing all other parts.
     */
     */
     readonly attribute DOMString            state;
     readonly attribute MmsAttachmentStorage attachments;     
     DOMRequest fetch();
    DOMRequest forward(DOMString number);
    DOMRequest cancel();
   }
   }
    
    
Line 89: Line 129:
   navigator.mms.onreceived = function (event) {
   navigator.mms.onreceived = function (event) {
     var message = event.message;
     var message = event.message;
     if (message.state == "unfetched") {
     if (message.delivery == "unfetched") {
       message.fetch().onsuccess(function (event) {
       message.fetch().onsuccess(function (event) {
         handleNewMessage(event.target.result);
         handleNewMessage(event.target.result);

Revision as of 04:20, 12 April 2012

Overview

On the surface, MMS messages are very similar to multipart HTML emails. One part is responsible for the layout of the message, though MMS uses SMIL rather than HTML. The other parts are attachments, such as text, picture, video, and sound files. Much like in multipart

API

 /**
  * TODO should we merge with this with SmsManager? There are good reasons for and against it.
  * Pro: One API to rule them all, less API clutter, easier to write integrated SMS/MMS app
  *      (which is what everybody wants anyway) 
  * Con: MMS is vastly more complex than SMS, both in terms of API as in terms of implementation
  *      and storing; implementations need to be acutely aware of MMS and how to deal with them.
  */
 interface MmsManager
 {
   DOMRequest   send(MmsMessage message);
   DOMRequest[] send(MmsMessage message[]);
   DOMRequest   delete(long id);
   DOMRequest   delete(MmsMessage message);
   DOMRequest   getMessage(long id);
   DOMRequest   getMessages(SMSFilter filter, bool reverse);
   /**
    * Fetch a message's data. Only applicable if message.delivery == "unfetched"
    */
   DOMRequest   fetchMessage(MmsMessage message);
   /**
    * Forward a message to a different number.
    */
   DOMRequest   forwardMessage(MmsMessage message, recipient);
   /**
    * Cancel a message's delivery with the MMSC.
    */
   DOMRequest   cancelMessage(MmsMessage message);
 }
 
 [Constructor]
 interface MmsMessage
 {
   /**
    * Cf. SmsMessage
    */
   readonly attribute long                 id;
   /**
    * Like SmsMessage::delivery, but with an additional possible value: "unfetched"
    */
   readonly attribute DOMString            delivery;
   /**
    * Cf. SmsMessage
    */
   readonly attribute DOMString            sender;
   /**
    * TODO Should this be plural? (AFAIK MMS supports group messaging.)
    */
   readonly attribute DOMString            receiver;
   /**
    * Cf. SmsMessage
    */
   readonly attribute Date                 timestamp;
   /**
    * DOM document object representing the SMIL document.
    */
   readonly attribute Document             contentDocument;
   /**
    * Object containing all other parts.
    */
   readonly attribute MmsAttachmentStorage attachments;     
 }
 
 /**
  * This object implements a mapping to look up attachments by their name.
  *
  *   var text = message.attachments["text.txt"];
  *   message.attachments["movie.mov"] = new MmsAttachment([data], {type: "application/video"});
  *   delete message.attachments["picture.png"];
  */
 interface MmsAttachmentStorage
 {
   getter MmsAttachment getAttachment(DOMString name);
   setter creator void setAttachment(DOMString name, MmsAttachment attachment);
   deleter void deleteAttachment(DOMString name);
 }
 
 /**
  * MmsAttachment constructor (cf. Blob constructor)
  */
 MmsAttachment MmsAttachment(
   [optional] Array parts,
   [optional] BlobPropertyBag properties
 );
 
 /**
  * MMS attachments extend the DOM Blob type, akin to how File extends Blob.
  */
 [Constructor]
 interface MmsAttachment : Blob
 {
   /**
    * Name of the attachment as it is referenced within the SMIL document (cf. File::name)
    */
   readonly attribute DOMString name;
   /**
    * An absolute URI under which User Agent makes the attachment available for download.
    * This is provided so that the data does not have to be loaded into memory first, but
    * can directly be linked to from an <img>, <video>, or <audio> element.
    */
   readonly attribute DOMString uri;
   /**
    * Inherited from Blob. See https://developer.mozilla.org/en/DOM/Blob
    */
   readonly attribute unsigned long long size;
   readonly attribute DOMString type;
 }

Example

Receiving an MMS

 navigator.mms.onreceived = function (event) {
   var message = event.message;
   if (message.delivery == "unfetched") {
     message.fetch().onsuccess(function (event) {
       handleNewMessage(event.target.result);
     });
   } else {
     handleNewMessage(message);
   }
 }
 
 function handleNewMessage(message) {
   var pars = message.contentDocument.querySelectorAll("par");
   for (var i = 0; i < pars.length; i++) {
     //TODO
   }
 }

Sending an MMS

 var smil = "<smil><body><par><video src="lolcat.mov"/></par></body></smil>";
 var parser = new DOMParser();
 var doc = parser.parseFromString(smil, "application/smil");  
 
 var message = new MmsMessage(recipient, doc);
 message.attachments["lolcat.mov"] = new MmsAttchment("lolcat.mov", "application/video", videoData);
 
 navigator.mms.send(message);