|
|
|
|
@ -1,8 +1,6 @@
|
|
|
|
|
@{
|
|
|
|
|
ViewBag.Title = "Chat";
|
|
|
|
|
}
|
|
|
|
|
@{ ViewBag.Title = "Chat"; }
|
|
|
|
|
<h2>Chat </h2>
|
|
|
|
|
|
|
|
|
|
<label><input type="checkbox" id="mute" />Muet</label>
|
|
|
|
|
<style>
|
|
|
|
|
.discussion {
|
|
|
|
|
color: black;
|
|
|
|
|
@ -27,7 +25,9 @@
|
|
|
|
|
<input type="hidden" id="displayname" />
|
|
|
|
|
<div style="float:right; background-color: grey; padding:1em; margin:1em;">
|
|
|
|
|
<h3>Salons</h3>
|
|
|
|
|
<ul><li id="pubChan">Public</li></ul>
|
|
|
|
|
<ul>
|
|
|
|
|
<li id="pubChan">Public</li>
|
|
|
|
|
</ul>
|
|
|
|
|
<h3>Utilisateurs</h3>
|
|
|
|
|
<ul id="userlist" style="list-style:none; padding: 1em; margin:1em;">
|
|
|
|
|
</ul>
|
|
|
|
|
@ -58,17 +58,16 @@
|
|
|
|
|
|
|
|
|
|
$(function () {
|
|
|
|
|
var pvuis;
|
|
|
|
|
var audio = new Audio('/sounds/bell.mp3');
|
|
|
|
|
|
|
|
|
|
var setPrivate = function(li)
|
|
|
|
|
{
|
|
|
|
|
var setPrivate = function (li) {
|
|
|
|
|
$("#sendmessagebox").addClass("hidden");
|
|
|
|
|
$("#sendpvbox").removeClass("hidden");
|
|
|
|
|
pvuis = { CXs: $(li).data("cxids"), UserName: $(li).data("name") };
|
|
|
|
|
$('#sendpvdest').html(pvuis.UserName)
|
|
|
|
|
$('#pv').focus();
|
|
|
|
|
}
|
|
|
|
|
var setPublic = function()
|
|
|
|
|
{
|
|
|
|
|
var setPublic = function () {
|
|
|
|
|
$("#sendmessagebox").removeClass("hidden");
|
|
|
|
|
$("#sendpvbox").addClass("hidden");
|
|
|
|
|
$('#message').focus();
|
|
|
|
|
@ -78,14 +77,12 @@
|
|
|
|
|
setPublic();
|
|
|
|
|
|
|
|
|
|
var getUsers = function () {
|
|
|
|
|
console.log("Try and get user list ...");
|
|
|
|
|
$('#userlist').empty();
|
|
|
|
|
$('#to').empty();
|
|
|
|
|
$.get("/api/chat/users").done(
|
|
|
|
|
function (users) {
|
|
|
|
|
$.each(users, function () {
|
|
|
|
|
var user = this;
|
|
|
|
|
console.log(user);
|
|
|
|
|
var existent = $('#userlist li').filterByData("name", user.UserName);
|
|
|
|
|
if (existent.length > 0) existent.remove();
|
|
|
|
|
var li = $('<li class="user"><img src="/Avatars/' + user.UserName + '.xs.png"> ' + htmlEncode(user.UserName) + '</li>');
|
|
|
|
|
@ -115,9 +112,13 @@
|
|
|
|
|
+ '</strong>: ' + htmlEncode(message) + '</li>');
|
|
|
|
|
};
|
|
|
|
|
chat.client.addPV = function (name, message) {
|
|
|
|
|
if (!$("#mute").prop('checked'))
|
|
|
|
|
{
|
|
|
|
|
audio.play();
|
|
|
|
|
}
|
|
|
|
|
// Add the pv to the page.
|
|
|
|
|
$('#discussion').append('<li class="pv"><strong>' + htmlEncode(name)
|
|
|
|
|
+ '</strong>: ' + htmlEncode(message) + '</li>');
|
|
|
|
|
+ '</strong>: ' + htmlEncode(message) + '</li>')
|
|
|
|
|
};
|
|
|
|
|
$.fn.filterByData = function (prop, val) {
|
|
|
|
|
return this.filter(
|
|
|
|
|
@ -158,8 +159,7 @@ onUserConnected(message, data);
|
|
|
|
|
$('#discussion').append('<li class="notif"><i>' + htmlEncode(tag)
|
|
|
|
|
+ '</i> ' + htmlEncode(data) + '</li>');
|
|
|
|
|
}
|
|
|
|
|
else if (tag === 'disconnected')
|
|
|
|
|
{
|
|
|
|
|
else if (tag === 'disconnected') {
|
|
|
|
|
onUserDisconnected(message, data);
|
|
|
|
|
$('#discussion').append('<li class="notif"><i>' + htmlEncode(tag)
|
|
|
|
|
+ '</i> ' + htmlEncode(data) + '</li>');
|
|
|
|
|
@ -189,13 +189,6 @@ $('#discussion').append('<li class="notif"><i>' + htmlEncode(tag)
|
|
|
|
|
$('#pv').val('');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@if (!ViewBag.IsAuthenticated) {
|
|
|
|
|
// Get the user name and store it to prepend to messages.
|
|
|
|
|
<text>
|
|
|
|
|
$('#displayname').val(prompt('Enter your name:', ''));
|
|
|
|
|
</text>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Start the connection.
|
|
|
|
|
$.connection.hub.start().done(function () {
|
|
|
|
|
@ -215,7 +208,8 @@ $('#discussion').append('<li class="notif"><i>' + htmlEncode(tag)
|
|
|
|
|
});
|
|
|
|
|
$('#sendpv').click(function () {
|
|
|
|
|
// Call the Send method on the hub.
|
|
|
|
|
sendPV().focus();
|
|
|
|
|
sendPV();
|
|
|
|
|
$("#sendpv").focus()
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
getUsers();
|
|
|
|
|
@ -229,6 +223,7 @@ $('#discussion').append('<li class="notif"><i>' + htmlEncode(tag)
|
|
|
|
|
}, 3000); // Re-start connection after 3 seconds
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$(window).unload(function () { chat.server.abort(); });
|
|
|
|
|
});
|
|
|
|
|
// This optional function html-encodes messages for display in the page.
|
|
|
|
|
@ -239,4 +234,9 @@ $('#discussion').append('<li class="notif"><i>' + htmlEncode(tag)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@if (!ViewBag.IsAuthenticated) { // Get the user name and store it to prepend to messages.
|
|
|
|
|
<script>
|
|
|
|
|
$('#displayname').val(prompt('Enter your name:', ''));
|
|
|
|
|
</script>
|
|
|
|
|
} }
|