增加用户地址信息

master
“zhenQin” 8 years ago
parent d2ec150fad
commit 90c80f70d5

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.3 KiB

@ -11,9 +11,9 @@ HiChat.prototype = {
var _pic=document.body.querySelectorAll("#nickWrapper .img-list li.checked img")[0].src; var _pic=document.body.querySelectorAll("#nickWrapper .img-list li.checked img")[0].src;
var curUser={ var curUser={
nickName:"我", nickName:"我",
pic:_pic pic:_pic,
address:""
} }
console.log(curUser);
this.socket = io.connect(); this.socket = io.connect();
this.socket.on('connect', function() { this.socket.on('connect', function() {
document.getElementById('info').textContent = '请输入一个昵称:'; document.getElementById('info').textContent = '请输入一个昵称:';
@ -43,12 +43,11 @@ HiChat.prototype = {
var listDiv=document.getElementById("online-list"); var listDiv=document.getElementById("online-list");
var str=""; var str="";
for (var i=0;i<users.length;i++){ for (var i=0;i<users.length;i++){
str+="<li class='user-span'><img src='"+users[i].pic+"'><div>"+users[i].nickName+"</div></li>"; str+="<li class='user-span' title='"+users[i].address+"'><img src='"+users[i].pic+"'><div>"+users[i].nickName+"</div></li>";
} }
listDiv.innerHTML=str; listDiv.innerHTML=str;
}); });
this.socket.on('newMsg', function(user, msg, color) { this.socket.on('newMsg', function(user, msg, color) {
console.log(user);
that._displayMsg(user, msg, color,"msg"); that._displayMsg(user, msg, color,"msg");
}); });
this.socket.on('newImg', function(user, img, color) { this.socket.on('newImg', function(user, img, color) {

@ -14,6 +14,8 @@ io.sockets.on('connection', function(socket) {
if (isHave(user)) { if (isHave(user)) {
socket.emit('nickExisted'); socket.emit('nickExisted');
} else { } else {
var address=socket.handshake.address.address+":"+socket.handshake.address.port;
user.address=address;
socket.userIndex = users.length; socket.userIndex = users.length;
socket.user = user; socket.user = user;
users.push(user); users.push(user);

Loading…
Cancel
Save