Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
beyondfengyu committed Jan 15, 2017
0 parents commit f7d33fa
Show file tree
Hide file tree
Showing 106 changed files with 2,805 additions and 0 deletions.
20 changes: 20 additions & 0 deletions HappyChat.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: com.alibaba:fastjson:1.2.23" level="project" />
<orderEntry type="library" name="Maven: io.netty:netty-all:4.1.6.Final" level="project" />
<orderEntry type="library" name="Maven: ch.qos.logback:logback-classic:1.1.7" level="project" />
<orderEntry type="library" name="Maven: ch.qos.logback:logback-core:1.1.7" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.20" level="project" />
</component>
</module>
Binary file added docs/arclist/1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/arclist/10.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/arclist/11.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/arclist/12.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/arclist/13.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/arclist/14.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/arclist/15.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/arclist/16.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/arclist/17.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/arclist/18.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/arclist/19.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/arclist/2.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/arclist/20.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/arclist/21.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/arclist/22.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/arclist/23.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/arclist/24.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/arclist/25.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/arclist/26.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/arclist/27.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/arclist/28.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/arclist/29.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/arclist/3.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/arclist/30.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/arclist/31.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/arclist/32.gif
Binary file added docs/arclist/33.gif
Binary file added docs/arclist/34.gif
Binary file added docs/arclist/35.gif
Binary file added docs/arclist/36.gif
Binary file added docs/arclist/37.gif
Binary file added docs/arclist/38.gif
Binary file added docs/arclist/39.gif
Binary file added docs/arclist/4.gif
Binary file added docs/arclist/40.gif
Binary file added docs/arclist/41.gif
Binary file added docs/arclist/42.gif
Binary file added docs/arclist/43.gif
Binary file added docs/arclist/44.gif
Binary file added docs/arclist/45.gif
Binary file added docs/arclist/46.gif
Binary file added docs/arclist/47.gif
Binary file added docs/arclist/48.gif
Binary file added docs/arclist/49.gif
Binary file added docs/arclist/5.gif
Binary file added docs/arclist/50.gif
Binary file added docs/arclist/51.gif
Binary file added docs/arclist/52.gif
Binary file added docs/arclist/53.gif
Binary file added docs/arclist/54.gif
Binary file added docs/arclist/55.gif
Binary file added docs/arclist/56.gif
Binary file added docs/arclist/57.gif
Binary file added docs/arclist/58.gif
Binary file added docs/arclist/59.gif
Binary file added docs/arclist/6.gif
Binary file added docs/arclist/60.gif
Binary file added docs/arclist/61.gif
Binary file added docs/arclist/62.gif
Binary file added docs/arclist/63.gif
Binary file added docs/arclist/64.gif
Binary file added docs/arclist/65.gif
Binary file added docs/arclist/66.gif
Binary file added docs/arclist/67.gif
Binary file added docs/arclist/68.gif
Binary file added docs/arclist/69.gif
Binary file added docs/arclist/7.gif
Binary file added docs/arclist/70.gif
Binary file added docs/arclist/71.gif
Binary file added docs/arclist/72.gif
Binary file added docs/arclist/73.gif
Binary file added docs/arclist/74.gif
Binary file added docs/arclist/75.gif
Binary file added docs/arclist/8.gif
Binary file added docs/arclist/9.gif
874 changes: 874 additions & 0 deletions docs/bootstrap/css/bootstrap.min.css

Large diffs are not rendered by default.

