Implemente la notification de connection

Ok coté serveur, et interface web
manque le client mobile
main
Paul Schneider 9 years ago
parent 5a0c3f7f51
commit 01ad21adee
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 // 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/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Security.Claims;
using System.Security.Principal;
using Microsoft.AspNet.SignalR; using Microsoft.AspNet.SignalR;
namespace Yavsc namespace Yavsc
@ -28,16 +30,24 @@ namespace Yavsc
{ {
public override Task OnConnected() public override Task OnConnected()
{ {
bool isAuth = false;
string userId = null;
if (Context.User!=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"; "authenticated":"anonymous";
// Log ("Cx: " + group); // Log ("Cx: " + group);
Groups.Add(Context.ConnectionId, group); Groups.Add(Context.ConnectionId, group);
} else Groups.Add(Context.ConnectionId, "anonymous"); } else Groups.Add(Context.ConnectionId, "anonymous");
Clients.Group("authenticated").notify("connected", Context.ConnectionId, userId);
return base.OnConnected (); return base.OnConnected ();
} }
public override Task OnDisconnected (bool stopCalled) public override Task OnDisconnected (bool stopCalled)
{ {
string userId = Context.User?.Identity.Name;
Clients.Group("authenticated").notify("disconnected", Context.ConnectionId, userId);
return base.OnDisconnected (stopCalled); return base.OnDisconnected (stopCalled);
} }
@ -59,14 +69,14 @@ namespace Yavsc
} }
[Authorize] [Authorize]
public void PV (string userId, string message) public void PV (string connectionId, string message)
{ {
var sender = Context.User.Identity.Name; var sender = Context.User.Identity.Name;
// TODO personal black|white list + // TODO personal black|white list +
// Contact list allowed only + // Contact list allowed only +
// only pro // only pro
var hubCxContext = Clients.User(userId); var hubCxContext = Clients.User(connectionId);
var cli = Clients.Client(hubCxContext.ConnectionId); var cli = Clients.Client(connectionId);
cli.addPV(sender,message); cli.addPV(sender,message);
} }
} }

@ -19,6 +19,8 @@
</ul> </ul>
<ul id="private"> <ul id="private">
</ul> </ul>
<ul id="chatnotifs">
</ul>
</div> </div>
@section scripts { @section scripts {
<!--Script references. --> <!--Script references. -->
@ -43,6 +45,11 @@
$('#private').append('<li><strong>' + htmlEncode(name) $('#private').append('<li><strong>' + htmlEncode(name)
+ '</strong>: ' + htmlEncode(message) + '</li>'); + '</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. // Get the user name and store it to prepend to messages.
$('#displayname').val(prompt('Enter your name:', '')); $('#displayname').val(prompt('Enter your name:', ''));
// Set initial focus to message input box. // Set initial focus to message input box.

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