Video chat with co-editing capabilities using Twilio Sync

Imagine that you need to create a video chat, the functionality of which should be under your control, for example, for a closed group of people with their own specific requirements. At the same time, the chat is needed yesterday, it’s too late to start writing it from scratch. In this material, the translation of which we decided to share by the start of the course about Frontend development, describes how to develop a programmable video chat based on Twilio. In this article, you will find two branches of code on Github, the first contains the basic chat framework, which will be discussed in the article, and the second contains a complete chat example.


Preparation

What you will need:

  • Free Twilio account. If you sign up here, you will receive $ 10 in Twilio Credits when you upgrade to a paid account.

  • Node.js (version 14.16.1 or higher) and npm

  • Code from of this repository.

Download and run the video notebook code

To download the code, select the location on your computer where you want to work with the project. Then open a terminal window and run the following command to clone the branch start:

git clone -b start https://github.com/adjeim/video-note-collab.git

Then go to your project root and install the required dependencies by running the following commands:

cd video-note-collab
npm install

Copy the .env file for environment variables with this command:

cp .env.template .env 

Then open the .env file in a code editor and replace the variable values ​​with your credentials:

TWILIO_ACCOUNT_SID
TWILIO_SYNC_SERVICE_SID
TWILIO_API_KEY_SID
TWILIO_API_KEY_SECRET

You can find your credentials in the Twilio console, the Twilio Sync Service page, and the Twilio API Keys page. The default SID can be used as the value for the TWILIO_SYNC_SERVICE_SID variable. Now that you’ve entered your credentials, start the Express server:

npm start

If you go to http: // localhost: 3000 / in your browser, you will see a note:

Test the app by typing a few words in notepad. When you enter a space, enter key, or punctuation marks, sync starts. If you open a second browser window at http: // localhost: 3000 / and look at them at the same time, you should see that the text you enter in one window is displayed in the other:

How does this happen? This application uses Twilio Sync to sync state and data between browsers and devices in real time. Here you have a Sync document called notepad. When the page loads, a new access token is generated and passed to the Sync client. If the document exists, its content is loaded into