|
|
|
@ -1,36 +1,36 @@
|
|
|
|
window.ChatHubHandler = (function ($) {
|
|
|
|
window.ChatHubHandler = (function ($) {
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
# chat control ids
|
|
|
|
# chat control ids
|
|
|
|
|
|
|
|
|
|
|
|
## inputs
|
|
|
|
## inputs
|
|
|
|
|
|
|
|
|
|
|
|
* msg_<rname> : input providing a room message
|
|
|
|
* msg_<rname> : input providing a room message
|
|
|
|
* pv_<uname> : input providing a private message
|
|
|
|
* pv_<uname> : input providing a private message
|
|
|
|
* command : input providing server command
|
|
|
|
* command : input providing server command
|
|
|
|
* roomname : input (hidden or not) providing a room name
|
|
|
|
* roomname : input (hidden or not) providing a room name
|
|
|
|
|
|
|
|
|
|
|
|
## persistent containers
|
|
|
|
## persistent containers
|
|
|
|
|
|
|
|
|
|
|
|
* chatview : the global container
|
|
|
|
* chatview : the global container
|
|
|
|
* rooms : container from room displays
|
|
|
|
* rooms : container from room displays
|
|
|
|
* pvs : container from pv displays
|
|
|
|
* pvs : container from pv displays
|
|
|
|
* server : container for server messages
|
|
|
|
* server : container for server messages
|
|
|
|
|
|
|
|
|
|
|
|
## temporary containers
|
|
|
|
## temporary containers
|
|
|
|
|
|
|
|
|
|
|
|
* room_<rname> : room message list
|
|
|
|
* room_<rname> : room message list
|
|
|
|
* pv_<uname> : private discussion display
|
|
|
|
* pv_<uname> : private discussion display
|
|
|
|
|
|
|
|
|
|
|
|
## css classes
|
|
|
|
## css classes
|
|
|
|
|
|
|
|
|
|
|
|
* form-control
|
|
|
|
* form-control
|
|
|
|
* btn btn-default
|
|
|
|
* btn btn-default
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
$.fn.filterByData = function (prop, val) {
|
|
|
|
$.fn.filterByData = function (prop, val) {
|
|
|
|
return this.filter(function () { return $(this).data(prop) == val; });
|
|
|
|
return this.filter(function () { return $(this).data(prop) == val; });
|
|
|
|
};
|
|
|
|
};
|
|
|
|
var ChatView = function ($view, full) {
|
|
|
|
var ChatView = function ($view, full) {
|
|
|
|
|
|
|
|
|
|
|
|
if (!full) throw new Error('not implemented');
|
|
|
|
if (!full) throw new Error('not implemented');
|
|
|
|
@ -61,24 +61,24 @@ window.ChatHubHandler = (function ($) {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
chat.client.notifyRoom = function (tag, targetid, message) {
|
|
|
|
chat.client.notifyRoom = function (tag, targetid, message) {
|
|
|
|
// Add the notification to the page.
|
|
|
|
// Add the notification to the page.
|
|
|
|
if (tag === 'connected' || tag === 'reconnected') onUserConnected(targetid, message);
|
|
|
|
if (tag === 'connected' || tag === 'reconnected') onUserConnected(targetid, message);
|
|
|
|
else if (tag === 'disconnected') onUserDisconnected(targetid, message);
|
|
|
|
else if (tag === 'disconnected') onUserDisconnected(targetid, message);
|
|
|
|
// eslint-disable-next-line no-warning-comments
|
|
|
|
// eslint-disable-next-line no-warning-comments
|
|
|
|
// TODO reconnected userpart userjoin deniedpv
|
|
|
|
// TODO reconnected userpart userjoin deniedpv
|
|
|
|
$('<li></li>').addClass(tag).append(tag + ': ' + targetid + ' ').append(message).addClass(tag).appendTo($('#room_' + targetid));
|
|
|
|
$('<li></li>').addClass(tag).append(tag + ': ' + targetid + ' ').append(message).addClass(tag).appendTo($('#room_' + targetid));
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
chat.client.notifyUser = function (tag, targetid, message) {
|
|
|
|
chat.client.notifyUser = function (tag, targetid, message) {
|
|
|
|
// Add the notification to the page.
|
|
|
|
// Add the notification to the page.
|
|
|
|
if (tag === 'connected' || tag === 'reconnected') onUserConnected(targetid, message);
|
|
|
|
if (tag === 'connected' || tag === 'reconnected') onUserConnected(targetid, message);
|
|
|
|
else if (tag === 'disconnected') onUserDisconnected(targetid, message);
|
|
|
|
else if (tag === 'disconnected') onUserDisconnected(targetid, message);
|
|
|
|
// eslint-disable-next-line no-warning-comments
|
|
|
|
// eslint-disable-next-line no-warning-comments
|
|
|
|
// TODO reconnected userpart userjoin deniedpv
|
|
|
|
// TODO reconnected userpart userjoin deniedpv
|
|
|
|
$('<li></li>').append(tag + ': ' + targetid).append(message).addClass(tag).appendTo(notifications);
|
|
|
|
$('<li></li>').append(tag + ': ' + targetid).append(message).addClass(tag).appendTo(notifications);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var setActiveRoom = function(room) {
|
|
|
|
var setActiveRoom = function (room) {
|
|
|
|
var frontRoom;
|
|
|
|
var frontRoom;
|
|
|
|
if (frontRoomName !== '') {
|
|
|
|
if (frontRoomName !== '') {
|
|
|
|
frontRoom = $('#vroom_' + frontRoomName);
|
|
|
|
frontRoom = $('#vroom_' + frontRoomName);
|
|
|
|
@ -100,7 +100,7 @@ window.ChatHubHandler = (function ($) {
|
|
|
|
var roomlist = $('<div class="roomlist"></div>');
|
|
|
|
var roomlist = $('<div class="roomlist"></div>');
|
|
|
|
roomlist.appendTo(chatbar);
|
|
|
|
roomlist.appendTo(chatbar);
|
|
|
|
$('<label for="channame">Join :</label>')
|
|
|
|
$('<label for="channame">Join :</label>')
|
|
|
|
.appendTo(roomjoin);
|
|
|
|
.appendTo(roomjoin);
|
|
|
|
var chanName = $('<input id="channame" title="channel name" hint="yavsc" >');
|
|
|
|
var chanName = $('<input id="channame" title="channel name" hint="yavsc" >');
|
|
|
|
chanName.appendTo(roomjoin);
|
|
|
|
chanName.appendTo(roomjoin);
|
|
|
|
roomjoin.appendTo(chatbar);
|
|
|
|
roomjoin.appendTo(chatbar);
|
|
|
|
@ -109,8 +109,8 @@ window.ChatHubHandler = (function ($) {
|
|
|
|
var chatlist = $('<div class="chatlist" ></div>');
|
|
|
|
var chatlist = $('<div class="chatlist" ></div>');
|
|
|
|
chatlist.appendTo($view);
|
|
|
|
chatlist.appendTo($view);
|
|
|
|
var buildRoom = function (room) {
|
|
|
|
var buildRoom = function (room) {
|
|
|
|
var roomTag = $('<a>' + room + '</a>').addClass('btn');
|
|
|
|
var roomTag = $('<a>' + room + '</a>').addClass('btn');
|
|
|
|
roomTag.prop('id', 'sel_' + room).click(function() {
|
|
|
|
roomTag.prop('id', 'sel_' + room).click(function () {
|
|
|
|
setActiveRoom(room);
|
|
|
|
setActiveRoom(room);
|
|
|
|
$(this).removeClass('btn-primary');
|
|
|
|
$(this).removeClass('btn-primary');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
@ -123,41 +123,41 @@ window.ChatHubHandler = (function ($) {
|
|
|
|
msglist.prop('id', 'room_' + room);
|
|
|
|
msglist.prop('id', 'room_' + room);
|
|
|
|
msglist.appendTo(roomview);
|
|
|
|
msglist.appendTo(roomview);
|
|
|
|
$('<input type="text">')
|
|
|
|
$('<input type="text">')
|
|
|
|
.prop('id', 'inp_' + room)
|
|
|
|
.prop('id', 'inp_' + room)
|
|
|
|
.prop('enable', false)
|
|
|
|
.prop('enable', false)
|
|
|
|
.prop('hint', 'hello')
|
|
|
|
.prop('hint', 'hello')
|
|
|
|
.prop('title', 'send to ' + room)
|
|
|
|
.prop('title', 'send to ' + room)
|
|
|
|
.addClass('form-control')
|
|
|
|
.addClass('form-control')
|
|
|
|
.keydown(function(ev) {
|
|
|
|
.keydown(function (ev) {
|
|
|
|
if (ev.which == 13) {
|
|
|
|
if (ev.which == 13) {
|
|
|
|
if (this.value.length == 0) return;
|
|
|
|
if (this.value.length == 0) return;
|
|
|
|
chat.server.send(room, this.value);
|
|
|
|
chat.server.send(room, this.value);
|
|
|
|
this.value = '';
|
|
|
|
this.value = '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}).appendTo(roomview);
|
|
|
|
}).appendTo(roomview);
|
|
|
|
chans.push(room);
|
|
|
|
chans.push(room);
|
|
|
|
setActiveRoom(room);
|
|
|
|
setActiveRoom(room);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
$view.data('chans').split(',').forEach(function(chan) {
|
|
|
|
$view.data('chans').split(',').forEach(function (chan) {
|
|
|
|
buildRoom(chan);
|
|
|
|
buildRoom(chan);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
function onCx () {
|
|
|
|
function onCx() {
|
|
|
|
setTimeout(function () {
|
|
|
|
setTimeout(function () {
|
|
|
|
getUsers();
|
|
|
|
getUsers();
|
|
|
|
}, 120);
|
|
|
|
}, 120);
|
|
|
|
|
|
|
|
|
|
|
|
$('#chatview').removeClass('disabled');
|
|
|
|
$('#chatview').removeClass('disabled');
|
|
|
|
|
|
|
|
|
|
|
|
chans.forEach(function(room) {
|
|
|
|
chans.forEach(function (room) {
|
|
|
|
chat.server.join(room).done(function(chatInfo) {
|
|
|
|
chat.server.join(room).done(function (chatInfo) {
|
|
|
|
setActiveRoom(chatInfo.Name);
|
|
|
|
setActiveRoom(chatInfo.Name);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function onDisCx () {
|
|
|
|
function onDisCx() {
|
|
|
|
$('#chatview').addClass('disabled');
|
|
|
|
$('#chatview').addClass('disabled');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -181,12 +181,12 @@ window.ChatHubHandler = (function ($) {
|
|
|
|
if (event.which == 13) {
|
|
|
|
if (event.which == 13) {
|
|
|
|
if (this.value.length == 0) return;
|
|
|
|
if (this.value.length == 0) return;
|
|
|
|
buildRoom(this.value);
|
|
|
|
buildRoom(this.value);
|
|
|
|
chat.server.join(this.value).done(function(chatInfo) {
|
|
|
|
chat.server.join(this.value).done(function (chatInfo) {
|
|
|
|
setActiveRoom(chatInfo.Name);
|
|
|
|
setActiveRoom(chatInfo.Name);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
this.value = '';
|
|
|
|
this.value = '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// else TODO showRoomInfo(this.value);
|
|
|
|
// else TODO showRoomInfo(this.value);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
var pvuis;
|
|
|
|
var pvuis;
|
|
|
|
@ -232,15 +232,15 @@ window.ChatHubHandler = (function ($) {
|
|
|
|
|
|
|
|
|
|
|
|
var getUsers = function () {
|
|
|
|
var getUsers = function () {
|
|
|
|
$.get('/api/chat/users').done(function (users) {
|
|
|
|
$.get('/api/chat/users').done(function (users) {
|
|
|
|
$.each(users, function () {
|
|
|
|
$.each(users, function () {
|
|
|
|
var user = this;
|
|
|
|
var user = this;
|
|
|
|
addChatUser(user.UserName);
|
|
|
|
addChatUser(user.UserName);
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// This optional function html-encodes messages for display in the page.
|
|
|
|
// This optional function html-encodes messages for display in the page.
|
|
|
|
function htmlEncode (value) {
|
|
|
|
function htmlEncode(value) {
|
|
|
|
var encodedValue = $('<div />').text(value).html();
|
|
|
|
var encodedValue = $('<div />').text(value).html();
|
|
|
|
return encodedValue;
|
|
|
|
return encodedValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -268,14 +268,14 @@ window.ChatHubHandler = (function ($) {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var onUserConnected = function (username) {
|
|
|
|
var onUserConnected = function (username) {
|
|
|
|
addChatUser(username);
|
|
|
|
addChatUser(username);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
$(window).unload(function () { chat.server.abort(); });
|
|
|
|
$(window).unload(function () { chat.server.abort(); });
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
$(document).ready(function($) {
|
|
|
|
$(document).ready(function ($) {
|
|
|
|
ChatView($('#chatview'), true);
|
|
|
|
ChatView($('#chatview'), true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|