|
|
|
@ -15,7 +15,7 @@
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<ul id="discussion">
|
|
|
|
<ul id="discussion">
|
|
|
|
</ul>
|
|
|
|
</ul>
|
|
|
|
<div id="targets" >
|
|
|
|
<div id="targets" class="disabled" >
|
|
|
|
<div id="sendmessagebox">
|
|
|
|
<div id="sendmessagebox">
|
|
|
|
<div class="col-md-10">
|
|
|
|
<div class="col-md-10">
|
|
|
|
<div class="row">
|
|
|
|
<div class="row">
|
|
|
|
@ -46,34 +46,35 @@
|
|
|
|
<script src="~/api/signalr/hubs"></script>
|
|
|
|
<script src="~/api/signalr/hubs"></script>
|
|
|
|
<!--SignalR script to update the chat page and send messages.-->
|
|
|
|
<!--SignalR script to update the chat page and send messages.-->
|
|
|
|
<script>
|
|
|
|
<script>
|
|
|
|
var pvuis;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var audio = new Audio('/sounds/bell.mp3');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// This optional function html-encodes messages for display in the page.
|
|
|
|
|
|
|
|
function htmlEncode(value) {
|
|
|
|
|
|
|
|
var encodedValue = $('<div />').text(value).html();
|
|
|
|
|
|
|
|
return encodedValue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var setPrivate = function (li) {
|
|
|
|
|
|
|
|
console.log("here I am");
|
|
|
|
</script>
|
|
|
|
$("#sendmessagebox").addClass("hidden");
|
|
|
|
|
|
|
|
$("#sendpvbox").removeClass("hidden");
|
|
|
|
@if (!ViewBag.IsAuthenticated) { // Get the user name and store it to prepend to messages.
|
|
|
|
pvuis = { CXs: $(li).data("cxids"), UserName: $(li).data("name") };
|
|
|
|
<script>
|
|
|
|
$('#sendpvdest').html(pvuis.UserName)
|
|
|
|
$('#displayname').val(prompt('Enter your name:', ''));
|
|
|
|
$('#pv').focus();
|
|
|
|
</script>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var setPublic = function () {
|
|
|
|
|
|
|
|
$("#sendmessagebox").removeClass("hidden");
|
|
|
|
<script>
|
|
|
|
$("#sendpvbox").addClass("hidden");
|
|
|
|
|
|
|
|
$('#message').focus();
|
|
|
|
var pvuis;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var audio = new Audio('/sounds/bell.mp3');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function addULI(uname, cxids)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
$('<li class="user"><img src="/Avatars/' + uname + '.xs.png"> ' + uname + '</li>')
|
|
|
|
|
|
|
|
.data("name", uname)
|
|
|
|
|
|
|
|
.data("cxids", cxids)
|
|
|
|
|
|
|
|
.css('cursor', 'pointer')
|
|
|
|
|
|
|
|
.click(function () { setPrivate(this); })
|
|
|
|
|
|
|
|
.appendTo('#userlist')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$('#pubChan').css('cursor', 'pointer');
|
|
|
|
|
|
|
|
$('#pubChan').click(setPublic);
|
|
|
|
|
|
|
|
setPublic();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var getUsers = function () {
|
|
|
|
function getUsers() {
|
|
|
|
$('#userlist').empty();
|
|
|
|
$('#userlist').empty();
|
|
|
|
$('#to').empty();
|
|
|
|
$('#to').empty();
|
|
|
|
$.get("/api/chat/users").done(
|
|
|
|
$.get("/api/chat/users").done(
|
|
|
|
@ -82,34 +83,46 @@
|
|
|
|
var user = this;
|
|
|
|
var user = this;
|
|
|
|
var existent = $('#userlist li').filterByData("name", user.UserName);
|
|
|
|
var existent = $('#userlist li').filterByData("name", user.UserName);
|
|
|
|
if (existent.length > 0) existent.remove();
|
|
|
|
if (existent.length > 0) existent.remove();
|
|
|
|
var li = $('<li class="user"><img src="/Avatars/' + user.UserName + '.xs.png"> ' + htmlEncode(user.UserName) + '</li>');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var cxids = [];
|
|
|
|
var cxids = [];
|
|
|
|
$.each(user.Connections, function () {
|
|
|
|
$.each(user.Connections, function () {
|
|
|
|
cxids.push(this.ConnectionId);
|
|
|
|
cxids.push(this.ConnectionId);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
$(li).data("name", user.UserName);
|
|
|
|
addULI(user.UserName,cxids)
|
|
|
|
$(li).data("cxids", cxids);
|
|
|
|
|
|
|
|
$(li).css('cursor', 'pointer');
|
|
|
|
|
|
|
|
$(li).click(function () {
|
|
|
|
|
|
|
|
setPrivate(this);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
li.appendTo('#userlist');
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
</script>
|
|
|
|
function onCx() {
|
|
|
|
|
|
|
|
setTimeout(function () {
|
|
|
|
@if (!ViewBag.IsAuthenticated) { // Get the user name and store it to prepend to messages.
|
|
|
|
getUsers();
|
|
|
|
<script>
|
|
|
|
},120),
|
|
|
|
$('#displayname').val(prompt('Enter your name:', ''));
|
|
|
|
$('#targets').removeClass('disabled')
|
|
|
|
</script>
|
|
|
|
};
|
|
|
|
|
|
|
|
function onDisCx () {
|
|
|
|
|
|
|
|
$('#targets').addClass('disabled')
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
// This optional function html-encodes messages for display in the page.
|
|
|
|
|
|
|
|
function htmlEncode(value) {
|
|
|
|
|
|
|
|
var encodedValue = $('<div />').text(value).html();
|
|
|
|
|
|
|
|
return encodedValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
var setPrivate = function (li) {
|
|
|
|
|
|
|
|
$("#sendmessagebox").addClass("hidden");
|
|
|
|
|
|
|
|
$("#sendpvbox").removeClass("hidden");
|
|
|
|
|
|
|
|
pvuis = { CXs: $(li).data("cxids"), UserName: $(li).data("name") };
|
|
|
|
|
|
|
|
$('#sendpvdest').html(pvuis.UserName)
|
|
|
|
|
|
|
|
$('#pv').focus();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var setPublic = function () {
|
|
|
|
|
|
|
|
$("#sendmessagebox").removeClass("hidden");
|
|
|
|
|
|
|
|
$("#sendpvbox").addClass("hidden");
|
|
|
|
|
|
|
|
$('#message').focus();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$('#pubChan').css('cursor', 'pointer');
|
|
|
|
|
|
|
|
$('#pubChan').click(setPublic);
|
|
|
|
|
|
|
|
setPublic();
|
|
|
|
// Reference the auto-generated proxy for the hub.
|
|
|
|
// Reference the auto-generated proxy for the hub.
|
|
|
|
var chat = $.connection.chatHub;
|
|
|
|
var chat = $.connection.chatHub;
|
|
|
|
// Create a function that the hub can call back to display messages.
|
|
|
|
// Create a function that the hub can call back to display messages.
|
|
|
|
@ -149,12 +162,7 @@
|
|
|
|
ids.push(cxid);
|
|
|
|
ids.push(cxid);
|
|
|
|
connected.data("cxids", ids)
|
|
|
|
connected.data("cxids", ids)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
var li = $('<li class="user"><img src="/Avatars/' + username + '.xs.png"> ' + username + '</li>');
|
|
|
|
addULI(username, [cxid])
|
|
|
|
li.data("name", username);
|
|
|
|
|
|
|
|
li.data("cxids", [cxid]);
|
|
|
|
|
|
|
|
li.css('cursor', 'pointer');
|
|
|
|
|
|
|
|
li.click(function () { console.log('no click?'); setPrivate(this); });
|
|
|
|
|
|
|
|
li.appendTo('#userlist');
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
chat.client.notify = function (tag, message, data) {
|
|
|
|
chat.client.notify = function (tag, message, data) {
|
|
|
|
@ -185,13 +193,14 @@
|
|
|
|
$('#message').val('')
|
|
|
|
$('#message').val('')
|
|
|
|
};
|
|
|
|
};
|
|
|
|
var sendPV = function () {
|
|
|
|
var sendPV = function () {
|
|
|
|
|
|
|
|
|
|
|
|
var msg = $('#pv').val();
|
|
|
|
var msg = $('#pv').val();
|
|
|
|
// Call the Send method on the hub.
|
|
|
|
// Call the Send method on the hub.
|
|
|
|
$.each(pvuis.CXs, function () {
|
|
|
|
$.each(pvuis.CXs, function () {
|
|
|
|
chat.server.sendPV(this, msg);
|
|
|
|
chat.server.sendPV(this, msg);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
$('#discussion').append('<li class="pv">' + htmlEncode(pvuis.UserName)
|
|
|
|
$('#discussion').append('<li class="pv">' + htmlEncode(pvuis.UserName)
|
|
|
|
+ '<< ' + htmlEncode(msg) + '</li>');
|
|
|
|
+ '<< ' + htmlEncode(msg) + pvuis.CXs.length +'</li>');
|
|
|
|
// Clear text box and reset focus for next comment.
|
|
|
|
// Clear text box and reset focus for next comment.
|
|
|
|
$('#pv').val('');
|
|
|
|
$('#pv').val('');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -199,6 +208,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
// Start the connection.
|
|
|
|
// Start the connection.
|
|
|
|
$.connection.hub.start().done(function () {
|
|
|
|
$.connection.hub.start().done(function () {
|
|
|
|
|
|
|
|
onCx();
|
|
|
|
|
|
|
|
|
|
|
|
$('#sendmessage').click(function () {
|
|
|
|
$('#sendmessage').click(function () {
|
|
|
|
// Call the Send method on the hub.
|
|
|
|
// Call the Send method on the hub.
|
|
|
|
sendMessage();
|
|
|
|
sendMessage();
|
|
|
|
@ -220,17 +231,13 @@
|
|
|
|
$("#sendpv").focus()
|
|
|
|
$("#sendpv").focus()
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
getUsers();
|
|
|
|
});
|
|
|
|
}).fail(function (e) {console.log(e) });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$("#btnDebug").click(getUsers);
|
|
|
|
|
|
|
|
$.connection.hub.disconnected(function () {
|
|
|
|
$.connection.hub.disconnected(function () {
|
|
|
|
setTimeout(function () {
|
|
|
|
onDisCx();
|
|
|
|
$.connection.hub.start().done(function () {
|
|
|
|
|
|
|
|
$("#mySignalRConnectionIdHidden").val($.connection.hub.id);
|
|
|
|
|
|
|
|
}, 3000); // Re-start connection after 3 seconds
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$(window).unload(function () { chat.server.abort(); delete chat; });
|
|
|
|
</script>
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|