- Source:
Examples
To get instance of MASPluginMQTTConstants : An interface that contains the required MQTT connection options for MQTT broker
var masMQTTConstants = new MASConnectaPlugin.MASMQTTConstants(host, port, false, "");
To get instance of MASPluginMQTTClient: An interface that corresponds to a Public Broker including MAG
var masMQTTClient = new MASConnectaPlugin.MASMQTTClient(clientId, masMQTTConstants);
Access MASConnectaPluginConstants: A static utility that contains the plugin related constants and Global callbacks
var MASConnetaConstants = MASConnectaPlugin.MASConnetaConstants;
To get instance of MASConnectaPluginMessage: An interface that is mapped to the native MASMessage structure
var MASConnectaMessage = new MASConnectaPlugin.MASConnectaMessage();
MASConnecta MASPluginUser APIs are static API that are called directly using the class reference as follows
MASConnectaPlugin.MASUser.sendMessageToUser(successHandler, errorHandler, message, userObjectId);
Methods
(static) MASRegisterListener(successHandler, errorHandler)
Call this function before using the MASConnecta messaging APIs. This API registers the notification receiver for observing the messages that are intended for the client.
Parameters:
| Name | Type | Description |
|---|---|---|
successHandler |
successCallbackFunction | user defined success callback that is invoked on success scenario. |
errorHandler |
errorCallbackFunction | user defined error callback that is invoked on failure scenario. |
- Source:
Example
Initializing and registering the listener
MASConnectaPlugin.MASRegisterListener(
function(success) {
if (null != success.Payload) {
var toAlert = {};
toAlert.sender = success.SenderId;
var payload = (success.Payload!=null?success.Payload:success.payload);
toAlert.payload = atob(payload);
toAlert.topic = success.Topic;
alert(JSON.stringify(toAlert));
}
}, function(error) {
console.log("Listener registration failed!!!:" + JSON.stringify(error));
}
);