Click here to Skip to main content
15,889,852 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link rel="Stylesheet" href="Styles/Site.css" />
<script src="Scripts/jquery-1.6.4.js" type="text/javascript"></script>
<script src="Scripts/json2.js" type="text/javascript"></script>
<script src="Scripts/jquery.signalR-1.0.0-rc2.min.js" type="text/javascript"></script>
<script src="signalr/hubs" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {

// Proxy created on the fly
var chat = $.connection.chatHub;
var lvID = '<%= lv_chat.ClientID %>';
chat.client.OnlineStatus = function (connectionId, userList) {
$("img[id^=stat]").attr('src', 'images/offline.png');
$(userList).each(function (index, obj) {
if (obj == '<%= Session["UserName"]%>') {
//$("#stat1").live.attr('src', 'images/online.png');
//$("#status1").live.addClass('online');
$("img[id^=stat1]").attr('src','images/online.png');
$("#status1").listview("#lv_chat").addClass('online');
//var content= $("#status1").text();
//alert(content);
}
//else if (obj == "Lokesh1") {
// $("#stat2").attr('src', 'images/online.png');
// $("#status2").addClass('online');
// alert(index);
// alert(obj);
//}
//else if (obj == "Lokesh2") {
// $("#stat3").attr('src', 'images/online.png');
// $("#status3").addClass('online');
// alert(index);
// alert(obj);
//}
});
};


chat.client.joined = function (connectionId, userList) {
$(userList).each(function (index, obj) {
if (obj == '<%= Session["UserName"]%>') {
//$("#stat1").live.attr('src', 'images/online.png');
$("img[id^=stat1]").attr('src','images/online.png');
$("img[id^=stat1]").addClass('online');
//$("#status1").live.addClass('online');
//var content= $("#status1").text();
//alert(content);
}
// else if (obj == "Lokesh1") {
// $("#stat2").attr('src', 'images/online.png');
// $("#stat2").addClass('online');
// }
// else if (obj == "Lokesh2") {
// $("#stat3").attr('src', 'images/online.png');
// $("#stat3").addClass('online');
// }
// });
//};

chat.client.setChatWindow = function (strGroupName, strChatTo) {
$('div[chatToId=' + strChatTo + ']').attr('groupname', strGroupName);
$('div[chatToId=' + strChatTo + ']').css('display', 'block')
};
// Declare a function on the chat hub so the server can invoke it
chat.client.addMessage = function (message, groupName) {
if ($('div[groupname=' + groupName + ']').length == 0) {
var chatWindow = $("#divChatWindow").clone(true);
$(chatWindow).css('display', 'block');
$(chatWindow).attr('groupname', groupName);
$("#chatContainer").append(chatWindow);
}
$('div[groupname=' + groupName + ']').find('ul').append('
  • ' + message + '');
    };
    $("#broadcast").click(function () {
    // Call the chat method on the server
    chat.server.send($('#msg').val());
    });
    // Start the connection
    $.connection.hub.start(function () {
    chat.server.getAllOnlineStatus();
    });

    $('.UserItem').click(function () {
    if ($(this).hasClass('online')) {
    chat.server.createGroup($('#hdnUserId').val(), $(this).attr('data-userid'));
    var chatWindow = $("#divChatWindow").clone(true);
    //$(chatWindow).css('display', 'block');
    $(chatWindow).attr('chatToId', $(this).attr('data-userid'));
    $("#chatContainer").append(chatWindow);
    }
    return false;
    });

    $(".ChatSend").click(function () {
    strChatText = $('.ChatText', $(this).parent()).val();
    if (strChatText != '') {
    var strGroupName = $(this).parent().attr('groupname');
    if (typeof strGroupName !== 'undefined' && strGroupName !== false)
    chat.server.send($("#hdnUserName").val() + ' : ' + strChatText, $(this).parent().attr('groupname'));
    $('.ChatText', $(this).parent()).find('ul').append(strChatText);
    $('.ChatText', $(this).parent()).val('');
    }
    return false;
    });
    });

    </script>
    </head>
    <body>
    <form id="form1" runat="server">







      <asp:TextBox runat="server" ID="msg" CssClass="ChatText" Width="280px" BorderColor="#666699"
      BorderStyle="Solid" BorderWidth="1px" Height="22px">
      <asp:Button ID="btnChatSend" runat="server" CssClass="ChatSend" Text="Submit" OnClientClick="return false"
      BackColor="#99ccff" Font-Size="Smaller" BorderStyle="Solid" BorderWidth="1px"
      BorderColor="#0066FF" ForeColor="#336699" Height="24px" />




      <asp:Label ID="lblUserName" runat="server" Font-Bold="true" />



      <asp:ListView ID="lv_chat" runat="server">
      <itemtemplate>
      <asp:Image ID="stat1" runat="server" Width="18px" Height="18px" ImageUrl="~/Images/offline.png" AlternateText="" />
      User


      <%-- <asp:Image ID="stat1" runat="server" Width="18px" Height="18px" ImageUrl="~/Images/offline.png" />
      Lokesh


      <asp:Image ID="stat2" runat="server" Width="18px" Height="18px" ImageUrl="~/Images/offline.png" />
      Lokesh1


      <asp:Image ID="stat3" runat="server" Width="18px" Height="18px" ImageUrl="~/Images/offline.png" />
      Lokesh2--%>



      <asp:HiddenField ID="hdnUserId" runat="server" />
      <asp:HiddenField ID="hdnUserName" runat="server" />

      </form>
      </body>
      </html>
    • Posted
      Comments
      Sunasara Imdadhusen 20-May-14 6:39am    
      Is this your question? don't post entire code over here

      This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



      CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900