|
|
|
@ -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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|