Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Encapsulates

Table of Contents

This module encapsulates code which is responsible for room chat

1. Wrapper function

createChat() code

Encapsulates chat code inside the closure

Code Block
languagejs
themeRDark
const createChat = function(room, messages, input, sendButton) {

2. Local variables

code

Define local variables - sfu constants and colours

Code Block
languagejs
themeRDark
const constants = SFU.constants;
const chatSelfColour = "green";
const chatTextColour = "black";
const chatOtherColour = "red";
const chatEventColour = "navy";

3. Subscribe to room events

code

Subscribe to room events that are related to chat functionality

...

Code Block
languagejs
themeRDark
.on(constants.SFU_ROOM_EVENT.LEFT, function(e) {
    appendMessage({
        nickName: e.name,
        message: e.type
    }, chatOtherColour, chatEventColour);
});

4. Send message to other participants

sendMessage() code

Define the sendMessage function which will be responsible for parsing input, sending it to server and displaying it in the local chat as a message

...

Code Block
languagejs
themeRDark
input.onkeyup = function(e) {
    if (e.keyCode === 13) {
        if (e.shiftKey) {

        } else {
            sendMessage();
        }
        return false;
    }
}

5. Display chat messages locally

Define function that will take care of formatting and displaying messages in local chat

...