Socket.IO不发光

时间:2019-02-19 16:00:32

标签: socket.io

我正在尝试学习有关套接字的一些知识,但我有一个问题。

user.js(客户端)

    $('#send-message').click(function () { 

    socket.emit('add user', {
        isAdmin: false,
        roomID: socket.id
    });
    sendMessage();
    });

server.js(服务器端)

socket.on('add user', function (data) { 

    socket.isAdmin = data.isAdmin;
    socket.roomID = data.roomID;
    if(users.indexOf(socket.roomID) == -1){
        socket.join(socket.roomID);
        users.push(socket.roomID);
        socket.emit('new client', {
            roomID: data.roomID
        })
    }
    console.log('Users: ' + users.length);
 })

admin.js(客户端)

socket.on('new client', function (data) { 
    console.log(data);
    $('#container').append("<div id = 'chat-box'> <div id = 'ChatBoxID'></div> <div id  = 'messages-container'></div><input id = 'user-message' type = 'text' class = '" + data.roomID + "'/><button id = 'send-message'>Send</button></div>");
    $inputMessage = $('.' + data.roomID);
    let $parent = $inputMessage.parent();
    let $chatHeader = $parent.children('#ChatBoxID');
    let chatID =  'ChatID  #' + data.roomID;
    $($chatHeader).append(chatID);
});

我的问题是:为什么我按下#send-message按钮后什么都没发生?

0 个答案:

没有答案