Last active
August 29, 2015 14:21
-
-
Save winterTTr/5591189f4d23e9d89085 to your computer and use it in GitHub Desktop.
sample code for Azure Tutorial - Index.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@using System.Security.Claims | |
@using Microsoft.AspNet.Identity | |
@{ | |
ViewBag.Title = "Online Chat"; | |
} | |
<div class="panel panel-info row"> | |
<div class="panel-heading"> | |
<h3 class="panel-title"> | |
Chat Room | |
@{ | |
var identity = User.Identity as ClaimsIdentity; | |
var givenName = identity.FindFirstValue(ClaimTypes.GivenName); | |
var surName = identity.FindFirstValue(ClaimTypes.Surname); | |
<span id="spnUserName" class="label label-primary">@(string.Format("{0} {1}", givenName, surName))</span> | |
} | |
</h3> | |
<div class="input-group" style="margin: 10px 0 0 0;"> | |
<input style="max-width: 100%" id="iptMesssage" type="text" class="form-control" placeholder="message to send..."> | |
<span class="input-group-btn"> | |
<button class="btn btn-primary" type="button" id="btnSendMessage">Send</button> | |
</span> | |
</div> | |
</div> | |
<div class="panel-body container"> | |
<div class="row"> | |
<div class="col-md-12" id="messageList"></div> | |
</div> | |
</div> | |
</div> | |
@section scripts { | |
<script src="~/Scripts/jquery.signalR-2.2.0.min.js"></script> | |
<script src="~/signalr/hubs"></script> | |
<script> | |
$(function () { | |
var proxy = $.connection.OnlineChat; | |
function init() { | |
$('#btnSendMessage').on('click', function (e) { | |
var text = $('#iptMesssage').val(); | |
if (text != "") { | |
var username = $('#spnUserName').text(); | |
proxy.server.sendMessage(username + " >" + text); | |
$('#iptMesssage').val(''); | |
} | |
}); | |
$('#iptMesssage').keypress(function(e) { | |
var key = e.which; | |
if (key == 13){ | |
$('#btnSendMessage').click(); | |
return false; | |
} | |
return true; | |
}); | |
} | |
proxy.client.broadcastMessage = function (msg) { | |
$('<div />'). | |
text(msg). | |
prependTo('#messageList'); | |
}; | |
$.connection.hub.start().done(init); | |
}); | |
</script> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment