Skip to content

Commit

Permalink
Merge pull request dyte-io#359 from dyte-in/docs/oss
Browse files Browse the repository at this point in the history
docs: community packages
  • Loading branch information
madhugb authored Aug 28, 2023
2 parents 76cdb4c + 70dd367 commit 6233ac4
Show file tree
Hide file tree
Showing 7 changed files with 244 additions and 45 deletions.
5 changes: 5 additions & 0 deletions docs/community-packages/device-emulator/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"position": 1,
"label": "Device Emulator",
"collapsible": false
}
161 changes: 161 additions & 0 deletions docs/community-packages/device-emulator/intro.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
---
slug: /device-emulator
sidebar_position: 1
keywords: [opensource]
---

# Introduction

For a product, integration tests are one of the crucial part that improves quality & stability. For a WebRTC based solution like Dyte, having integration tests that can test multi-user call with Audio/Video on is necessary.

For an end user, sharing a camera & mic is easy. For this, browsers expose APIs such as enumerateDevices & getUserMedia on MediaDevices interface, on which user interfaces can be built easily.

Access to camera & mic prompts the users to allow permissions to do so. This works great as long as an end-user is using the product and actively allowing permissions and selecting devices, However this makes it impossible to write integration tests because for integration tests there is no active user and you need to somehow allow permissions programmatically which at the moment of writing this README is not reliably supported in modern tools like Playwright.

Even if we can somehow allow permissions, The next set of questions would be: What would the video & audio feed look like? Can we customize the feed? Can we use the feed to detect delays between a video feed producer and consumer? How do we test multiple devices? How do we test media ejection on the fly? How do we test addition of a new device?

Dyte's Device Emulator is a solution that answers all these questions and provides a easier way to mimic, add, remove devices & their feed.

## Installation

<Tabs groupId="cdn-npm">
<TabItem value="cdn" label="CDN" default>

To set up device-emulator add the following script tags inside
the `<head />` tag.

```html
<script>
window.addEventListener('dyte.deviceEmulatorLoaded', () => {
// use device emulator methods here...
});
</script>
<script src="https://cdn.jsdelivr.net/npm/@dytesdk/device-emulator/dist/index.iife.js"></script>
```

</TabItem>
<TabItem value="npm" label="npm">

```bash
npm install @dytesdk/device-emulator
```

use the package like below

```js
import '@dytesdk/device-emulator';

// use the device emulator methods
```

</TabItem>

<TabItem value="yarn" label="yarn">

```bash
yarn add @dytesdk/device-emulator
```

use the package like below

```js
import '@dytesdk/device-emulator';

// use the device emulator methods
```

</TabItem>
</Tabs>

## API reference

### Add a virtual device

```js {1}
const virtualDeviceID = navigator.mediaDevices.addEmulatedDevice('videoinput');

// get a media track from the virtual device
navigator.mediaDevices
.getUserMedia({
video: {
deviceId: {
exact: virtualDeviceID,
},
},
})
.then((mediaStream) => {
const video = document.querySelector('video');
video.srcObject = mediaStream;
video.onloadedmetadata = () => {
video.play();
};
})
.catch((err) => {
// always check for errors at the end.
console.error(`${err.name}: ${err.message}`);
});
```

### Remove virtual device

```js
navigator.mediaDevices.removeEmulatedDevice(deviceId);
```

### Stop the device

You can use `brickDevice` method to test scenarios where the devices stops working abruptly.

```js {4}
const virtualDeviceID = navigator.mediaDevices.addEmulatedDevice('videoinput');

// Stop the device from working
navigator.mediaDevices.brickDevice(virtualDeviceID, true);

navigator.mediaDevices
.getUserMedia({
video: {
deviceId: {
exact: virtualDeviceID,
},
},
})
.then((mediaStream) => {
// This will not work
const video = document.querySelector('video');
video.srcObject = mediaStream;
video.onloadedmetadata = () => {
video.play();
};
})
.catch((err) => {
// catch `NotReadableError` thrown from the device
console.error(`${err.name}: ${err.message}`);
});
```

Executing the `brickDevice` after getting the tracks will stop the active tracks.

### Resume the device

Use `brickDevice` method to make the device work normally

```js
navigator.mediaDevices.unbrickDevice(deviceId, false);
```

### Silence the tracks

Generate tracks that are silent

```js
navigator.mediaDevices.silenceDevice(deviceId, true);
```

### Unmute the tracks from the device

Remove the silence check on the device

```js
navigator.mediaDevices.silenceDevice(deviceId, false);
```
30 changes: 30 additions & 0 deletions docs/community-packages/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
slug: /
sidebar_position: 1
sidebar_class_name: community_packages_sidebar_index
---

# Community packages

At Dyte, we believe in empowering developers to create innovative solutions that go beyond our own use cases. By opening access to some of our resources, we aim to foster creativity, collaboration, and technological advancement across diverse domains.

We are excited to see the new applications and platforms that you will build using our technology.

<CardSection id="packages" title="Packages">
<Card
title="Device Emulator"
to="/community-packages/device-emulator"
description="Simulate media devices within your browser, by providing a seamless testing environment and enabling more efficient development and debugging."
tag={{
label: 'OSS',
color: '#2160FD',
description: 'Opensource Software',
}}
>
<span class="community-tag">Opensource</span>
</Card>
<Card
title="Troubleshooter (Coming soon)"
description="Our diagnostic tool designed to analyze, identify, and resolve real-time communication issues, enhancing connection stability and performance."
/>
</CardSection>
7 changes: 7 additions & 0 deletions docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ const docs = [
},
},

