Home Reference Source
import {ContactManager} from '@quobis/sippojs'
public class | source

ContactManager

Extends:

src/eventemitter.js~EventEmitter → ContactManager

ContactManager instance is obtained by calling the Session#getContactManager method of Session and must not be directly instantiated. Once the ContactManager instance is obtained ContactManager#init method must be called to initialize it.

Events

  • create is emitted every time a new contact is added to the contact list.
    • Contact contact The contact that has just been created.
  • contact-added is emitted every time a new contact is added to the cache after have been created
    • Contact contact The contact that has just been created.
  • update is emitted when some contact is updated.
    • Contact contact The contact that has just been updated.
  • delete is emitted when some contact is deleted.
    • Contact contact The contact that has just been deleted.
  • start-synchronizing is emitted when a synchronizing process starts
  • start-synchronizing-background is emitted when a synchronizing process starts in background
  • start-synchronizing-avatars is emitted when a avatar synchronizing process starts
  • stop-synchronizing is emitted when a synchronizing process ends
  • sync-all-device-contacts is emitted when all device contacts are going to be uploaded

You can check EventEmitter2 documentation for additional information about adding and removing listeners for this events events.

See:

Example:

Get contact list
contactManager.init().then(function() {
  contactManager.getContacts().forEach(function(contact) {
    console.log(contact.name);
  });
});

To sync contacts, a new function must be called (contact Manager has to be initialized previously)
Try the sync process
contactManager.launchSynchronize().then(function() {
  contactManager.getContacts().forEach(function(contact) {
    console.log(contact.name);
  });
});

Member Summary

Public Members
public

Allows to change the presence of this session

public get

prototypes: Object: {"Contact": *, "GroupContact": *, "Presence": *, "OwnPresence": *}

Method Summary

Public Methods
public

Clears all user contacts data and invalidates the cache from the persistent storage

public

createContact(displayName: String, phones: string | {name: string, address: string}[], emails: {email: string}[]): *

Call stack.addContact once the manager is initialized and return a promise.

public

createGroupContact(displayName: String, participants: Object): *

If the contact is successfully created the promise will be resolved, otherwise will be rejected.

public

Retrieves a contact given an address

public

Retrieves a contact given an email

public

Retrieves a contact given a WAC id

public

Retrieves a list with the available contacts

public

getFakeContact(options: object, name: string, presence: Presence, avatar: string, phone: string, email: string): *

Returns a new local only contact with the specified parameters

public

Retrieves the presence of a user given an address

public

Retrieves the presence of a user given its WAC id

public

Initializes the contact manager

public

Launch the sinchronizing to check if a change has occured

public

onUpdateAvatarsContacts(avatarsContacts: Map)

Internal callback for Synchronizer event.

public

Internal callback for Synchronizer event

public

Uninitializes the contact manager

Public Members

public ownPresence: OwnPresence source

Allows to change the presence of this session

public get prototypes: Object: {"Contact": *, "GroupContact": *, "Presence": *, "OwnPresence": *} source

Properties:

NameTypeAttributeDescription
Contact Object

The prototype for Contact objects

GroupContact Object

The prototype for Group Contact objects

Presence Object

The prototype for Presence objects

OwnPresence Object

The prototype for Own Presence objects

Return:

Object

Returns an object with the prototypes to allow customizing the getters with any kind of application specific behaviours

Return Properties:

NameTypeAttributeDescription
Contact Object

The prototype for Contact objects

GroupContact Object

The prototype for Group Contact objects

Presence Object

The prototype for Presence objects

OwnPresence Object

The prototype for Own Presence objects

Public Methods

public clearContactsDataFromPersistentStorage() source

Clears all user contacts data and invalidates the cache from the persistent storage

public createContact(displayName: String, phones: string | {name: string, address: string}[], emails: {email: string}[]): * source

Call stack.addContact once the manager is initialized and return a promise.

If the contact is successfully created the promise will be resolved, otherwise will be rejected. The wac will send a qs-contact-add event to every session.

Params:

NameTypeAttributeDescription
displayName String

The name of the new contact

phones string | {name: string, address: string}[]

Phone or phones of the new contact

emails {email: string}[]

Email or emails of the new contact

Return:

*

public createGroupContact(displayName: String, participants: Object): * source

If the contact is successfully created the promise will be resolved, otherwise will be rejected. The wac will send a qs-contact-add event to every session.

Params:

NameTypeAttributeDescription
displayName String

The name of the new contact

participants Object
participants.name String

The name associated to the phone of the participant

participants.address String

The phone of the participant

Return:

*

public getContactByAddress(address: String, sync: boolean): Contact source

Retrieves a contact given an address

Params:

NameTypeAttributeDescription
address String
sync boolean
  • optional
  • default: true

If false returns a Promise of a contact

Return:

Contact

public getContactByEmail(email: String): Contact | undefined source

Retrieves a contact given an email

Params:

NameTypeAttributeDescription
email String

Return:

Contact | undefined

public getContactByWacId(wacId: *): Contact source

Retrieves a contact given a WAC id

Params:

NameTypeAttributeDescription
wacId *

Return:

Contact

public getContacts(): Array<Contact> source

Retrieves a list with the available contacts

Return:

Array<Contact>

public getFakeContact(options: object, name: string, presence: Presence, avatar: string, phone: string, email: string): * source

Returns a new local only contact with the specified parameters

Params:

NameTypeAttributeDescription
options object
options.id string
name string
  • optional
presence Presence
  • optional
avatar string
  • optional
phone string
  • optional
email string
  • optional

Return:

*

public getPresenceByAddress(address: *): Promise<Presence> source

Retrieves the presence of a user given an address

Params:

NameTypeAttributeDescription
address *

Return:

Promise<Presence>

public getPresenceByWacId(wacId: *): Contact source

Retrieves the presence of a user given its WAC id

Params:

NameTypeAttributeDescription
wacId *

Return:

Contact

public init(): Promise<ContactManager, Error> source

Initializes the contact manager

Return:

Promise<ContactManager, Error>

A promise that returns when fulfilled the contact manager instance

public launchSynchronize(): Promise source

Launch the sinchronizing to check if a change has occured

Return:

Promise

if success

public onUpdateAvatarsContacts(avatarsContacts: Map) source

Internal callback for Synchronizer event. Update contacts with his avatar.

Params:

NameTypeAttributeDescription
avatarsContacts Map

A map with contactDeviceId as key and avatar as value

public onUpdateListContacts(contacts: Array) source

Internal callback for Synchronizer event

Params:

NameTypeAttributeDescription
contacts Array

To insert in contact list

public uninit(): Promise<undefined, Error> source

Uninitializes the contact manager

Return:

Promise<undefined, Error>

A promise that is fulfilled when unitialization finishes