Please Wait

Loading..

JavaScript SDK 1.0.0

Create amazing realtime applications easily with Yalgaar JavaScript SDK

.Net SDK

1 Connect To Yalgaar

Download package and insert library in head tag in your code.

<html>
    <head>
        <script src="yalgaar.js" type="text/javascript"> </script>
	</head>
</html>

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

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 (optional)
    • 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 (optional)
    • Description: Secret key use for encrypt/decrypt message.
    • DataType: String
  • AESType (optional)
    • 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. .

PublishMessage({
    ChannelName: 'YourChannel',
    Message: 'This is Yalgaar WebSocket 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.

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 with channel name 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.

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.

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.

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.

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 :

Include Yalgaar WebSocket SDK(yalgaar.js) in your code

<html>
    <head>
        <script src="yalgaar.js" type="text/javascript"> </script>
        <script type="text/javascript">
            ConnectToYalgaar({
                ClientKey: 'ClientKey',
                SSL: false,
                Callback: function (acknowledgment) {
                    alert(acknowledgment);
                    SubscribeMessage2();
                    PublishMessage2();
                },
                Error: function (err) {
                    console.log(err);
                }
            });
            function PublishMessage2() {
                PublishMessage({
                    ChannelName: 'YourChannel',
                    Message: 'This is Yalgaar WebSocket SDK Example',
                    Callback: function (acknowledgment) {
                    if (acknowledgment)
                        console.log(acknowledgment);
                    }
                });
            }
            function SubscribeMessage2() {
                SubscribeMessage({
                    ChannelName: 'YourChannel',
                    Callback: function (message, channel, acknowledgment) {
                    if (acknowledgment)
                        alert(acknowledgment);
                    if (message)
                        alert(message);
                    }
                });
            }
        </script>
    </head>
</html>