Core
This module handles the SDK initialization and registration. This module has the following classes:
IMI.IMIconnect
This class contains the methods to initialize the SDK and register a user. When integrating the SDK into your app it is mandatory to use this class to initialize the SDK before any other features are used. With exception to the Authentication module, it is also necessary to register a user before other features are used.
Public Methods | |
---|---|
void | startup(config) |
void | shutdown() |
void | register(deviceProfile, regcallback) |
void | unregister() |
boolean | isRegistered() |
void | updateProfileData() |
boolean | removeProfileData() |
void | setSecurityToken |
void | registerListener |
void | unregisterListener |
startup
This method is used to initialize the SDK using the provided configuration options.
Syntax: void startup(config)
Parameters:
Parameter | Type | Description |
---|---|---|
config | ICConfig | Refer to ICConfig class. |
Click here to view ICConfig class.
Example:
try {
//Initialize an ICConfig instance with an appId, clientKey
var config = new IMI.ICConfig(appId, clientKey);
// Initialize the IMIconnect SDK with ICConfig instance
IMI.IMIconnect.startup(config);
}
catch (e) {
console.log(e)
}
shutdown
This method is used to cleanup of the SDK, freeing all internal object instances. Invoking this method will stop the SDK features from functioning as such RTM will no longer be received.
Syntax: void shutdown()
Example:
// Provides a means to shutdown the SDK and perform cleanup, after this method is called none of the SDK features will work
try {
IMI.IMIconnect.shutdown();
} catch (error) {
console.log(error)
}
register
This method is used to register the userId with IMIconnect. This method reads the device details and sent to IMIconnect platform. Once a user is registered all further SDK calls take place in the context of that user.
Syntax: register(deviceProfile, regcallback)
Parameters:
Parameter | Type | Description |
---|---|---|
deviceProfile | [ICDeviceProfile] | Specifies the device profile registered with IMIconnect. |
regcallback | Object | Refer to example below. |
Example:
//Verify whether the user is registered or not, if not registered, register the user.
if (!IMI.IMIconnect.isRegistered()) {
var callback = {
onSuccess: function() {
console.log("reg success");
//Write you code to connect to IMIconnect.
},
onFailure: function(errormsg) {
console.log("reg failed");
}
};
var deviceProfile=new IMI.ICDeviceProfile(deviceId, userId);
//here user id is optional (If user id not there user can call deviceID,
userId will be generated by IMIConnect and passed to callback function)
//var deviceProfile = new IMI.ICDeviceProfile(deviceId);
IMI.IMIconnect.register(deviceProfile, callback);
}
else{
//Write you code to connect to IMIconnect.
}
unregister
This method is used to unregister the current user. The features that rely on a registered user will no longer function after this method has been called.
Syntax: IMI.IMIconnect.unregister(unregisterCallback);
Parameter | Type |
---|---|
unregisterCallback | Callback |
Example:
var unregisterCallback = {
onSuccess: function (msg) {
console.log("de register...");
},
onFailure: function (err) {
console.log("failed to un register");
}
};
IMI.IMIconnect.unregister(unregisterCallback );
isRegistered
This method is used to check whether the user is currently registered with IMIconnect.
Syntax: boolean isRegistered()
Returns:
Returns true if the user is registered, else false is returned.
Example:
var isRegistered = IMI.IMIconnect.isRegistered();
updateProfileData
This method is used to update userID and customerID parameters of current device profile registered with IMIconnect.
To update UserID
Syntax: IMI.IMIconnect.updateProfileData(IMI.ICDeviceProfileParam.UserId, newuserid, userIdcallbck);
Parameters:
Parameter | Type | Description |
---|---|---|
DeviceProfileParam | IMI.ICDeviceProfileParam.UserId | Specifies the user ID to register with IMIconnect. |
newUserId | String | Specifies the new user ID to register with IMIconnect. |
userIdcallback | Object | Refer to example below. |
To update CustomerID
Syntax: IMI.IMIconnect.updateProfileData(IMI.ICDeviceProfileParam.CustomerId, newcustomerid, customerCallback);
Parameters:
Parameter | Type | Description |
---|---|---|
DeviceProfileParam | IMI.ICDeviceProfileParam.CustomerId | Specifies the customer ID to register with IMIconnect. |
newcustomerId | String | Specifies the new customer ID to register with IMIconnect. |
customerCallback | Object | Refer to example below. |
Example:
var userIdcallbck = {
onSuccess: function (msg) {
console.log("usermodified...");
},
onFailure: function (err) {
console.log("failed to add user");
}
};
IMI.IMIconnect.updateProfileData(IMI.ICDeviceProfileParam.UserId, "2130", userIdcallbck);
var customerCallback = {
onSuccess: function (msg) {
console.log("customer...");
$("#setCustomerModel").modal('hide');
},
onFailure: function (err) {
console.log("failed to add customer");
alert(err)
}
};
IMI.IMIconnect.updateProfileData(IMI.ICDeviceProfileParam.CustomerId, "2130", customerCallback);
removeProfileData
This method is used to remove the profile data (user ID or customer ID).
To Remove UserID
This method is used to remove the userID.
Syntax: IMI.IMIconnect.removeProfileData(IMI.ICDeviceProfileParam.UserId, removeUserCallback);
Parameters:
Parameter | Type | Description |
---|---|---|
DeviceProfileParam | IMI.ICDeviceProfileParam.UserId | Specifies the user ID to register with IMIconnect. |
removeUserCallback | Object | Refer to example below. |
To Remove customerID
This method is used to remove the userID.
Syntax: IMI.IMIconnect.removeProfileData(IMI.ICDeviceProfileParam.CustomerId, CustomerIdcallbck);
Returns:
Returns customerId.
Parameters:
Parameter | Type | Description |
---|---|---|
DeviceProfileParam | IMI.ICDeviceProfileParam.CustomerId | Specifies the customer ID to register with IMIconnect. |
customerIdcallback | Callback | Refer to example below. |
Example:
var removeUserCallback = {
onSuccess: function (resrmsg) {
console.log("remove userId...");
},
onFailure: function (err) {
console.log("failed to remove customerid..");
}
};
IMI.IMIconnect.removeProfileData(IMI.ICDeviceProfileParam.UserId, userIdcallbck);
var CustomerIdcallbck = {
onSuccess: function (msg) {
console.log("usermodified...");
},
onFailure: function (err) {
console.log("failed to add user");
}
};
IMI.IMIconnect.removeProfileData(IMI.ICDeviceProfileParam.CustomerId, customerCallback);
setSecurityToken
This method allows to specify the security token that the SDK will pass to Connect platform.
Syntax: void setSecurityToken(token)
//generate token and call the below method using the token
IMI.IMIconnect.setSecurityToken(token);
registerListener
This method allows to register an object which implements the onFailure
method to listen for security token related exceptions which occur from internal (indirect) connect platform API calls.
Syntax: void registerListener(callbackListener)
Parameters:
Parameter | Description |
---|---|
callbackListener | Security Token Exception listener object. |
var callback= {
onFailure: function () {
console.log("token got expired...");
alert("token got expired...");
//need to generate token your (for more information, refer to docs) }
};
//this method should be called after startup()
IMI.IMIconnect.registerListener(callback);
unregisterListener
This method allows to unregister a previously registered object inorder to stop listening for security token exceptions.
Syntax: void unregisterListener(callbackListener)
Parameters:
Parameter | Description |
---|---|
callbackListener | Security Token Exception listener object. |
var callbackListener={
onFailure:function(error){
//This method will be called when security token issues comes
}
}
IMI.IMIconnect.unregisterListener(callback);
IMI.ICConfig
This class holds the configuration information that is used to initialize the SDK.
Public Constructors |
---|
ICConfig(appId, clientKey) |
Public Methods | |
---|---|
String | getAppID() |
String | getClientKey() |
ICConfig
This method is used to initialize an ICConfig
instance with an appId and clientKey.
Syntax: ICConfig(appId, clientKey)
Parameters:
Parameter | Type | Description |
---|---|---|
appId | String | Specifies the appId that is created in IMIconnect. |
clientKey | String | Specifies the clientKey that is created in IMIconnect. |
Example:
try {
//Initialize an ICConfig instance with an appId, clientKey
var config = new IMI.ICConfig(appId, clientKey);
// Initialize the IMIconnect SDK with ICConfig instance
IMI.IMIconnect.startup(config);
} catch ( e) {
console.log(e)
}
getAppId
This method is used to get the app id.
Syntax: String getAppId()
Return Value:
Returns the appid.
getClientKey
This method is used to get the client key.
Syntax: String getClientKey()
Return Value:
Returns the client key.
IMI.ICDeviceProfile
An ICDeviceProfile instance should be instantiated to register a device profile.
The developer can choose to register the device profile with a deviceId
only or with a deviceId
and an appUserId
. Users' can generate their own device ID or can choose the default deviceId
provided by the SDK.
If the user chooses to register a device profile with the deviceId
only, then the backend will automatically generate an appUserId
.
The current device profile is accessible via the IMIconnect class.
Public Constructors |
---|
ICDeviceProfile(deviceId, userId) |
Public Methods | |
---|---|
String | getDefaultDeviceId() |
String | isAppUserSystemGenerated() |
String | getUserId() |
String | getDeviceId() |
ICDeviceProfile()
The current device profile, which is accessible via the IMIconnect class.
Syntax: ICDeviceProfile(deviceId, userId)
Parameters:
Parameter | Type | Description |
---|---|---|
deviceId | Property | Specifies the device ID that is created in IMIconnect. |
userId | Property | Specifies the user ID that is created in IMIconnect. |
getDefaultDeviceId()
This method is used to get the value of default deviceId.
var deviceId=IMI.ICDeviceProfile.getDefaultDeviceId();
var deviceProfile =new IMI.ICDeviceProfile(deviceId, userId);
isAppUserSystemGenerated()
This method is used to know whether the appuserId is generated by the end-system or the user.
Syntax: String isAppUserSystemGenerated()
Return Value:
Returns the appuserid.
Example:
var deviceProfile =new IMI.ICDeviceProfile(deviceId, userId);
var isAppUserSystemGenerated=deviceProfile.isAppUserSystemGenerated(); if(isAppUserSystemGenerated)
{
console.log("system generated appuser");
}
getUserId()
This method is used to get the user ID.
Syntax: String getUserId()
Return Value:
Returns the userId.
getDeviceId()
This method is used to get the user ID.
Syntax: String getDeviceId()
Return Value:
Returns the deviceId.
IMI.ICMediaFileManager
uploadFile
This method is used to check the status of the file upload.
Syntax: uploadFile(file, file.type, callback)
Return Value:
Returns the file upload status.
onFileUploadComplete: function
This method is used to execute the callback method after the file upload is complete.
Syntax: onFileUploadComplete: function(file, mediaId, error)
onFileUploadComplete: function(file, mediaId, error){
if(error){
console.log(error);
} else{
$("#mediaid").val(mediaId);
}
}
setMediaId
This method is used to set the media id in the attachment section.
function pubMessage(threadtitle, threadid, msg, mediaId, callback){
----------------
----------------
if(mediaId && mediaId !==""){
var mediaArr = [];
var icAttach = new IMI.ICAttachment();
icAttach.setMediaId(mediaId);
mediaArray.push(icAttach);
message.setAttachment(mediaArray);
}
Updated over 1 year ago