WebAPI/LogAPI: Difference between revisions

no edit summary
No edit summary
 
(46 intermediate revisions by one other user not shown)
Line 1: Line 1:
== Proposer ==
José M. Cantera, Telefónica, jmcf@tid.es
== Use Cases ==
== Use Cases ==


To record the history of user activity with the device, particularly with communication services (Phone Calls, Messages, Social Networks, etc.)  
To record the history of user activity with the device, particularly with communication services (Phone Calls, Messages, Social Networks, etc.)
The Communications Log can have different views: Global or Per-Contact
 
Using the API the occurrence of incoming calls, missed calls, incoming messages, outgoing messages etc. is automatically recorded.


=== Consumers ===
=== Consumers ===
Line 9: Line 16:
=== Producers ===  
=== Producers ===  


* Dialer, SMS, e-mail, Facebook, Twitter, ...  
* Dialer, SMS, e-mail, Facebook, Twitter, ...


== WebIDL ==
== WebIDL ==


interface ContactsManager
<pre>
  {
[NoInterfaceObject]
     DOMRequest find(in ContactFindOptions options);
interface NavigatorLog {
    DOMRequest clear();
     readonly attribute LogManager mozLog;
    DOMRequest save(in Contact contact); // Success value is id? Or new Contact?
};
    DOMRequest remove(in Contact contact);
 
  };
Navigator implements NavigatorLog;


interface LogManager : EventTarget  
[NoInterfaceObject]
  {
interface LogManager : EventTarget {
     DOMRequest save(LogEntry entry);
     DOMRequest put(LogEntry entry);
     DOMRequest delete(DOMString entryId);
     DOMRequest delete(DOMString entryId); // Delete one entry
     DOMRequest clear(LogClearOptions coptions);
     DOMRequest clear(LogClearOptions coptions); // To clear the log for maintenance purposes
     LogIterator find(LogFindOptions options);
    // Entries are always returned ordered by timestamp (desc)
   attribute Function onentryadded;
     DOMRequest find(optional LogFindFilter filter,optional IteratorOptions iopts);
       
   attribute Function? onentryadded; // To listen for log changes
  };
  };


interface LogIterator
// The iterator will be initialized with a window indicated in the iteration parameters
{
[NoInterfaceObject]
   DOMRequest next(optional unsigned short n);
interface DOMIterator {
   DOMRequest advance(unsigned short count);
   DOMRequest next();   // request to refresh the window of objects with the next
  DOMRequest prev();  // request to refresh the window of objects with the prev
   DOMRequest skipTo(unsigned long chunk);
  readonly attribute boolean hasMore;
  readonly attribute unsigned long count;  // total number of objects
  readonly attribute any[]? values;  // Contains the current window of objects
  readonly attribute chunkSize;
};
};
dictionary LogOptions
 
{
dictionary LogFindFilter {
   attribute unsigned long maxRecords;
  DOMString? contactId;
  attribute DOMString contactId;
  Date? from;   // for defining a time interval
  Date? to;      // for defining a time interval
  DOMString? service; // to filter by service
  DOMString? type;     // to filter by Log type
};
};
dictionary LogFindOptions : LogOptions
 
{
dictionary LogClearOptions {
  attribute Date from;
  Date deadline; // To clear all the entries older than the date passed as parameter
  attribute Date to;
  DOMString? contactId;  // To clear all the entries corresponding to a contact
  attribute DOMString service;
  DOMString? tel;           // To clear all the entries corresponding to a tel number
};
};
interface LogEntryProperties
 
{
dictionary IteratorOptions {
  attribute DOMString type;                      // possible values: ['incoming', 'outgoing', 'missing']
  unsigned long? maxRecords = -1; // Max number of records to be returned (-1 means all)
  attribute DOMString[] contactId;            // ContactId
  unsigned long? chunkSize = 10;    // Chunk size for the iterator
  attribute DOMString[] tel;                       // Tel number if not already in contacts
  attribute DOMString objectId;                // Object id (for example SMS message on the SMS database)
  attribute DOMString service;                 // oneOf ['SMS', 'Telephony', 'Facebook', 'Twitter']
  attribute DOMString title;           
   attribute DOMString description;
  attribute any extra;                                // Any extra data to be used by applications
};
};
interface LogEntryProperties {
  attribute DOMString type;  // possible values: ['incoming', 'outgoing'']
  attribute DOMString? status;  // [missed, new]       
  attribute DOMString[]? contactId;  // ContactId   
  attribute DOMString[]? tel;  // Tel number if not in contacts
  attribute DOMString? objectId;  // Object id (for example SMS message on the SMS database) 
  attribute DOMString service;  // oneOf ['SMS', 'Telephony', 'Facebook', 'Twitter']
  attribute DOMString? title;           
  attribute DOMString? description;
  attribute any? extra;  // Any extra data to be used by applications
};
[Constructor(LogEntryProperties properties)]
[Constructor(LogEntryProperties properties)]
interface LogEntry : LogEntryProperties  
interface LogEntry : LogEntryProperties {
{
   readonly attribute DOMString id;
   readonly attribute DOMString id;
   readonly attribute DOMTimestamp timestamp;                  // When this happened
   readonly attribute DOMTimestamp timestamp;                  // When happened
};
};
</pre>
== Examples ==
Get latest global 30 log entries (ordered by timestamp, newest to oldest) in chunks of 10
<pre>
var pageOptions = {maxNumber: 30, chunkSize: 10};
var req = navigator.mozLog.find(null,pageOptions);
req.onsuccess = function(e) {
  var iterator = e.target.result;
 
  doSomething(iterator.values);
  if(iterator.hasMore) {
    iterator.next();
  }
}
</pre>
Get all the log entries corresponding to a contactId
<pre>
var filterOptions = {contactId: 'ax1234'};
var req = navigator.mozLog.find(filterOptions);
req.onsuccess = function(e) {
  var iterator = e.target.result;
 
  var logEntries = iterator.values;
  for(var c = 0; c < logEntries.length; c++) {
    window.console.log('LogEntry: ', logEntries[c].type,logEntries[c].timestamp);
  }
  if(iterator.hasMore) {
    iterator.next();
  }
}
</pre>
[[Category:Web APIs]]
Confirmed users
1,340

edits