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.
-
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
The idea here is similar to that of other note collaboration tools like Google Docs or Notion. With this type of application, you can, together with another person browse the same document and edit it together in real time. Run the application – and go to the next step
Update the app layout
The first thing you need to do is update your app’s layout a bit. If you open public / index.html right now in a code editor, you will see that Tailwind CSS and Twilio Sync are already included in the project. Update the
element to include the Twilio Video library, as shown in the code below:<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link href="https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css" rel="stylesheet">
<script type="text/javascript" src="https://media.twiliocdn.com/sdk/js/sync/v2.0/twilio-sync.min.js"></script>
<script src="https://sdk.twilio.com/js/video/releases/2.15.0/twilio-video.min.js"></script>
<title>Video Collaboration with Notes</title>
</head>
Update the
element. First, add a