MenuMenu

RTCMultiConnection.onmessage

Use this event to receive chat messages, or any kind of non-File data

Usage

connection.onmessage = function(event) {
    var sender = event.userid;
    var senderFullName = event.extra.fullName;

    var div = document.createElement('div');
    div.innerHTML = event.data;
    document.body.insertBefore(div, document.body.firstChild);
};

Description

parameterdescription
data text chat message or any kind of javascript data except "Blob" and "File"
connection.onmessage = function(event) {
    var chatMesssge = event.data;
};
userid the person who sent chat message
connection.onmessage = function(event) {
    var sender = event.userid;
};
extra extra information along with chat message
connection.onmessage = function(event) {
    var senderFullName = event.extra.fullName;
    var senderEmail = event.extra.email;
    var senderPhoto = event.extra.photo;
    var sentAt = event.extra.sentAt; // date-time in ISO format
};

Demo

<script src="https://rtcmulticonnection.herokuapp.com/dist/RTCMultiConnection.min.js"></script>
<script src="https://rtcmulticonnection.herokuapp.com/socket.io/socket.io.js"></script>

<script>
var connection = new RTCMultiConnection();

// this line is VERY_important
connection.socketURL = 'https://rtcmulticonnection.herokuapp.com:443/';

// if you want text chat
connection.session = {
    data: true
};

connection.onopen = function(event) {
    connection.send('hello everyone');
};

connection.onmessage = function(event) {
    alert(event.userid + ' said: ' + event.data);
};

connection.openOrJoin('your-room-id');
</script>