Permalink
Browse files

temp-commit

  • Loading branch information...
1 parent 18459e2 commit 61565d0a2cc3f932c6cba2cb7b95d7e99cd92ced @abnanda1 abnanda1 committed Apr 16, 2013
@@ -6,6 +6,7 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNet.SignalR.Client.Hubs;
+using Microsoft.AspNet.SignalR.Transports;
namespace Microsoft.AspNet.SignalR.Client.Samples
{
@@ -13,6 +13,12 @@ namespace Microsoft.AspNet.SignalR.Samples.Hubs.DemoHub
{
public class ChatHub : Hub
{
+ private class Person
+ {
+ public string Name { get; set; }
+ public int Age { get; set; }
+ public string Id { get; set; }
+ }
// User Names mapped to User objects
private static readonly ConcurrentDictionary<string, ChatUser> _users = new ConcurrentDictionary<string, ChatUser>(StringComparer.OrdinalIgnoreCase);
@@ -22,6 +28,12 @@ public class ChatHub : Hub
// Room names mapped to romm objects
private static readonly ConcurrentDictionary<string, ChatRoom> _rooms = new ConcurrentDictionary<string, ChatRoom>(StringComparer.OrdinalIgnoreCase);
+ public override Task OnConnected()
+ {
+ Clients.Caller.UserName = "John Phillips";
+ return base.OnConnected();
+ }
+
public void Send(string message)
{
// Call the broadcastMessage method to update clients.
@@ -31,6 +43,17 @@ public void Send(string message)
}
}
+ public Task SendUserName()
+ {
+ Clients.Caller.UserName = "John Phillips";
+ Person p = new Person();
+ p.Name = "John Phillips";
+ p.Age = 30;
+ p.Id = Context.ConnectionId;
+ Clients.Caller.Id = Context.ConnectionId;
+ return Clients.Caller.showUserName(p);
+ }
+
public Task AddUser(string userName)
{
var user = new ChatUser(userName, Context.ConnectionId);
@@ -0,0 +1,42 @@
+<!DOCTYPE html>
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+ <title></title>
+ <script src="../../Scripts/jquery-1.8.2.min.js"></script>
+ <script src="../../Scripts/jquery.signalR.min.js"></script>
+ <script type="text/javascript">
+ $(function () {
+ // var chat = $.connection.chatHub;
+ var connection = $.hubConnection();
+ var chatProxy = connection.createHubProxy("ChatHub");
+
+ // $.connection.hub.logging = true;
+
+ connection.start({ transport: 'webSockets' }).done(function () {
+ alert("Succesfully connected");
+ chatProxy.invoke("SendUserName");
+ });
+
+ //$.connection.hub.start({ transport: 'webSockets' }).done(function () {
+ // alert("Succesfully connected");
+ // chat.server.sendUserName();
+ // chatProxy.server.sendUserName();
+ //});
+
+ chatProxy.on("ShowUserName", function (person) {
+ // alert(chat.state.UserName);
+ alert(connection.id + person.Name + " : " + person.Age);
+ //$.connection.hub.log("Person Id" + person.Id);
+ //$.connection.hub.log("Id from the Hub" + $.connection.hub.id);
+ });
+ });
+ </script>
+</head>
+<body>
+ <div id="message-area">
+ <ul id =" messages">
+
+ </ul>
+ </div>
+</body>
+</html>
@@ -153,6 +153,7 @@
<Content Include="Hubs\Chat\Chat.css" />
<Content Include="Hubs\Chat\Chat.js" />
<Content Include="Hubs\Chat\index.htm" />
+ <Content Include="Hubs\DemoHub\ChatPage.html" />
<Content Include="Hubs\DrawingPad\Default.aspx" />
<Content Include="Hubs\MouseTracking\Default.aspx" />
<Content Include="Hubs\MouseTracking\images\wand.png" />
@@ -130,6 +130,11 @@
/// <summary>Calls the Send method on the server-side ChatHub hub.&#10;Returns a jQuery.Deferred() promise.</summary>
/// <param name=\"message\" type=\"String\">Server side type is System.String</param>
return proxies.chatHub.invoke.apply(proxies.chatHub, $.merge(["Send"], $.makeArray(arguments)));
+ },
+
+ sendUserName: function () {
+ /// <summary>Calls the SendUserName method on the server-side ChatHub hub.&#10;Returns a jQuery.Deferred() promise.</summary>
+ return proxies.chatHub.invoke.apply(proxies.chatHub, $.merge(["SendUserName"], $.makeArray(arguments)));
}
};

0 comments on commit 61565d0

Please sign in to comment.