// Community packages
{
id: 'community-packages',
path: 'docs/community-packages',
routeBasePath: '/community-packages',
},

// Web UI Kits
{
id: 'ui-kit',
Expand Down
25 changes: 21 additions & 4 deletions src/components/CardComponents.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { ReactNode } from 'react';
import React, { ReactNode, PropsWithChildren } from 'react';
import { paramCase } from 'param-case';
import Link from '@docusaurus/Link';
import clsx from 'clsx';
Expand All @@ -17,7 +17,7 @@ export function CardSection({
children: ReactNode;
description?: ReactNode;
hasSubSections?: boolean;
HeadingTag?: any;
HeadingTag?: keyof JSX.IntrinsicElements;
className?: string;
}) {
return (
Expand All @@ -41,13 +41,19 @@ export function Card({
title,
description,
to,
}: {
tag,
}: PropsWithChildren<{
id?: string;
icon?: JSX.Element;
title: string;
description?: string;
to: string;
}) {
tag?: {
label: string;
color: string;
description: string;
};
}>) {
return (
<Link to={to} className="homepage-card">
{icon && <div className="icon">{icon}</div>}
Expand All @@ -57,6 +63,17 @@ export function Card({
</div>
{description && <div className="description">{description}</div>}
</div>
{tag && (
<div className="tag absolute right-0 top-0 h-16 w-16">
<span
className="absolute right-[-28px] top-[-2px] w-[80px] rotate-45 transform bg-gray-600 py-1 text-center font-semibold text-white"
style={{ backgroundColor: tag.color }}
title={tag.description}
>
{tag.label}
</span>
</div>
)}
</Link>
);
}
16 changes: 14 additions & 2 deletions src/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,8 @@ img[src$='#terminal'] {
transition-property: background-color, color;

border-radius: 8px;
position: relative;
overflow: hidden;
}

.homepage-card.row {
Expand All @@ -932,8 +934,6 @@ img[src$='#terminal'] {
width: 48px;
height: 48px;
@apply mx-1;
/* background-color: #262626;
border-radius: 8px; */
}

.card-content {
Expand All @@ -954,6 +954,14 @@ img[src$='#terminal'] {
line-height: 1.5;
}

.homepage-card .tag {
font-size: 12px;
padding: 0.25rem 0.5rem;
border-radius: 4px;
font-weight: 500;
position: absolute;
}

details {
font-size: 14px;
font-weight: 500;
Expand Down Expand Up @@ -1134,6 +1142,10 @@ article ul {
@apply -ml-2;
}

.community_packages_sidebar_index {
@apply -ml-2;
}

.video_sidebar_header > div > a::before {
@apply mt-1 mr-2;
content: url('data:image/svg+xml,<svg fill="currentColor" class="sidebar-icon-header ___12fm75w f1w7gpdv fez10in fg4l7m0" aria-hidden="true" width="1em" height="1em" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="M4.5 4A2.5 2.5 0 0 0 2 6.5v7A2.5 2.5 0 0 0 4.5 16h7a2.5 2.5 0 0 0 2.5-2.5v-1l2.4 1.8a1 1 0 0 0 1.6-.8v-7a1 1 0 0 0-1.6-.8L14 7.5v-1A2.5 2.5 0 0 0 11.5 4h-7ZM14 8.75l3-2.25v7l-3-2.25v-2.5ZM13 6.5v7c0 .83-.67 1.5-1.5 1.5h-7A1.5 1.5 0 0 1 3 13.5v-7C3 5.67 3.67 5 4.5 5h7c.83 0 1.5.67 1.5 1.5Z" fill="currentColor"></path></svg>');
Expand Down
45 changes: 6 additions & 39 deletions src/snippets/resources.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,6 @@
Developer Portal
</a>
</li>
<!-- <li>
<a
href="https://github.com/dyte-samples"
class="flex items-center gap-2 text-inherit"
target="_blank"
>
<img src="/static/landing-page/sdk-icons/resources/apps.png" />
Sample Apps
</a>
</li> -->
<li>
<a href="/faq" class="flex items-center gap-2 text-inherit">
<img
Expand Down Expand Up @@ -72,37 +62,14 @@
Release Notes
</a>
</li>
</ul>

<!-- <div class="hr-line"></div> -->

<!-- <h2 class="text-sm text-primary dark:text-primary-100">
Getting started with Dyte
</h2>
<ul
class="flex list-none flex-col gap-2 pl-0 text-gray-700 dark:text-zinc-200"
>
<li>
<a href="#" class="flex items-center gap-2 text-inherit">
<img src="/static/landing-page/sdk-icons/resources/video-library.png" />
Videos
</a>
</li>
<li>
<a href="#" class="flex items-center gap-2 text-inherit">
<img src="/static/landing-page/sdk-icons/resources/menu-book.png" />
Blog
</a>
</li>
<li>
<a href="/guides" class="flex items-center gap-2 text-inherit">
<img src="/static/landing-page/sdk-icons/resources/book.png" />
Guides
<a
href="/community-packages"
class="flex items-center gap-2 text-inherit"
>
<img src="/static/landing-page/sdk-icons/resources/book-open.svg" />
Community packages
</a>
</li>
</ul>
<a href="#" class="mt-4 font-semibold text-primary dark:text-primary-100">
View all resources &rarr;
</a> -->
</div>

0 comments on commit 6233ac4

Please sign in to comment.