Please Wait

Loading..

WebRTC SDK 1.0.0

Create amazing realtime applications easily with Yalgaar WebRTC SDK

1 Connect To Yalgaar

Note:

Your web application must be hosted on secure domain (with https).

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

<html>
    <head>
        <script src="YalgaarWebRTC.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',
    UUID: 'UserID',
    SSL: true,
    Video: true, 
    Audio: true, 
    Data: true, 
    EnableFileSharing: true,
    FileContainer: DivElement,
    Callback: function (acknowledgment) {},
    Error: function (error) {},
    Presence: function (data) {},
    OnStream: function (data) {},
    OnMessage: function (data) {},
    OnOpen: function (data) {},
    OnClose: function (data) {},
    MediaError: function (data, constraint){}
});

Parameter:

  • ClientKey
    • Description: Yalgaar provided authentic client key for project.
    • DataType: String
  • 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
  • SSL
    • Description: Specifies connection is establish with SSL or not.
    • DataType: boolean
  • EnableFileSharing
    • Description: To enable file sharing.
    • DataType: boolean
  • Audio
    • Description: To allow to send and receive audio.
    • DataType: boolean
  • Video
    • Description: To allow to send and receive video
    • DataType: boolean
  • Data
    • Description: To allow to share text data.
    • DataType: boolean
  • FileContainer
    • Description: Specify div element to handle file transferring.
    • DataType: Div Element
  • Callback
    • Description: Called when successfully connected to server or disconnect from server.
    • DataType: Callback
  • Error
    • Description: called when system error occurred on during connection.
    • DataType: Callback
  • Presence
    • Description: called when presence events take place such as user join or leave.
    • DataType: Callback
  • Stream
    • Description: Called when stream receive from local or remote connection.
    • DataType: Callback
  • OnMessage
    • Description: Called when text message receive from remote connection.
    • DataType: Callback
  • OnOpen
    • Description: Called when connection successfully established with other client(s).
    • DataType: Callback
  • OnClose
    • Description: Called when client disconnection from other client(s).
    • DataType: Callback
  • MediaError
    • Description: Called when user media devices error occur.
    • DataType: Callback


2 Join User

To connect with other user, use following method.

JoinUser({
    RemoteUUID: 'UserId', 
    Error: function (Err) {}
});

Parameter:

  • RemoteUUID
    • Description: Remote user id that you want to connect with. UUID is CASE SENSITIVE and only alpha numeric, hyphens, @, underscore allowed and maximum length must be 50.
    • DataType: String
  • Error
    • Description: Called when any error occur during connecting with other user.
    • DataType: Callback


3 Add User

To add user in ongoing conversation/conference, use following method.

AddUser({
    RemoteUUID: 'UserId',
    Error: function (Err) {}
});

Parameter:

  • RemoteUUID
    • Description: Remote user id that you want to add in conversation/conference. UUID is CASE SENSITIVE and only alpha numeric, hyphens, @, underscore allowed and maximum length must be 50.
    • DataType: String
  • Error
    • Description: Called when any error occur during adding user in conversation/conference.
    • DataType: Callback


4 Remove User

To disconnect specific user from conversation, use following method.

 RemoveUser({
    RemoteUUID: user,
    Error: function (err) {}
});

Parameter:

  • RemoteUUID
    • Description: Remote user id that you want to disconnect user from conversation. UUID is CASE SENSITIVE and only alpha numeric, hyphens, @, underscore allowed and maximum length must be 50.
    • DataType: String
  • Error
    • Description: Called when any error occur during removing user from conversation.
    • DataType: Callback


5 Get User List

To get list of all online users list, use following method

UserIDList({
    Callback: function (data) {},
    Error: function (Err) {}
});

Parameter:

  • Callback
    • Description: Called when successfully get user list.
    • DataType: Callback
  • Error
    • Description: Called when any error occur during fetching users list.
    • DataType: Callback


6 Send Text Message

To send text message to all connected user or to specific user, use following method.

SendTextMessage({
    Message: 'This is Yalgaar JavaScript SDK Example',
    RemoteUUID: 'UserId', 
    Error: function (Err) {}
});

