Merge branch 'vnext' of https://github.com/pazof/yavsc.git
This commit is contained in:
@ -19,55 +19,65 @@
|
||||
// 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
|
||||
{
|
||||
|
||||
public class ChatHub : Hub
|
||||
public class ChatHub : Hub
|
||||
{
|
||||
public override Task OnConnected()
|
||||
{
|
||||
public override Task OnConnected()
|
||||
{
|
||||
if (Context.User!=null) {
|
||||
var group = (Context.User.Identity.IsAuthenticated)?
|
||||
"authenticated":"anonymous";
|
||||
// Log ("Cx: " + group);
|
||||
Groups.Add(Context.ConnectionId, group);
|
||||
} else Groups.Add(Context.ConnectionId, "anonymous");
|
||||
return base.OnConnected ();
|
||||
}
|
||||
public override Task OnDisconnected (bool stopCalled)
|
||||
{
|
||||
return base.OnDisconnected (stopCalled);
|
||||
}
|
||||
bool isAuth = false;
|
||||
string userId = null;
|
||||
if (Context.User!=null) {
|
||||
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);
|
||||
}
|
||||
|
||||
public override Task OnReconnected ()
|
||||
{
|
||||
return base.OnReconnected ();
|
||||
}
|
||||
|
||||
public void Send(string name, string message)
|
||||
{
|
||||
|
||||
Clients.All.addMessage(name,message);
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public void AuthSend (string name, string message)
|
||||
{
|
||||
Clients.All.addMessage("#"+name,message);
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public void PV (string userId, 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);
|
||||
cli.addPV(sender,message);
|
||||
}
|
||||
{
|
||||
return base.OnReconnected ();
|
||||
}
|
||||
|
||||
public void Send(string name, string message)
|
||||
{
|
||||
|
||||
Clients.All.addMessage(name,message);
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public void AuthSend (string name, string message)
|
||||
{
|
||||
Clients.All.addMessage("#"+name,message);
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
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(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.
|
||||
|
5
Yavsc/wwwroot/js/site.min.js
vendored
5
Yavsc/wwwroot/js/site.min.js
vendored
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user