Aws Video Chat

 

Live Chat Amazon Interactive Video Service (Amazon IVS) is a managed live streaming solution that is quick and easy to set up, and ideal for creating interactive video experiences. Danilo Poccia (@danilop), Principal Evangelist Serverless, AWS will dive deep into how to use WebSockets with the API Gateway, providing as an example a rea. In our final part, we want to add a new AWS Service called Kinesis Video Stream to the application. Brief Explanation Kinesis Video Streams Kinesis Video Streams also supports WebRTC, an open-source project that enables real-time media streaming and interaction between web browsers, mobile applications, and connected devices via simple APIs.

One of the most common questions from our customers about vidyo.io is how to record video conference calls. The answer is simple: Record with the media bridge. In this article I’ll walk you through deploying and using the media bridge.

If you haven’t heard of Docker, check out “What Is Docker?” and “Building Applications with Dockerfiles.” In a nutshell, Docker is a container platform that allows developers to package an application and deploy it identically across multiple platforms or even cloud services such as Amazon AWS. No more “But it works on my machine!” problems. Docker lets the developer package the application along with everything it needs, like libraries, scripts, environment variables, and all its dependencies together in one stand-alone container. This guarantees the correct running environment for each deployment.The vidyo.io media bridge is a Docker image that is deployed with ease on your application’s server.

Using the media bridge, you’ll be able to:

The chat application consists of a “chat-app” feature module that’s composed of several components. Each component interacts with the module’s simple Angular service that provides access to the AWS AppSync client. Messages are sent in the format as part of each chat 'bubble'. Chat users can send plain text messages, text links, and emojis. Chat messages have a character limit of 510 characters. Getting Started. IMPORTANT NOTE: Deploying this demo application in your AWS account will create and consume AWS resources, which will cost.

  1. Record audio and video from a video conference call
  2. Stream or broadcast a call to an RTMP server
  3. Provide interconnectivity for SIP-enabled systems

You’ll continue to use vidyo.io SDK to add group video chat to your web/mobile/desktop application — no changes required there. However, if you want to take advantage of recording, broadcast, or interoperability, you can incorporate the media bridge into your application. As the name suggests, the media bridge allows you to build a bridge from your vidyo.io video conference to other destinations.

Adding Docker to your application back end and running the media bridge is straightforward. Follow the steps in the documentation and you’ll be good to go. We also recently conducted a webinar on this topic; you can check out the recording below.

Step 1. Set Up AWS EC2 to Run the Media Bridge

Docker is in no way, shape, or form limited to AWS, and you can deploy it on any Linux, Windows, or other popular cloud server service. I picked AWS because it’s one of the most popular cloud services, it offers a free tier so you can try the setup at no cost, and it provides first-class Docker support via the EC2 Container Service (ECS), which can be easily scaled to meet your demands.

To get started, log in to your AWS Console, click the “EC2” link to go to the EC2 Console, and click the blue “Launch Instance” button.

From the list of Amazon machine instances, select the Amazon Linux machine, which is eligible for the free tier. You’ll see in the description that it already includes some useful command line tools and the Docker repository.

Next, for the instance type, choose t2.micro, which is also eligible for the free tier.

We won’t be changing anything in the default options for Instance Details, Storage, or Tags, so you can click “Next” until you get to the “Configure Security Group” section.

For our media bridge to connect to a video conference call and receive media packets we’ll enable all the ports for TCP and UDP. Let’s create a new security group, give it a name, and add all TCP and UDP traffic. Click the blue “Review and Launch” button.

From the “Review Instance Launch” page, click the blue “Launch” button. You’ll get a dialog box asking you to pick a key pair. Using this key pair we’ll be able to connect to our EC2 instance over SSH. Select “Create a new key pair” from the drop-down, give the key pair a name like vidyoMB-ec2-key-pair, and click “Download Key Pair.” Save this .pem on your drive, because once you close this dialog box you won’t be able to access it. After you download the key pair, the blue “Launch Instance” button will become active.

