点击列表中用户的姓名,不会将人员姓名添加到div

时间:2017-04-24 11:56:04

标签: javascript jquery node.js sockets

我已经构建了一个基本的套接字聊天程序。当人们登录时,他们的名字会被添加到在线用户列表中(左侧)。当用户单击其他在线用户之一时,该名称应附加到顶部的div。但正如你所看到的那样:

  

div class =" well"> null(图片右上方区域)。

似乎服务器没有捕获列表中人员的姓名。 我错过了什么?

这是聊天内容的图像 enter image description here

客户端:

var people = {};
socket.on("connection", function(client) {
client.on("join", function(name){
    console.log("Someone joined the chat", name);
    roomID = null;
    people[client.id] = {"name" : name, "room" : roomID};
    sizePeople = _.size(people);
    sizeRooms = _.size(rooms);
    socket.sockets.emit("update-peopleCount", {people: people, count: sizePeople});
    socket.sockets.emit("update-people", {people: people});
    socket.sockets.emit("roomList", {rooms: rooms, count: sizeRooms});
    client.emit("updateToSelf", "You have connected to the server. Join or create room to chat");
    client.broadcast.emit('updateToOthers', name + " is online.");
    clients.push(client); //populate the clients array with the client object
});
    client.on("whispering", function(id) {
    var person = people[id];
    client.emit("addWhispering", person);

    console.log("Whisper caught");
});

服务器端:

public String getSDCARDiD()
{
    String sd_cid = null;
    try {

        File file = new File("/sys/block/mmcblk1");
        String memBlk;
        if (file.exists() && file.isDirectory()) {

            memBlk = "mmcblk1";
        } else {
            //System.out.println("not a directory");
            memBlk = "mmcblk0";
        }

        Process cmd = Runtime.getRuntime().exec("cat /sys/block/"+memBlk+"/device/cid");
        BufferedReader br = new BufferedReader(new InputStreamReader(cmd.getInputStream()));
        sd_cid = br.readLine();
        //System.out.println(sd_cid);

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return sd_cid;
}

0 个答案:

没有答案