Embed Video Call on Website & Application
Tags: javascript, webrtc, showdev, webdev
Published: 2021-10-05 12:49:59

####Embed and Add video call and chat feature can be easily integrated into any website and application with just a few lines of code in just 5 steps and just 5 minutes. enabling 5000 users to video chat in a web and app.

**UPDATE 1 (31st Oct 2021)**: Updated article with pin screen and layouts configuration

**UPDATE 2 (15th Dec 2021)**: Updated article with whiteboard configuration

Check official Guide: [Video SDK Prebuilt SDK](https://docs.videosdk.live/docs/guide/prebuilt-video-and-audio-calling/getting-started) for more information.

We will also implement a demo and use Video SDK to make a video call using [rtc-js-prebuilt](https://www.npmjs.com/package/@videosdk.live/rtc-js-prebuilt)


Introduction <a href="introduction"></a>
---
Video calling is becoming norm for everyone. According to Cisco, 87% of the workforce says they feel more connected to each other when using video.

###What is video call embed?
[Video SDK](https://videosdk.live) is provide embed video call in prebuilt SDK adding video calls on your website and application with just a few lines of code and nothing could be simpler than this best video chat experience with just 10 lines of code. 

Embed video calling enables the opportunity to integrate real-time communication SDK without writing explicit code. It supports all modern javascript frameworks such as React JS, Vue, and Angular including Vanilla JS.

- 10,000 minutes free each month
- Completely Low code and serverless.
- Video API with real-time audio, video and data streams
- 5,000+ participants support
- Chat support with rich media.
- Screen sharing with HD and Full HD.
- Play realtime video in meeting
- Connect it with social media such as Facebook, Youtube etc (RTMP out support).
- Intelligent speaker switch
- Record your meetings on cloud
- Inbuilt support of whiteboard, poll and Q & A.
- Customize UI as per your needs.

Let's begin with the prebuilt sdk setup. Read all the steps carefully before installing one in your application.

It supports all the modern frameworks such as plain JavaScript, React JS, Vue JS and Angular JS.


#Video Calling Embed in Any Website and App

##1: First of all, Register yourself to [app.videosdk.live](https://app.videosdk.live/)

![Register yourself to Video SDK](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pg7m27d2gd2pyqxwhmn9.png)

##2: Generate an API key and Secret 

![Generate an API key and Secret](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8o6czz1o4y9c1vukiz10.png)

Implementation
---
##3: Import the script in your html page
```html
 <script src="https://sdk.videosdk.live/rtc-js-prebuilt/0.3.21/rtc-js-prebuilt.js"></script>
```
Note: You can also use official Npm package: [rtc-js-prebuilt](https://www.npmjs.com/package/@videosdk.live/rtc-js-prebuilt)

##4: Embed Video Calling javascript prebuilt code to your HTML page
```js
<script>
  var script = document.createElement("script");
  script.type = "text/javascript";

  script.addEventListener("load", function (event) {
    const meeting = new VideoSDKMeeting();

    const config = {
      name: "John Doe",
      apiKey: "<API KEY>", // generated in Setup
      meetingId: "milkyway", // enter your meeting id

      containerId: null,
      redirectOnLeave: "https://www.videosdk.live/",

      micEnabled: true,
      webcamEnabled: true,
      participantCanToggleSelfWebcam: true,
      participantCanToggleSelfMic: true,

      chatEnabled: true,
      screenShareEnabled: true,
      pollEnabled: true,
      whiteBoardEnabled: true,
      raiseHandEnabled: true,

      recordingEnabled: true,
      recordingWebhookUrl: "https://www.videosdk.live/callback",
      participantCanToggleRecording: true,

      brandingEnabled: true,
      brandLogoURL: "https://picsum.photos/200",
      brandName: "Awesome startup",
      poweredBy: true,

      participantCanLeave: true, // if false, leave button won't be visible

      // Live stream meeting to youtube
      livestream: {
        autoStart: true,
        outputs: [
          // {
          //   url: "rtmp://x.rtmp.youtube.com/live2",
          //   streamKey: "<STREAM KEY FROM YOUTUBE>",
          // },
        ],
      },

      whiteboardEnabled: true,

      permissions: {
        askToJoin: false, // Ask joined participants for entry in meeting
        toggleParticipantMic: true, // Can toggle other participant's mic
        toggleParticipantWebcam: true, // Can toggle other participant's webcam
        drawOnWhiteboard: true,
        toggleWhiteboard: true,

      },

      joinScreen: {
        visible: true, // Show the join screen ?
        title: "Daily scrum", // Meeting title
        meetingUrl: window.location.href, // Meeting joining url
      },
    };

    meeting.init(config);
  });

  script.src =
    "https://sdk.videosdk.live/rtc-js-prebuilt/0.1.21/rtc-js-prebuilt.js";
  document.getElementsByTagName("head")[0].appendChild(script);
</script>
```

##5: Insert API key in your code to run it

```js
apiKey: "<API-KEY>"
```
**Note**: To restrict use of your API key on other domains, you can add domain URL which will block use of your API key in other domains. 

Run the demo <a href="run-the-demo"></a>
---
To run the demo, you have to use any local server. Best could be Xampp or IIS as per your environment. We are going to use live-server package to run simple http server.

```js
$ npm install -g live-server
$ live-server --port=8000
```
and open [http://localhost:8000](http://localhost:8000) in your web browser.

![Video Call Example](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j5xt1yhcxvxotiu5d1o8.gif)

Record the meeting <a href="record-the-meeting"></a>
---
To record the meeting, You have to first enable recording flag in the configuration. 
- recordingEnabled: set `true` or `false` to enable and disable online recordings
- recordingWebhookUrl: Callback url, generally helps to store recording details on your database.

```js
 recordingEnabled: true,
 recordingWebhookUrl: "https://www.videosdk.live/callback",
```
After enabling recording option, you'll be able to see recording button on the screen. Click on it to start and stop recording

![Recording button](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rc4aj1iaajvai6bf43g4.png)

Enable WhiteBoard <a href="go-live-on-social-media"></a>
--
To enable whiteboard, you have to configure whiteboard flag and permissions.
- whiteboardEnabled: if `true`, it will enable whiteboard
- permission: you can also set permission of who can `drawOnWhiteboard` and `toggleWhiteboard ` by using boolean value

```js
whiteboardEnabled: true,
  permissions: {
    drawOnWhiteboard: true,
    toggleWhiteboard: true,
  },
```

![Video SDK whiteboard example](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hcgcdhatl78dd9wtwhik.png)


Go live on social media <a href="go-live-on-social-media"></a>
---
To enable live streaming, you have to configure list of stream key and URL. We only support RTMP protocol enabled broadcasting. 
- autoStart: If `true`, it will trigger re-streaming automatically when meeting will start. 

```js
livestream: {
    autoStart: true,
    outputs: [
        // {
        //   url: "rtmp://x.rtmp.youtube.com/live2",
        //   streamKey: "<STREAM KEY FROM YOUTUBE>",
        // },
    ],
}
```

Pin Screen <a href="pin-screen"></a>
---
To enable pin screen, you have to configure `pin` property. It includes two major properties:
- allowed: If it is true then that participant can pin or unpin other participants in the meeting, by default it is set to false.
- layout: It should be a any of GRID or SPOTLIGHT or SIDEBAR, by default it is set to GRID.

![Example of pin layouts](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e2j2zcrlcg9jqt6p8go0.png)

####Better understanding of Layouts

{% collapsible GRID %} 

- GRID: This layout is default layout if no participants are pinned, it will look same as a normal meeting grid layout, when any participant is pinned that participant will be moved on top of the main screen grid above all non pinned participants
{% endcollapsible %}

{% collapsible SIDEBAR %} 
- SIDEBAR: This layout will have one main screen view and other sidebar grid layout. Only pinned participant will be visible in this layout, all unpinned participants will not be visible in this layout. If more than one participant is pinned then the first participant who was pinned will appear in main screen layout and all other remaining pinned participants will be visible in sidebar.
{% endcollapsible %}

{% collapsible SPOTLIGHT %} 
- SPOTLIGHT: This layout will only contain main screen layout, multiple pinned participants will be visible in main screen view. Same as SIDEBAR layout only pinned participants will be visible in main screen.
{% endcollapsible %}

```js
pin: {
 allowed: true,
 layout: "SPOTLIGHT",
}
```
 


Conclusion <a href="conclusion"></a>
---
In this article, I have explained Video Chat in JavaScript. You can modify couple of parameters in code according to your need. This was the small introduction to Video SDK Prebuilt SDK.

Here is video version of the same. 

{% youtube b3IzLHeDvyE %}

I hope this blog helped you understand **Video Calling** of Video SDK. For more information visit [official documentation of Video SDK](https://docs.videosdk.live/). 

P.S. Find official example of [Video SDK No Code Prebuilt App](https://github.com/videosdk-live/videosdk-rtc-js-prebuilt-embedded-example)


###{% collapsible Official Github %} 

{% github https://github.com/videosdk-live/videosdk-rtc-js-prebuilt-embedded-example %} 

{% endcollapsible %}