Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <html>
<title>PubNub ChatEngine</title>

<head>
    <link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css"></link>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/3.0.0/handlebars.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/list.js/1.1.1/list.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/chat-engine@0.8.4/dist/chat-engine.min.js" type="text/javascript"></script>
</head>

<body>
    <audio id="audioElement" style="display: none;"></audio>
    <div class="container clearfix">
        <div class="people-list" id="people-list">
            <ul class="list">
            </ul>
        </div>
        <div class="chat">
            <div class="chat-header clearfix">
                <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/195612/chat_avatar_01_green.jpg" alt="avatar" />
                <div class="chat-about">
                    <div class="chat-with">ChatEngine Demo Chat</div>
                </div>
            </div>
            <div class="chat-history">
                <ul></ul>
            </div>
            <form id="sendMessage" class="chat-message clearfix">
                <input type="text" name="message-to-send" id="message-to-send" placeholder="Type your message" rows="1"></input>
                <input type="submit" value="Send"></input>
            </form>
            <!-- end chat-message -->
        </div>
        <!-- end chat -->
    </div>
    <!-- end container -->
    
    <script id="message-template" type="text/x-handlebars-template">
        <li class="clearfix">
            <div class="message-data align-right">
                <span class="message-data-time">{{time}}, Today</span> &nbsp; &nbsp;
                <span class="message-data-name">{{user.first}}</span> <i class="fa fa-circle me"></i>
            </div>
            <div class="message other-message float-right">
                <button class="polly" data-text="{{messageOutput}}" onclick="textToSpeech(this)"></button>
                {{messageOutput}}
            </div>
        </li>
    </script>
    <script id="message-response-template" type="text/x-handlebars-template">
        <li>
            <div class="message-data">
                <span class="message-data-name"><i class="fa fa-circle online"></i> {{user.first}}</span>
                <span class="message-data-time">{{time}}, Today</span>
            </div>
            <div class="message my-message">
                <button class="polly" data-text="{{messageOutput}}" onclick="textToSpeech(this)"></button>
                {{messageOutput}}
            </div>
        </li>
    </script>
    <script id="person-template" type="text/x-handlebars-template">
        {{#if state.full}}
        <li class="clearfix" id="{{uuid}}">
            <img src="{{state.avatar}}" alt="avatar" />
            <div class="about">
                <div class="name">{{state.full}}</div>
                <div class="status">
                    <i class="fa fa-circle online"></i> online
                </div>
            </div>
        </li>
        {{/if}}
    </script>
  
</body>

</html>
              
            
!

CSS

              
                @import url(https://fonts.googleapis.com/css?family=Lato:400,700);

$green: #86BB71;
$blue: #94C2ED;
$orange: #E38968;
$gray: #92959E;

*, *:before, *:after {
  box-sizing: border-box;
}

body {
  background: #C5DDEB;
  font: 14px/20px "Lato", Arial, sans-serif;
  padding: 20px 0;
  color: white;
}

.container {
  margin: 0 auto;
  width: 750px;
  background: #444753;
  border-radius: 5px;
}

.people-list {
  width:260px;
  float: left;
  overflow-y: auto; 
  max-height: 532px;
  .search {
    padding: 20px;
  }
  
  input {
    border-radius: 3px;
    border: none;
    padding: 14px;
    color: white;
    background: #6A6C75;
    width: 90%;
    font-size: 14px;
  }
  
  .fa-search {
    position: relative;
    left: -25px;
  }
  
  ul {
    padding: 20px;
    height: 500px;
 
    
    
    
    li {
      padding-bottom: 20px;
    }
  }
  
  img {
    float: left;
  }
  
  .about {
    float: left;
    margin-top: 8px;
  }
  
  .about {
    padding-left: 8px;
  }
  
  .status {
    color: $gray;
  }
  
}

.chat {
  width: 490px;
  float:left;
  background: #F2F5F8;
  border-top-right-radius: 5px;
  border-bottom-right-radius: 5px;
  
  color: #434651;
  
  .chat-header {
    padding: 20px;
    border-bottom: 2px solid white;
    
    img {
      float: left;
    }
    
    .chat-about {
      float: left;
      padding-left: 10px;
      margin-top: 6px;
    }
    
    .chat-with {
      font-weight: bold;
      font-size: 16px;
    }
    
    .chat-num-messages {
      color: $gray;
    }
    
    .fa-star {
      float: right;
      color: #D8DADF;
      font-size: 20px;
      margin-top: 12px;
    }
  }
  
  .chat-history {
    padding: 30px 30px 20px;
    border-bottom: 2px solid white;
    overflow-y: scroll;
    height: 300px;
    
    .message-data {
      margin-bottom: 15px;
    }
    
    .message-data-time {
      color: lighten($gray, 8%);
      padding-left: 6px;
    }
    
    .message {      
      color: white;
      padding: 8px 10px;
      line-height: 26px;
      font-size: 16px;
      border-radius: 7px;
      margin-bottom: 15px;
      width: 90%;
      position: relative;
      
      &:after {
        bottom: 100%;
        left: 7%;
        border: solid transparent;
        content: " ";
        height: 0;
        width: 0;
        position: absolute;
        pointer-events: none;
        border-bottom-color: $green;
        border-width: 10px;
        margin-left: -10px;
      }
    }
    
    .my-message {
      background: $green;
    }
    
    .other-message {
      background: $blue;
      
      &:after {
        border-bottom-color: $blue;
        left: 93%;
      }
    }
    
  }
  
  .chat-message {
    padding: 30px;
    
    input[type="text"] {
      width: 100%;
      border: none;
      padding: 10px 20px;
      font: 14px/22px "Lato", Arial, sans-serif;
      margin-bottom: 10px;
      border-radius: 5px;
      resize: none;
      background-color: #fff;
    }
    
    .fa-file-o, .fa-file-image-o {
      font-size: 16px;
      color: gray;
      cursor: pointer;
      
    }
    
    input[type="submit"] {
      float: right;
      color: $blue;
      font-size: 16px;
      text-transform: uppercase;
      border: none;
      cursor: pointer;
      font-weight: bold;
      background: #F2F5F8;
      
      &:hover {
        color: darken($blue, 7%);
      }
    }
  }
}

.online, .offline, .me {
    margin-right: 3px;
    font-size: 10px;
  }
  
.online {
  color: $green;
}
  
.offline {
  color: $orange;
}

.me {
  color: $blue;
}

.align-left {
  text-align: left;
}

.align-right {
  text-align: right;
}

.float-right {
  float: right;
}

.clearfix:after {
	visibility: hidden;
	display: block;
	font-size: 0;
	content: " ";
	clear: both;
	height: 0;
}

.chat .chat-history .polly {
  width: 25px;
  height: 25px;
  margin-right: 6px;
  background-color: #FFFFFF;
  border-radius: 50%;
  border: solid 1px #404040;
  vertical-align: top;
  outline: none;
  cursor: pointer;
  background-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNTEuMzggMjQ5LjYiPjxkZWZzPjxzdHlsZT4uY2xzLTF7ZmlsbDpub25lO30uY2xzLTJ7ZmlsbDojMjQyZjNlO30uY2xzLTN7ZmlsbDojZWQ3NDIyO30uY2xzLTR7ZmlsbDojZWQ3NTIzO308L3N0eWxlPjwvZGVmcz48dGl0bGU+QXNzZXQgMTwvdGl0bGU+PGcgaWQ9IkxheWVyXzIiIGRhdGEtbmFtZT0iTGF5ZXIgMiI+PGcgaWQ9IkxheWVyXzEtMiIgZGF0YS1uYW1lPSJMYXllciAxIj48cGF0aCBjbGFzcz0iY2xzLTEiIGQ9Ik0xODcuNDQsMTE4LjgzYy0uOTUsMS45Mi0zLjEsMi4yMi00Ljc3LDMuMTYtMTIuMDksNi44My0xOS4wNiwxNi45Mi0xOS4xNSwzMS0uMDYsOS4xNyw1LjI3LDEzLjI5LDE0LjIyLDExLjc0YTM2LjU0LDM2LjU0LDAsMCwwLDEyLjk1LTVjNS41NS0zLjM3LDUuNzEtMy4zLDksMi41YTMuMzMsMy4zMywwLDAsMCwyLjUzLDJj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DMTg5LjQsMTU4LjIsMTg0LjQ0LDE2MC4yMywxNzkuMTQsMTYxLjY4Wm0yMi4xNy0zLjEyYy02LjYyLTEzLjE3LTE2Ljc5LTE5LjU4LTMwLjk0LTIwLjkzLDQuMTUtNi4zMSw4LjY3LTExLjQxLDE1LjYzLTE0YTUuMzMsNS4zMywwLDAsMSw0LjcxLjI1YzcuMjgsMy44LDExLjYyLDkuNjUsMTIuNDMsMTcuOTNBMzguNjEsMzguNjEsMCwwLDEsMjAxLjMxLDE1OC41NloiLz48L2c+PC9nPjwvc3ZnPg==");
}
              
            
!

JS

              
                // Setup Chat
ChatEngine = ChatEngineCore.create({
    publishKey: 'pub-c-c15809de-713c-4e15-b53d-a37e5af52e6c',
    subscribeKey: 'sub-c-6a9e7a02-32d1-11e8-a385-722195e66eb1'
});

const pollyFunctionURI = "https://pubsub.pubnub.com/v1/blocks/sub-key/sub-c-6a9e7a02-32d1-11e8-a385-722195e66eb1/polly-endpoint";

const source_language = "en";
const target_language = "es";

// use a helper function to generate a new profile
let newPerson = generatePerson(true);

// create a bucket to store our ChatEngine Chat object
let myChat;

// create a bucket to store 
let me;

// compile handlebars templates and store them for use later
let peopleTemplate = Handlebars.compile($("#person-template").html());
let meTemplate = Handlebars.compile($("#message-template").html());
let userTemplate = Handlebars.compile($("#message-response-template").html());

// this is our main function that starts our chat app
const init = () => {
  
  // connect to ChatEngine with our generated user
  ChatEngine.connect(newPerson.uuid, newPerson);

  // when ChatEngine is booted, it returns your new User as `data.me`
  ChatEngine.on('$.ready', function(data) {

      // store my new user as `me`
      me = data.me;

      // create a new ChatEngine Chat
      myChat = new ChatEngine.Chat('chatengine-demo-chat');

      // when we recieve messages in this chat, render them
      myChat.on('message', (message) => {
          renderMessage(message);
      });

      // when a user comes online, render them in the online list
      myChat.on('$.online.*', (data) => {   
        $('#people-list ul').append(peopleTemplate(data.user));
      });

      // when a user goes offline, remove them from the online list
      myChat.on('$.offline.*', (data) => {
        $('#people-list ul').find('#' + data.user.uuid).remove();
      });

      // wait for our chat to be connected to the internet
      myChat.on('$.connected', () => {

          // search for 50 old `message` events
          myChat.search({
            event: 'message',
            limit: 50
          }).on('message', (data) => {
            
            console.log(data)
            
            // when messages are returned, render them like normal messages
            renderMessage(data, true);
            
          });
        
      });

      // bind our "send" button and return key to send message
      $('#sendMessage').on('submit', sendMessage)

  });

};

// send a message to the Chat
const sendMessage = () => {

    // get the message text from the text input
    let message = $('#message-to-send').val().trim();
  
    // if the message isn't empty
    if (message.length) {
      
        // emit the `message` event to everyone in the Chat
        myChat.emit( 'message', {
            text: message,
            translate: {
                text: message,
                source: source_language,
                target: target_language
            }
        } );

        // clear out the text input
        $('#message-to-send').val('');
    }
    
    // stop form submit from bubbling
    return false;
  
};

// render messages in the list
const renderMessage = (message, isHistory = false) => {

    // use the generic user template by default
    let template = userTemplate;

    // if I happened to send the message, use the special template for myself
    if (message.sender.uuid == me.uuid) {
        template = meTemplate;
    }

    let el = template({
        messageOutput: message.data.text,
        time: getCurrentTime(),
        user: message.sender.state
    });
  
    // render the message
    if(isHistory) {
      $('.chat-history ul').prepend(el); 
    } else {
      $('.chat-history ul').append(el); 
    }
  
    // scroll to the bottom of the chat
    scrollToBottom();

};

// scroll to the bottom of the window
const scrollToBottom = () => {
    $('.chat-history').scrollTop($('.chat-history')[0].scrollHeight);
};

// get the current time in a nice format
const getCurrentTime = () => {
    return new Date().toLocaleTimeString().replace(/([\d]+:[\d]{2})(:[\d]{2})(.*)/, "$1$3");
};

function play(audioDataURI){
  console.log(audioDataURI);
  let $audioElement = $('#audioElement');
  $audioElement.attr( 'src', audioDataURI );
  $audioElement.trigger('play');
}

function textToSpeech(e) {
  console.log($(e.target).html());  
  if (e.dataset.voiceAudioContent) {
    return play(e.dataset.voiceAudioContent);
  }

  $.ajax({
    method: "POST",
    url: pollyFunctionURI,
    data: JSON.stringify({
      "data": {
        "text": e.dataset.text,
        "polly": {
          "voice": "Miguel",
          "format": "mp3",
          "location": "text"
        }
      }
    })
  }).done(function(res) {
    e.dataset.voiceAudioContent = 'data:audio/mp3;base64,' + res.polly_sound;
    play(e.dataset.voiceAudioContent);
  });
}

// boot the app
init();
              
            
!
999px

Console