chat sounds on pv

main
Paul Schneider 9 years ago
parent 1dd4f25860
commit c3537ebdb0
2 changed files with 127 additions and 127 deletions

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

Binary file not shown.
Loading…