diff --git a/rc-num.txt b/rc-num.txt index 8a0f05e1..9e22bcb8 100644 --- a/rc-num.txt +++ b/rc-num.txt @@ -1 +1 @@ -01 +02 diff --git a/src/Yavsc/Hubs/ChatHub.cs b/src/Yavsc/Hubs/ChatHub.cs index 81834394..09cd85d1 100644 --- a/src/Yavsc/Hubs/ChatHub.cs +++ b/src/Yavsc/Hubs/ChatHub.cs @@ -19,19 +19,17 @@ // You should have received a copy of the GNU Lesser General Public License // along with this program. If not, see . using Microsoft.AspNet.SignalR; -using Microsoft.AspNet.SignalR.Hosting; using System.Threading.Tasks; using System.Collections.Generic; using System.Linq; +using System; +using System.Collections.Concurrent; +using Microsoft.Data.Entity; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; namespace Yavsc { - using System; - using System.Collections.Concurrent; - using Microsoft.AspNet.WebUtilities; - using Microsoft.Data.Entity; - using Microsoft.Extensions.DependencyInjection; - using Microsoft.Extensions.Logging; using Models; using Models.Chat; @@ -113,7 +111,12 @@ namespace Yavsc return Context.User.Identity.Name; } anonymousSequence++; - var aname = $"{Constants.AnonymousUserNamePrefix}{anonymousSequence}"; + var reqKeys = Context.Request.QueryString.Select(pv => pv.Key); + _logger.LogInformation(string.Join(" ", reqKeys)); + + var queryUname = Context.Request.QueryString[Constants.KeyParamChatUserName] ; + + var aname = $"{Constants.AnonymousUserNamePrefix}{queryUname}{anonymousSequence}"; ChatUserNames[Context.ConnectionId]=aname; _logger.LogInformation($"Anonymous chat user name set to : {aname}"); return aname; diff --git a/src/Yavsc/Views/Home/Chat.cshtml b/src/Yavsc/Views/Home/Chat.cshtml index 2ea78f1e..ef1bae5f 100644 --- a/src/Yavsc/Views/Home/Chat.cshtml +++ b/src/Yavsc/Views/Home/Chat.cshtml @@ -13,11 +13,10 @@ @if (!ViewBag.IsAuthenticated) { // Get the user name and store it to prepend to messages. -} +} - } diff --git a/src/Yavsc/wwwroot/js/chat.js b/src/Yavsc/wwwroot/js/chat.js index 53a963c6..1a2256fd 100644 --- a/src/Yavsc/wwwroot/js/chat.js +++ b/src/Yavsc/wwwroot/js/chat.js @@ -32,7 +32,6 @@ { if (!full) throw "not implemented"; - var chat = $.connection.chatHub // Create a function that the hub can call back to display messages. chat.client.addMessage = function (name, room, message) { @@ -72,8 +71,7 @@ chat.client.onJoined = function (rinfo) { console.log(rinfo); - $('#inp_'+rinfo.Name).prop('enable',true) - + setActiveRoom(rinfo.Name); } $.fn.filterByData = function (prop, val) { @@ -82,44 +80,54 @@ ) } - var roomlist = $("
"); + var activeRoom; + var activeRoomName; + var setActiveRoom = function(room) { + if (activeRoom) { + // TODO animate + activeRoom.addClass("hidden"); + $("sel_"+activeRoomName).addClass("btn-primary"); + } + activeRoom=$("#vroom_"+room); + activeRoomName=room; + activeRoom.removeClass("hidden"); + } + var roomlist = $('
'); roomlist.appendTo($view); + var chatlist = $('
'); + chatlist.appendTo($view); var buildRoom = function (room) { - console.log('building:'+room); - - var roomTag = $(""+room+""); - roomTag.addClass('btn').addClass('default') + var roomTag = $(""+room+"").addClass("btn").addClass("btn-primary"); + roomTag.prop("id","sel_"+room) .click(function(){ - setRoom(room) + setActiveRoom(room); + $(this).removeClass("btn-primary"); }); - - var roomview = $("
"); - roomTag.appendTo(roomlist); + var roomview = $("
").addClass("container"); + roomview.appendTo(chatlist); roomview.prop('id',"vroom_"+room); - var msglist = $(""); + var msglist = $("").addClass("mesglist"); msglist.prop('id',"room_"+room); msglist.appendTo(roomview); - $("") .prop('id','inp_'+room) .prop('enable',false) .prop('hint','hello') .prop('title','send to '+room) - .keydown(function(ev){ + .addClass('form-control') + .keydown(function(ev) { if (ev.which == 13) { - console.log('sending:'+room+' '+this.value); - chat.server.send(room, this.value) - this.value="" - } - }).appendTo(roomview); + if (this.value.length==0) return; + console.log("sending to "+room+" "+this.value) + chat.server.send(room, this.value); + this.value=""; + }}).appendTo(roomview); chans.push(room); - roomview.appendTo($view); - console.log('done with built:'); - console.log(chans); + setActiveRoom(room); } // build a channel list @@ -151,6 +159,7 @@ }) $.connection.hub.disconnected(function () { + onDisCx() setTimeout(function () { $.connection.hub.start().done(function () { @@ -160,16 +169,19 @@ }) }) + + $("") .appendTo($view); var chanName = $(""); chanName.appendTo($view); - chanName.keydown( function (event) { if (event.which == 13) { + if (this.value.length==0) return; buildRoom(this.value); + chat.server.join(this.value); this.value="" } else { // TODO showRoomInfo(this.value); @@ -180,15 +192,7 @@ ulist.appendTo($view); - var activeRoom; - var setRoom = function(room) { - if (activeRoom) { - // TODO animate - activeRoom.addClass("hidden"); - } - activeRoom=$("#vroom_"+room); - activeRoom.removeClass("hidden") - } + var pvuis // TODO get this data from the chatview element var audio = new Audio('/sounds/bell.mp3') diff --git a/src/Yavsc/wwwroot/js/chat.min.js b/src/Yavsc/wwwroot/js/chat.min.js index 2d40bb60..f748c643 100644 --- a/src/Yavsc/wwwroot/js/chat.min.js +++ b/src/Yavsc/wwwroot/js/chat.min.js @@ -1 +1 @@ -!function(t){var s,e=new Audio("/sounds/bell.mp3");function a(n,s){t('
  • ").data("name",n).data("cxids",s).css("cursor","pointer").click(function(){i(this)}).appendTo("#userlist")}function n(){setTimeout(function(){t("#userlist").empty(),t("#to").empty(),t.get("/api/chat/users").done(function(n){t.each(n,function(){var n=this,s=t("#userlist li").filterByData("name",n.UserName);0").text(n).html()}var i=function(n){t("#sendmessagebox").addClass("hidden"),t("#sendpvbox").removeClass("hidden"),s={CXs:t(n).data("cxids"),UserName:t(n).data("name")},t("#sendpvdest").html(s.UserName),t("#pv").focus()},c=function(){t("#sendmessagebox").removeClass("hidden"),t("#sendpvbox").addClass("hidden"),t("#message").focus()};t("#pubChan").css("cursor","pointer"),t("#pubChan").click(c),c();var d=t.connection.chatHub;d.client.addMessage=function(n,s){t("#discussion").append('
  • '+o(n)+": "+o(s)+"
  • ")},d.client.addPV=function(n,s){t("#mute").prop("checked")||e.play(),t("#discussion").append('
  • '+o(n)+": "+o(s)+"
  • ")},t.fn.filterByData=function(n,s){return this.filter(function(){return t(this).data(n)==s})};d.client.notify=function(n,s,e){var i;e&&("connected"===n?(!function(n,s){var e=t("#userlist li").filterByData("name",s);if(0'+o(n)+" "+o(e)+"")):"disconnected"===n?(i=s,t("#userlist li").filter(function(){var n=t(this).data("cxids").filter(function(){return t(this)!==i});0==n.Length?t(this).remove():t(this).data("cxids",n)}),t("#discussion").append('
  • '+o(n)+" "+o(e)+"
  • ")):t("#discussion").append('
  • '+o(n)+" "+o(s)+" : "+o(e)+"
  • "))};var u=function(){d.server.send(t("#displayname").val(),t("#message").val()),t("#message").val("")},l=function(){var n=t("#pv").val();t.each(s.CXs,function(){d.server.sendPV(this,n)}),t("#discussion").append('
  • '+o(s.UserName)+"<< "+o(n)+"
  • "),t("#pv").val("")};t.connection.hub.start().done(function(){n(),t("#sendmessage").click(function(){u(),t("#message").focus()}),t("#message").keydown(function(n){13==n.which&&u()}),t("#pv").keydown(function(n){13==n.which&&l()}),t("#sendpv").click(function(){l(),t("#sendpv").focus()})}),t.connection.hub.disconnected(function(){t("#chatview").addClass("disabled"),t("#sendmessage").prop("disabled",!0),t("#sendpv").prop("disabled",!0),setTimeout(function(){t.connection.hub.start().done(function(){t("#mySignalRConnectionIdHidden").val(t.connection.hub.id),n()},3e4)})}),t(window).unload(function(){d.server.abort()})}(jQuery); \ No newline at end of file +!function(C){var e=function(o,n){if(!n)throw"not implemented";var a=C.connection.chatHub;a.client.addMessage=function(n,e,i){C("#room_"+e).append('
  • '+f(n)+": "+f(i)+"
  • ")},a.client.addPV=function(n,e){C("#mute").prop("checked")||p.play(),C("#pv_"+n).append('
  • '+f(n)+": "+f(e)+"
  • ")},a.client.notify=function(n,e,i){i&&("connected"===n?(g(l,e,i),C("#notifications").append('
  • '+f(n)+" "+f(i)+"
  • ")):"disconnected"===n?(b(l,e,i),C("#notifications").append('
  • '+f(n)+" "+f(i)+"
  • ")):C("#notifications").append('
  • '+f(n)+" "+f(e)+" : "+f(i)+"
  • "))},a.client.onJoined=function(n){console.log(n),C("#inp_"+n.Name).prop("enable",!0)},C.fn.filterByData=function(n,e){return this.filter(function(){return C(this).data(n)==e})};var s=C("
    ");s.appendTo(o);var e=function(e){console.log("building:"+e);var n=C(""+e+"");n.addClass("btn").addClass("default").click(function(){u(e)});var i=C("
    ");n.appendTo(s),i.prop("id","vroom_"+e);var t=C('
      ');t.prop("id","room_"+e),t.appendTo(i),C('').prop("id","inp_"+e).prop("enable",!1).prop("hint","hello").prop("title","send to "+e).keydown(function(n){13==n.which&&(console.log("sending:"+e+" "+this.value),a.server.send(e,this.value),this.value="")}).appendTo(i),c.push(e),i.appendTo(o),console.log("done with built:"),console.log(c)},c=Array();function i(){setTimeout(function(){var t;C("#userlist").empty(),C("#to").empty(),C.get("/api/chat/users").done(function(n){C.each(n,function(){var n=this,e=C("#userlist li").filterByData("name",n.UserName);0> ').appendTo(o);var t=C('');t.appendTo(o),t.keydown(function(n){13==n.which&&(e(this.value),this.value="")});var d,l=C("
        ").addClass("userlist");l.appendTo(o);var r,u=function(n){d&&d.addClass("hidden"),(d=C("#vroom_"+n)).removeClass("hidden")},p=new Audio("/sounds/bell.mp3");function h(n,e,i){C('
      • '+e+"
      • ").data("name",e).data("cxids",i).css("cursor","pointer").click(function(){v(this)}).appendTo(n)}function f(n){return C("
        ").text(n).html()}C("#pv").keydown(function(n){var e;13==n.which&&(e=C("#pv").val(),C.each(r.CXs,function(){a.server.sendPV(this,e)}),C("#discussion").append('
      • '+f(r.UserName)+"<< "+f(e)+"
      • "),C("#pv").val(""))}),C("#command").keydown(function(n){13==n.which&&sendCommand()});var v=function(n){C("#rooms").addClass("hidden"),C("#sendpvbox").removeClass("hidden"),r={CXs:C(n).data("cxids"),UserName:C(n).data("name")},C("#sendpvdest").html(r.UserName),C("#pvs").focus()},m=function(){C("#rooms").removeClass("hidden"),C("#sendpvbox").addClass("hidden"),C("#message").focus()};C("#pubChan").css("cursor","pointer"),C("#pubChan").click(m),m();var b=function(e){C("#userlist li").filter(function(){var n=C(this).data("cxids").filter(function(){return C(this)!==e});0==n.length?C(this).remove():C(this).data("cxids",n)})},g=function(n,e,i){var t=C("#userlist li").filterByData("name",i);if(0