Click on the blue “View Instances” button to check the status of your instance.

If everything looks good, you’re now ready to connect to your cloud server to deploy the media bridge instance.

Step 2. Deploying the Media Bridge

To deploy the media bridge on our EC2 instance, we’ll first connect to our instance using SSH. Open a terminal and go to the folder where you saved your key pair. Set read-only access to the key pair file using chmod:

Note your instance’s public IP address from your AWS console (Public DVS IPv4 field in your instance description). Then SSH to it using the following command:

$ ssh -i my-ec2-key-pair.pem ec2-user@<EC2-INSTANCE-PUBLIC-IP-ADDRESS>

If everything goes well you’ll see something like this:

Last login: Thu Jan 1119:00:212018 from 24.17.215.22
__ __ _ )
_ (/ Amazon Linux AMI
___ ___ ___
https://aws.amazon.com/amazon-linux-ami/2017.09-release-notes/
[ec2-user ~]$

To install Docker, run the following command:

[ec2-user]$ sudo yum update -y
[ec2-user]$ sudo yum install -y docker
[ec2-user]$ sudo service docker start

Once Docker is installed, you can pull the latest media bridge version and run a container with the following commands:

[ec2-user]$ sudo docker pull vidyo/mediabridge
[ec2-user]$ sudo docker run -d --name my_mediabridge vidyo/mediabridge

And there you go. You now have a media bridge instance ready to connect to your video call!

Step 3. Create a Simple Web Service

Now you have the media bridge instance deployed and you’re almost ready to connect to a call.

Before it can connect it needs three things:

  1. A valid token
  2. The name of the resourceId to connect to
  3. A destination, whether it is going to record, stream, or connect to a SIP gateway

All of this information, along with some other parameters, needs to be set in the config file of the media bridge and saved under /opt/vidyo within the container. You can find sample config files at https://developer.vidyo.io/documentation/4-1-19-7/getting-started.

In our case we’re going to set our media bridge to record a video conference. Instead of statically setting the parameters in the config file, we’re going to create a web service that will have a method called “record” that will take in the conference room name to join. We’re going to create a web service using python and web.py. Note that we need to install the dependencies inside the my_mediabridge container that we created in the previous step. To do that you can run bash to get to the container shell:

[ec2-user]$ sudo docker exec -i -t my_mediabridge bash

Now that you’re in your container, install web-py to this Docker image:

$ apt-get update
$ apt-get install -y python python-webpy

Within the container, create a new python script:

App.py:

#!/usr/bin/python
import web,sys
importos
importurllib2
importbase64
importbinascii
fromdatetimeimportdatetime
importcalendar,time
import hashlib
importhmac
importsys
importrandom
urls =(
'/record/(.*)','record'
)
app = web.application(urls,globals())
# Developer specific parameters copy it from your vidyo.io dashboard
# https://developer.vidyo.io/dashboard
VIDYO_IO_DEVELOPER_KEY = XXXXX
VIDYO_IO_APPLICATION_ID = YYYYY
TOKEN_VALID_DURATION_SECS =600
EPOCH_SECONDS =62167219200
def getVidyoIOToken():
type='provision'
key = VIDYO_IO_DEVELOPER_KEY
jid ='[email protected]' + VIDYO_IO_APPLICATION_ID
expires = TOKEN_VALID_DURATION_SECS + EPOCH_SECONDS + int(time.mktime(datetime.now().timetuple()))
vCard ='
def to_bytes(o):
returnstr(o).encode('utf-8')
sep = b'0'# Separator is a NULL character
body = to_bytes(type) + sep + to_bytes(jid) + sep + to_bytes(expires) + sep + to_bytes(vCard)
mac =hmac.new(bytearray(key,'utf8'), msg=body, digestmod=hashlib.sha384).digest()
## Combine the body with the hex version of the mac
serialized = body + sep + binascii.hexlify(mac)
b64 =base64.b64encode(serialized)
token= b64.encode('utf8')
encoded_token =urllib2.quote(token)
return encoded_token;
class record:
def GET(self, roomId):
encoded_token = getVidyoIOToken()
os.system('cp /home/webapp/config /opt/vidyo')
withopen('/opt/vidyo/config','a')as myfile:
myfile.write('resourceId='%s'n' % (roomId))
myfile.write('token='%s'n' % (encoded_token))
os.system('/opt/vidyo/connect &')
return roomId
if __name__ '__main__' :
app = web.application(urls,globals())
app.run()

Create a sample config file in the webapp folder:

Config:

##main video/audio settings
width=1280
height=720
fps=30
kbps=2000
layout=1
maxParticipants=8
overlay=1
videoCodec=H264
audioCodec=PCM
maxCallDuration=1000
#Presentation settings
presentationAllowed=1 #0- ignore presentations 1- replace main video with presentation
presWidth=1280
presHeight=720
presFps=5
presKbps=300
destination='flv:/opt/vidyo/recording.flv'
log=error
#vidyo.io connection info
host='prod.vidyo.io'

Note that we did not set the token or resourceId parameter in our template config file, since our web service will set it in the record method.

Now that we have everything set up in our container, let’s go back to the EC2 instance:

We’ll create a new image from the Docker container we just modified and name it “simple_record_ws”:

[ec2-user ~]$ sudo docker commit my_mediabridge simple_record_ws:0.1

You can confirm that the image was created by calling Docker images:

[ec2-user ~]$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
Simple_record_ws 0.1 6a9cbe31b862 2 minutes ago 5.54GB
vidyo/mediabridge latest afa973ff5c05 2 months ago 5.51GB

Finally, start your web service by calling:

[ec2-user ~]$ sudo docker run -d -p 80:5000--name my_vidyombws simple_record_ws:0.1 python /home/webapp/app.py5000

The -p 80:5000 flag in the run command above tells Docker to link port 5000 on the Docker container to port 80 on the EC instance.

Step 4. Testing Your New Web App

We have now successfully deployed the media bridge on the cloud, and it’s just waiting for someone to call it with the record command so that it can start recording a video conference. Let’s test it out.

Go to https://developer.vidyo.io/demo and launch an instance. Note that you should be signed in to the same account you used to copy the developer key and app Id values.

By default the demo sample on the demo page joins the room named demoRoom. Try signing in from different machines so you have multiple participants on the call.

Aws video chat

Copy your EC2 instance public IP address, open a browser, and enter the following:

http://EC2-INSTANCE-PUBLIC-IP-ADDRESS/record/demoRoom

A page will open with the text “demoRoom,” but, more importantly, you’ll notice on your video conference a message that Recorder/Streamer has joined.

Your recorder is working. Once every participant leaves the call, the recorder will automatically stop. You can copy the recording:

[ec2-user ~]$ sudo docker cp my_mediabridge:/opt/vidyo/recording.flv

Aws Video Chat Free

Open another terminal in the same folder where your key pair is and copy the recording from your EC2 instance to your local computer using the following command:

$ scp -i vidyoMB-ec2-keypair.pem ec2-user@EC2-INSTANCE-PUBLIC-IP:~/recording.flv .
Chat

Aws Video Chat Systems

There you go. You’ve built a simple web service that will record your vidyo.io conferences on command. One of the cool things about using the EC2 service from Amazon is that you can easily scale your service to deploy multiple containers on demand to record or stream a number of conferences in parallel. In our example we deployed one container to record one conference, but you can use Amazon’s cluster service ECS Console to manage your containers.

Aws Video Chat Software

To learn more about vidyo.io, visit our developer website.

Aws Video Chat App

If you have any questions, comments, or suggestions on topics we should cover on our how-to blogs, feel free to reach out to me at [email protected]