31 changes: 31 additions & 0 deletions docs/bootstrap/css/chat.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
.qqFace{margin-top:4px;background:#fff;padding:2px;border:1px #dfe6f6 solid;}
.qqFace table td{padding:0px;}
.qqFace table td img{cursor:pointer;border:1px #fff solid;}
.qqFace table td img:hover{border:1px #0066cc solid;}
.top{
padding:10px 0;
background:transparent;
background-color:rgba(0,0,0,0.4);
}
#userCount{
margin:0 2px;
font-weight:bolder;
font-size:16px;
}
#content{
width:100%;
height:100%;
padding:10px 15px;
font-size:16px;
overflow: auto;
}
.title{
padding: 4px 0 0;
color: #1259d2;
font-weight:bold;
}
.item{
font-family: "Microsoft YaHei UI";
padding:4px 4px 0;

}
7 changes: 7 additions & 0 deletions docs/bootstrap/css/reset.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
288 changes: 288 additions & 0 deletions docs/bootstrap/fonts/glyphicons-halflings-regular.svg

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
7 changes: 7 additions & 0 deletions docs/bootstrap/js/bootstrap.min.js

Large diffs are not rendered by default.

195 changes: 195 additions & 0 deletions docs/bootstrap/js/chat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
/**
* Created by yu on 2017/1/15.
*/
var socket = null;
var isAuth = false;
var userNick = null;
var userCount = 0;
$(function () {
$("#menuModal").modal('show');
var height = $(window).height();
$('#content').css("height", height - $('#top').height() - $('#opt').height() - 40);

$('#loginBtn').click(function(){
userLogin();
});

$('#faceBtn').qqFace({
id: 'facebox',
assign: 'mess',
path: 'arclist/' //表情存放的路径
});

$('#sendBtn').click(function () {
var mess = $("#mess").val().trim();
if(mess){
sendMess(mess);
$("#mess").val('');
}
}).keyup(function(e){
var keyCode = e.which || e.keyCode;
if(keyCode==13){
$("#sendBtn").click();
}
});
});

function sendMess(mess) {
send(true, "{'code':10086,'mess':'"+mess+"'}");
}
;


function userLogin() {
if (!userNick) {
userNick = $('#nick').val().trim();
}
if (userNick) {
if (!window.WebSocket) {
window.WebSocket = window.MozWebSocket;
}
if (window.WebSocket) {
window.socket = new WebSocket("ws://chat.wolfbe.com:9688/websocket");
window.socket.onmessage = function (event) {
var data = eval("(" + event.data + ")");
console.log("onmessage data: " + JSON.stringify(data));
switch (data.uri) {
case 1 << 8 | 220: // ping message
case 2 << 8 | 220: // pong message
console.log("ping message: " + JSON.stringify(data));
pingInvake(data);
break;
case 3 << 8 | 220: // system message
console.log("system message: " + JSON.stringify(data));
sysInvake(data);
break;
case 4 << 8 | 220: // error message
console.log("error message: " + JSON.stringify(data));
closeInvake(null);
break;
case 5 << 8 | 220: // auth message
console.log("auth message: " + JSON.stringify(data));
break;
case 6 << 8 | 220: // broadcast message
console.log("broadcast message: " + JSON.stringify(data));
broadcastInvake(data);
break;

}
};
window.socket.onclose = function (event) {
console.log("connection close!!!");
closeInvake(event);
};
window.socket.onopen = function (event) {
console.log("connection success!!");
openInvake(event);
};
} else {
alert("您的浏览器不支持WebSocket!!!");
}
} else {
$('#tipMsg').text("请输入昵称");
$('#tipModal').modal('show');
}
}

function send(auth, mess) {
if (!window.socket) {
return;
}
if (socket.readyState == WebSocket.OPEN || auth) {
console.log("send: " + mess);
window.socket.send(mess);
} else {
$('#tipMsg').text("连接没有成功,请重新登录");
$('#tipModal').modal('show');
}
}
;

function openInvake(event) {
var obj = {};
obj.code = 10000;
obj.nick = $('#nick').val().trim();
send(true, JSON.stringify(obj));
}
;


function closeInvake(event) {
window.socket = null;
window.isAuth = false;
window.userCount = 0;
$('#tipMsg').text("登录失败,网络连接异常");
$('#tipModal').modal('show');
}
;

/**
* 处理系统消息
* @param data
*/
function sysInvake(data) {
switch (data.extend.code) {
case 20001: // user count
console.log("current user: " + data.extend.mess);
userCount = data.extend.mess;
$('#userCount').text(userCount);
break;
case 20002: // auth
console.log("auth result: " + data.extend.mess);
isAuth = data.extend.mess;
if (isAuth) {
$("#menuModal").modal('hide');
$('#chatWin').show();
$('#content').append('欢迎来到嗨皮聊天室!!');
// $('#content').scrollTop($('#content')[0].scrollHeight);
}
break;
case 20003: // system message
console.log("system message: " + data.extend.mess);
break;
}
}
;

/**
* 处理广播消息
* @param data
*/
function broadcastInvake(data) {
var mess = data.body;
var nick = data.extend.nick;
var uid = data.extend.uid;
var time = data.extend.time;
mess = replace_em(mess);
var html = '<div class="title">'+nick+'&nbsp;('+uid+') &nbsp;'+time+'</div><div class="item">'+mess+'</div>';
$("#content").append(html);
$('#content').scrollTop($('#content')[0].scrollHeight);

}
;

function erorInvake(data) {

}
;

/**
* 处理ping消息
* @param data
*/
function pingInvake(data) {
//发送pong消息响应
send(isAuth, "{'code':10016}");
}
;
//查看结果
function replace_em(str) {
str = str.replace(/\</g, '&lt;');
str = str.replace(/\>/g, '&gt;');
str = str.replace(/\n/g, '<br/>');
str = str.replace(/\[em_([0-9]*)\]/g, '<img src="arclist/$1.gif" border="0" />');
return str;
};
4 changes: 4 additions & 0 deletions docs/bootstrap/js/jQuery-2.2.0.min.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions docs/bootstrap/js/jquery.min.js

Large diffs are not rendered by default.

106 changes: 106 additions & 0 deletions docs/bootstrap/js/jquery.qqFace.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// QQ表情插件
(function($){
$.fn.qqFace = function(options){
var defaults = {
id : 'facebox',
path : 'face/',
assign : 'content',
tip : 'em_'
};
var option = $.extend(defaults, options);
var assign = $('#'+option.assign);
var id = option.id;
var path = option.path;
var tip = option.tip;

if(assign.length<=0){
alert('缺少表情赋值对象。');
return false;
}

$(this).click(function(e){
var strFace, labFace;
if($('#'+id).length<=0){
strFace = '<div id="'+id+'" style="position:fixed;display:none;z-index:1000;" class="qqFace">' +
'<table border="0" cellspacing="0" cellpadding="0"><tr>';
for(var i=1; i<=75; i++){
labFace = '['+tip+i+']';
strFace += '<td><img src="'+path+i+'.gif" onclick="$(\'#'+option.assign+'\').setCaret();$(\'#'+option.assign+'\').insertAtCaret(\'' + labFace + '\');" /></td>';
if( i % 15 == 0 ) strFace += '</tr><tr>';
}
strFace += '</tr></table></div>';
}
$(this).parent().append(strFace);
var offset = $(this).position();
var top = offset.top + $(this).outerHeight();
$('#'+id).css('bottom',top + 10);
$('#'+id).css('left',offset.left);
$('#'+id).show();
e.stopPropagation();
});

$(document).click(function(){
$('#'+id).hide();
$('#'+id).remove();
});
};

})(jQuery);

jQuery.extend({
unselectContents: function(){
if(window.getSelection)
window.getSelection().removeAllRanges();
else if(document.selection)
document.selection.empty();
}
});
jQuery.fn.extend({
selectContents: function(){
$(this).each(function(i){
var node = this;
var selection, range, doc, win;
if ((doc = node.ownerDocument) && (win = doc.defaultView) && typeof win.getSelection != 'undefined' && typeof doc.createRange != 'undefined' && (selection = window.getSelection()) && typeof selection.removeAllRanges != 'undefined'){
range = doc.createRange();
range.selectNode(node);
if(i == 0){
selection.removeAllRanges();
}
selection.addRange(range);
} else if (document.body && typeof document.body.createTextRange != 'undefined' && (range = document.body.createTextRange())){
range.moveToElementText(node);
range.select();
}
});
},

setCaret: function(){
if(!$.browser.msie) return;
var initSetCaret = function(){
var textObj = $(this).get(0);
textObj.caretPos = document.selection.createRange().duplicate();
};
$(this).click(initSetCaret).select(initSetCaret).keyup(initSetCaret);
},

insertAtCaret: function(textFeildValue){
var textObj = $(this).get(0);
if(document.all && textObj.createTextRange && textObj.caretPos){
var caretPos=textObj.caretPos;
caretPos.text = caretPos.text.charAt(caretPos.text.length-1) == '' ?
textFeildValue+'' : textFeildValue;
} else if(textObj.setSelectionRange){
var rangeStart=textObj.selectionStart;
var rangeEnd=textObj.selectionEnd;
var tempStr1=textObj.value.substring(0,rangeStart);
var tempStr2=textObj.value.substring(rangeEnd);
textObj.value=tempStr1+textFeildValue+tempStr2;
textObj.focus();
var len=textFeildValue.length;
textObj.setSelectionRange(rangeStart+len,rangeStart+len);
textObj.blur();
}else{
textObj.value+=textFeildValue;
}
}
});
Loading

0 comments on commit f7d33fa

Please sign in to comment.