Instant Messaging issue

55 views
Skip to first unread message

Marcus Hellner

unread,
May 28, 2014, 6:27:05 AM5/28/14
to eas...@googlegroups.com

Hello,

i have got an issue with the insatnt messaging. I have merged video chat and text chat on one site.
So if 2 participants are in a chat and sending text messages, a third one which is in another room can see the messages which are sent.

attached you find my main.js

function connect() {
    easyrtc.setSocketUrl(":8010");
    easyrtc.enableDebug(true);
    easyrtc.enableAudio(true);
    easyrtc.enableVideo(true);
    joinRoom();
    easyrtc.setRoomOccupantListener(loggedInListener);
    easyrtc.setPeerListener(addToConversation);
    easyrtc.easyApp("AudioVideoChat", "self", ["caller"],
            function(myId) {
                //console.log("My easyrtcid is " + myId + " and Username: " + benutzername);
            }
    );
}


function loggedInListener(roomName, otherClients, myInfo) {
    var easyrtcid_Owner = myInfo.easyrtcid; // tmp
    var roomJoinTime_Owner = myInfo.roomJoinTime; // tmp

    var iamOwner = true;
    var aClient;
    var selfVideo = document.getElementById("self");
    var callerVideo = document.getElementById("caller");

    for (aClient in otherClients) {
        if (aClient === otherClients[0]) {
            easyrtc.setUsername("Kunde");
        } else {
            easyrtc.setUsername("Agent");
        }
        if (myInfo.roomJoinTime > otherClients[aClient].roomJoinTime) {           
            iamOwner = false;
        }
        document.getElementById("sendMessageText").onkeydown = function(event) {
            if (event.keyCode === 13) {
                sendStuffWS(aClient); // Message senden
            }
            ;
        };
    }

    if (iamOwner === true) {
        selfVideo.style.display = "block";
        callerVideo.style.display = "block";
    }
    else
    {
        selfVideo.style.display = "block";
        callerVideo.style.display = "block";

        for (aClient in otherClients) {
            if (roomJoinTime_Owner > otherClients[aClient].roomJoinTime) {
                roomJoinTime_Owner = otherClients[aClient].roomJoinTime;
                easyrtcid_Owner = otherClients[aClient].easyrtcid;
            }
        }

        performCall(easyrtcid_Owner);
    }
}



function addToConversation(otherEasyrtcid, msgType, content) {
    // Escape html special characters, then add linefeeds.
    content = content.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
    content = content.replace(/\n/g, '<br />');
    var newText = document.createElement("div");
    newText.innerHTML = "<b>" + easyrtc.idToName(otherEasyrtcid) + ":</b>&nbsp;" + links(content) + "<br />";
    document.getElementById("conversation").appendChild(newText);
    newText.scrollIntoView();
    //document.getElementById('conversation').innerHTML +="<b>" + easyrtc.idToName(otherEasyrtcid) + ":</b>&nbsp;" + links(content) + "<br />";
}

function sendStuffWS(otherEasyrtcid) {
    var text = document.getElementById('sendMessageText').value;
    if (text.replace(/\s/g, "").length === 0) { // Don't send just whitespace
        return;
    }

    easyrtc.sendDataWS(otherEasyrtcid, "message", text);
    addToConversation(easyrtc.idToName(easyrtc.myEasyrtcid), "message", text);
    document.getElementById('sendMessageText').value = "";
}

Eric Davies

unread,
May 29, 2014, 4:31:39 PM5/29/14
to eas...@googlegroups.com
If we understand the problem correctly,

Each of your clients is a member of two rooms, the room they intentionally joined after connecting, and the default room.
Your loggedInListener is firing twice, one for each room.
You can either check the roomName passed to loggedInListener or you can joiin the room before connecting (which will prevent you from joining the default room).

Eric.
Reply all
Reply to author
Forward
0 new messages