Please Wait

Loading..

AngularJS SDK 1.0.0

Create amazing realtime applications easily with Yalgaar AngularJS SDK

1 Connect To Yalgaar

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

<html>
    <head>
        <script src="angular.min.js" type="text/javascript"> </script>
        <script src="YalgaarAngular.js" type="text/javascript"> </script>
	</head>
</html>

Inside app.js add an angular dependency on the Yalgaar Angular js library.

angular.module(‘YalgaarAngularApp’,[‘YalgaarAngular’])

AngularJS Yalgaar service is injected into the controllers as follows.

.controller(‘YalgaarCntrl’,function($scope,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 (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. .

Yalgaar.PublishMessage(ChannelName, Message, 
    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, 
    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.

Yalgaar.UnsubscribeMessage(ChannelName,
    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,
    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,
    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,MessageCount,
    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.

Yalgaar.DisconnectToYalgaar();


You can publish/subscribe message like so :

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

<html>
<head>
    <script src="angular.min.js" type="text/javascript"> </script>
    <script src="YalgaarAngular.js" type="text/javascript"> </script>
    <script type="text/javascript">
        var app = angular.module("YalgaarAngularApp", ['YalgaarAngular']);
        app.controller('YalgaarCntrl', function ($scope, Yalgaar) {
            Yalgaar.ConnectToYalgaar({
                ClientKey: 'ClientKey',
                SSL: false
                },
                Callback = function (acknowledgment) {
                    alert(acknowledgment);
                    $scope.SubscribeMessage2();
                    $scope.PublishMessage2();
                },
                Error = function (err) {
                    console.log(err);
            });
            $scope.PublishMessage2 = function () {
                Yalgaar.PublishMessage('YourChannel', 'This is Yalgaar AngularJS SDK Example', Callback = function (acknowledgment) {
                    if (acknowledgment)
                        console.log(acknowledgment);
                });
            }
            $scope.SubscribeMessage2 = function () {
                Yalgaar.SubscribeMessage('YourChannel', Callback = function (message, channel, acknowledgment) {
                    if (acknowledgment)
                        alert(acknowledgment);
                    if (message)
                        alert(message);
                });
            }
        });
        </script>
    </head>
    <body ng-app="YalgaarAngularApp">
        <div ng-controller="YalgaarCntrl">
        </div>
    </body>
</html>