The following procedures walk you through the individual steps of implementing custom presence.
To create a presence extension object
-
In your JavaScript file, declare a variable containing the extension name.
-
This value must be unique within the application and must not exceed 64 characters.
var extensionName = 'com.example.ExtNm';
-
Create the necessary code for the functionality of the extension.
-
In this particular example, the extension stores a name-value pair. The function is used as a constructor, and the other functions in the class are defined by using the prototype property.
function MyPresenceExtension(name, content)
{
this.name = name;
this.content = content;
}
MyPresenceExtension.prototype.get_name = function() {
return this.name;
}
MyPresenceExtension.prototype.get_content = function() {
return this.content;
}
To create a PresenceExtensionFactory object
-
Declare the PresenceExtensionFactory object.
This object serializes and deserializes your custom presence extension.
MyPresenceFactory = function () {}
-
Create the serialize and deserialize functions.
MyPresenceFactory.prototype.serialize = function(prop) {
return prop.get_content();
}
MyPresenceFactory.prototype.deserialize = function(name, content) {
return new MyPresenceExtension(name, content);
}
To set the PresenceExtensionFactory as the active presence factory
To add the presence extension to users' presence
-
Add the custom presence extension for the signed-in user.
function addCustomPresence()
{
endpointCollection = _user.get_endpoints();
endpointPresence = endpointCollection.get_item(0).get_presence();
extensionCollection = endpointPresence.get_extensions();
extensionCollection.add(new MyPresenceExtension(extensionName, '*'));
}
-
Add code to check for the presence extension in each endpoint of this contact's presence.
function getCustomPresenceContent(address)
{
endpointEnum = address.get_endpoints().getEnumerator();
while (endpointEnum.moveNext())
{
endpoint = endpointEnum.get_current();
extensionEnum = endpoint.get_presence().get_extensions().getEnumerator();
while (extensionEnum.moveNext())
{
extension = extensionEnum.get_current();
if (extension.get_name() == extensionName)
{
return extension.get_content();
}
}
}
return '';
}