Table of contents
TOC
Collapse the table of content
Expand the table of content

GeneralHelper library

John Austin|Last Updated: 6/17/2016
|
1 Contributor

GeneralHelper.js is a JavaScript library of generally useful functions.

Applies to: Skype for Business 2015

Use the functions in the GeneralHelper library to create namespaces, to check for null or undefined objects, and to generate unique numbers.

Create a GeneralHelper object

A GeneralHelper object is created as shown in the following example.

var _generalHelper = new GeneralHelper(); 

The variable declared in the preceding example is used in subsequent examples in this topic.

extractDataFromDataUri(uri, options)

The extractDataFromDataUri function extracts textual data from a Data URI.

ParameterDescription
uriThe Data URI to be decoded.
optionsThe only option currently available is options.unescape. If set, replaces each escape sequence in the URI.

Returns: The string contained in the Data URI.

Syntax

extractDataFromDataUri(uri , options )

Example

function decodeMessage(message) {
 return _generalHelper.extractDataFromDataUri(message, { unescape: true });
}

Remarks

In UCWA 2.0, Data URIs are used to transmit instant message bodies. For more information about Data URIs, see the "data" URL scheme.

extractOriginFromAbsoluteUrl(url)

The extractOriginFromAbsoluteUrl function extracts the origin from an absolute URL.

ParameterDescription
urlThe URL from which to extract the origin.

Returns: The origin as a string or an empty string.

Syntax

extractOriginFromAbsoluteUrl(url )

Example

_domain = _generalHelper.extractOriginFromAbsoluteUrl(xframe);

Remarks

An origin consists of SCHEME + "://" + HOST + (optional) ":" + (optional) PORT. The origin in the following URL is the portion shown in brackets. [https://example.com:8080]/some/long/path. For more information, see The Web Origin Concept, Section 3.2.1 Examples.

generateUUID()

The generateUUID function generates a Universally Unique Identifier (UUID) based on the RFC 4122 specification.

Returns: UUID that can be used as a unique object.

Syntax

generateUUID()

Example

The following example uses generateUUID to generate an operation ID. The operation ID and the target participant ( to) are input values when startOperation is called.

imData.sessionContext = ucwa.GeneralHelper.generateUUID();
imData.to = $("#outgoingContacts option:selected") [0].value;
messagingId = opRes.startOperation({
 url: ucwa.Cache.findEmbeddedLinkInCache("communication", "startMessaging"),
 type: "post",
 data: imData
},
{
 started: function(data, resources) {
 handleMessagingStart(data, resources);
 },
 completed: function(data, resources) {
 handleMessagingStart(data, resources);
 }
});

isDefined(object)

The isDefined function verifies that the supplied object is defined; specifically, that it is not undefined and not null.

ParameterDescription
objectObject to check.

Returns: Boolean indicating whether the object is defined.

Syntax

isDefined(object )

Example

The following sample uses the isDefined function to first determine whether _data._embedded_is defined, and if so, to determine whether _data._embedded.message_is defined. If _data._embedded_is not defined, the second expression is not evaluated.

function findRelation(data) {
 if (_generalHelper.isDefined(data._embedded) &&
 _generalHelper.isDefined(data._embedded.message)) {
 // Do something.
 }
}

isEmpty(object)

The isEmpty function determines whether the specified object is empty.

ParameterDescription
objectObject to check.

Returns: Boolean indicating whether the object is empty.

Syntax

isEmpty(object )

Example

The following example shows how the isEmpty function can be used to check an expression before assigning its value to a variable.

if (data.results._embedded.contact && !_generalHelper.isEmpty(data.results._embedded.contact)) {
 var contacts = data.results._embedded.contact;
 .
 .
 .
}

namespace(namespaceString)

The namespace function generates an object placed in a namespace, based on the supplied string. This function splits the namespace string on '.' and begins iterating over the parts, creating a new object if necessary.

ParameterDescription
namespaceStringNamespace to generate.

Returns: JSON object representing the namespace.

Syntax

namespace(namespaceString )

Example

_generalHelper. namespace("microsoft.rtc.ucwa.samples");
© 2017 Microsoft