Please Wait

Loading..

NodeJS SDK 1.0.6

Create amazing realtime applications easily with Yalgaar NodeJS SDK

1 Connect To Yalgaar

Install package from npm

npm install yalgaar

Load yalgaar module in your program

var yalgaar = require('yalgaar');

To connect to a Yalgaar client,use following method, it must have valid Client Key.

yalgaar.ConnectToYalgaar({
    ClientKey: 'ClientKey',
    SSL: [true/false],
    UUID: 'UserId', //optional
    AESSecretKey: 'SecretKey', //optional
    AESType: [128/192/256], //optional
    Callback: function (acknowledgment) {
    },
    Error: function (err) {
    }
});

Parameter:

  • ClientKey
    • Description: Yalgaar provided authentic client key for project.
    • DataType: String
  • SSL
    • Description: Specifies connection is establish with SSL or not.
    • DataType: boolean (value must be true or false)
  • UUID:
    • Description: Any unique user name for user id. UUID is CASE SENSITIVE and only alpha numeric, hyphens, @, underscore allowed and maximum length must be 50.
    • DataType: String
  • AESSecretKey
    • Description: Secret key use for encrypt/decrypt message.
    • DataType: String
  • AESType
    • Description: Type of AES algorithm use for encrypt/decrypt message. Support AES type 128,192 and 256.
    • DataType: Number
  • Callback
    • Description: Called when successfully connected to server.
    • DataType: Callback
  • Error
    • Description: called when system error occurred on during connection.
    • DataType: Callback


2 Publish Message

To publish message,use following method. .

yalgaar.PublishMessage({
    ChannelName: 'YourChannel',
    Message: 'This is Yalgaar NodeJS SDK Example',
    Callback: function (acknowledgment) {
    }
});

Parameter:

  • ChannelName
    • Description: Single channel name on which message will be published. Only alpha numeric, hyphens, @, underscore allowed and maximum length must be 50.
    • DataType: String
  • Message
    • Description: Data to be send on given channel.
    • DataType: String
  • Callback
    • Description: Called when successfully published message or any error occur.
    • DataType: Callback


3 Subscribe Message

To subscribe message,use following method.

yalgaar.SubscribeMessage({
    ChannelName: 'YourChannel',
    Callback: function (message, channel, acknowledgment) {
    },
    CallbackPresence: function (message, channel, acknowledgment) {
    }
});

Parameter:

  • ChannelName
    • Description: Single channel name or list of channels name on which message will be subscribed. For multiple channel names use comma (','). Channel name is CASE SENSITIVE and only alpha numeric, hyphens, @, underscore allowed and maximum length must be 50.
    • DataType: String
  • MessageCallback
    • Description: Called when successfully subscribe channel(s), consume received messages or any error.
    • DataType: Callback
  • PresenceCallback
    • Description: called when presence events take place such as user join or leave.
    • DataType: Callback


4 Unsubscribe Message

To unsubscribe message,use following method.

yalgaar.UnsubscribeMessage({
    ChannelName: 'YourChannel',
    Callback: function (acknowledgment) {
    }
});

Parameter:

  • ChannelName
    • Description: Single channel name or list of channels to be unsubscribe. For multiple channel names use comma (','). Channel name is CASE SENSITIVE and only alpha numeric, hyphens, @, underscore allowed and maximum length must be 50.
    • DataType: String
  • Callback
    • Description: Called when successfully unsubscribe channel or any error occur.
    • DataType: Callback


5 Get User List

To get list of all user subscribe with specified channel name, use following method.

yalgaar.GetUUIDList({
    ChannelName: 'YourChannel',
    Callback: function (list, err) {
    }
});

Parameter:

  • ChannelName
    • Description: Valid channel name. Channel name is CASE SENSITIVE and only alpha numeric, hyphens, @, underscore allowed and maximum length must be 50.
    • DataType: String
  • Callback
    • Description: Called when successfully get user list or any error occur.
    • DataType: Callback


6 Get Channel List

To get list of all channels subscribed by specified user, use following method.

yalgaar.GetChannelList({
    UUID: 'YourUUID',
    Callback: function (list, err) {
    }
});

Parameter:

  • UUID
    • Description: Valid user Id. user Id is CASE SENSITIVE and only alpha numeric, hyphens, @, underscore allowed and maximum length must be 50.
    • DataType: String
  • Callback
    • Description: Called when successfully get channel list or any error occur.
    • DataType: Callback


7 Get Message History

To get the already published messages, use following method.

yalgaar.GetHistory({
    ChannelName: 'YourChannel',
    MessageCount: 10,
    Callback: function (message, err) {
    }
});

Parameter:

  • ChannelName
    • Description: Valid channel name. Channel name is CASE SENSITIVE and only alpha numeric, hyphens, @, underscore allowed and maximum length must be 50.
    • DataType: String
  • MessageCount
    • Description: How many messages that you want to fetch. Maximum 100 messages allow at a time.
    • DataType: Number
  • Callback
    • Description: Called when successfully get message history or any error occur.
    • DataType: Callback


8 Disconnect

To disconnect connection with YalgaarClient, use following method.

DisconnectToYalgaar();


You can publish/subscribe message like so :

var yalgaar = require('yalgaar');

yalgaar.ConnectToYalgaar({
    ClientKey: 'ClientKey',
    SSL: false,
    Callback: function (acknowledgment) {
        console.log(acknowledgment);
        SubscribeMessage();
    },
    Error: function (err) {
        console.log(err);
    }
});
function PublishMessage() {
    yalgaar.PublishMessage({
        ChannelName: 'YourChannel',
        Message: 'This is Yalgaar NodeJS SDK Example',
        Callback: function (acknowledgment) {
            console.log(acknowledgment);
        }
    });
}
function SubscribeMessage() {
    yalgaar.SubscribeMessage({
        ChannelName: 'YourChannel',
        Callback: function (message, channel, acknowledgment) {
            if (acknowledgment)
            {
                console.log(acknowledgment);
                PublishMessage();
            }
            if (message)
            {
                console.log(message);
            }
        },
        CallbackPresence: function (message, channel, acknowledgment) {
            if (acknowledgment)
                console.log(acknowledgment);
            if (message)
                console.log(message);
        }
    });
}