Paul Schneider 8 years ago
commit 7d3f91219e
3 changed files with 58 additions and 42 deletions

@ -19,6 +19,8 @@
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using System.Threading.Tasks;
using System.Security.Claims;
using System.Security.Principal;
using Microsoft.AspNet.SignalR;
namespace Yavsc
@ -28,16 +30,24 @@ namespace Yavsc
{
public override Task OnConnected()
{
bool isAuth = false;
string userId = null;
if (Context.User!=null) {
var group = (Context.User.Identity.IsAuthenticated)?
isAuth = Context.User.Identity.IsAuthenticated;
userId = Context.User.Identity.Name;
var group = isAuth ?
"authenticated":"anonymous";
// Log ("Cx: " + group);
Groups.Add(Context.ConnectionId, group);
} else Groups.Add(Context.ConnectionId, "anonymous");
Clients.Group("authenticated").notify("connected", Context.ConnectionId, userId);
return base.OnConnected ();
}
public override Task OnDisconnected (bool stopCalled)
{
string userId = Context.User?.Identity.Name;
Clients.Group("authenticated").notify("disconnected", Context.ConnectionId, userId);
return base.OnDisconnected (stopCalled);
}
@ -59,14 +69,14 @@ namespace Yavsc
}
[Authorize]
public void PV (string userId, string message)
public void PV (string connectionId, string message)
{
var sender = Context.User.Identity.Name;
// TODO personal black|white list +
// Contact list allowed only +
// only pro
var hubCxContext = Clients.User(userId);
var cli = Clients.Client(hubCxContext.ConnectionId);
var hubCxContext = Clients.User(connectionId);
var cli = Clients.Client(connectionId);
cli.addPV(sender,message);
}
}

@ -19,6 +19,8 @@
</ul>
<ul id="private">
</ul>
<ul id="chatnotifs">
</ul>
</div>
@section scripts {
<!--Script references. -->
@ -43,6 +45,11 @@
$('#private').append('<li><strong>' + htmlEncode(name)
+ '</strong>: ' + htmlEncode(message) + '</li>');
};
chat.client.notify = function (tag, message) {
// Add the pv to the page.
$('#chatnotifs').append('<li><i>' + htmlEncode(tag)
+ '</i> ' + htmlEncode(message) + '</li>');
};
// Get the user name and store it to prepend to messages.
$('#displayname').val(prompt('Enter your name:', ''));
// Set initial focus to message input box.

File diff suppressed because one or more lines are too long
Loading…