Parameter:

  • Message
    • Description: Your text Message to be send to conversation
    • DataType: String
  • RemoteUUID
    • Description: This is optional. If you specified than will send message to only that user otherwise will send to all connected users. RemoteUUID is CASE SENSITIVE.
    • DataType: Number
  • Error
    • Description: Called when any error occur during sending message to user.
    • DataType: Callback


7 Send File

To Share file to connected users or with specified connected user, use following method

SendFile({
    RemoteUUID: 'UserId'. 
    Error: function (Err) {}
});

Parameter:

  • RemoteUUID
    • Description: This is optional. If you specified then will send file to only that user otherwise will send to all connected users. RemoteUUID is CASE SENSITIVE.
    • DataType: String
  • Error
    • Description: Called when any error occur during sending file to user.
    • DataType: Callback


8 Manage Stream

To manage stream audio and video output, use following method.

ManageStream({
    StreamId: 'StreamId',
    Type: "audio/video",
    Disable: true",
    Error: function (Err) {}
});

Parameter:

  • StreamId
    • Description: StremId provided in OnStream Event.
    • DataType: String
  • Type
    • Description: Type of stream to disable, must be video or audio.
    • DataType: String
  • Disable
    • Description: True to disable provided type and false to enable it.
    • DataType: boolean
  • Error
    • Description: Called when any error occur during manage stream.
    • DataType: Callback


You can publish/subscribe message like so :

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

<html>
<head>
    <style>
        .column {
            float: left;
            width: 35%;
            padding: 10px;
            height: 300px;
			border:1px solid #000
        }
    </style>
    <script src="YalgaarWebRTC-0.0.1.js"></script>
    <script>
        var uuid = new Date().getUTCMilliseconds();
        ConnectToYalgaar({
            ClientKey: 'ck-f4c99752ee4640ae',
            SSL: false,
            UUID: uuid,
            Video: true,
            Audio: true,
            Data: true,
            EnableFileSharing: true,
            Callback: function (ack) {
                console.log(ack);
            },
            OnStream: function (data) {
                if (data.type == "local") {
                    var localVideoContainer = document.getElementById("localVideo");
                    localVideoContainer.srcObject = data.stream;
                } else {
                    var RemoteVideoContainer = document.getElementById("remoteVideo");
                    RemoteVideoContainer.srcObject = data.stream;
                }
            },
            Presence: function (data) {
                console.log(data);
                var message = JSON.parse(data);
                if (message.action == "bind") {
                    joinConnection(message.uuid); //Remote UUID
                }
            },
            OnMessage: function (data) {
                console.log(data);
            },
            FileContainer: document.getElementById('fileContainer'),
            OnOpen: function (data) {
                SendMessage(data.userid); //Remote UUID
            },
            OnClose: function (data) {
                removeUser(data.userid); //Remote UUID
            },
            Error: function (err) {
                console.log("Error:" + err);
            },
            MediaError: function (data, constraint) {
                alert(data.name);
            },
        });

        function joinConnection(value) {
            JoinUser({
                RemoteUUID: value,
                Error: function (err) {
                    console.log("Error:" + err);
                }
            });
        }

        function removeUser(user) {
            RemoveUser({
                RemoteUUID: user,
                Error: function (err) {
                    console.log("Error:" + err);
                }
            });
        }

        function AddToConference(value) {
            AddUser({
                RemoteUUID: value,
                Error: function (err) {
                    console.log("Error:" + err);
                }
            });
        }

        function SendMessage(remoteID) {
            SendTextMessage({
                RemoteUUID: remoteID,
                Message: 'Hello there, We are connected through Yalgaar WebRTC SDK',
                Error: function (err) {
                    console.log("Error:" + err);
                }
            });
        }
    </script>
</head>
<body>
    <h2>Yalgaar WebRTC SDK Demo </h2>
    <div>
        <div class="column">
            <h3>WebRTC Local User</h3>
            <video id="localVideo" autoplay muted width="100%"></video>
        </div>
        <div class="column">
            <h3>WebRTC Remote User</h3>
            <video id="remoteVideo" autoplay muted width="100%"></video>
        </div>
    </div>
</body>
</html>