JavaScript

Sending a Signal

Now that you have connected to the session and have a session object, you can now send a Signal. Signals are arbitrary text or data that are sent in a session which can be sent to a specific client or all connected clients. You can learn more about them in the Vonage Video Signaling developer guide. For this tutorial you will be sending text.

  1. Copy the following code and paste it below the existing code in your app.js file after the initializeSession() function:
const form = document.querySelector('form');
const msgTxt = document.querySelector('#msgTxt');

// Send a signal once the user enters data in the form
form.addEventListener('submit', (event) => {
  event.preventDefault();

  session.signal({
    type: 'msg',
    data: msgTxt.value
  }, (error) => {
    if (error) {
      handleError(error);
    } else {
      msgTxt.value = '';
    }
  });
});

This code creates variables to reference the form and it's containing text from the earlier html page. Once the form is submitted, session.signal is called to send the text as a Signal. session.signal takes the type of Signal and some data. The type is optional but can be used to differentiate between types of Signals in your app.

If the Signal sends successfully the form is cleared, if not the error is handled using the same handleError function from earlier.

Basic text chat

Follow this tutorial to build basic text chat from scratch using the Vonage Video API. It is the quickest way to build a proof of concept for this functionality on the video platform.

Steps
1
Overview
2
Before You Begin
3
Configure a Vonage Video Application
4
Creating the Project Folders and HTML Template
5
Setting Up Authentication
6
Connecting to the Session
7
Sending a Signal
8
Receiving a Signal
9
Testing your Code in a Browser
10
A little bit of CSS customization
11
Conclusion