andrerpena / chatjs

Platform-independent jQuery plugin for chatting
MIT License
184 stars 91 forks source link

Cannot create received message with socket.io #14

Open gusreyes01 opened 9 years ago

gusreyes01 commented 9 years ago

What I'm trying to achieve is to receive a message sent by a user in another window, however the response is printed multiple times.

Its seems to me like the 'DemoServerAdapter.prototype.sendMessage' function is called x times as messages already sent.

               socket.on('chat_receive', function(message) {
                console.log(message);
                var echoMessage = new ChatMessageInfo();
                echoMessage.UserFromId = message.send_user_id; // It will be from Echobot
                echoMessage.RoomId = roomId;
                echoMessage.ConversationId = conversationId;
                echoMessage.Message = "The other: " + message.message;

                // if it's not a private message, the echo message will be to the current user
                if (!roomId && !conversationId)
                    echoMessage.UserToId = current_user_id;  // Id del usuario actual

                // this will send a message to the user 1 (you) as if it was from user 2 (Echobot)
                _this.clientAdapter.triggerMessagesChanged(echoMessage);
                 });

Example:

image