/
Auth.js
48 lines (45 loc) · 2.13 KB
/
Auth.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
$(function () {
var hubs = {
'Messages': $.connection.noAuthHub,
'Messages Invoked By Admin or Invoker': $.connection.invokeAuthHub,
'Messages Requiring Authentication to Send or Receive': $.connection.authHub,
'Messages Requiring Authentication to Send or Receive Because of Inheritance': $.connection.inheritAuthHub,
'Messages Requiring Authentication to Send': $.connection.incomingAuthHub,
'Messages Requiring Authentication to Receive': $.connection.outgoingAuthHub,
'Messages Requiring Admin Membership to Send or Receive': $.connection.adminAuthHub,
'Messages Requiring Name to be "User" and Role to be "Admin" to Send or Receive': $.connection.userAndRoleAuthHub
};
$.each(hubs, function (title, hub) {
var list = $('<ul>').appendTo($('#messages').append('<h4>' + title + '</h4>')),
addMessage = function (value, className) {
list.append('<li class="' + className + '">' + value + '</li>');
};
$.extend(hub.client, {
joined: function (id, when, authInfo) {
var info = [];
if ($.connection.hub.id === id) {
addMessage(id, 'blue');
}
$.each(authInfo, function (k, v) {
info.push("<strong>" + k + ":</strong> " + v);
});
addMessage(id + ' joined at ' + when + '<br />' + info.join('; '), 'text-success');
},
rejoined: function (id, when) {
addMessage(id + ' reconnected at ' + when, 'text-warning');
},
left: function (id, when) {
addMessage(id + ' left at ' + when, 'text-error');
},
invoked: function (id, when) {
addMessage(id + ' invoked hub method at' + when, 'text-info');
}
});
});
$.connection.hub.logging = true;
$.connection.hub.start({ transport: activeTransport, jsonp: isJsonp }).done(function () {
$.each(hubs, function () {
this.server.invokedFromClient().fail($.connection.hub.log);
});
});
});